- function glCreateWnd(Width, Height : Integer; PixelDepth, TextureDepth : Integer) : Boolean;
- var
- wndClass : TWndClass; // Window class
- dwStyle : DWORD; // Window styles
- dwExStyle : DWORD; // Extended window styles
- PixelFormat : GLuint; // Settings for the OpenGL rendering
- h_Instance : HINST; // Current instance
- pfd : TPIXELFORMATDESCRIPTOR; // Settings for the OpenGL window
- begin
- InitOpenGL;
- SCREEN_WIDTH := Width;
- SCREEN_HEIGHT := Height;
- AddToConsole('--- Creating Window ---');
- h_Instance := GetModuleHandle(nil); //Grab An Instance For Our Window
- ZeroMemory(@wndClass, SizeOf(wndClass)); // Clear the window class structure
- with wndClass do begin // Set up the window class
- style := CS_HREDRAW or // Redraws entire window if length changes
- CS_VREDRAW or // Redraws entire window if height changes
- CS_OWNDC; // Unique device context for the window
- lpfnWndProc := @WndProc; // Set the window procedure to our func WndProc
- hInstance := h_Instance;
- hCursor := LoadCursor(0, IDC_ARROW);
- hIcon := LoadIcon(hInstance, 'MAINICON');
- lpszClassName := 'OpenGL';
- end;
- if (RegisterClass(wndClass) = 0) then begin// Attemp to register the window class
- AddToConsole('Failed to register the window class!');
- Result := False;
- Exit
- end;
- AddToConsole('Registered Class...');
- //ChangeToFullScreen;
- // If we are still in fullscreen then
- if (Fullscreen) then begin
- dwStyle := WS_POPUP or // Creates a popup window
- WS_CLIPCHILDREN // Doesn't draw within child windows
- or WS_CLIPSIBLINGS; // Doesn't draw within sibling windows
- dwExStyle := WS_EX_APPWINDOW; // Top level window
- //ShowCursor(false); // Turn of the cursor (gets in the way)
- end
- else begin
- dwStyle := WS_OVERLAPPEDWINDOW or // Creates an overlapping window
- WS_CLIPCHILDREN or // Doesn't draw within child windows
- WS_CLIPSIBLINGS; // Doesn't draw within sibling windows
- dwExStyle := WS_EX_APPWINDOW or // Top level window
- WS_EX_WINDOWEDGE; // Border with a raised edge
- //ShowCursor(false); // Turn of the cursor (gets in the way)
- end;
- // Attempt to create the actual window
- h_Wnd := CreateWindowEx(dwExStyle, // Extended window styles
- 'OpenGL', // Class name
- WND_TITLE, // Window title (caption)
- dwStyle, // Window styles
- 0, 0, // Window position
- Width, Height, // Size of window
- 0, // No parent window
- 0, // No menu
- h_Instance, // Instance
- nil); // Pass nothing to WM_CREATE
- if h_Wnd = 0 then begin
- AddToConsole('Unable to create window!');
- glKillWnd(False); // Undo all the settings we've changed
- Result := False;
- Exit;
- end;