new Opengl Window
#1 Members - Reputation: 100
Posted 24 July 2011 - 08:21 AM
if this is possible can anyone please tell me how i could achieve that......
working with opengl and glut
thank you.
#3 Members - Reputation: 3678
Posted 24 July 2011 - 09:35 AM
or if you have powerpoint:
http://www.cs.uml.edu/~hmasterm/Charts/Managing_Multiple_Windows.ppt
The voices in my head may not be real, but they have some good ideas!
#4 Members - Reputation: 3794
Posted 24 July 2011 - 02:15 PM
It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.
#5 Members - Reputation: 100
Posted 24 July 2011 - 02:34 PM
@Brother Bob ..i have a window already with 2D buttons rendered...but i want to also add animations into my program..but i want the animations to run in another opengl window after the animation button has been clicked....then return back to the first window after the animation is finished...
@SimonForsman...thanks for the link ..i'll take a look at it...
#6 Moderators - Reputation: 4633
Posted 24 July 2011 - 03:04 PM
From your vague description of your program, it sounds like you just need to do the following:
- When clicking the button, create a new window and register the callbacks for that window.
- The new window's display callback displays the animation.
- The new window's idle callback drives the animation forward.
- When the animation is finished, destroy it.
#7 Members - Reputation: 100
Posted 26 July 2011 - 03:45 AM
All you need to do is create the second window as you need it, draw as usual, and destroy it when you're done. As I said in my first post, I'm not sure what specific part, or if it's the whole concept of having multiple window, you're having problem with.
From your vague description of your program, it sounds like you just need to do the following:
- When clicking the button, create a new window and register the callbacks for that window.
- The new window's display callback displays the animation.
- The new window's idle callback drives the animation forward.
- When the animation is finished, destroy it.
thanks Brother Bob for your reply.......i am still having issues creating the second window.....the first window creates alright but when i click the button for the animation window to be created nothing happens..
any idea why this might be happening??
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);
if(animate){
// Create First subwindow
window2 = glutCreateWindow("Animation");
glutDisplayFunc(display2);
glutReshapeFunc(animation_Reshape);
glutIdleFunc(OnIdle1);
}
glutKeyboardFunc(OnKey);
glutSpecialFunc (keyboard_s);
glutMouseFunc(Mouse);
glutMotionFunc(Motion);
glutPassiveMotionFunc(MousePassiveMotion);
InitGL();
glutMainLoop();
}
static void TheButtonCallback8()
{
animate=true;
loadMast = true;
loadReflector = true;
loadReceiver = true;
loadConnector = true;
loadStand = true;
printf("Run Animation");
}
thanks alot for your help
#8 Moderators - Reputation: 4633
Posted 26 July 2011 - 04:20 AM
I will be created when main executes and animate is true. The variable animate is not true when you start the program, so it won't be created when the program starts. Is the function main executed again, at any time, after animate is set to true? If not, then that code is never going to be reached again. But if it is called again, so the second window can be created, you have other problems as well; you will completely reinitialize everything, including creating another primary window. Not to mention that in a well-formed program, you are not allowed to call main yourself.
You need to create the window in some piece of code that is actually executed when you press your button. If it's not executed, well, then nothing happens. Take a look at this quick example.
#include <GL/glut.h>
int primaryWindow = 0;
int secondaryWindow = 0;
GLfloat angle = 0;
void idleFunc();
void redisplaySecondaryFunc()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0, 0, -5);
glRotatef(angle, 0, 1, 0);
glutWireTeapot(2);
glutSwapBuffers();
}
void reshapeSecondaryFunc(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 1, 10);
glMatrixMode(GL_MODELVIEW);
}
void redisplayFunc()
{
glClearColor(0.75, 0.75, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
void reshapeFunc(int w, int h)
{
glViewport(0, 0, w, h);
}
void mouseFunc(int button, int state, int, int)
{
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && secondaryWindow == 0)
{
secondaryWindow = glutCreateWindow("animation");
glutDisplayFunc(redisplaySecondaryFunc);
glutReshapeFunc(reshapeSecondaryFunc);
glutIdleFunc(idleFunc);
angle = 0;
}
}
void idleFunc()
{
if(secondaryWindow != 0)
{
angle += 1;
if(angle < 360)
{
glutPostWindowRedisplay(secondaryWindow);
}
else
{
glutIdleFunc(0);
glutDestroyWindow(secondaryWindow);
secondaryWindow = 0;
angle = 0;
}
}
}
void main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowSize(400,400);
primaryWindow = glutCreateWindow(argv[0]);
glutDisplayFunc(redisplayFunc);
glutMouseFunc(mouseFunc);
glutReshapeFunc(reshapeFunc);
glutMainLoop();
}
It creates secondary window with some animation when you click inside the primary window. Keep in mind though that the idle callback is global and not tied to any particular window.
#9 Members - Reputation: 100
Posted 26 July 2011 - 05:15 PM
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();
#11 Members - Reputation: 100
Posted 27 July 2011 - 04:13 AM
the only problem i now is that....the first model in the animation seem to go further than its end position in the animation....dont know the cause of that
static void TheButtonCallback8()
{
animate=true;
loadMast = true;
loadReflector = true;
loadReceiver = true;
loadConnector = true;
loadStand = true;
if(window2==0){
window2 = glutCreateWindow("animation");
glutDisplayFunc(display2);
glutReshapeFunc(OnReshape);
glutIdleFunc(OnIdle1);
glutKeyboardFunc(OnKey);
glutSpecialFunc (keyboard_s);
glutMouseFunc(Mouse);
glutMotionFunc(Motion);
glutPassiveMotionFunc(MousePassiveMotion);
InitGL();
glutMainLoop();
}
printf("Run Animation");
}
#13 Members - Reputation: 100
Posted 28 July 2011 - 02:01 AM
i also noticed that when i click the button again to create the window after i have destroyed it ...it does not create
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");
}
#15 Members - Reputation: 100
Posted 29 July 2011 - 06:59 AM
I cannot say much about your problems since the description is quite vague and you're only showing small pieces of code. But whatever you do, you absolutely don't want to call glutMainLoop again after creating the window.
its a very long code....i omitted ones i thought were not necessary.... but if you still want me to put them ...just let me know...........
i still could not find ways of working around the problem...since its imperative for me to create the window only when the button is clicked....the keyboard response has become very slow that i have to wait over 20secs for it to respond......this only happens after the second window has been created an destroyed....on first run(ie when its just the first window running) the keyboard works just fine.
Problem Description
what i want to achieve is to run my program which then creates the first window....then click a run anmation button which has the buttoncallback8 to start the animation.....if i then press esc to close the second window i want to be able to continue using both mouse and key function on window1.....but so far all i can do is create and destroy the second window(the animation also runs when the button is clicked which is fine)...but after destroying the second window i cant use the first effectively as the keyboard response slows down tremendously ...i have to wait over 20sec......i think the problem might be from my approach but i cant find an alternative method that will give the results i want...........i hope my description was better
thanks for your help.
#16 Moderators - Reputation: 4633
Posted 30 July 2011 - 07:27 AM






