Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: vbos and GLSL

  1. #1
    Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    vbos and GLSL

    Anyone know offhand if anything special is needed to set up vbos for sending to a vertex shader? I've got the following code:
    Code :
    void test()
    {
    //	glUseProgramObjectARB(NodeProgram);
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glDrawElements(GL_LINES, ELEMENTS*24, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
    	glDisableClientState(GL_VERTEX_ARRAY);
    }
    Runs fine, but if I try to use the vertex shader instead, I get a black screen. The vertex shader in question is just:
    Code :
    void main()
    {
    	gl_Position = ftransform();
    }
    So nothing special. The vertex shader is set up correctly - I have fairly robust setup code for that. I suspect there is some state I'm not setting that lets the shader know that I'm sending in vbo data, but I couldn't find it in the 1.5 or 2.0 spec, or the extension registry. Anyone know?

    Thanks in advance.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: vbos and GLSL

    No, you donīt have to do anything special, to use VBOs with vertex-shaders.

    However, in your code, you use glDrawElements wrong. The last parameter should be a pointer to an array, which holds indices to the vertices you want to draw. The BUFFER_OFFSET shouldnīt be used there, it is used to setup the vertex-arrays.
    Take another look into the VBO spec to check out how to use it properly.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  3. #3
    Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: vbos and GLSL

    The indices are in a buffer object too. The BUFFER_OFFSET(0) refers to the indices. Like the "Vertex arrays using a mapped buffer object for array data and an unmapped buffer object for indices" example in the vbo spec except I'm using unmapped buffer objects for both vertices and indices. Anyway, like I said it works fine like that without the shader (with buffer object indices). Thanks, though.

  4. #4
    Member Regular Contributor
    Join Date
    Feb 2002
    Location
    Hamburg, Germany
    Posts
    413

    Re: vbos and GLSL

    GLSL does not care where the vertex arrays are defined -> there is no special call to be done when using vbos.
    so your (shown)code is absolutely correct, but:

    what are you actually trying to draw ? you maybe allready drawing it, but can't see it.
    make your background non-black. to see if you draw anything...(back objects on a black screen are hardly visible )
    when you are using shaders, the official opengl-pipeline gets replaced by the vertexprogram or/and fragmentprogram specified in the shader.
    if you don't specifiy any vertex color, you'll get "undefined colors".
    just try setting the vertexcolor in your shader.
    (or simply passthrou the current color...)

    your shader should be:

    void main(void)
    { gl_Position = ftransform;
    gl_FrontColor = gl_Color;
    }

  5. #5
    Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: vbos and GLSL

    I'm an idiot. Thanks AdrianD. I've done that before and completely forgot. I spent an hour or so on that yesterday - no errors anywhere and I couldn't figure out what was wrong. There's something to be said for glClearColor(0.0f, 0.0f, 1.0f, 1.0f).

Posting Permissions

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