PDA

View Full Version : How to create one more window when a key is pressed?



10-07-2002, 07:11 AM
I have written a program by starting with a window and waiting for the user to press any keys from keyboard to create a new window. (the existing window will not be destroyed)
My program can create the first window but after the user press the key, it seems no response. I have registered the keyboard function in the main function...but it still cant work.
How can this be done?

jono_123
10-07-2002, 10:59 PM
try posting some code

mikael_aronsson
10-07-2002, 11:01 PM
Hi !

I guess you are using GLUT then ?, it's pretty difficult to answer what the problem is without having a look at the code. There are lot's of examples out there, have a look at thoose and see if there is anything that do something similar to what you want to do.

Mikael

10-08-2002, 12:40 AM
i pick up some code and post it here

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>

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

if(key == 66) // B-key
{
glutCreateSubWindow(0, 30, 30, 100, 100);
}
}

void main (int argc, char **argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowPosition (0, 0);
glutInitWindowSize (300, 300);
glutCreateWindow ("OpenGL");
glutReshapeFunc(myReshape);
glutDisplayFunc (Display);
glutKeyboardFunc(KeyPressFunc);
glutMainLoop ();
}

10-08-2002, 05:42 AM
GLUT: Warning in main: The following is a new check for GLUT 3.0; update your co
de.
GLUT: Fatal Error in main: redisplay needed for window 2, but no display callbac
k.

10-08-2002, 05:43 AM
when run the program then these errors appear

GLUT: Warning in main: The following is a new check for GLUT 3.0; update your co
de.
GLUT: Fatal Error in main: redisplay needed for window 2, but no display callbac
k.

10-08-2002, 05:48 AM
these errors appear when press a B-key

GLUT: Warning in main: The following is a new check for GLUT 3.0; update your co
de.
GLUT: Fatal Error in main: redisplay needed for window 2, but no display callbac
k.

mikael_aronsson
10-08-2002, 05:49 AM
Hi !

If you have a look at the documentation for the redisplay callback function registration you find the note "Will register a callback function for the current window", so when you create a new window there is no callback function for that window, you must do that when you have created the (second) window also.

Mikael

10-08-2002, 10:15 PM
hi, Mikael
where can i find the documentation for the redisplay callback function registration "Will register a callback function for the current window" ?

10-08-2002, 10:36 PM
hi, Mikael
can you post some code that show how to register the second window?

Gavin
10-09-2002, 12:46 AM
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(flir.header.width, flir.header.height);
glutInitWindowPosition(200, 200);
flir_win = glutCreateWindow("Tabu Search");
glutDisplayFunc(MyDisplayFLIR);
glutReshapeFunc(MyReshape);
glutMouseFunc(MyMouse);
MyInit();

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(flir.header.width, flir.header.height);
glutInitWindowPosition(200, 200);
neighbour_win = glutCreateWindow("Neighbour");
glutDisplayFunc(MyDisplayNeighbour);
glutReshapeFunc(MyReshape);
MyInit();

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(flir.header.width, flir.header.height);
glutInitWindowPosition(200, 200);
best_win = glutCreateWindow("Best");
glutDisplayFunc(MyDisplayBest);
glutReshapeFunc(MyReshape);
MyInitBest();

glutMainLoop();

10-11-2002, 06:54 AM
hi Gvain
thx for ur code
http://www.opengl.org/discussion_boards/ubb/smile.gif