No image after rectf

The code works until The following code is inserted before the image code is run.

glColor3f (0.2, 0.2, 0.2);
glRectf(0.0f,0.00f, 120.0f, 60.0f);
glEnd();

All I get is the gray rectangle. If I comment out the above code all image code works fine.

What am I missing?

You are not supposed to have glEnd after glRect.
GlRect by definition is the following series of commands:
glBegin (gl_Polygon)
glVertex …
glVertex …
glVertex …
glVertex …
glEnd

I have the same results after removing the glEnd(). I found by accident that the

glColor3f (0.2, 0.2, 0.2);
glRectf(0.0f,0.00f, 120.0f, 60.0f);

is after the image code, everything is displayed correctly.
Why does it matter?

May be its in between a glBegin and glEnd already. Can’t say without seeing all the drawing code.

Somehow I missed that glRectf cannot be in between a glBegin and glEnd. I have not found an error yet. I will keep looking. I thought if such a condition existed I would get some kind of error. If there was any kind of error I thought I would notified somehow, compiler error or something. Do I have to look for errors?

It won’t be a compiler error but an OpenGL error. You have to call glGetError every frame. In fact in you keep calling that function continuously in a loop until it returns back no error. You might find it returns back invalid operation for such violations such as glRect between glBegin and glEnd.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.