OpenGL + Win32

Started by
3 comments, last by acw83 24 years, 3 months ago
There is something wrong with my code. I know the Win32 works fine, but it''s the OpenGL that has got me stumped. This code should clear the screen red, but I don''t see it happening. ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // // // NAME: WinGL.cpp // // // // DESC: A basic tempalte for Windows fullscreen // // OpenGL. // // // // AUTH: Andrew C. White // // // // DATE: January 17 2000 // // // ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// //============================================================ // Includes //============================================================ #include "stdafx.h" //============================================================ // Defines //============================================================ #define NAME "WinGL" #define WIDTH 800 #define HEIGHT 600 #define BPP 24 //============================================================ // Globals //============================================================ static HDC hDC =NULL; static HGLRC hRC =NULL; //============================================================ // Functions //============================================================ //============================= // RenderScene // Renders the scene. //============================= void RenderScene(void) { glClearColor(1.0f, 0.0f, 0.0f, 1.0f); SwapBuffers(hDC); } //============================= // ExitOnError // Displays message box with error and closes. //============================= void ExitOnError(HWND hWnd, LPSTR szError) { ShowCursor(TRUE); MessageBox(hWnd, szError, "Error", MB_OK); PostQuitMessage(0); return; } //============================= // WndProc // Window message handler. //============================= LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: // Initialize the app. { hDC = GetDC(hWnd); if( !hDC ) ExitOnError(hWnd, "Not enought free resources!"); static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW / PFD_SUPPORT_OPENGL / PFD_DOUBLEBUFFER, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0 ,0 ,0 }; SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); return(0); } break; case WM_DESTROY: // Shut down the app. { wglMakeCurrent(NULL, hRC); wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); return(0); } break; case WM_KEYDOWN: // Process keyboard input. { switch((int) wParam) { case VK_ESCAPE: { PostQuitMessage(0); } break; default: break; } return(0); } break; } return (DefWindowProc(hWnd, message, wParam, lParam)); } //============================= // WinMain // The entry point, and main loop. //============================= int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX winclass = { sizeof(winclass), CS_OWNDC / CS_HREDRAW / CS_VREDRAW, WndProc, NULL, NULL, hInstance, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH) GetStockObject(BLACK_BRUSH), NULL, "winclass", LoadIcon(NULL, IDI_APPLICATION) }; RegisterClassEx(&winclass); HWND hWnd = CreateWindowEx(WS_EX_TOPMOST, "winclass", NAME, WS_POPUP / WS_CLIPCHILDREN / WS_CLIPSIBLINGS, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); MSG message; while(1) { if( PeekMessage(&message, hWnd, 0, 0, PM_REMOVE) ) { if( message.message == WM_QUIT ) { SendMessage(hWnd, WM_DESTROY, NULL, NULL); break; } TranslateMessage(&message); DispatchMessage(&message); } RenderScene(); } SendMessage(hWnd, WM_DESTROY, NULL, NULL); return (0); }
Advertisement
In RenderScene() you set the color that it should clear the screen to, but you don''t actually clear the screen. The glClear( int ) function should do the trick.
Tried that, but still nothing happens.
Umm... I think you should put glClear(GL_COLOR_BUFFER_BIT) after setting the glClearColor code.
glClearColor does not actual clear the screen it only sets the color that will be on the screen once it is cleared.
also you need to call glFinish() try code that looks like this:

glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT);
glFinish();
glSwapBuffers(Graphics_hGLDC);

This topic is closed to new replies.

Advertisement