-1
我有一個程序,我從我的主窗口創建了一個子窗口。問題在於它總是在那裏,我的目標是按下一個鍵,然後將該子窗口「打開」,然後再次按下時,使其消失。我設法用glutDistroyWindow摧毀它,但後來我不知道如何讓它再次出現。這是我的代碼:Glut子窗口切換
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;
}
好的,所以這些是重要的功能。在我的鍵盤功能中,我想切換damageWindow。我怎麼做 ?我知道如何摧毀它,但我似乎無法再重複它。 LE:我不斷收到downvotes,因爲人們並不真正理解這個問題。鍵盤功能是多餘的,因爲什麼也沒有,那是什麼IM要求you.But爲你們在這裏它的緣故:
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);
}
}
}
請修復格式。爲什麼你使用兩個重塑功能?我沒有看到「鍵盤」功能,你忘了發佈嗎? –
-1,代碼不完整。 – genpfault