Sign in to follow this  

Problems with GL_TRIANGLES

This topic is 4021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm new to OpenGL and I'm trying to write a program that displays a bunch of triangles. Right now I'm just testing some stuff and when I used GL_TRIANGLES it just displayed one triangle, but according to my code it should display 2. What am I doing wrong?
void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_TRIANGLES);
	  glVertex2f(0.0f, 0.0f);      // V0
	  glVertex2f(25.0f, 25.0f);    // V1
	  glVertex2f(50.0f, 0.0f);    // V2

	  glVertex2f(-50.0f, 0.0f);    // V3
	  glVertex2f(-75.0f, 50.0f);    // V4
	  glVertex2f(-25.0f, 0.0f);    // V5
	glEnd();
	glFlush();
}
int main(int argc, char** argv)
{
	glutInit(&argc,argv);
	glutCreateWindow("simple");
	glutDisplayFunc(display);
	glutMainLoop();
}
}

Share this post


Link to post
Share on other sites
If that code is all there is (except for the needed headers), then the second triangle is definitely outside the viewing volume. The default coordinate system ranges from -1 to 1 along all axes, and you specify coordinates way outside that range.

The reason you see the first triangle is because it happens to have one corner within the view volume. However, what you see of the triangle is just a tiny part of it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
The default coordinate system ranges from -1 to 1 along all axes, and you specify coordinates way outside that range.


How do I change the default coordinate system?

Share this post


Link to post
Share on other sites
Quote:
Original post by mea36
Quote:
Original post by Brother Bob
The default coordinate system ranges from -1 to 1 along all axes, and you specify coordinates way outside that range.


How do I change the default coordinate system?


You could change your coordinates. You could also use gltranslate into the screen. You also do gluMultMatrix or another command called either ( can't totally remember and I am betting its wrong ) gluSetPrespective or gluLookAt.

Share this post


Link to post
Share on other sites

This topic is 4021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this