#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")
bool active = TRUE;
bool keys[256];
HGLRC hRC = NULL;
HDC hDC = NULL;
HWND hWnd = NULL;
HINSTANCE hInstance;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void killWindow(void)
{
ChangeDisplaySettings(NULL, 0);
ShowCursor(TRUE);
if(hRC)
{
if(!wglMakeCurrent(NULL, NULL))
{
MessageBox(NULL, "Release Of DC And RC Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
}
if(!wglDeleteContext(hRC))
{
MessageBox(NULL, "Release Rendering Context Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
}
hRC = NULL;
}
if(hDC && !ReleaseDC(hWnd, hDC))
{
MessageBox(NULL, "Release Device Context Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hDC = NULL;
}
if(hWnd && !DestroyWindow(hWnd))
{
MessageBox(NULL, "Could Not Release hWnd", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hWnd = NULL;
}
if(!UnregisterClass("Space", hInstance))
{
MessageBox(NULL, "Could Not Unregister Class", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hInstance = NULL;
}
}
bool createWindow()
{
WNDCLASS Window;
int pixelFormat;
DWORD dwExStyle;
hInstance = GetModuleHandle(NULL);
Window.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
Window.lpfnWndProc = (WNDPROC) WndProc;
Window.cbClsExtra = 0;
Window.cbWndExtra = 0;
Window.hInstance = hInstance;
Window.hIcon = LoadIcon(NULL, IDI_WINLOGO);
Window.hCursor = LoadCursor(NULL, IDC_ARROW);
Window.hbrBackground = NULL;
Window.lpszMenuName = NULL;
Window.lpszClassName = "Space";
if(!RegisterClass(&Window))
{
MessageBox(NULL, "Failed To Register The Window Class", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
dwExStyle = WS_EX_APPWINDOW;
ShowCursor(FALSE);
if(!(hWnd = CreateWindowEx(dwExStyle,
"Space",
"Space Quest",
WS_POPUP,
0, 0,
800, 600,
NULL,
NULL,
hInstance,
NULL)))
{
killWindow();
MessageBox(NULL, "Window Creation Error", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
DEVMODE newSettings;
EnumDisplaySettings(NULL, 0, &newSettings);
newSettings.dmPelsWidth = 800;
newSettings.dmPelsHeight = 600;
newSettings.dmBitsPerPel = 16;
newSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&newSettings, CDS_FULLSCREEN)
!= DISP_CHANGE_SUCCESSFUL)
return FALSE;
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
16,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if (!(hDC = GetDC(hWnd)))
{
killWindow();
MessageBox(NULL, "Can't Create A GL Device Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
if (!(pixelFormat = ChoosePixelFormat(hDC, &pfd)))
{
killWindow();
MessageBox(NULL, "Can't Find A Suitable PixelFormat", "ERROR",MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
if(!SetPixelFormat(hDC, pixelFormat, &pfd))
{
killWindow();
MessageBox(NULL, "Can't Set The PixelFormat", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
if (!(hRC = wglCreateContext(hDC)))
{
killWindow();
MessageBox(NULL, "Can't Create A GL Rendering Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
if(!wglMakeCurrent(hDC, hRC))
{
killWindow();
MessageBox(NULL, "Can't Activate The GL Rendering Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_ACTIVATE:
{
if (!HIWORD(wParam))
{
active = TRUE;
}
else
{
active = FALSE;
}
return 0;
}
case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}
case WM_KEYDOWN:
{
keys[wParam] = TRUE;
return 0;
}
case WM_KEYUP:
{
keys[wParam] = FALSE;
return 0;
}
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
MSG msg;
bool escape = FALSE;
if (!createWindow())
{
return 0;
}
while(!escape)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
escape = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
if (active)
{
if (keys[VK_ESCAPE])
{
escape = TRUE;
}
else
{
SwapBuffers(hDC);
}
}
}
}
killWindow();
return (msg.wParam);
}
Whats wrong with this?
OK, i am new to game programming and win32 programming and i have created a basecode but its got a but in it i cant figure out for the life of me, i mean i just have it go to full screen and thats ALL but it does weird thing..
heres a copy of the exe: esc closes it..
http://www.guzba.com/openglerror/Space.exe
and heres the source..
or since that isnt formatted you can download the c++ file here:
http://www.guzba.com/openglerror/sys_win.cpp
thanx.. i have tried changing the height and width and nothing helps.. its crazy lol
[edited by - Guzba on March 18, 2003 6:28:32 PM]
As you''re using OpenGL why dont you get a copy of Nehe''s basecode (available in various flavours) from http://nehe.gamedev.net which will do all of what you''re trying to do for you (includes switching to fullscreen).
I dont want to use his, if i did i would, and i really want to know whats wrong with this because i for the life of me cant find it.. it doesnt make sense
nehe's basecode is available with a tutorial, why dont you read the tutorial? maybe he explains something that you are missing. i havent made my own basecode so this is the most help i can be good luck
,Matt
-= kill one your a murderer, kill thousands your a conquerer =-
[edited by - samosa on March 18, 2003 7:27:38 PM]
,Matt
-= kill one your a murderer, kill thousands your a conquerer =-
[edited by - samosa on March 18, 2003 7:27:38 PM]
i got it figured out, in the CreateWindowEx i had to change WS_POPUP to WS_POPUPWINDOW for some reason lol
The NeHe basecode isn''t alt-tab safe in fullscreen mode, this is probably something you should work out in your basecode (if you did already, sorry, I didn''t read it)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement