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.

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 on other sites
Are you sure your view frustum is big enough for you to see both triangles?

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 on other sites
Quote:
 Original post by Brother BobThe 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 on other sites
Quote:
Original post by mea36
Quote:
 Original post by Brother BobThe 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 on other sites
Check out glFrustum, glOrtho, gluOrtho2D and gluPerspective. They all create projection matrices that maps a view volume onto your window.

Share on other sites
As you're working in 2d you can either scale your triangles down or use

glScalef(float,float,float);

before defining the triangles;

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.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628719
• Total Posts
2984385

• 25
• 11
• 10
• 15
• 14