Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: FBOs and OpenGL Extensions

  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    FBOs and OpenGL Extensions

    Well, long time no see PGD! Looks like I found some trouble though and after a few days of googling in the dark nothing seems to have solved my problem(s) while implementing some FBO goodness in OpenGl.

    Issue number 1:
    On my desktop (ATI 5750 w/ fglrx and mint 11 64 bit) fpc spits out things that look like this:
    Code:
    FrameBuffer.pas(38,37) Error: Identifier not found "GL_FRAMEBUFFER"
    which is unnafected by whether I do
    Code:
    glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
    or
    Code:
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    which doest happen on my laptop (Intel GMA 4500MHD) which is weird. I tried downgrading FPC from 2.6.0 to 2.4.4 with an "apt-get --purge fpc fp-*" but no luck, apparently fpc denies all existence of GL_FrameBuffer O.o As to why, I have no clue since I put gl, glu and glext under the uses section...

    Issue number 2:
    Once I compield it on my laptop with the intel card there were no issues, until I ran it in GDB which is convinced that
    Code:
    glGenFrameBuffersEXT(1, @FrameBufferID);
    as well as
    Code:
    glGenFrameBuffers(1, @FrameBufferID);
    crashes the program and doesnt identify a cause other than:
    Code:
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    Cannot find new threads: generic error
    Anyone have any ideas as to what I should hit up next? I'm totally lost on this one....
    Thanks.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #2
    Code:
    FrameBuffer.pas(38,37) Error: Identifier not found "GL_FRAMEBUFFER"
    This is simple compiler error. You are using something that's not found in the namespace. Check that you have right OpenGL header unit in the uses list, and that GL_FRAMEBUFFER is defined there at interface section. Check that header version is same on both computers.

    The above might solve your second problem, but if it doesn't, make sure that header has initialized those functions (glGenFrameBuffers...).
    (Also you need to have a render context ready.)

  3. #3
    Quote Originally Posted by code_glitch View Post
    Issue number 2:
    Once I compield it on my laptop with the intel card there were no issues, until I ran it in GDB which is convinced that
    Code:
    glGenFrameBuffersEXT(1, @FrameBufferID);
    as well as
    Code:
    glGenFrameBuffers(1, @FrameBufferID);
    crashes the program and doesnt identify a cause other than:
    Code:
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    Cannot find new threads: generic error
    Anyone have any ideas as to what I should hit up next? I'm totally lost on this one....
    Thanks.
    I'm guessing that you have something like this in your main FP program code?

    Code:
      {$IFDEF UNIX}{$IFDEF UseCThreads}
      cthreads,
      {$ENDIF}{$ENDIF}
    If not, this might help...

    Just a thought

  4. #4
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Thanks for all the fast replies and sorry for this late one, I just got off the phone from BT whom now admit the line fault was their doing efter an hour of 'your extension wiring is faulty and is not done by BT...' when I've got the modem hooked into their test socket.... Anyway, I digress.

    User137: Thats what baffled me: the opengl headers come from the same package and are thus identical on both machines - why they differ is beyond me O.o

    Paul: Yes, the glGenFrameBuffers() is in the main program code and you're right in including cthreads as it is a common unit often ommited form some code that causes issues later. However, in this case its inclusion seems to have no effect and the behaviour GDB reported earlier continues to occur.

    After now 5 days of tweaking this and searching high and low I've found that in C/C++ and other such languages, glGenFrameBuffers is a pointer and must be set to the actual procedure. Is this the case with the header files in fpc? And if so does anyone have any ideas where I might find some example code/documentation?

    Thanks
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  5. #5
    I use dglOpenGL headers. Some say fpc headers are outdated. Additional bonus is that dglOpenGL works for Delphi and fpc.

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Speaking of "outdated," aren't FBOs supposed to be obsolete with the newest version of OpenGL? At least that's what I've been told not too long ago.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    I must admit to having heard something similar to you WILL though my issue with a lot of the new OpenGl stuff is that a lot of computers I use are knocking on 3 years of age and although all but one are intel GMA chips the standard of the new OpenGl implementations seems to vary greatly (*cough*ATI*cough*). Oh, and I still havent come accross much in the way of tutorials and native FPC support (I'm lazy when it comes to unit hunting )

    Of course if anyone has any pointers in these departments all suggestions are welcome Especially since I'm not getting any luck on this front...
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  8. #8
    Quote Originally Posted by code_glitch View Post
    Thats what baffled me: the opengl headers come from the same package and are thus identical on both machines - why they differ is beyond me O.o
    Did you actually verify that they differ? It should propably be mentioned in the beginning of header. Do you have same FPC and Lazarus versions on both computers?

  9. #9
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Its the fact they DONT differ across platforms (their md5sums are the same - to be expected if you install from the same tarball ) and yet throw up different errors which baffles me. I also happen to have no lazaruses and the fpc version is exactly the same - 2.6.0 - (probably due to them being installed from the same tarball )

    And to be on the same side I did do a
    Code:
    sudo du -ah / | grep -i /gl.ppu
    Just to make sure there were any other gl.ppu headers anywhere There werent...

    My issue with OpenGl 3 is the the GMA4500MHD chips in one of my laptops is OpenGl 2.1 only which happens to be overly popular in england at the moment since we've now had about 3 years of intel fever where every ad break would have at least one advert from currys and pc world advertising the fact that a 'intel graphics' are better -_-
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  10. #10
    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 1 of 3 123 LastLast

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
  •