Jump to content
  • Advertisement
Sign in to follow this  
GogetaX

OpenGL Delphi, glWindow Creation problem

This topic is 3596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, for some reason, i cant create an gl window.. i see that it cant Create a OpenGL rendering context for some reason..
program Project2;

uses OpenGL,Windows,Messages;

var WinInterface:HINST;
  WinClass:TWndClass;
  OGLWindow:HINST;
  dwstyle : DWORD;
  dwExstyle : DWORD;
  pfd : TPIXELFORMATDESCRIPTOR;
  PixelFormat : GLuint;
  h_DC   : HDC;
  h_RC   : HGLRC;



function WndProc(hWnd: HWND; Msg: UINT;  wParam: WPARAM;  lParam: LPARAM): LRESULT; stdcall;
begin
//
end;


begin
WinInterface := GetModuleHandle(Nil);
ZeroMemory(@WinClass,SIZEOF(WinClass));

with WinClass do begin
  style := CS_HREDRAW or CS_VREDRAW or CS_OWNDC;
  lpfnWndProc := @WndProc;
  hInstance := winInterface;
  hCursor := loadCursor(0,IDC_Arrow);
  lpszClassName := 'OpenGL';
end;

if RegisterClass(WinClass)=0 then begin
  MessageBox(0,'Could not create window..','Error',MB_OK or MB_ICONERROR);
  Exit;
end;

dwstyle := WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or WS_CLIPSIBLINGS;
dwExstyle := WS_EX_APPWINDOW or WS_EX_WINDOWEDGE;
OGLWindow := CreateWindowEx(dwExstyle,'OpenGL','Goga''s Learning..',dwstyle,
                            0,0,800,600,0,0,WinInterface,nil);

if OGLWindow = 0 then begin
  MessageBox(0,'Could not create window..','Error',MB_OK or MB_ICONERROR);
  Exit;
end;

with pfd do begin
    nSize           := SizeOf(TPIXELFORMATDESCRIPTOR); // Size Of This Pixel Format Descriptor
    nVersion        := 1;                    // The version of this data structure
    dwFlags         := PFD_DRAW_TO_WINDOW    // Buffer supports drawing to window
                       or PFD_SUPPORT_OPENGL // Buffer supports OpenGL drawing
                       or PFD_DOUBLEBUFFER;  // Supports double buffering
    iPixelType      := PFD_TYPE_RGBA;        // RGBA color format
    cColorBits      := 32;           // OpenGL color depth
    cRedBits        := 0;                    // Number of red bitplanes
    cRedShift       := 0;                    // Shift count for red bitplanes
    cGreenBits      := 0;                    // Number of green bitplanes
    cGreenShift     := 0;                    // Shift count for green bitplanes
    cBlueBits       := 0;                    // Number of blue bitplanes
    cBlueShift      := 0;                    // Shift count for blue bitplanes
    cAlphaBits      := 0;                    // Not supported
    cAlphaShift     := 0;                    // Not supported
    cAccumBits      := 0;                    // No accumulation buffer
    cAccumRedBits   := 0;                    // Number of red bits in a-buffer
    cAccumGreenBits := 0;                    // Number of green bits in a-buffer
    cAccumBlueBits  := 0;                    // Number of blue bits in a-buffer
    cAccumAlphaBits := 0;                    // Number of alpha bits in a-buffer
    cDepthBits      := 16;                   // Specifies the depth of the depth buffer
    cStencilBits    := 0;                    // Turn off stencil buffer
    cAuxBuffers     := 0;                    // Not supported
    iLayerType      := PFD_MAIN_PLANE;       // Ignored
    bReserved       := 0;                    // Number of overlay and underlay planes
    dwLayerMask     := 0;                    // Ignored
    dwVisibleMask   := 0;                    // Transparent color of underlay plane
    dwDamageMask    := 0;
end;
h_DC := GetDC(OGLWindow);

if (h_DC = 0) then
  begin
    MessageBox(0,'Could not create window..','Error',MB_OK or MB_ICONERROR);
    Exit;
  end;

PixelFormat := ChoosePixelFormat(h_DC,@pfd);

if PixelFormat = 0 then begin
  MessageBox(0,'Could not create window.. PixelFormat','Error',MB_OK or MB_ICONERROR);
  Exit;
end;

h_RC := wglCreateContext(h_DC); `PROBLEM IS HERE!!
if H_RC = 0 then begin
  MessageBox(0,'Could not create window.. H_RC','Error',MB_OK or MB_ICONERROR);
  Exit;
end;

if wglMakeCurrent(h_DC,H_RC)=False then begin
  MessageBox(0,'Could not create window.. wglMakeCurrent','Error',MB_OK or MB_ICONERROR);
  Exit;
end;



end.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!