- Procedure glInit();
- Begin
- glEnable(GL_TEXTURE_2D);
- glShadeModel(GL_SMOOTH);
- glClearColor(0.0, 0.0, 0.0, 0.5);
- glClearDepth(1.0);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- glStatus.glInit:= True;
- End;
- Procedure glResizeWnd(Width, Height: Integer);
- Begin
- If glStatus.glInit then
- Begin
- If (Height = 0) then Height := 1;
- glViewport(0, 0, Width, Height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- gluPerspective(45.0, Width/Height, 1.0, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity;
- End;
- End;
- Function glNewWindow(Width, Height: Integer; BPP: Integer; Var Fullscreen: Boolean; Window_Title: String): Boolean;
- Var
- wndClass: TWndClass;
- dwStyle: DWORD;
- dwExStyle: DWORD;
- dmScreenSettings: DEVMODE;
- PixelFormat: GLuint;
- h_Instance: HINST;
- pfd: TPIXELFORMATDESCRIPTOR;
- Begin
- glConfig.WindowTitle:= Window_Title;
- h_Instance:= GetModuleHandle(nil);
- ZeroMemory(@wndClass, SizeOf(wndClass));
- With wndClass do
- Begin
- style:= CS_HREDRAW or CS_VREDRAW or CS_OWNDC;
- lpfnWndProc:= @WndProc;
- hInstance:= h_Instance;
- hCursor:= LoadCursor(0, IDC_ARROW);
- lpszClassName:= 'OpenGL';
- End;
- If (RegisterClass(wndClass) = 0) then
- Begin
- MessageBox(0, 'Die Fensterklasse konnte nicht registriert werden!', 'Atomkraft GAU', MB_OK or MB_ICONERROR);
- Result:= False;
- Exit;
- End;
- If Fullscreen then
- Begin
- ZeroMemory(@dmScreenSettings, SizeOf(dmScreenSettings));
- With dmScreenSettings do
- Begin
- dmSize:= SizeOf(dmScreenSettings);
- dmPelsWidth:= Width;
- dmPelsHeight:= Height;
- dmBitsPerPel:= BPP;
- dmFields:= DM_PELSWIDTH or DM_PELSHEIGHT or DM_BITSPERPEL;
- End;
- If (ChangeDisplaySettings(dmScreenSettings, CDS_FULLSCREEN) = DISP_CHANGE_FAILED) then
- Begin
- MessageBox(0, 'Der Vollbildmodus konnte nicht eingestellt werden!', 'Atomkraft GAU', MB_OK or MB_ICONERROR);
- Fullscreen:= False;
- dwStyle:= WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or WS_CLIPSIBLINGS;
- dwExStyle:= WS_EX_APPWINDOW or WS_EX_WINDOWEDGE;
- End;
- End;
- If (Fullscreen) then
- Begin
- dwStyle:= WS_POPUP or WS_CLIPCHILDREN or WS_CLIPSIBLINGS;
- dwExStyle:= WS_EX_APPWINDOW;
- ShowCursor(False);
- End
- else
- Begin
- dwStyle:= WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or WS_CLIPSIBLINGS;
- dwExStyle:= WS_EX_APPWINDOW or WS_EX_WINDOWEDGE;
- End;
- glSystem.h_Wnd:= CreateWindowEx(dwExStyle, 'OpenGL', PChar(glConfig.WindowTitle), dwStyle, 0, 0, Width, Height, 0, 0, h_Instance, nil);
- If glSystem.h_Wnd = 0 then
- Begin
- glCloseWindow;
- MessageBox(0, 'Das Fenster konnte nicht erstellt werden!', 'Atomkraft GAU', MB_OK or MB_ICONERROR);
- Result:= False;
- Exit;
- End;
- InitOpenGL;
- glSystem.h_DC := GetDC(glSystem.h_Wnd);
- If (glSystem.h_DC = 0) then
- Begin
- glCloseWindow;
- MessageBox(0, 'Die Atomkraft konnte nicht initialisiert werden!', 'Atomkraft GAU', MB_OK or MB_ICONERROR);
- Result:= False;
- Exit;
- End;
- With pfd do
- Begin
- nSize:= SizeOf(TPIXELFORMATDESCRIPTOR);
- nVersion:= 1;
- dwFlags:= PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
- iPixelType:= PFD_TYPE_RGBA;
- cColorBits:= BPP;
- cRedBits:= 0; cGreenBits:= 0; cBlueBits:= 0; cAlphaBits:= 0;
- cRedShift:= 0; cGreenShift:= 0; cBlueShift:= 0; cAlphaShift:= 0;
- cAccumBits:= 0; cAccumRedBits:= 0; cAccumGreenBits:= 0; cAccumBlueBits:= 0; cAccumAlphaBits:= 0;
- cDepthBits:= 16;
- cStencilBits:= 0;
- cAuxBuffers:= 0;
- iLayerType:= PFD_MAIN_PLANE;
- bReserved:= 0;
- dwLayerMask:= 0;
- dwVisibleMask:= 0;
- dwDamageMask:= 0;
- End;
- PixelFormat:= ChoosePixelFormat(glSystem.h_DC, @pfd);
- If (PixelFormat = 0) then
- Begin
- glCloseWindow;
- MessageBox(0, 'Es konnte keine unterstützte Auflösung gefunden werden', 'Atomkraft GAU', MB_OK or MB_ICONERROR);
- Result:= False;
- Exit;
- End;
- If (not SetPixelFormat(glSystem.h_DC, PixelFormat, @pfd)) then
- Begin
- glCloseWindow;
- MessageBox(0, 'Die gewählte Auflösung konnte nicht eingestellt werden', 'Error', MB_OK or MB_ICONERROR);
- Result:= False;
- Exit;
- End;
- glSystem.h_RC:= wglCreateContext(glSystem.h_DC);
- If (glSystem.h_RC = 0) then
- Begin
- glCloseWindow;
- MessageBox(0, 'Fehler bei der Initialisierung', 'Atomkraft GAU', MB_OK or MB_ICONERROR);
- Result:= False;
- Exit;
- End;
- ActivateRenderingContext(glSystem.h_DC, glSystem.h_RC);
- If (not wglMakeCurrent(glSystem.h_DC, glSystem.h_RC)) then
- Begin
- glCloseWindow;
- MessageBox(0, 'Fehler bei der Initialisierung', 'Atomkraft GAU', MB_OK or MB_ICONERROR);
- Result:= False;
- Exit;
- End;
- SetTimer(glSystem.h_Wnd, FPS_TIMER, FPS_INTERVAL, nil);
- ShowWindow(glSystem.h_Wnd, SW_SHOW);
- SetForegroundWindow(glSystem.h_Wnd);
- SetFocus(glSystem.h_Wnd);
- glInit;
- glResizeWnd(Width, Height);
- Result:= True;
- glSystem.appStart:= GetTickCount;
- WriteLn(Fullscreen);
- End;