Which used select and set the pixel format
660 |
|
|
---|
When a window is created, it first receives a WM_CREATE message from the operating system. This is the ideal location to create and set up the OpenGL rendering context. A window also receives a WM_DESTROY message when it is being destroyed. Naturally, this is the ideal place to put cleanup code. Listing 19.2 shows the SetDCPixelFormat format, which is used to select and set the pixel format, along with the window procedure for the application. This function contains the same basic functionality that we have been using with the GLUT framework.
LISTING 19.2 Setting the Pixel Format and Handling the Creation and Deletion of the OpenGL Rendering Context
{
int nPixelFormat;
PFD_SUPPORT_OPENGL | // Support OpenGL calls in window
PFD_DOUBLEBUFFER, // Double-buffered mode
|
|
Putting It All Together | 661 |
---|
/////////////////////////////////////////////////////////////////////// // Window procedure, handles all messages for this program
LRESULT CALLBACK WndProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
static HGLRC hRC = NULL; // Permanent rendering context
static HDC hDC = NULL; // Private GDI device contextswitch (message)
{
// Window creation, set up for OpenGL
case WM_CREATE:
// Store the device context
hDC = GetDC(hWnd);