Sign in to follow this  

glViewport 2D and 3D renders not working

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this