Кто-нибудь поделится компонетом с OpenGL или классом-оберткой для создания OpenGL контекста с поддержкой сглаживания (FSAA)Я написал свой класс который устанавливает макс сглаживание поддерживаемое видеокартой столкнулся с множеством проблем 1)На некоторых карта от NVidia контекст не создается если в настройках стоит Сглаживание = Управляемое от приложения 2)Выдает Floating point overflow на некоторых ATI картах 3)Не знаю как убить OpenGL контекст из самого контрола - в деструкторе Handle на котором создается контекст не существует и выдается AV при удалении текстур. По идее это надо оверрайдить DestroyWindowHandle - но процедура почему-то не вызывается Мой код: | Код |
во временном окне создаю контекст так: procedure SetPF(DC: HDC); var nPixelFormat: Integer; pfd: TPixelFormatDescriptor; err: Integer; begin
// Initialise the form's DC for OpenGL, and setup a palette. FillChar(pfd, SizeOf(pfd), 0); with pfd do begin nSize := SizeOf(TPixelFormatDescriptor); nVersion := 1; dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL; dwFlags := dwFlags or PFD_DOUBLEBUFFER; iPixelType := PFD_TYPE_RGBA; cColorBits := 24; cAlphaBits := 0; cDepthBits := 0; cStencilBits := 0; iLayerType := PFD_MAIN_PLANE; end;
nPixelFormat := ChoosePixelFormat(DC, @pfd); if nPixelFormat = 0 then begin err := GetLastError; raise Exception.Create('Couldn''t set pixel format for temp window - ' + IntToStr(Err)); end;
if not SetPixelFormat(DC, nPixelFormat, @pfd) then begin err := GetLastError; raise Exception.Create('Couldn''t set pixel format for temp window - ' + IntToStr(Err)); end;
end;
procedure TGLContext.CreateRC; var TW: TTempGLWindow; DisplayBPP: Integer;
function GetDisplayBPP: Integer; var DC: HDC; begin DC := CreateDC('DISPLAY', nil, nil, nil); if DC <> 0 then begin try Result := GetDeviceCaps(DC, BITSPIXEL) * GetDeviceCaps(DC, PLANES); finally DeleteDC(DC); end; end else Result := 0; end;
begin GLWriteLog('Creating OpenGL context');
TW := TTempGLWindow.CreateNew(Application, 0); try ReadImplementationProperties; ReadExtensions; GLWriteLog('Vendor: ' + glGetString(GL_VENDOR)); GLWriteLog('Renderer: ' + glGetString(GL_RENDERER)); GLWriteLog('Version: ' + glGetString(GL_VERSION)); GLWriteLogExt('WGL_ARB_pixel_format',WGL_ARB_pixel_format); GLWriteLogExt('GL_ARB_multisample',GL_ARB_multisample); finally TW.Free; end;
FDC := GetDC(FControlHandle); if FDC = 0 then begin GLWriteLog('Can not get descriptor of rendering window'); Exit; end; //Âûáèðàåì ïîäõîäÿùèé ôîðìàò ïèêñåëÿ DisplayBPP := GetDisplayBPP; if ARBFSAA and GL_ARB_multisample then begin if not SetDCPixelFormat(DisplayBPP, 24, 8) then if not SetDCPixelFormat(DisplayBPP, 24, 4) then if not SetDCPixelFormat(DisplayBPP, 24, 2) then if not SetDCPixelFormat(DisplayBPP, 24, 0) then if not SetDCPixelFormat(DisplayBPP, 16, 0) then begin GLWriteLog('Can not set up pixel format'); Exit; end; end else if not SetDCPixelFormat(DisplayBPP, 24, 0) then if not SetDCPixelFormat(DisplayBPP, 16, 0) then begin GLWriteLog('Can not set up pixel format'); Exit; end;
if MemoryContext then SetPalette(FDC);
FGLRC := wglCreateContext(FDC); if FGLRC=null then begin GLWriteLog('Can not create OpenGL context'); Exit; end; FRCAvailable := True; MakeCurrent; GLWriteLog('OpenGL context has been created');
ReadExtensions; ReadImplementationProperties; MaxTextureSize := MaxTextureSize; GLWriteLog('Max texture size = '+IntToStr(MaxTextureSize));
if not (GL_VERSION_1_0) then MessageDlg('There is no OpenGL library on the computer', mtError, [mbOK], 0);
if not (GLU_VERSION_1_1) then MessageDlg('There is no GLU library on the computer', mtError, [mbOK], 0);
SetDefaultOptions;
TextManager.CreateRC(FDC); Model.ContextCreated; Background.ContextCreated; MtList.ContextCreated; {$IFDEF 3DCHECKGLERROR} CheckOpenGLError; {$ENDIF} end;
|
|