PDA

View Full Version : Gradient background - First drawing problem



AllForum
05-15-2012, 03:01 AM
Hello,

I used this post to do a gradient background :
http://www.opengl.org/discussion_boards/showthread.php/164345-Gradient-background?p=1161258 (http://ttp://www.opengl.org/discussion_boards/showthread.php/164345-Gradient-background?p=1161258)
The principle is to draw a background quad with glOrtho and then to draw the model in the perspective view.

Here is the code ; I added it in my existing ClearBackground function ; it is called before every drawing.


glClear(/*GL_COLOR_BUFFER_BIT |*/ GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION );
glLoadIdentity();
glOrtho(0,1,0,1,-1,1);

glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDepthMask(GL_FALSE);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin(GL_QUADS);
glColor3f(85/255.0f, 85/255.0f, 255/255.0f);
...
glEnd();

glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);

Here is the problem (see the attached image) : after the first view drawing the background is a small quad in the bottom left. And after a refresh the background is on the full view.

It seems that some initializations are missing before the first drawing...
Do you have an idea of what causes this problem ?

Thanks for your help

menzel
05-15-2012, 04:13 AM
Maybe glViewport is called after your clear function?
Without more code it's hard to tell.

BTW: Is there any special reason why you program in ancient OpenGL? (I ask because I often have the impression that people who want to lern OpenGL google, find ancient tutorials, try to learn that, wonder why it's slow when they try there first big program, notice OpenGL is done differently nowadays and have to relearn everything again...)

AllForum
05-15-2012, 09:32 AM
You have found the problem ! :angel:
We have a function BeginGL() that calls our clear function. It is used at the beginning and the first time glviewport was not called before...

Many thanks for your help ! :)


> Is there any special reason why you program in ancient OpenGL
Where do you see that it is in ancient OpenGL ?

menzel
05-15-2012, 01:35 PM
Where do you see that it is in ancient OpenGL ?

Immediate mode.