Draw a viewport inside a viewport

Started by
2 comments, last by owl 13 years, 4 months ago
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]
Advertisement
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
[size="2"]I like the Walrus best.
Sorry for interruption.
Stupid problem but quite tricky.
I invoke the drawsolidcube(1) function without declaration "extern void drawsolidcube(float size);"
But I passed the checking of vs compiler , only with param size always 0.
So nothing can be seen. :P
What interruption? And what happened to the viewport inside a viewport thing?
[size="2"]I like the Walrus best.

This topic is closed to new replies.

Advertisement