Jump to content

  • Log In with Google      Sign In   
  • Create Account

OpenGL + Win32


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 acw83   Members   -  Reputation: 174

Like
Likes
Like

Posted 17 January 2000 - 08:47 AM

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); }

Sponsor:

#2 Kyle Radue   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 January 2000 - 09:19 AM

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.

#3 acw83   Members   -  Reputation: 174

Like
Likes
Like

Posted 17 January 2000 - 09:52 AM

Tried that, but still nothing happens.


#4 Someone   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 January 2000 - 02:27 PM

Umm... I think you should put glClear(GL_COLOR_BUFFER_BIT) after setting the glClearColor code.

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 17 January 2000 - 03:35 PM

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);





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS