rendering OGL in a win32 control

Started by
5 comments, last by qesbit 19 years, 2 months ago
i want to render some openGL stuff in a control (a static control, if it matters) on a window, in straight win32 (no MFC, .net, or anything else). needless to say, i can't get it to work. if i use a normal message pump, and update the static control with OGL when the form is painted (i.e. in the WM_PAINT handler), it never updates or anything. if i use the "game loop" type loop (with peekmessage, etc) the opengl control updates but the rest of the window never does, it just gets stuck with whatever was on the screen when the window first appeared. any suggestions?
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Advertisement
I've got this working before, but don't have access to my source code at the moment and it was a while ago. So, based on that my suggestion would be, in the first version with the message pump are you calling SwapBuffers( hDC ) after your opengl code?
Go to where you create your control in the resource viewer (if using MSVC) and turn 'Owner Draw' (or Parent Draw or something) off. If your static control doesn't have one of those, try a button control :)
do unto others... and then run like hell.
Quote:Original post by paulc
in the first version with the message pump are you calling SwapBuffers( hDC ) after your opengl code?

yes i am.
Quote:Original post by FReY
Go to where you create your control in the resource viewer (if using MSVC) and turn 'Owner Draw' (or Parent Draw or something) off. If your static control doesn't have one of those, try a button control :)

i am not using any sort of resource viewer, i am just typing my code in:
// in WM_CREATE message:g_PBHWND = CreateWindowEx(WS_EX_CLIENTEDGE, "STATIC", "", WS_CHILD | WS_VISIBLE,           0, 0, 100, 100, hWnd, (HMENU)NULL, GetModuleHandle(NULL), NULL);


i read that you must give the child window (control) a CS_OWNDC flag when the class is registered, so i think i'm going to try and create my own window class to use instead of the static control... but if anyone has any other information please post it, since i don't have such a great feeling about this :)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
make sure get hDC from static control hWnd (hDC = ::GetDC(statichWnd)
wglMakeCurrent()
set viewport to static client rect.

Or make your own OpenGL window control.

Oh, if you want to get WM_PAINT from static control you have to subclass it and do your own painting.
Wouldnt it be easier to just register a new window class and then init that to work with GL?

Surley you dont need the extended features of a Static, (basically because it has very few extra features above that of a normal window)
Quote:Original post by ZedFx
Wouldnt it be easier to just register a new window class and then init that to work with GL?

Surley you dont need the extended features of a Static, (basically because it has very few extra features above that of a normal window)



Yes certainly but it is not rocket science to do it on static control.

I forgot, the easy way is to do SS_OWNERDRAW. Your window proc will get a WM_DRAWITEM. When you get that check if it is the static control, and then you can paint on it. This means simply doing your OpenGL->drawScene() functions. The HDC and HWND will be in the WM_DRAWITEM message you just wglMakeCurrent(hDC,hRC) and away you go no need to subclass it.

This topic is closed to new replies.

Advertisement