I have a program and i have created a subwindow from my main window. The problem is that its always there, my goal is to press a key and then get that subwindow "on" and when i press it again , to make it disappear. I managed to destroy it with glutDistroyWindow but then i dont know how to make it appear again. Here is my code:
void init(void)
{
// pregatim o scena noua in opengl
if(glutGetWindow() == mainWindow)
glClearColor(0.0, 0.0, 0.0, 0.0);
else
glClearColor(1.0, 1.0, 1.0, 1.0); fereastra
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
}
void reshape2(int w,int h){
glViewport(0,0,(GLsizei) w,(GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,(float)w/h,1.0,40.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
init();
}
void reshape(int w, int h)
{
// Main Window
glViewport(0,0, (GLsizei) w, (GLsizei) h);
// calculare aspect ratio ( Width/ Height )
GLfloat aspect = (GLfloat) w / (GLfloat) h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, aspect, 1.0, 100);
// init context
init();
if(damageWindow != -1)
glutDestroyWindow(damageWindow);
damageWindow=glutCreateSubWindow(mainWindow,0,0,w/5,h/5);
glutDisplayFunc(display);
glutReshapeFunc(reshape2);
glutKeyboardFunc(keyboard);
glutSpecialFunc(keyboard);
glutKeyboardUpFunc(keyboardup);
glutMouseFunc(mouse);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
int w = 800, h= 600;
glutInitWindowSize(w,h);
glutInitWindowPosition(100,100);
// Main window
mainWindow=glutCreateWindow("Tema4 - Asteroid Attack!");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutKeyboardUpFunc(keyboardup);
glutReshapeFunc(reshape);
glutSpecialFunc(keyboard);
glutMouseFunc(mouse);
// Initializeaza scena 3D
initScene();
glutMainLoop();
return 0;
}
Ok so these are the functions that matters. In my keyboard function i want to toggle damageWindow. How do i do that ? I know how to destroy it but i can't seem to make it again.
LE: I keep getting downvotes because people dont really understand the question. The keyboard function is redundant because there is nothing there , thats what im asking you.But for the sake of you guys here it is:
void keyboard(unsigned char ch,int x,int y){
switch(ch){
case 27: exit(0);break;
case 'n':
view_subwindow=!view_subwindow;
if(view_subwindow == false)
glutDestroyWindow(damageWindow);
else{
//here i want to recreate my window DONT KNOW HOW
damageWindow=glutCreateSubWindow(mainWindow,0,0,w/5,h/5);
glutDisplayFunc(display);
glutReshapeFunc(reshape2);
glutKeyboardFunc(keyboard);
glutSpecialFunc(keyboard);
glutKeyboardUpFunc(keyboardup);
glutMouseFunc(mouse);
}
}
}