Page 2 of 2 FirstFirst 12
Results 11 to 20 of 24

Thread: FBOs and OpenGL Extensions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Well I managed to sort out the weird FPC error... Seems when I upgraded from 2.4.whatever to 2.6.0 the installer didnt change the path for fpc to look for some PPU files and kept using the 2.4.4 files... Nothing a reinstall couldn't fix

    On the other hand, although this now compiles fine, I still cant get it to run - the dglOpenGl headers seem to make no difference (aside from making things run a little faster ). Next stop: porting a C/C++ demo and seeing if that runs. Fun -_-.

    Edit/Update:
    So I wondered if it was the way I was creating my OpenGl context since I do it from the ground up with XLib and GlX, so I headed over to the wiki pages for lazarus and fpc and found their demo program for GLUT which compiles and runs fine out of the box, thus I included the FBO code so it all looks like this:
    Code:
    program firstprogram;
    
    {$mode objfpc}{$H+}
    
    uses
      gl, glu, glut,
      glext;
    
    const
      AppWidth = 640;
      AppHeight = 480;
    
    procedure InitializeGL;
    begin
      glClearColor(0.18, 0.20, 0.66, 0);
    end;
    
    var
        Tex1, FBO, Ren: GLUint;
        Status: GLEnum;
    
    procedure DrawGLScene; cdecl;
    begin
        glGenTextures(1, @Tex1);
        glBindTexture(GL_TEXTURE_2D, Tex1);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        writeln('Tex OK');
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, Nil);
    
        write('Gen FBO... ');
        glGenFramebuffersEXT(1, @FBO);
        write(' OK! ');
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
        writeln('FBO Bound OK!');
    
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, Tex1, 0);
    
        glGenRenderbuffersEXT(1, @Ren);
        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, Ren);
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 256, 256);
    
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, Ren);
    
        status := glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    
      glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
      glutSwapBuffers;
    end;
    
    procedure ReSizeGLScene(Width, Height: Integer); cdecl;
    begin
      if Height = 0 then
        Height := 1;
    
      glViewport(0, 0, Width, Height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity;
      gluPerspective(45, Width / Height, 0.1, 1000);
    
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity;
    end;
    
    procedure GLKeyboard(Key: Byte; X, Y: Longint); cdecl;
    begin
      if Key = 27 then
        Halt(0);
    end;
    
    procedure glutInitPascal(ParseCmdLine: Boolean);
    var
      Cmd: array of PChar;
      CmdCount, I: Integer;
    begin
      if ParseCmdLine then
        CmdCount := ParamCount + 1
      else
        CmdCount := 1;
      SetLength(Cmd, CmdCount);
      for I := 0 to CmdCount - 1 do
        Cmd[I] := PChar(ParamStr(I));
      glutInit(@CmdCount, @Cmd);
    end;
    
    var
      ScreenWidth, ScreenHeight: Integer;
    begin
      glutInitPascal(True);
      glutInitDisplayMode(GLUT_DOUBLE or GLUT_RGB or GLUT_DEPTH);
      glutInitWindowSize(AppWidth, AppHeight);
      ScreenWidth := glutGet(GLUT_SCREEN_WIDTH);
      ScreenHeight := glutGet(GLUT_SCREEN_HEIGHT);
      glutInitWindowPosition((ScreenWidth - AppWidth) div 2, (ScreenHeight - AppHeight) div 2);
      glutCreateWindow('OpenGL Tutorial :: First Program');
    
      InitializeGL;
    
      glutDisplayFunc(@DrawGLScene);
      glutReshapeFunc(@ReSizeGLScene);
      glutKeyboardFunc(@GLKeyboard);
    
      glutMainLoop;
    end.
    And I know this would only work on the first loop but it crashes before then - on glGenFrameBuffersEXT() again which means I must clearly be missing something when I initialize OpenGl or doing something so idiotic I'm overlooking it each time...
    Last edited by code_glitch; 24-07-2012 at 05:07 PM.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •