Original Post
Hi.
I have got a framework that opens up a Window, however, when I try to draw anything to it, be it lines or a polygon, the window stays blank, nothing shows. Below is my code (C++):
#include
#include
#include
#include
#include
#include
#include
#define WINDOWS_CLASS_NAME "WINCLASS1"
#define WIN32_LEAN_AND_MEAN
HWND main_windows_handle = NULL;
int Game_Init(void);
int Game_Shutdown(void);
int Game_Main(void);
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_CREATE:
{
return 0; //20
} break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
default : break;
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int WINAPI WinMain (HINSTANCE hinstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, // 40
int nCmdShow)
{
WNDCLASS winclass;
HWND hwnd;
MSG msg;
winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOWS_CLASS_NAME;
//60
if(!(RegisterClass(&winclass)))
return 0;
if(!(hwnd = CreateWindow(WINDOWS_CLASS_NAME,
"Dominic Mulligan :: GLWINDOW",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 320, 240, NULL, NULL, hinstance,
NULL)))
return 0;
main_windows_handle = hwnd;
Game_Init();
while(true)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Game_Main();
}
Game_Shutdown();
return (msg.wParam);
}
int Game_Init(void)
{
glViewport(0, 0, 320, 240);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 320 / 240, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return 1;
}
int Game_Shutdown(void)
{
PostQuitMessage(0);
return 1;
}
int Game_Main(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0, 1.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(1.0, 0.0, -1.0);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.5, 1.0, 1.0);
glEnd();
return 1;
}
I cannot personally see a problem with it, perhaps you can?
Thanks in advance for any suggestions.
+MDI