PDA

View Full Version : Creating two Opengl Windows



gottijay
07-26-2011, 04:39 PM
i'm trying to create a program where a click of a button will create a new window which would carry out animation...

i first programmed the animation and made sure they were working before i linked it to run on a new window when the button was clicked. the second opengl window creates alright but my animation is screwed up..introducing some abnormalities and also models dont display properly(display like 2D shadows)....
cant quite understand why



static void TheButtonCallback8()
{

if(window2==0){
window2 = glutCreateWindow("animation");
glutDisplayFunc(display2); //animation display
glutReshapeFunc(OnReshape);
glutIdleFunc(onIdle1);
}


printf("Run Animation");
}

void OnIdle1()
{
if(window2 != 0)
{
rY += 0.05;

glutPostWindowRedisplay(window2);
}
else
{
glutIdleFunc(0);
glutDestroyWindow(window2);
glutPostWindowRedisplay(window1);

window2 = 0;
rY = 0;
}

}

void main(int argc, char** argv) {
atexit(OnShutdown);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(width, height);
//glutCreateWindow("GLUT Picking Demo [using selection buffer]");

// Make Main outer window
window1 = glutCreateWindow("Satellite Assembly");
glutDisplayFunc(OnRender);
glutReshapeFunc(OnReshape);
glutIdleFunc(onIdle);

glutKeyboardFunc(OnKey);
glutSpecialFunc (keyboard_s);
glutMouseFunc(Mouse);
glutMotionFunc(Motion);
glutPassiveMotionFunc(MousePassiveMotion);

InitGL();

glutMainLoop();
}


am i supposed to create separate callbacks for each window

thanks

Alfonse Reinheart
07-26-2011, 04:57 PM
No. In your callbacks, you're supposed to get which window you're currently using and do different things based on that.

glutCreateWindow returns a number representing that window. glutGetWindow can be called to get whichever window is "current" at the time of that call. So if you're in your display call back, you can check glutGetWindow to find out which window you should be doing rendering for. And so on.

gottijay
07-27-2011, 03:23 AM
thanks fixed it.

gottijay
07-28-2011, 01:03 AM
hi, i am still having problems with multiple windows.....when i destroy the second window by pressing the esc key it closes but then i cant use the keyboard function on the main window..... .i also noticed i could not create the second window again after destroying, i would like to be able to create by clicking button destroy by hitting the escape key and create again by clicking button again.....it does not work like this on my program..
please could you give me an idea how to fix it.......

thank you..




void OnKeyAnimation(unsigned char key, int x, int y){

if (key == 27){
bool loadMast= false;
bool loadReflector= false;
bool loadReceiver= false;
bool loadConnector= false;
bool loadStand= false;
glutDestroyWindow(window2);


//exit(0);
}
}

static void TheButtonCallback8()
{

loadMast = true;
loadReflector = true;
loadReceiver = true;
loadConnector = true;
loadStand = true;

animate=true;

if(window2==0){

window2 = glutCreateWindow("animation");
glutDisplayFunc(display2);
glutReshapeFunc(animation_Reshape);
glutIdleFunc(OnIdle1);

glutKeyboardFunc(OnKeyAnimation);
glutMouseFunc(Mouse);
glutMotionFunc(Motion);
InitGL();
glutMainLoop();


}


printf("Run Animation");
}