//Fonctions spécifiques bool MyGraphicHandler::Init() { // Make it the active window for OpenGL calls WindowUpdate(); //pour avoir la fenêtre à jour en fonction de la config avant le glMatrixMode (??) m_focusedWindow.setActive(); //------------------------OPENGL-------------------------------------- // Set the color and depth clear values glClearDepth(1.f); glClearColor(0.f, 0.f, 0.f, 1.f); // Enable Z-buffer read and write glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); // Disable lighting and texturing glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); // Configure the viewport (the same size as the window) glViewport(0, 0, m_focusedWindow.getSize().x, m_focusedWindow.getSize().y); // Setup a perspective projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat ratio = static_cast<float>(m_focusedWindow.getSize().x) / m_focusedWindow.getSize().y; glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); return true; }
// Program Entry (WinMain) //int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) int main() { HINSTANCE hInstance = NULL; application_t *app; // = ApplicationNew("OpenGL", hInstance); application_t *app2; // = ApplicationNew("OpenGL 2", hInstance); gl_window_t *win1, *win2; app = ApplicationNew("OpenGL", hInstance); app2 = ApplicationNew("OpenGL 2", hInstance); start: // left, top, width, height char title[1024]; sprintf(title, "system metrics: %dx%d", GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); win1 = WindowNew(app, title, 100, 100, 1024, 768, MyInitialize, MyDeinitialize, MyUpdate, MyDraw); if ( ! win1->isCreated) { MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION); return -1; } win2 = WindowNew(app2, title, 100, 100, 1024, 768, MyInitialize, MyDeinitialize, MyUpdate, MyDraw); if ( ! win2->isCreated) { MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION); return -1; } // Ask The User If They Want To Start In FullScreen Mode? (Remove These 4 Lines If You Want To Force Fullscreen) //if (MessageBox (HWND_DESKTOP, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO) //{ // window.init.isFullScreen = FALSE; // If Not, Run In Windowed Mode //} WindowInit(win1); WindowInit(win2); int quitcounter = 0; while (1) { if (! win1->quit) { WindowUpdate(win1); WindowDraw(win1); WindowMessageLoop(win1); } if (! win2->quit) { WindowUpdate(win2); WindowDraw(win2); WindowMessageLoop(win2); } if (win1->quit && win2->quit) break; } goto start; ApplicationClose(app); ApplicationClose(app2); return 0; }
// Process Window Message Callbacks LRESULT CALLBACK WindowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // Get The Window Context gl_window_t *win = (gl_window_t *)(GetWindowLong (hWnd, GWL_USERDATA)); //printf("hwnd=%d uMsg=%d\n", hWnd, uMsg); switch (uMsg) { case WM_ERASEBKGND: // Check To See If Windows Is Trying To Erase The Background return 0; // Return 0 (Prevents Flickering While Resizing A Window) case WM_PAINT: // Window Needs Updating { //PAINTSTRUCT ps; //BeginPaint(win->hWnd, &ps); // uncomment this to repaint window on size/move event, maybe add win->sizemoveevent = TRUE, // so it will not interfer with main loop if (win->win32_wndproconly) { WindowUpdate(win); WindowDraw(win); } // I've read that opengl should be drawn in WM_PAINT, but that just caused problems (unfocused window e.g. just would not update at all) //EndPaint(win->hWnd, &ps); return 0; } case WM_SYSCOMMAND: // Intercept System Commands { switch (wParam) // Check System Calls { case SC_SCREENSAVE: // Screensaver Trying To Start? case SC_MONITORPOWER: // Monitor Trying To Enter Powersave? return 0; // Prevent From Happening } break; // Call DefWindowProc() } case WM_CREATE: // Window Creation { CREATESTRUCT* creation = (CREATESTRUCT*)(lParam); // Store Window Structure Pointer win = (gl_window_t *)(creation->lpCreateParams); SetWindowLong (hWnd, GWL_USERDATA, (LONG)(win)); return 0; } case WM_CLOSE: WindowTerminate(win); return 0; case WM_SIZE: // Size Action Has Taken Place //printf("WM_SIZE\n"); switch (wParam) { case SIZE_MINIMIZED: // Was Window Minimized? win->isVisible = FALSE; // Set isVisible To False return 0; case SIZE_MAXIMIZED: // Was Window Maximized? win->isVisible = TRUE; // Set isVisible To True WindowMakeCurrent(win); ReshapeGL (win, LOWORD (lParam), HIWORD (lParam)); // Reshape Window - LoWord=Width, HiWord=Height return 0; case SIZE_RESTORED: // Was Window Restored? win->isVisible = TRUE; // Set isVisible To True WindowMakeCurrent(win); ReshapeGL (win, LOWORD (lParam), HIWORD (lParam)); // Reshape Window - LoWord=Width, HiWord=Height return 0; } break; case WM_KEYDOWN: // Update Keyboard Buffers For Keys Pressed if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range? { win->keys.keyDown [wParam] = TRUE; // Set The Selected Key (wParam) To True return 0; // Return } break; case WM_KEYUP: // Update Keyboard Buffers For Keys Released if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range? { win->keys.keyDown [wParam] = FALSE; // Set The Selected Key (wParam) To False return 0; // Return } break; case WM_TOGGLEFULLSCREEN: // Toggle FullScreen Mode On/Off //win->toggleFullscreen = TRUE; PostMessage (hWnd, WM_QUIT, 0, 0); break; } return DefWindowProc (hWnd, uMsg, wParam, lParam); // Pass Unhandled Messages To DefWindowProc }
void Window::Update() { WindowUpdate(mHandle); }