PDA

View Full Version : Two viewport inside a unique glut window



remedios79
10-04-2002, 09:57 AM
Hi,

I have a program that makes volume rendering and it has a unique glut
window with a glui subwindows for the controls.

I need to split the space I use to display my volume rendering into
two different viewport in order to display two different images.

I tryed different ways but none work.

I hope to make something thanks to glViewport function, but the only
thing I obtain this way is to disable one half window, and paint only
the active one.

To paint my picture I use functions like glVertex and I can't anyway
set an offset on their output (I think).

Someone can explain me if exist a way to manage a glut window as two
different viewport? I'm desperate!
And I can't split the program in two glut window and a glui one for
elegance reasons.

Thank you,
Remedios

tinak
10-04-2002, 11:41 AM
I've played with this myself and I have a sample Windows C project setup that uses it.

In my project I use the following sequence of commands to set up each view from the scene.

glScissor uses the physical size of the window.. eg 0-640 and 0-480.
glViewport uses the virtual size of the scene.. eg 0-800 and 0-600
The virtual coordinates are used from then on as required.
=========================================
glScissor(x0,y0,w,h);
glEnable(GL_SCISSOR_TEST);
glClearColor(r,g,b,a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(x0,y0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (OP == 'O') gluOrtho2D(x0,w,y0,h);
if (OP == 'P') gluPerspective(angle,w/h,n,f);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
============================================

I initialise a view with something like this:
ScreenWidth = 512 ScreenHeight = 256
Scissor Values 1 O : (000,sh-256,256,256);
2 P : (256,000,sw-256,sw);
Scene Values 1 O : (000,000,256,256);
2 P : (000,000,256,256);
This way I have 2 scenes. One Perspective and one ortho.

Whenever you resize the window/scene you need to call the viewport setup code again so best put it in a routine somewhere.

Then in my scene routine I do the following to utilise it.

glPushMatrix();
SetUpView(1);
DrawScene(1);
glPopMatrix();

glPushMatrix();
SetUpView(2);
DrawScene(2);
glPopMatrix();


My website is having problems at the moment so if you want to see my source code example of using viewports then email me and I'll send you the source code.

Tina

remedios79
10-04-2002, 01:57 PM
Thank you very much!

It works as I need and I can't believe I've lost the last three days 'cause I never used the glScissor function!

THANK YOU VERY MUCH! You saved me!

Remedios http://www.opengl.org/discussion_boards/ubb/smile.gif

tinak
10-04-2002, 02:29 PM
You're welcome... I just stumbled across it while investigating what the scissor command actually did... I have a whole include file now so that all my apps use this to set up my scenes... whether 1 or many...

Tina