Results 1 to 4 of 4

Thread: Some OpenGL functions do not load proprerly.

  1. #1

    Some OpenGL functions do not load proprerly.

    Hey guy's

    I'm trying to learn OpenGL, but it's not going as fast as i hoped for. I want to render a quad using a VBO. I made the following class:

    [pascal]
    TVertexBuffer = class
    private
    fVBOVertices: TGLUInt;
    fVBONormals: TGLUInt;
    public
    fVertices: array of TGLVector3f;
    fNormals: array of TGLVector3f;

    constructor Create();
    destructor Destroy(); override;

    procedure Update();
    procedure Render();
    end;

    { TVertexBuffer }
    constructor TVertexBuffer.Create;
    begin
    glGenBuffersARB(1, @fVBOVertices);
    glGenBuffersARB(1, @fVBONormals);
    end;

    destructor TVertexBuffer.Destroy;
    begin
    glDeleteBuffersARB(1, @fVBOVertices);
    glDeleteBuffersARB(1, @fVBONormals);

    inherited;
    end;

    procedure TVertexBuffer.Render;
    begin
    //Enable client states
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    //bind vertices
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, fVBOVertices);
    glVertexPointer(3, GL_FLOAT, 0, nil);

    //bind normals
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, FVBONormals);
    glNormalPointer(GL_FLOAT, 0, nil);

    //Render it now!
    glDrawArrays(GL_TRIANGLES,0,Length(fVertices)-1);

    //Disable client states
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    end;

    procedure TVertexBuffer.Update;
    begin
    //load vertices
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, fVBOVertices);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, Length(fVertices)*sizeof(TGLVector3f),
    fVertices, GL_STATIC_DRAW_ARB);

    //Load normals
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, FVBONormals);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, Length(fNormals)*sizeof(TGLVector3f),
    fNormals, GL_STATIC_DRAW_ARB);

    SetLength(fVertices,0);
    SetLength(fNormals,0);
    end;

    [/pascal]

    It's simple. User fills the vertex and normal array's and calls update. The VBO is rendered every frame.

    But as soon as i try to call a routine like glGenBuffersARB, an AV pops up with adress 00000000. I know this means the function-variable is not assigned.

    I'm using the latest version of the dglOpenGL.pas header and the very first thing i do in my application is this:

    [pascal]
    InitOpenGL();
    ReadImplementationProperties;
    ReadExtensions;
    [/pascal]

    ReadExtensions calls Read_GL_ARB_buffer_object which loads the routines i'm using here. But they appear not to be assigned. I even called glGetString to get a list of the extensions, and GL_ARB_vertex_buffer_object is on that list. But somehow, the routines don't seem te be assigned. :cry:

    What is happening here? I have a nice 8600GT with fairly recent drivers. How come i can't create/use any VBO's?

    Can anyone help me?

    Thanks.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2

    Some OpenGL functions do not load proprerly.

    What delphi are you using? The latest headers give problems with Delphi 2009 and unicode.

  3. #3

    Some OpenGL functions do not load proprerly.

    I just discovered something that might have caused this.

    I was calling:

    [pascal]
    ReadImplementationProperties;
    ReadExtensions;
    [/pascal]

    while no rendercontext was activated. glProcedure, who assigns adresses to all the procvars failed miserably. So tons of procs weren't initialized.

    I tried to manualy load the functions by using:

    [pascal]
    type
    PFNGLBINDBUFFERARBPROC = procedure(target: GLenum; buffer: GLuint); stdcall;
    PFNGLDELETEBUFFERSARBPROC = procedure(n :GLsizei; const buffers: PGLuint); stdcall;
    PFNGLGENBUFFERSARBPROC = procedure(n :GLsizei; buffers: PGLuint); stdcall;
    PFNGLBUFFERDATAARBPROC = procedure(target: GLenum; size: integer; const data: pointer; usage: GLenum); stdcall;

    const
    GL_ARRAY_BUFFER_ARB = $8892;
    GL_STATIC_DRAW_ARB = $88E4;

    var
    glGenBuffersARB: PFNGLGENBUFFERSARBPROC = nil;
    glBindBufferARB: PFNGLBINDBUFFERARBPROC = nil;
    glBufferDataARB: PFNGLBUFFERDATAARBPROC = nil;
    glDeleteBuffersARB: PFNGLDELETEBUFFERSARBPROC = nil;

    {....}
    //PROCVAR ASSIGNMENTS
    glGenBuffersARB := wglGetProcAddress('glGenBuffersARB');
    glBindBufferARB := wglGetProcAddress('glBindBufferARB');
    glBufferDataARB := wglGetProcAddress('glBufferDataARB');
    glDeleteBuffersARB := wglGetProcAddress('glDeleteBuffersARB');
    [/pascal]

    And it worked, but it's a messy workaround. During the last tests i outcommented the procvar-assignments and continued debugging. I should have outcommented all the code shown above, because the procedure-variables hid the variables in dglOpenGL.pas, because they had the same name. The variables in my app never got initialized, so the AV kept popping up. Basicly i created my own bug by not cleaning up the mess. :shock:
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  4. #4

    Some OpenGL functions do not load proprerly.

    personally i call

    ReadImplementationProperties;
    ReadExtensions

    after i have initializedmy window and context.

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
  •