PDA

View Full Version : Very new at openGL, can someone help me with this code and explain why it wont draw?



TraxRyu
02-21-2004, 05:08 AM
Sorry to do this to all of you but I cant understand why this code wont draw a simple triangle. If someone could explain what is going on I would really appreciate it.

Here is the code:

#include<glut.h>

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);

glBegin(GL_TRIANGLES);
glVertex3f(0.0,25.0,0.25);
glEnd();

glFlush();
}

void init()
{
glClearColor(0.0,0.0,0.0,0.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0,50.0,-50.0,50.0,-1.0,1.0);
}

int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(200,200);
glutCreateWindow("Program1");

init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

TraxRyu
02-21-2004, 05:39 AM
Hehe, never mind. I figured it out myself.
Sorry to post such a dumb question. Im sure you guys will be hearing alot from me. hehe

nexusone
02-21-2004, 06:09 PM
You need to supply each of the triangles corners.

glBegin(GL_TRIANGLES);
glVertex3f(0.0,25.0,0.25);
glVertex3f....
glVertex3f....
glEnd();