Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Map Editor

NIN666NIN666 Member Posts: 90
[b][red]This message was edited by NIN666 at 2003-3-26 12:27:40[/red][/b][hr]
[b][red]This message was edited by NIN666 at 2003-3-26 12:27:10[/red][/b][hr]
Ok, I am making a game but I am having a problem with the map editor. I open a main window here:
[code]
HWND hWnd;
HDC hDC;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left= (long)200;
WindowRect.right= (long)800;
WindowRect.top= (long)150;
WindowRect.bottom= (long)600;

hInstance = GetModuleHandle(NULL);

wc.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_SAVEBITS;
wc.lpfnWndProc = (WNDPROC) MainWnd;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground= (HBRUSH) COLOR_APPWORKSPACE;
wc.lpszMenuName = "MyMenu";
wc.lpszClassName= "Map Editor";

if (!RegisterClass(&wc))
{
MessageBox(NULL,"Failed To register the window class.","INIT ERROR",MB_OK|MB_ICONINFORMATION);
ChangeDisplaySettings(NULL,0);
return false; //Returns false
}



dwExStyle = WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;

//adjust window to true requested size
AdjustWindowRectEx(&WindowRect,dwStyle,false,dwExStyle);

//Create The Window
if (!(hWnd=CreateWindowEx(dwExStyle,
"Map Editor",
"Europa3D Map Editor",
dwStyle|
WS_CLIPSIBLINGS|
WS_CLIPCHILDREN,
0,0,
WindowRect.right-WindowRect.left,
WindowRect.bottom-WindowRect.top,
NULL,
NULL,
hInstance,
NULL)))

{
MessageBox(NULL,"Window Creation Error","INIT ERROR",MB_OK|MB_ICONINFORMATION);
return false;
}

if (!(hDC=GetDC(hWnd)))
{
MessageBox(NULL,"Cant Create a Device Context.","INIT ERROR",MB_OK|MB_ICONINFORMATION);
return false;
}

ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd); Focus to the window
[/code]
That works fine everytime, now I try to open an OpenGL compatible window, which fails, here is the code for that:
[code]
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_SAVEBITS;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground= NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName= "OpenGL";

if (!RegisterClass(&wc))
{
MessageBox(NULL,"Failed To register the window class.","INIT ERROR",MB_OK|MB_ICONINFORMATION);
ChangeDisplaySettings(NULL,0);
return false;
}


dwExStyle = WS_EX_MDICHILD;

AdjustWindowRectEx(&WindowRect,WS_CLIPSIBLINGS,false,dwExStyle);

//Create The Window
//THIS FAILS EVERY SINGLE TIME!
if (!(hWnd=CreateWindowEx(dwExStyle,
"OpenGLWin",
title,
WS_CHILD,
100,100,
WindowRect.right-WindowRect.left,
WindowRect.bottom-WindowRect.top,
PWnd,
NULL,
hInstance,
NULL)))

{
DestroyWin();
MessageBox(NULL,"Window Creation Error","WINDOW ERROR",MB_OK|MB_ICONINFORMATION);
ChangeDisplaySettings(NULL,0);
return false;
}

static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|
PFD_SUPPORT_OPENGL|
PFD_GENERIC_ACCELERATED|
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
bpp,
0,0,0,0,0,0,
16,
0,
0,
0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};

if (!(hDC=GetDC(hWnd)))
{
DestroyWin();
MessageBox(NULL,"Cant Create a GL Device Context.","INIT ERROR",MB_OK|MB_ICONINFORMATION);
ChangeDisplaySettings(NULL,0);
return false; //RETURN FALSE
}

if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
{
DestroyWin();
MessageBox(NULL,"Cant find a suitable pixel format","ERROR",MB_OK|MB_ICONINFORMATION);
ChangeDisplaySettings(NULL,0);
return false;
}

if (!SetPixelFormat(hDC,PixelFormat,&pfd))
{
DestroyWin();
MessageBox(NULL,"Can't set the pixel format","ERROR",MB_OK|MB_ICONINFORMATION);
ChangeDisplaySettings(NULL,0);
return false;
}

if (!(hRC=wglCreateContext(hDC)))
{
DestroyWin();
MessageBox(NULL,"Unable to create an OpenGL rendering context(RC)","ERROR",
MB_OK|MB_ICONINFORMATION);
ChangeDisplaySettings(NULL,0);
return false;
}

if (!wglMakeCurrent(hDC,hRC))
{
DestroyWin();
MessageBox(NULL,"Can't activate the OpenGL rendering Context",
"ERROR",MB_OK|MB_ICONINFORMATION);
ChangeDisplaySettings(NULL,0);
return false;
}[/code]
That fails every single time, this is the function prototype:
[code]bool glWindow::CreateWin(char* title, int width, int height, int bpp, WNDPROC WndProc, HWND PWnd);[/code]

So I was wondering if anyone could tell me why my OpenGL window will never init right. If you can help, great, if not that's ok, I can edit maps by hand. Thanks.






Sign In or Register to comment.