Jump to content
  • Advertisement
Sign in to follow this  
zoret

problem with glViewport & glClear

This topic is 4133 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm desperately trying to render in a render target (fbo) with 2 different viewports Unfortunately when I clear the second viewport it clears everything ! so I've decided to modify the simple_framebuffer_object sample from the NVidia SDK (9.5) but I've exactly the same result !! Is there really a problem ? you can replace and test your SDK with this display function if you want :
void display()
{
    // render to the render target texture first
    glBindTexture(texTarget, 0);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
    {
        glPushAttrib(GL_VIEWPORT_BIT); 
        glViewport(0, 0, texWidth/2, texHeight/2);
		glScissor(0, 0, texWidth/2, texHeight/2);
        
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
        glTranslatef(0.0, 0.0, -1.5);
        glRotatef(teapot_rot, 0.0, 1.0, 0.0);

        glClearColor(18, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, renderProgram);
        glEnable(GL_FRAGMENT_PROGRAM_ARB);

        glColor3f(0.0, 1.0, 0.0);
        glutWireTeapot(0.5f);

        glPopMatrix();
        glPopAttrib();
	}
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

    // render to the render target texture again
    glBindTexture(texTarget, 0);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
    {
	    glPushAttrib(GL_VIEWPORT_BIT); 
        glViewport(texWidth/2, texHeight/2, texWidth/2, texHeight/2);
		glScissor(texWidth/2, texHeight/2, texWidth/2, texHeight/2);
        
        glClearColor(0, 0, 18, 0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
        glTranslatef(0.0, 0.0, -1.5);
        glRotatef(teapot_rot, 0.0, 1.0, 0.0);

        glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, renderProgram);
        glEnable(GL_FRAGMENT_PROGRAM_ARB);

        glColor3f(0.0, 1.0, 0.0);
        glutWireTeapot(0.5f);

        glPopMatrix();
        glPopAttrib();
	}
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

    // now render to the screen using the texture...
    glClearColor(0.2, 0.2, 0.2, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    object.apply_transform();

    // draw textured quad
    glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, textureProgram);
    glEnable(GL_FRAGMENT_PROGRAM_ARB);

    glBindTexture(texTarget, tex);
    glEnable(texTarget);  

    glColor3f(1.0, 1.0, 1.0);
    glBegin(GL_QUADS);
    {
        glTexCoord2f(0,         0);         glVertex2f(-1, -1);
        glTexCoord2f(maxCoordS, 0);         glVertex2f( 1, -1);
        glTexCoord2f(maxCoordS, maxCoordT); glVertex2f( 1,  1);
        glTexCoord2f(0,         maxCoordT); glVertex2f(-1,  1);
    }
    glEnd();

    glPopMatrix();
    glDisable(GL_FRAGMENT_PROGRAM_ARB);

    glutSwapBuffers();
}

Any ideas ? Thank you

Share this post


Link to post
Share on other sites
Advertisement
Follow a call to glViewport with a call to glScissor to set the scissor box to the same as the viewport and enable the scissor test. If you check the documentation for glClear you will see that the viewport does not affect the region cleared, but the scissor test does.

Share this post


Link to post
Share on other sites
arggh I've added a glScissor after the glViewport... just forgot to enable the Scissor test ! ;)

now I'm going to try it in my engine..

thank you very much

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!