bool bOGL_Core::bCreateWindow(const char *title, int width, int height, int bits, bool fullscr)
{
// Get a microsoft windows window class
WNDCLASS wc;
// Styles for window class
DWORD dwExStyle;
DWORD dwStyle;
// Set up window rect
RECT WindowRect;
WindowRect.left = long(0);
WindowRect.right = long(width);
WindowRect.top = long(0);
WindowRect.bottom = long(height);
// Toggle fullscreen flag
fullscreen = fullscr;
// Set the window class properties
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Move, And Own DC For Window
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don''t Want A Menu
wc.lpszClassName = "baros"; // Set The Class Name
// check
if(!hInstance)
{
bOGL_Info::msgError("Did not get a handle.", "INIT ERROR");
bOGL_Info::ReportError(bINIT_ERROR);
bOGL_Info::ShowSysErr();
return false;
}
// Register the class
if(!RegisterClass(&wc))
{
bOGL_Info::msgError("Could not register window class.", "INIT ERROR");
bOGL_Info::ReportError(bINIT_ERROR);
bOGL_Info::ShowSysErr();
return false;
}
// Set fullscreen if needed
if(fullscreen)
{
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory''s Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
// Change the display
if((ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL))
{
// Not able to set fullscreen, ask for window
if(bOGL_Info::qryWarning("Could not set fullscreen, use windowed\nmode instead?", "bOGL"))
{
fullscreen = false;
}
else
{
// print error
bOGL_Info::msgWarning("Program will now close", "bOGL");
bOGL_Info::ReportError(bINIT_ERROR);
// return false
return false;
}
}
}
// Check again for fullscreen and complete registration
if(fullscreen)
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle = WS_OVERLAPPEDWINDOW; // Windows Style
}
// Adjust the rect according to our settings
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
// Create the window
hWnd = CreateWindowEx(dwExStyle, // Extended Style For The Window
"baros", // Class Name
"fu", // Window Title
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN | // Required Window Style
dwStyle, // Selected Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Adjusted Window Width
WindowRect.bottom-WindowRect.top, // Calculate Adjusted Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL); // Don''t Pass Anything To WM_CREATE
// Check
if (!hWnd)
{
bKillWindow();
bOGL_Info::msgError("Could not create window", "INIT ERROR");
bOGL_Info::ReportError(bINIT_ERROR);
bOGL_Info::ShowSysErr();
return false;
}
// Get a suitable pixel format
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
// Get a device context for the window
if(!(hDC = GetDC(hWnd)))
{
bKillWindow();
bOGL_Info::msgError("Could not get a Device Context (hDC).", "INIT ERROR");
bOGL_Info::ReportError(bINIT_ERROR);
bOGL_Info::ShowSysErr();
return false;
}
// Get and set the pixel format
if (!(PixelFormat=ChoosePixelFormat(bOGL_Core::hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
{
bOGL_Core::bKillWindow(); // Reset The Display
MessageBox(NULL,"Can''t Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
bOGL_Info::ShowSysErr();
return false; // Return FALSE
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
{
bOGL_Core::bKillWindow(); // Reset The Display
MessageBox(NULL,"Can''t Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
bOGL_Info::ShowSysErr();
return false; // Return FALSE
}
// Create a rendering context
if(!wglMakeCurrent(hDC, hRC))
{
bKillWindow();
bOGL_Info::msgError("Could not get a Rendering Context (hRC).", "INIT ERROR");
bOGL_Info::ReportError(bINIT_ERROR);
bOGL_Info::ShowSysErr();
return false;
}
// Set the focus for the window
ShowWindow(hWnd,SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To The Window
bOGL_Core::ResizeWindow(width, height); // Set Up Our Perspective GL Screen
// All done
return true;
}
Lesson 1 problem
I have a problem with the first lesson, as I cannot create a OGL window. The problem is right after the CreateWindowEx function, but I will post my entire window creation method (yes method, class member).
The GetLastError returns 1813 which is defined as "The specified resource type cannot be found in the image file. " or ERROR_RESOURCE_TYPE_NOT_FOUND.
I wonder why it is that I cannot create a window. Just for your information, I tried checking my class registration and the loading of icon/cursor and it gave no error.
If anyone knows what the error might be I''d love to hear it.
-----------------------------
Final Frontier Trader
-----------------------------Final Frontier Trader
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement