Problems with GL_TRIANGLES

Started by
5 comments, last by Exilberliner 17 years, 4 months ago
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();
}
}
Advertisement
Are you sure your view frustum is big enough for you to see both triangles?
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.
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?

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.
slymrHopefully game is in progress.
Check out glFrustum, glOrtho, gluOrtho2D and gluPerspective. They all create projection matrices that maps a view volume onto your window.
As you're working in 2d you can either scale your triangles down or use

glScalef(float,float,float);

before defining the triangles;

This topic is closed to new replies.

Advertisement