Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Gradient background - First drawing problem

  1. #1
    Intern Newbie
    Join Date
    Oct 2010
    Posts
    47

    Gradient background - First drawing problem

    Hello,

    I used this post to do a gradient background :
    http://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.

    Code :
    glClear(/*GL_COLOR_BUFFER_BIT |*/ GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    glMatrixMode(GL_PROJECTION );
    glLoadIdentity();
    [COLOR=#ff0000]glOrtho(0,1,0,1,-1,1);[/COLOR]
     
    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
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	GradientBack.jpg 
Views:	33 
Size:	8.7 KB 
ID:	723  

  2. #2
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    302
    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...)

  3. #3
    Intern Newbie
    Join Date
    Oct 2010
    Posts
    47
    You have found the problem !
    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 ?

  4. #4
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    302
    Quote Originally Posted by AllForum View Post
    Where do you see that it is in ancient OpenGL ?
    Immediate mode.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •