4 opengl windows in one app

Started by
15 comments, last by TheMatrixXXX 22 years, 4 months ago
You can use the glutCreatSubWindow function

#define space 10 //space betwenn subwindow
Gluint window,first_subwindow,second_subwindow

window = glutCreateWindow("Main Window");
glutReshapeFunc(main_reshape);
glutDisplayFunc(main_display);
glutKeyboardFunc(main_keyboard);

first_subwindow= glutCreateSubWindow(window, space, space, 256, 256);
glutReshapeFunc(world_reshape);
glutDisplayFunc(world_display);
glutKeyboardFunc(main_keyboard);

second_subwindow = glutCreateSubWindow(window, space+256+space, space, 256, 256);
glutReshapeFunc(screen_reshape);
glutDisplayFunc(screen_display);
glutKeyboardFunc(main_keyboard);

I think the glutCreateSubWindow worls like this...
Advertisement
glViewport( x, y, width, height ) defines the area in the window where openGL does its rendering. So if you do something like

  glViewport( 0, 0, 100, 100 );doProjection( 100, 100 );renderWindowA();glViewport( 100, 0, 100, 100 );doProjection( 100, 100 );renderWindowB();glViewport( 0, 100, 200, 100 );doProjection( 200, 100 );renderWindowC();  


You will have 3 images rendered in your window according to the pattern:

AAABBB
AAABBB
AAABBB
CCCCCC
CCCCCC
CCCCCC
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
@fruny
thx i will try it

--=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--
Be careful to glFlush() and glutSwapBuffer() only once.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
@fruny:
what do you mean with doProjection?
i have my multiple viewport now but i don´t know how to draw on each one
how can i select them?
i know with the renderWindow but where i have to call these funcs ?
and can i use different views? (gluPerspective and 3xglOrtho)

thx
--=[[TheMatrixXXX]]=--

Edited by - TheMatrixXXX on November 19, 2001 1:31:32 PM
--=[[TheMatrixXXX]]=--
If you are doing a projection, it is usually dependent on the width to height ratio of your openGL viewport, no ? So, since I had different sized viewports, I called my doProjection function with the appropriate parameters.

And actually, you don't have several viewports, you have only one. GL will render where you tell it to. That's why I have several renderWindow() functions.

Follow this pattern:

    {  glViewport( whole window );  glClear();  glViewport( a corner );  glWhateverProjection( a corner );  Render( a corner );  glViewport( another corner );  glWhateverProjection( another corner );  Render( another corner );  .  .  .  glFlush();  glutSwapBuffers(); // May have to restore the viewport to the whole window though...}    


If you want separate input processing for each viewport, you are better off with glut sub-windows, as Major pointed out.

Or you can put 4 calls to glutCreateWindow(), register callbacks for each, save the window handle, and use glutSetWindow() in the right places (e.g. before calls to glutPostRedisplay() ).

(Sorry if I sound confused, I've had 3 hours of sleep over the pas 2 days. )

Edited by - Fruny on November 19, 2001 2:04:18 PM
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
thx i know what you mean

but i want to draw in orthographic views like in a level editor and view the world in a perspective view

i programmed it so far the only problem i have is that the app only show one of four windows and that is a problem of the handles someone told me.

thx
--=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--

This topic is closed to new replies.

Advertisement