Archived

This topic is now archived and is closed to further replies.

a2k

glut and multiple windows

Recommended Posts

is there a way to open up 2 windows (for multiplayer) of the same instance of the game, with different camera viewports using glut? a2k

Share this post


Link to post
Share on other sites
Hi a2k,

You''re not talkin'' ye-olde split-screen two-people-fighting-for-space-on-one-keyboard multiplayer, are you? Ah, that takes me back...

If that''s what you mean, then there is a couple of ways to show two different views within the same app.
The first is to create another window (using glutCreateWindow(..), is it?) for the second player''s view. Then, in your rendering procedure, just set the active window to player one''s (using glutSetWindow(int window)... or something similar), render the scene from their POV, then change the active window to player two''s, rinse, repeat.

Option 2 is to use one window, and just modify the viewport to draw to half the window for each player (using glViewport(..) )...
    
void Render()
{
// clear buffers if you want...

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


// Player one gets top half of the window

glViewport(0,0, windowWidth, windowHeight/2);


// set player point of view

glLoadIdentity();
glRotatef(...);
...
glTranslatef(...);


DrawScene();


// Player two gets bottom half of screen

glViewport(0, windowHeight/2, windowWidth, windowHeight/2);


// set POV...

glLoadIdentity();
...
...


DrawScene();


// flip to screen

glutSwapBuffers();
}


This is probably the better way to go, ''coz then you can still run it in fullscreen if you want.

Hope I didn''t totally misunderstand your question

-------------
squirrels are a remarkable source of protein...

Share this post


Link to post
Share on other sites
nope, that''s exactly what i mean. thanks. i want to be able to get "ye-olde split-screen two-people-fighting-for-space-on-one-keyboard multiplayer" working before i go onto full-blown network programming. i have to make sure player-player collision works without having to worry about packets and synchronization. thanks again.

a2k

Share this post


Link to post
Share on other sites
okay, i''m not out of this one yet. i don''t know how to render different camera angles to the 2 viewports. i know that i can obtain the integer identifier from the createwindow function, but how do i use this in my rendering function?

a2k

Share this post


Link to post
Share on other sites
Hmmm, which method are you doing? You don''t need to create another window if you''re doing the viewport method (which is the better of the two). All you have to do is take pretty much the guts out of one of your Reshape3D (or similarly named) callback functions, actually you could create two different ones (one for each viewport) to call in your render function, kinda like this:

    
/********************> ViewPort1() <*****/
void Reshape3D( int w, int h )
{
// Set the top one

glViewport( 0, 0, w, h/2 );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 65.0, ( GLfloat )w / ( GLfloat )h, 0.5, 100 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, 0.0 );

}

/********************> ViewPort1() <*****/
void ViewPort2( int w, int h )
{
// Set the bottom one

glViewport( 0, h/2, w, h );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 65.0, ( GLfloat )w / ( GLfloat )h, 0.5, 100 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, 0.0 );

}

/********************> RenderScene() <*****/

void RenderScene( void )
{
glClearColor( 0.23, 0.35, 0.78, 1.0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

ViewPort1( 640, 480 ); //Set this to whatever you want


// Translate to player 1''s camera position

// Render Scene


ViewPort2( 640, 480 );

// Translate to player 2''s camera position

// Render scene


}


Hope that explains it.

Morgan

Share this post


Link to post
Share on other sites
i''m actually doing it by the first method, because it''s only for testing purposes. if i can''t get it to work this way, i''ll end up doing it with the split-screen method, but i''d still like to know how to render to the two Windows windows.

a2k

Share this post


Link to post
Share on other sites
Okay, I''ll look it up quickly when I get home from work later this afternoon. It would still be cool to leave both local multiplayer and network multiplayer.

Morgan

Share this post


Link to post
Share on other sites
I knew I had a program lying around that demonstrated this. What you need to do is first create two windows:

            
glutInitWindowSize(320, 240);
glutInitWindowPosition(0, 20);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
Window1 = glutCreateWindow("Player 1");

glutInitWindowSize(320, 240);
glutInitWindowPosition(320, 20);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
Window2 = glutCreateWindow("Player 2");
[/source]

Then, when you want to draw each one, just do something like the following:

[source]
glutSetWindow(Window1);
// Do your rendering for player 1


glutSetWindow(Window2);
// Do your rendering for player 2



If that doesn't seem to work for you, then let me know.

Morgan

Hmmm, that's wierd, I guess you can't put two source things in the same post,

Edited by - Morgan on July 24, 2000 6:28:11 PM

Edited by - Morgan on July 24, 2000 6:29:11 PM

Share this post


Link to post
Share on other sites
thanks, morgan. it works great. i'm just wondering why neither of my OpenGL books even mention glutSetWindow(int). that's the function i needed to know. now, i linked both players to my keyboard input, and i'm having fun playing against myself =) right now, my game isn't demo-worthy, but in time, people will see it...

a2k

                
cout << "hello world" << endl;
[/source]

i'm wondering...

[source]
cout << "okay, you're right, it doesn't work" << endl;




Edited by - a2k on July 24, 2000 10:49:41 PM

Edited by - a2k on July 24, 2000 11:01:26 PM

Edited by - a2k on July 24, 2000 11:03:29 PM

Share this post


Link to post
Share on other sites