PDA

View Full Version : open gl help student



Donny T
03-15-2010, 04:00 PM
i need help can u me i got home work and the triangle isnt showing up

#include <GL/glut.h>

void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0); // Set display-window color to white.
glMatrixMode (GL_PROJECTION); // Set projection parameters.
gluOrtho2D (0.0, 200.0, 0.0, 200.0);
}

void lineSegment (void)
{
glClear (GL_COLOR_BUFFER_BIT); // Clear display window.
glColor3f (0.0, 0.85, 1.0); // Set line segment color to red.



glBegin(GL_QUADS);
glVertex2i(50, 150);
glVertex2i(50, 100);
glVertex2i(150, 100);
glVertex2i(150, 150);

glBegin(GL_QUADS);
glVertex2i(85, 160);
glVertex2i(85, 150);
glVertex2i(115, 150);
glVertex2i(115, 160);

glBegin(GL_TRIANGLES);
glVertex2i(75, 160);
glVertex2i(100, 180);
glVertex2i(125, 160);

glEnd();



glFlush ( ); // Process all OpenGL routines as quickly as possible.
}


void main (int argc, char** argv)
{
glutInit (&amp;argc, argv); // Initialize GLUT.
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Set display mode.
glutInitWindowPosition (100, 150); // Set top-left display-window position.
glutInitWindowSize (400, 400); // Set display-window width and height.
glutCreateWindow ("An Example OpenGL Program"); // Create display window.

init ( ); // Execute initialization procedure.
glutDisplayFunc (lineSegment); // Send graphics to display window.
glutMainLoop ( ); // Display everything and wait.
}

Ehsan Kamrani
03-15-2010, 05:26 PM
You must load the identity matrix after your projection matrix and you must switch to the modelview matrix after gluOrtho2D() :


void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0); // Set display-window color to white.
glMatrixMode (GL_PROJECTION); // Set projection parameters.
glLoadIdentity();
gluOrtho2D (0.0, 200.0, 0.0, 200.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}

Each glBegin() must have a glEnd() pair(). So :


glBegin(GL_QUADS);
glVertex2i(50, 150);
glVertex2i(50, 100);
glVertex2i(150, 100);
glVertex2i(150, 150);
glEnd();

glBegin(GL_QUADS);
glVertex2i(85, 160);
glVertex2i(85, 150);
glVertex2i(115, 150);
glVertex2i(115, 160);
glEnd();

glBegin(GL_TRIANGLES);
glVertex2i(75, 160);
glVertex2i(100, 180);
glVertex2i(125, 160);
glEnd();

Note that the second glBegin()/glEnd() pair is redundant, so you can remove them in your code:


glBegin(GL_QUADS);
glVertex2i(50, 150);
glVertex2i(50, 100);
glVertex2i(150, 100);
glVertex2i(150, 150); //the first quad
glVertex2i(85, 160);
glVertex2i(85, 150);
glVertex2i(115, 150);
glVertex2i(115, 160); //the second quad
glEnd();

beginnertom
03-15-2010, 07:56 PM
your codes are so empty.
i suggest you first download a code.
and then compile it.
at least .download a complete run code.
for servel days you are not alone.
beacause you need to learn how to compile

Ehsan Kamrani
03-15-2010, 09:59 PM
your codes are so empty.
i suggest you first download a code.
and then compile it.
at least .download a complete run code.
for servel days you are not alone.
beacause you need to learn how to compile

I guess he has compiled his own code , since he says nothing is shown...

beginnertom
03-15-2010, 10:21 PM
hello ehsan.

i agree with you.how about your engine&amp;#12290;
does it have some new updates?

Ehsan Kamrani
03-15-2010, 11:38 PM
hello ehsan.

i agree with you.how about your engine&amp;#12290;
does it have some new updates?


You could send me a private message. I don't like to change the subject of the topic.