PDA

View Full Version : A stupid problem on rendering..



abominable
09-14-2010, 01:05 PM
I create a 512x512 window and try to draw a simple square using the following function ::


void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.0, 0.0, 0.0);
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0f); // glPointSize(1);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(100.0, 0.0, 0.0);
glVertex3f(100.0, 100.0, 0.0);
glVertex3f(0.0, 100.0, 0.0);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
And I expect to get a square of 100x100 in the left down corner of my window. But all I end up is a red square covering the upper right 256x256 corner of my window.

And I can't figure out what my fault is !!

Also this is my init function, in case these calls might cause the problem.

void init(void)
{
// cout << "[init :: Running]" << endl;
// We enable the DEPTH BUFFER so we get our drawings to the right position in 3D space.
glEnable(GL_DEPTH_TEST);
glClearColor(grey, grey, grey, white); // Sets the window Color to the one chosen.
glShadeModel(GL_FLAT);
glMatrixMode(GL_PROJECTION); //
glLoadIdentity(); // Loads the Identity Matrix
glOrtho(0, width, 0, height, 0.0, -depth); // Sets our viewing to Orthographic.
}


If someone could give any idea, would be really gratefull !!

mhagain
09-14-2010, 01:46 PM
Your matrix mode is still GL_PROJECTION when drawing, so first thing you need to do is put a glMatrixMode(GL_MODELVIEW) and glLoadIdentity () after your glOrtho call.

abominable
09-14-2010, 01:50 PM
Thanx for your reply.

I tried it, but no change on the results.

mhagain
09-14-2010, 02:11 PM
What are the values of width and height that you pass into your glOrtho call?

abominable
09-14-2010, 03:55 PM
Thank you mhagain.

The width, height were set properly, but I had set the depth 0. When I changed it to 1, the problem was solved..