Post by Lucian Wischikwc.style = CS_HREDRAW | CS_VREDRAW;
You need CS_OWNDC for an opengl window.
WM_CREATE is too early to set up the opengl context, for some drivers.
It's better if you create it lazily. (ie. in the WM_PAINT handler,
check to see if the context has been created, and if it hasn't yet
then create it).
--
Lucian
Still not quite there!
I have never done much extra window creation apart from the main window, so
I think this is where my main problem lies. Anyway, This is what I have.
The LRESULT APIENTRY RenderDialogGL (...) isnt getting called, as I have a
Beep() in the WM_CREATE which isnt playing.
I dont know what you meant by defining a control in my dialog template. I
use VC6 and everything is done graphically.
Can I do this with CreateWindowEx()? If not, could you please tell me how to
edit the dialog template?
Thanks
Allan
BOOL CALLBACK ChooseColour (HWND hDlg, UINT message, WPARAM wParam, LPARAM
lParam)
{
static HDC hdc, hdcGL;
static PAINTSTRUCT ps;
static HWND hwndGL;
static HGLRC hrcGL;
unsigned SelectedColour;
HBRUSH CurrentBrush, OldBrush;
unsigned Red, Green, Blue;
RECT rect;
static done = false;
WNDCLASSEX wc;
switch (message)
{
case WM_INITDIALOG :
if (done) // move the dialog to the last position the user specified
MoveWindow(hDlg,
gDialogPosition.left,
gDialogPosition.top,
gDialogPosition.right - gDialogPosition.left,
gDialogPosition.bottom - gDialogPosition.top,
TRUE);
else
done = true;
ghDlg = hDlg;
SetDlgItemText(hDlg, IDC_TEXT, gTextToDisplay);
// set ranges
SendMessage(GetDlgItem(hDlg, IDC_RED), TBM_SETRANGE, (WPARAM)TRUE,
MAKELONG(0, 255));
SendMessage(GetDlgItem(hDlg, IDC_GREEN), TBM_SETRANGE, (WPARAM)TRUE,
MAKELONG(0, 255));
SendMessage(GetDlgItem(hDlg, IDC_BLUE), TBM_SETRANGE, (WPARAM)TRUE,
MAKELONG(0, 255));
SendMessage(GetDlgItem(hDlg, IDC_RED), TBM_SETPOS, (WPARAM)TRUE,
(LPARAM)127);
SendMessage(GetDlgItem(hDlg, IDC_GREEN), TBM_SETPOS, (WPARAM)TRUE,
(LPARAM)127);
SendMessage(GetDlgItem(hDlg, IDC_BLUE), TBM_SETPOS, (WPARAM)TRUE,
(LPARAM)127);
SendMessage(GetDlgItem(hDlg, IDC_DIFFUSE), TBM_SETRANGE, (WPARAM)TRUE,
MAKELONG(0, 100));
SendMessage(GetDlgItem(hDlg, IDC_SPECULAR), TBM_SETRANGE, (WPARAM)TRUE,
MAKELONG(0, 100));
SendMessage(GetDlgItem(hDlg, IDC_TRANSPARENCY), TBM_SETRANGE,
(WPARAM)TRUE, MAKELONG(0, 100));
SendMessage(GetDlgItem(hDlg, IDC_SHININESS), TBM_SETRANGE, (WPARAM)TRUE,
MAKELONG(0, 100));
// set ticks
SendMessage(GetDlgItem(hDlg, IDC_RED), TBM_SETTICFREQ , (WPARAM)32, 0);
SendMessage(GetDlgItem(hDlg, IDC_GREEN), TBM_SETTICFREQ , (WPARAM)32, 0);
SendMessage(GetDlgItem(hDlg, IDC_BLUE), TBM_SETTICFREQ , (WPARAM)32, 0);
SendMessage(GetDlgItem(hDlg, IDC_DIFFUSE), TBM_SETTICFREQ , (WPARAM)10,
0);
SendMessage(GetDlgItem(hDlg, IDC_SPECULAR), TBM_SETTICFREQ , (WPARAM)10,
0);
SendMessage(GetDlgItem(hDlg, IDC_TRANSPARENCY), TBM_SETTICFREQ ,
(WPARAM)10, 0);
SendMessage(GetDlgItem(hDlg, IDC_SHININESS), TBM_SETTICFREQ , (WPARAM)10,
0);
SetWindowText(hDlg, gTextToDisplay);
wc.cbSize = sizeof (wc);
wc.lpszClassName = "WndClass_OglView";
wc.lpfnWndProc = RenderDialogGL;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = NULL;
wc.hIconSm = NULL;
wc.lpszMenuName = NULL;
wc.hInstance = ghInstance;
if (!RegisterClassEx(&wc)) // Register class named "WndClass_OglView"
Beep(1000, 100);
return TRUE;
case WM_PAINT:
return TRUE;
case WM_VSCROLL :
GetClientRect(hDlg, &rect);
InvalidateRect(hDlg, &rect, FALSE);
return TRUE;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case ID_CCOK:
GetWindowRect(hDlg, &gDialogPosition);
gMaterial.colour[0] = (float)(255 - SendMessage(GetDlgItem(hDlg,
IDC_RED), TBM_GETPOS, 0, 0))/255;
gMaterial.colour[1] = (float)(255 - SendMessage(GetDlgItem(hDlg,
IDC_GREEN),TBM_GETPOS, 0, 0))/255;
gMaterial.colour[2] = (float)(255 - SendMessage(GetDlgItem(hDlg,
IDC_BLUE), TBM_GETPOS, 0, 0))/255;
gMaterial.colour[3] = 1.0f;
gMaterial.diffuse[0] = (float)(SendMessage(GetDlgItem(hDlg, IDC_DIFFUSE),
TBM_GETPOS, 0, 0))/100;
gMaterial.diffuse[1] = (float)(SendMessage(GetDlgItem(hDlg, IDC_DIFFUSE),
TBM_GETPOS, 0, 0))/100;
gMaterial.diffuse[2] = (float)(SendMessage(GetDlgItem(hDlg, IDC_DIFFUSE),
TBM_GETPOS, 0, 0))/100;
gMaterial.diffuse[3] = 1.0f;
gMaterial.specularity[0] = (float)(SendMessage(GetDlgItem(hDlg,
IDC_SPECULAR), TBM_GETPOS, 0, 0))/100;
gMaterial.specularity[1] = (float)(SendMessage(GetDlgItem(hDlg,
IDC_SPECULAR), TBM_GETPOS, 0, 0))/100;
gMaterial.specularity[2] = (float)(SendMessage(GetDlgItem(hDlg,
IDC_SPECULAR), TBM_GETPOS, 0, 0))/100;
gMaterial.specularity[3] = 1.0f;
gMaterial.shininess = (float)(SendMessage(GetDlgItem(hDlg,
IDC_SHININESS), TBM_GETPOS, 0, 0))/100;
gMaterial.transparency = (float)(SendMessage(GetDlgItem(hDlg,
IDC_TRANSPARENCY), TBM_GETPOS, 0, 0))/100;
GetDlgItemText(hDlg, IDC_TEXNAME, gMaterial.texture, 64);
if (gMaterial.texture[0] == '\0')
strcpy(gMaterial.texture, "NULL");
else if ((toupper(gMaterial.texture[strlen(gMaterial.texture-1)]) != 'P')
||
(toupper(gMaterial.texture[strlen(gMaterial.texture-2)]) != 'M') ||
(toupper(gMaterial.texture[strlen(gMaterial.texture-3)]) != 'B') ||
(gMaterial.texture[strlen(gMaterial.texture-1)] != '.'))
strcat(gMaterial.texture, ".bmp"); // if user didnt specify .bmp then
add it
EndDialog(hDlg, 0);
break;
case ID_EXIT:
gUserQuits = true;
EndDialog(hDlg, 0);
wglMakeCurrent(hDC, hRC); // select main window for rendering
wglDeleteContext(hrcGL); // delete dialog GL window
return FALSE;
}
return TRUE;
}
return FALSE ;
}
LRESULT APIENTRY RenderDialogGL (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HWND hwndGL;
HDC hdcGL;
HGLRC hrcGL;
int nPixelFormat;
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this structure
1, // Version of this structure
PFD_DRAW_TO_WINDOW | // draw to window (not bitmap)
PFD_SUPPORT_OPENGL | // support OpenGL calls
PFD_DOUBLEBUFFER, // Double-buffered mode
PFD_TYPE_RGBA, // RGBA colour mode
24, // Use 24-bit colour
0,0,0,0,0,0, // not used to select mode
0,0, // not used to select mode
0,0,0,0,0, // not used to select mode
32, // size of depth buffer
0, // not used to select mode
0, // not used to select mode
PFD_MAIN_PLANE, // draw in main plane
0, // not used to select mode
0,0,0 }; // not used to select mode
switch (message)
{
case WM_CREATE:
Beep(1000, 1000);
hwndGL = CreateWindowEx(WS_EX_CLIENTEDGE ,
"WndClass_OglView" , (LPSTR) NULL, WS_VISIBLE | WS_CHILD,
165, 75, 50, 50, ghDlg, (HMENU) 0, ghInstance, NULL);
hdcGL = GetDC(hwndGL);
// choose pixel format that best matches that described in PFD
nPixelFormat = ChoosePixelFormat(hdcGL, &pfd);
// set the pixel format for the device context
SetPixelFormat(hdcGL, nPixelFormat, &pfd);
hrcGL=wglCreateContext(hdcGL);
wglMakeCurrent(hdcGL, hrcGL);
core.ChangeViewSize(50, 50);
core.SetupRC();
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
auxSolidSphere(2.0f);
EndPaint(hwnd, &ps);
break;
default :
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}