• Advertisement
Sign in to follow this  

glViewport 2D and 3D renders not working

This topic is 4978 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

Ok Ive been looking in the forum for problems like mine but couldnt find any solution so I decided to post, anyway here is the thing : I had 2 different windows, one that renders 2D images and the other 3D objects, everything was working fine but now I want to have the 2 renders in the same window, so I red about the good glViewport() and everything seems easy, but when I try to implement it, it doesnt work, actually I can see the "first" render and then it turns black not to ever come again, so I wonder if you guys can help me, this is the code : void renderScene() { glClear(GL_COLOR_BUFFER_BIT); // set 3D viewport glViewport(0, n2DWindowHeight, n3DWindowWidth, n3DWindowHeight); gluPerspective(45.0, n3DWindowWidth/n3DWindowHeight, 1.0, 1000.0); renderScene3D(); // set 2D viewport glViewport(0, 0, n2DWindowWidth, n2DWindowHeight); gluOrtho2D(0,n2DWindowWidth,0,n2DWindowHeight); renderScene2D(); glutSwapBuffers(); } void initGlut(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(10,80); glutInitWindowSize(nWindowWidth,nWindowHeight); glutCreateWindow("Viewer"); gluPerspective(45.0, n3DWindowWidth/n3DWindowHeight, 1.0, 1000.0); glutDisplayFunc(renderScene); glutIdleFunc(idleGLut); glutMainLoop(); } Thw window size is enough to contain both viewports, glClear and glutSwapBuffers are not called within render2D() and render3D(). And one more thing, if I comment the 3 lines concerning the 2D render the 3D render works perfectly, and viceversa. Thanks a lot for your help.

Share this post


Link to post
Share on other sites
Advertisement
Where's the glLoadIdentity calls?You must call them before gluPerspective and glOrtho2D.And what about the z-buffer.Do you have depth testing?When do you clear the z-buffer?

Share this post


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

  • Advertisement