PDA

View Full Version : rendering an animation on multiple windows



UtilMan
10-16-2002, 09:18 PM
I've got a problem in figuring out how to render the same objects in two seperate windows at the same time. Right now all it does is render in one window when the mouse pointer is over it. I've seen posts here talking about how you set the current window and then render it and then set the next window and render that...then you swap the buffers.

Well I've tried to do that but I'm not sure if I'm going the right way about it. Here's some code.

This is my renderScene function that draws the animation on the window thats selected with the mouse pointer over it.

void RenderScene(void)
{
int i, j;
int x, y ,z, r, g, b;
glLoadIdentity();
glTranslatef(70.0, 125.0, 0.0);
glPushMatrix();
glRotatef(rotate,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CW);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_COLOR_MATERIAL);

for (j = 0; j <= 1; j++)
{
if (j == 0){
currentSize = overAllSize;
PolySel = polygons;
}
else{
currentSize = overAllSize2;
PolySel = polygons2;
}

for (i = 0; i < currentSize; i++){

glBegin(GL_TRIANGLES);

glNormal3f(PolySel[i].norm.x,PolySel[i].norm.y,PolySel[i].norm.z);

x = PolySel[i].v1.x;
y = PolySel[i].v1.y;
z = PolySel[i].v1.z;
glVertex3f(x,y,z);
glColorMaterial(GL_FRONT, GL_SPECULAR);
glColor3f(PolySel[i].spec.r, PolySel[i].spec.g, PolySel[i].spec.b);
glColorMaterial(GL_FRONT, GL_AMBIENT);
glColor3f(PolySel[i].amb.r, PolySel[i].amb.g, PolySel[i].amb.b);


x = PolySel[i].v2.x;
y = PolySel[i].v2.y;
z = PolySel[i].v2.z;
glVertex3f(x,y,z);
glColorMaterial(GL_FRONT, GL_EMISSION);
glColor3f(PolySel[i].emm.r, PolySel[i].emm.g, PolySel[i].emm.b);
glColorMaterial(GL_FRONT, GL_SPECULAR);
glColor3f(PolySel[i].spec.r, PolySel[i].spec.g, PolySel[i].spec.b);


x = PolySel[i].v3.x;
y = PolySel[i].v3.y;
z = PolySel[i].v3.z;
glVertex3f(x,y,z);
glColorMaterial(GL_FRONT, GL_SPECULAR);
glColor3f(PolySel[i].spec.r, PolySel[i].spec.g, PolySel[i].spec.b);
glColorMaterial(GL_FRONT, GL_AMBIENT);
glColor3f(PolySel[i].amb.r, PolySel[i].amb.g, PolySel[i].amb.b);
glEnd();
}
glPopMatrix();
glTranslatef(130.0, -10.0, 0.0);
glRotatef(rotate,1.0,-1.0,0.0);
}
glutIdleFunc(RotateSceneClockwise);
glutSwapBuffers();// I KNOW IT SHOULD MOVE

}

This is my main function...

void main(int argc, char **argv)
{
int i, win1, win2;
fileLoader("file1.txt", "file2.txt");

for (i = 0; i <= 1; i++){
if (i == 0){
currentSize = overAllSize;
PolySel = polygons;
}
else{
currentSize = overAllSize2;
PolySel = polygons2;
}
addPolygonNormals();
}

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glEnable(GL_DEPTH_TEST);

glutInitWindowSize(500,500);
glutInitWindowPosition(100,0);
win1 = glutCreateWindow("WINDOW 1");
SetupScreen(0);
glutSetWindow(win1);

glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);


glutInitWindowPosition(610,0);
win2 = glutCreateWindow("WINDOW 2");
glutSetWindow(win2);
SetupScreen(1);
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);

// glutSwapBuffers(); <- Doesn't work

glutMainLoop();
}

UtilMan
10-16-2002, 10:49 PM
Anyone got a simple example showing how to syncronise multiple windows?

I just can't seem to get mine to work. As soon as I take out the swapbuffers() call and put it anywhere else it doesn't work (windows don't display anything at all) even if I put it just after the displayfunc call. All these posts I read state that you must only call swapbuffers when all the windows have glutpostredisplayed.

Someone please help!

UtilMan
10-16-2002, 11:35 PM
Ok can anyone use this simple animation (which compiles and runs) and make both the windows render at the same time. This should be easier than looking at my previous code.

If you can make this work then I'm sure I can figure it out.

#include <windows.h>
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

static GLfloat spin = 0.0;

void init(void){
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}

void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix();
glutSwapBuffers();
}

void spinDisplay(void){
spin = spin + 2.0;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}

void reshape(int w, int h){
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
init();
glutInitWindowSize (250, 250);
glutInitWindowPosition (100,100);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(spinDisplay);


glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
init();
glutInitWindowPosition(450, 100);
glutInitWindowSize (250, 250);
glutCreateWindow("2");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(spinDisplay);


glutMainLoop();
return 0;
}


Thanks!

UtilMan
10-17-2002, 05:20 PM
Can someone please show how its done? I really need this.

Thanks!

nexusone
10-17-2002, 05:50 PM
You know people don't live on here 24/7 to answer your questions, and maybe the person with the answer has not been on yet.

But I will give it a shot.
First you have to tell openGL which window to render to.

First need to have the address of each window

int window1, window2;


window1 = glutCreateWindow("1");
window2 = glutCreateWindow("2");

Now we can set the rendering window by using glutSetWindow( windowX );

make a loop with glutIdleFunc or glutTimerFunc.

void my_loop()
{
glutSetWindow( window1 );
glutPostRedisplay();

glutSetWindow( window2 );
glutPostRedisplay();

}

display();

if ( window1 ) draw_scene_one();

if ( window2 ) draw_scene_two();

glutSwapBuffers();
}


Something like that should work.


Originally posted by UtilMan:
Can someone please show how its done? I really need this.

Thanks!

UtilMan
10-17-2002, 07:14 PM
It totally works!!!

THANK YOU SO MUCH!