Archived

This topic is now archived and is closed to further replies.

MDI

Initialisation problem. (Code inc.)

Recommended Posts

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

Share this post


Link to post
Share on other sites
Hmm, my include files did not copy for some reason.

Here they are:

#include iostream
#include windows.h
#include windowsx.h
#include math.h
#include gl/gl.h
#include gl/glu.h
#include gl/glaux.h


*EDIT : Damned triangular bracket html things.

+MDI

Edited by - MDI on November 14, 2001 8:18:19 AM

Share this post


Link to post
Share on other sites
Here's a basic framework I use for OpenGL window creation

  

HINSTANCE hInstance;
HWND hWnd;
HDC hDC;
HGLRC hRC;



int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
hInstance = hInst;

wndRegisterClass();
wndChangeDisplayMode(1024, 768, 32);
hWnd = wndCreateWindow(1024, 768);
hDC = GetDC(hWnd);
wndSetPixelFormat(1024, 768, 32, 24, 8);

//game init


while(MessageHandler() == true)
{
//main game loop

}

//game shutdown


wndDestroyWindow();

return 0;
}



LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return false;
break;

case WM_SYSCOMMAND:
switch(lParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
default: break;
}
break;

case WM_CLOSE:
PostQuitMessage(0);
return false;
break;

case WM_SIZE:
//ResizeGLScene(LOWORD(lparam),HIWORD(lparam));

return false;
break;

default:break;
}

return DefWindowProc(hWnd, msg, wParam, lParam);
}



bool MessageHandler(void)
{
MSG msg;

while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

if(msg.message == WM_QUIT)
{
return false;
}
}

return true;
}



unsigned short wndRegisterClass(void)
{
WNDCLASS wndClass;

wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndClass.lpfnWndProc = (WNDPROC) WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = NULL;
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "Game";

return RegisterClass(&wndClass);
}



bool wndChangeDisplayMode(long Width, long Height, long ColorBits)
{
DEVMODE dmScreenSettings;

ZeroMemory (&dmScreenSettings, sizeof(dmScreenSettings));

dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = Width;
dmScreenSettings.dmPelsHeight = Height;
dmScreenSettings.dmBitsPerPel = ColorBits;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

return (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);
}



HWND wndCreateWindow(long Width, long Height)
{
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;

dwExStyle = WS_EX_APPWINDOW;
dwStyle = WS_POPUP;

ShowCursor(FALSE);

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);

return CreateWindowEx(dwExStyle, "Game", "Game", dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, Width, Height, NULL, NULL, hInstance, NULL);
}



void wndSetPixelFormat(long Width, long Height, char ColorBits, char DepthBits, char StencilBits)
{
PIXELFORMATDESCRIPTOR pfd;

ZeroMemory(&pfd, sizeof(pfd));

pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = ColorBits;
pfd.cRedBits = 0;
pfd.cRedShift = 0;
pfd.cGreenBits = 0;
pfd.cGreenShift = 0;
pfd.cBlueBits = 0;
pfd.cBlueShift = 0;
pfd.cAlphaBits = 0;
pfd.cAlphaShift = 0;
pfd.cAccumBits = 0;
pfd.cAccumRedBits = 0;
pfd.cAccumGreenBits = 0;
pfd.cAccumBlueBits = 0;
pfd.cAccumAlphaBits = 0;
pfd.cDepthBits = DepthBits;
pfd.cStencilBits = StencilBits;
pfd.cAuxBuffers = 0;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.bReserved = 0;
pfd.dwLayerMask = 0;
pfd.dwVisibleMask = 0;
pfd.dwDamageMask = 0;

int PixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC,PixelFormat, &pfd);

hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);

ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);

ReSizeGLScene(Width, Height);

glClearColor(0.0f, 0.0f, 0.5f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

SwapBuffers(hDC);
}



void wndDestroyWindow(void)
{
ChangeDisplaySettings(NULL, 0);
ShowCursor(TRUE);

wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
hRC = NULL;

ReleaseDC(hWnd, hDC);
hDC = NULL;

DestroyWindow(hWnd);
hWnd=NULL;

UnregisterClass("OpenGL", hInstance);
hInstance = NULL;
}





Edited by - Shag on November 14, 2001 3:17:26 PM

Share this post


Link to post
Share on other sites