Jump to content
  • Advertisement
Sign in to follow this  
mea36

Problems with GL_TRIANGLES

This topic is 4239 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
Advertisement
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
Check out glFrustum, glOrtho, gluOrtho2D and gluPerspective. They all create projection matrices that maps a view volume onto your window.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!