Generally , I want "Draw a viewport inside a viewport".
And My idear is something like below:
------------------------------------------------------
float ar = (float) width / (float) height;
glGetIntegerv(GL_SCISSOR_BOX,para);
glGetIntegerv(GL_VIEWPORT,para1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glViewport(xof,yof,width,height);
glScissor(xof,yof,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
glClearColor(0.0f,0.0f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,1.0f,1.0f);
glTranslated(0.0f,0.0f,-6.0f);
drawsolidcube(1);
glViewport(para1[0],para1[1],para1[2],para1[3]);
glScissor(para[0],para[1],para[2],para[3]);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
-----------------------------------------------------------------
With same viewport width,height drawsolidcube() translation and also glFrustum params .
It works when I test it.
http://i486.photobucket.com/albums/rr230/HuaMuLanChina/test-1.png
But when I nest it into blender(which did all the UI drawings with opengl),
only black rectangle viewport without box(did by drawsolidcube function).
http://i486.photobucket.com/albums/rr230/HuaMuLanChina/failed.jpg
I want to known where the possible problems lay?
Thanx in advance.
[Edited by - HuaMuLan on December 5, 2010 12:46:55 PM]
Draw a viewport inside a viewport
I do it like this:
- Set viewport1 to some size and location
- Save it's global location and size in variables
- Draw stuff that belongs to viewport1
- Before setting viewport2 check if it's size and location lie inside viewport1. If it doesn't crop it accordingly (just recalculate x,y,w,h)
- Set viewport2
- Draw stuff that belongs to viewport2
- Set viewport1 to some size and location
- Save it's global location and size in variables
- Draw stuff that belongs to viewport1
- Before setting viewport2 check if it's size and location lie inside viewport1. If it doesn't crop it accordingly (just recalculate x,y,w,h)
- Set viewport2
- Draw stuff that belongs to viewport2
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement