Results 1 to 10 of 10

Thread: glViewport

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Location
    Espaņa
    Posts
    9

    glViewport

    Hi, I am trying to slpit the screen between two views. A 3D view for navigation, and a 2D one for indcators, gauges and such.
    I use glViewport to split the screen in half. The problem is that the 2D indcators don't get shown, unless I don't show the 3D enviroment.
    When I comment the 3D methods, the indcators show up fine, but when both are working, only the 3D eviroment gets displayed in its half of the screen.

    Is there anything I can do about that? Is there anything wrong with the code I'm using?

    Any help would be much appreciated. Thanks!

    Code :
    glViewport (0, 0, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)/2);
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 840.0, 0.0, 380.0);
     
    /* 2D methods */
     
    glViewport (0, GetSystemMetrics(SM_CYFULLSCREEN)/2, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)/2+100);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0,1.0,1,20000000);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    /* 3D methods */
     
    glFlush();
    glutSwapBuffers();
    glutTimerFunc(10,myTimer,1);

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2007
    Posts
    268

    Re: glViewport

    You don't use the scissor test. It means when you call glClear the entire window is cleared. You have to enable the scissor test on the relevant part of the window. glViewport just set a transformation but draw commands like glClear don't take glViewport into account:

    glScissor(left,bottom,width,height);
    glEnable(GL_SCISSOR_TEST);
    // draw commands here

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2009
    Location
    Espaņa
    Posts
    9

    Re: glViewport

    Thanks for your reply. I have replaced view port with scissor test. It looks better, view port stretched the 3D environment to fit half the screen, distorting the aspect ratio. Scissor test removed the lower half, which is what I wanted.
    But still the 2D methods don't get displayed. Now, however, they disappear after the first redisplay, instead of not being displayed at all.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654

    Re: glViewport

    Quote Originally Posted by A elalaily
    ...the 2D methods don't get displayed. Now, however, they disappear after the first redisplay, instead of not being displayed at all.
    Well, seems something your 3D scene is doing is keeping your 2D objs from rendering. Could be a number of things (the pipeline "tests" most likely), but before rendering your 2D objs, try:

    glDisable( GL_DEPTH_TEST );
    glDisable( GL_ALPHA_TEST );
    glDisable( GL_STENCIL_TEST );
    glDisable( GL_SCISSOR_TEST );

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2009
    Location
    Espaņa
    Posts
    9

    Re: glViewport

    Still nothing, 2D drawings show up, then disappear.

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2009
    Location
    Espaņa
    Posts
    9

    Re: glViewport

    Now the code is:
    Code :
    glScissor(0,0,GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)/2);
    glEnable(GL_SCISSOR_TEST);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_ALPHA_TEST);
    glDisable(GL_STENCIL_TEST);
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 840.0, 0.0, 380.0);
     
    /* 2D methods */
     
    glScissor(0, GetSystemMetrics(SM_CYFULLSCREEN)/2, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)/2+100);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0,1.0,1,20000000);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    /*3D methods */
     
    glDisable(GL_SCISSOR_TEST);
    glFlush();
    glutSwapBuffers();
    glutTimerFunc(10,myTimer,1);

    And the 2D drawings disappear after the first redisplay. Is there something wrong with the code?

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654

    Re: glViewport

    Quote Originally Posted by A elalaily
    And the 2D drawings disappear after the first redisplay. Is there something wrong with the code?
    Just to make sure, you do realize that scissor test affects the operation of glClear. Disable scissor test before you clear unless you do intend to do a viewport clear. And you didn't disable scissor test before drawing the 2D stuff, so that's a possible cause. Disable scissor test and see if your 2D stuff comes back.

    Also, try changing your first glClear(GL_COLOR_BUFFER_BIT) to glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT), and change
    your next glClear from glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) to glClear(GL_DEPTH_BUFFER_BIT).

    Scissor test and the glClears of the color buffer are the two most likely things I see that might be killing your 2D stuff.


  8. #8
    Junior Member Newbie
    Join Date
    Dec 2009
    Location
    Espaņa
    Posts
    9

    Re: glViewport

    Thanks for your help, but still nothing...

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654

    Re: glViewport

    Quote Originally Posted by A elalaily
    Thanks for your help, but still nothing...
    Post a little stand-alone test prog with the above and some really simple 2D/3D drawing so folks can compile and help you diagnose.

  10. #10
    Junior Member Newbie
    Join Date
    Dec 2009
    Location
    Espaņa
    Posts
    9

    Re: glViewport

    OK it worked, yes it was a problem with the glClear(). Thanks for all your help.

Similar Threads

  1. using glViewport
    By richman.feynard in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-31-2017, 04:07 AM
  2. glViewport
    By jamse101 in forum OpenGL: Windows
    Replies: 3
    Last Post: 08-06-2013, 03:33 AM
  3. glViewport
    By V-man in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 03-08-2005, 05:54 PM
  4. glViewport
    By gurkama in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-14-2005, 10:46 PM
  5. glViewport()
    By huizhang in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-24-2002, 12:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean