I have implemented a engine class based on the example in "OpenGL game programming" ch 20. But
for some reason I cant get it to work Could someone take a look?
the WinMain;
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
teEngine* theEngine;
CoInitialize(NULL);
if (!teGLWindow::registerWindowClass(hInstance))
{
MessageBox(NULL,"Could not register window class",0,0);
return 0;
}
try{
theEngine = new teEngine("The Terra Engine", 640,480,32);
theEngine->Init();
theEngine -> MessageLoop();
theEngine->Shutdown();
}
catch (char* sz)
{
MessageBox(NULL,sz,0,0);
return 0;
}
CoUninitialize();
return 0;
}
The teEngine Class:
class teEngine : public teGLWindow
{
public:
LRESULT MessageLoop();
void updateWindow(int width, int height);
void Run();
bool Init();
void Shutdown();
teEngine(char* name, int width, int height, int bits) : teGLWindow(name, width,height,bits) {};
virtual ~teEngine();
};
The glWindow class
class teGLWindow
{
public:
teGLWindow();
void paint();
void endFullScreen();
void beginFullScreen(int width, int height, int bits);
int pixelFormat;
void setupPixelFormat();
static bool registerWindowClass(HINSTANCE hI);
Screeninfo Screen;
bool createGLWindow();
bool killGLWindow();
bool initGL();
HINSTANCE hInstance;
HGLRC hRC;
HDC hDC;
HWND hWnd;
bool ReSizeGLScene(int width, int height);
teGLWindow(char* name, int width, int height, int b);
virtual ~teGLWindow();
};
The WinProc function
LRESULT APIENTRY WndProcGL(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
teGLWindow *glWindow = (teGLWindow*)GetWindowLong(hWnd, GWL_USERDATA);
if ((glWindow == NULL) && (uMsg != WM_CREATE))
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
// dispatch messages
switch (uMsg)
{
case WM_CREATE: // window creation
{
HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
glWindow = (teGLWindow*)(((LPCREATESTRUCT)lParam)->lpCreateParams);
if (!SetWindowLong(hWnd, GWL_USERDATA, (LONG)glWindow))
{
DWORD a = GetLastError();
return a;
}
glWindow->hWnd = hWnd;
return glWindow->createGLWindow(); (calls setPixelformat below and tries to create
the rendering context)
}
<removed some code>
The pixelformat setup
void teGLWindow::setupPixelFormat()
{
PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
pixelFormat = ChoosePixelFormat(hDC, &pfd);
if(pixelFormat == 0)
{
throw "Could not setup pixelformat";
return;
}
SetPixelFormat(hDC, pixelFormat, &pfd);
}
and finally the registerWindow class function
bool teGLWindow::registerWindowClass(HINSTANCE hI)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProcGL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hI;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenGL";
if (!RegisterClass(&wc))
{
return false;
}
return true;
}
What happens is that the window opens but the rendering context hasn't been initialized.
Sorry about the amount of code, but I'm getting desperate
"A witty and slightly sarcastic quote from an unkown source"
-- The generic SIG
/trysil
Edited by - trysil on February 7, 2002 4:19:58 PM
"A witty and slightly sarcastic quote from an unkown source"-- The generic SIG/trysil