2
votes

I am trying to get OpenGL to render inside of a Win32 api static control. I've gone through Nehe's tutorial (http://nehe.gamedev.net/tutorial/creating_an_opengl_window_%28win32%29/13001/) on how to force openGl to render to an entire window. I understand how to do that but I'm not totally sure how to get it to render inside of a static control(or any control). Currently, I am trying to do this:

HDC         hDC = NULL;
HGLRC       hRC = NULL; 
HWND        hWnd = NULL; 
HWND        panel;
HINSTANCE   hInstance;  
void CreatePanelGL(HWND hWnd){
    panel = CreateWindowEx(
    WS_EX_CLIENTEDGE,
    "STATIC",
    "",
    WS_CHILDWINDOW | WS_VISIBLE | CS_OWNDC | CS_VREDRAW | CS_HREDRAW,
    30, 30, 100, 100,
    hWnd,
    (HMENU)BUTTON_ID,
    GetModuleHandle(NULL),
    NULL);

    hDC = GetDC(panel);
    PIXELFORMATDESCRIPTOR pfd = { 0 };
    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 32;
    pfd.cDepthBits = 16;
    pfd.cStencilBits = 8;

    SetPixelFormat(hDC, 1, &pfd);
    hRC = wglCreateContext(hDC);
    wglMakeCurrent(hDC, hRC);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam){
switch(uMsg){
   case WM_CREATE:{
      CreatePanelGL(hWnd);
      break;
   }}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

I have way more code than this but I figured this is the only important bits. If you want me to post more, let me know. The callback function is cut down by a lot, the CreatePanelGL() function is a complete copy and paste. The code is pretty much a heavily modified version of Nehe's code. While this is not throwing any errors, openGl is not rendering the clear color inside of the panel. Can anyone help me out? I'm sure I am doing at least a hundred things wrong.

1
Have to tried subclassing the control and overriding its paint messages and doing nothing in them or drawing in them with OpenGL?Brandon
@ Calvin: I will take a look at using a custom control @Brandon: Right now I just have OpenGL clearing with a color, I haven't done anything with the control paint messages. How would I go about doing that?Matt B

1 Answers

1
votes

Static control has its own drawing operations that may mess things up. Create a custom child window instead.