Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: how to bind two vertex buffers to vertex shader input, as in DirectX

  1. #11
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,101
    Your vertex positions sizes don't match

    Code :
    glVertexAttribPointer(vertexId, 2, GL_FLOAT, GL_FALSE, sizeof(vertices), 0)


    size 2

    Code :
    attribute vec4 vertex;


    size 4

  2. #12
    I did not find any line in my code that binds the VBO to the shader program, is it possible that it's missing, or the code is complete and correct?

  3. #13
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,099
    that binds the VBO to the shader program
    VBOs aren't bound to a shader. VBOs even need not be bound at all to source data from their data store. You can associate a vertex buffer object with an index in the range [0 .. GL_MAX_VERTEX_ATTRIBS] via glVertexAttribPointer (and other means with GL4.3, but since you're obviously on a lower version you shouldn't bother until you get a hold of the concept. You then bind that index to a corresponding location in your shader, either via glBindAttribLocation or, more preferably, via explicit assignment in the shader. For more details, please read this.

    Also, I refer you to the corresponding wiki page.

  4. #14
    Thanks for the reference.
    The shape I rendered is merely what I wanted. Though, 1/4 of the circle is rendered. (I need to find where that comes from).
    Now, let's say I need to change the value of colors in my program. I know that for this I need to use glMapBuffer() & glUnmapBuffer().
    This code gives me a segmentation fault. Could you tell me the correct way of accessing and modifying the colors variable please.
    Code :
        float* colors = (float *) glMapBuffer( GL_ARRAY_BUFFER, GL_WRITE_ONLY );
     
        int k = segmentIndex * RANGE_COUNT * 6;
            for(int i = 0; i < RANGE_COUNT; ++i)
            {
                float rnd = ((rand() + segmentIndex) % 10000) / 10000.0f;
     
                colors[k++] = rnd;
                colors[k++] = rnd;
                colors[k++] = rnd;
                colors[k++] = rnd;
                colors[k++] = rnd;
                colors[k++] = rnd;
            }
        glUnmapBuffer( GL_ARRAY_BUFFER );

    I want to copy only a specified portion everytime, so this way I think I should use the write() function as glMapBuffer() copies the whole buffer. could explain this to me with a sample please.
    Last edited by saman_artorious; 07-01-2013 at 03:19 AM.

  5. #15
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    Quote Originally Posted by tonyo_au View Post
    Your vertex positions sizes don't match
    Code :
    glVertexAttribPointer(vertexId, 2, GL_FLOAT, GL_FALSE, sizeof(vertices), 0)
    Code :
    attribute vec4 vertex;
    This doesn't matter. Vertex attributes are always 4-element vectors. If you specify fewer than 4 components, y and z default to 0 while w defaults to 1.

Posting Permissions

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