void keyPressed(KeySym key) { switch (key) { case XK_Escape: done = True; break; case XK_F1: killGLWindow(); GLWin.fs = !GLWin.fs; createGLWindow("NeHe's Texture Mapping Tutorial", 640, 480, 24, GLWin.fs); break; case XK_Left: rotz -= 0.8f; /* rotate left */ break; case XK_Right: rotz += 0.8f; /* rotate left */ break; case XK_Up: divs++; /* Update the patch */ mybezier.dlBPatch = genBezier(mybezier, divs); keys[XK_Up%256] = False; break; case XK_Down: divs--; /* Update the patch */ mybezier.dlBPatch = genBezier(mybezier, divs); keys[XK_Down%256] = False; break; case XK_space: showCPoints = !showCPoints; keys[XK_space%256] = False; break; } }
int InitGL(GLvoid) // All Setup For OpenGL Goes Here { glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.05f, 0.05f, 0.05f, 0.5f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations initBezier(); // Initialize the Bezier's control grid NeHeLoadBitmap("../../data/NeHe.bmp",mybezier.texture); // Load the texture mybezier.dlBPatch = genBezier(mybezier, divs); // Generate the patch return TRUE; // Initialization Went OK }
int initGL() /* All Setup For OpenGL Goes Here */ { glEnable(GL_TEXTURE_2D); /* Enable Texture Mapping */ glShadeModel(GL_SMOOTH); /* Enable Smooth Shading */ glClearColor(0.05f, 0.05f, 0.05f, 0.5f); /* Black Background */ glClearDepth(1.0f); /* Depth Buffer Setup */ glEnable(GL_DEPTH_TEST); /* Enables Depth Testing */ glDepthFunc(GL_LEQUAL); /* The Type Of Depth Testing To Do */ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); /* Really Nice Perspective Calculations */ initBezier(); /* Initialize the Bezier's control grid */ LoadGLTexture(&(mybezier.texture), "./data/NeHe.bmp"); /* Load the texture */ mybezier.dlBPatch = genBezier(mybezier, divs); /* Generate the patch */ resizeGLScene(GLWin.width, GLWin.height); glFlush(); return True; /* Initialization Went OK */ }
int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows Message Structure BOOL done=FALSE; // Bool Variable To Exit Loop // Ask The User Which Screen Mode They Prefer if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; // Windowed Mode } // Create Our OpenGL Window if (!CreateGLWindow("David Nikdel & NeHe's Bezier Tutorial",640,480,16,fullscreen)) { return 0; // Quit If Window Was Not Created } while(!done) // Loop That Runs While done=FALSE { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? { if (msg.message==WM_QUIT) // Have We Received A Quit Message? { done=TRUE; // If So done=TRUE } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene() if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received? { done=TRUE; // ESC or DrawGLScene Signalled A Quit } else // Not Time To Quit, Update Screen { SwapBuffers(hDC); // Swap Buffers (Double Buffering) } if (keys[VK_LEFT]) rotz -= 0.8f; // rotate left if (keys[VK_RIGHT]) rotz += 0.8f; // rotate right if (keys[VK_UP]) { // resolution up divs++; mybezier.dlBPatch = genBezier(mybezier, divs); // Update the patch keys[VK_UP] = FALSE; } if (keys[VK_DOWN] && divs > 1) { divs--; mybezier.dlBPatch = genBezier(mybezier, divs); // Update the patch keys[VK_DOWN] = FALSE; } if (keys[VK_SPACE]) { // SPACE toggles showCPoints showCPoints = !showCPoints; keys[VK_SPACE] = FALSE; } if (keys[VK_F1]) // Is F1 Being Pressed? { keys[VK_F1]=FALSE; // If So Make Key FALSE KillGLWindow(); // Kill Our Current Window fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode // Recreate Our OpenGL Window if (!CreateGLWindow("David Nikdel & NeHe's Bezier Tutorial",640,480,16,fullscreen)) { return 0; // Quit If Window Was Not Created } } } } // Shutdown KillGLWindow(); // Kill The Window return (msg.wParam); // Exit The Program }