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 8 of 8

Thread: problems with glVertexPointer

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    180

    problems with glVertexPointer

    Hi

    Im storing my vertices in an array, where each vertex is x,y,z,w: float

    now, if i pass the w component like this

    glVertexPointer(4, GL_FLOAT, 0, my_vertices)

    all looks good, however if i do something like this

    glVertexPointer(3, GL_FLOAT, 4, my_vertices)

    my mesh gets messed up.

    since i got the w for my normals too, using
    glNormalPointer(GL_FLOAT, 4, my_normals)

    makes it all messed up

    any ideas as to what can be wrong?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Portsmouth, Hampshire, England
    Posts
    926

    Re: problems with glVertexPointer

    glVertexPointer(3, GL_FLOAT, 4, my_vertices) is incorrect. The stride argument should be in bytes, so it should be 16 not 4.

    That should fix it.

    Nutty

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,755

    Re: problems with glVertexPointer

    Also, there is no w component for normals. Normals will always be 3 elements each. The value 4 that you are passing for glNormalPointer is wrong too. That's the stride, not the number of components. It should be 12. (3 floats * 4 bytes/float)

    Using glVertexPointer(3, GL_FLOAT, 4, my_vertices) Is saying that you only have x,y,z (the first parameter is how many components) and as Nutty pointed out, sets the stride to 4. So unless you changed your vertices to not have a w, you should do this.

    glVertexPointer(4, GL_FLOAT, 16, my_vertices)
    Deiussum
    Software Engineer and OpenGL enthusiast

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Portsmouth, Hampshire, England
    Posts
    926

    Re: problems with glVertexPointer

    Using glVertexPointer(3, GL_FLOAT, 16, my_verts); will also work, it will just ignore the w component.

    Get rid of the W, as you rarely need to specify that anyway, and use

    glVertexPointer(3, GL_FLOAT, 0, myverts);
    or
    glVertexPointer(3, GL_FLOAT, 12, myverts);

    both will work, as your xyz will be tightly packed with no w.

    personally I prefer to specify the stride explicitly.

    Nutty

  5. #5
    Junior Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    180

    Re: problems with glVertexPointer

    if you're going to do matrix transformations yourself, you need the W component in both cases. (im using ogl for this, just reusing my matrix lib since i just started)

    i see now what i missinterpreted, thanks for the heads up.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,407

    Re: problems with glVertexPointer

    the third value is the stride. ie the byte offset between the vertices. i assume u supply the data without any gaps so you need to use zero offset

    glVertexPointer(4, GL_FLOAT, 0, my_vertices);

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Portsmouth, Hampshire, England
    Posts
    926

    Re: problems with glVertexPointer

    The byte offset between vertices on 4 floats, is 16. The reason you can put 0 in, is because of a tiny little extra feature of that function. If verts are tightly packed, you can put 0 in, and gl will automatically calculate the correct stride.

    As I said, I personally prefer to specify it explicity.

    I think alot of people get confused on this. They know it works with 0, so they think gl is measuring the byte difference between vert(n).z and vert(n+1).x When it's not, it's the difference between vert(n).x and vert(n+1).x

    Nutty

    P.S. Why do you need to specify the W component if you write your own matrix code?

  8. #8
    Junior Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    180

    Re: problems with glVertexPointer

    that was exactly what i was confusing it with. and the wording in the msdn doc's doesnt quite help (in my view): "The byte offset between consecutive vertices. When stride is zero, the vertices are tightly packed in the array"

    the last part could be rewritten to cause less confusion.

    anyway, why i need W? and so i can transform the vectors and vertices with the same matrix (and matrix function) and perform perspective correction.

    thanks for the help, its all running perfectly now

Posting Permissions

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