Results 1 to 2 of 2

Thread: Simple Vertex Color Problem when using Indices

  1. #1

    Simple Vertex Color Problem when using Indices

    Without any code at first let me describe the problem.

    I recreated the basic lesson for a rotating cube. Lesson 4 Learning Webgl
    http://learningwebgl.com/lessons/lesson04/index.html

    The code has 4 vertices listed for each face for a total of 24 vertices. It uses indices to these 24 vertices 0-23 to do a drawElements(...) and it uses a color buffer array with 24 different colors.

    So the end result of course is a rotating cube with each face assigned a different color.

    What I did was work with the fact that a cube really only has 8 vertices not 24. So I made an array of 8 vertices. And I reworked the position index array to work with indices from 0-7 instead of what was given 0-23. I left the color buffer array alone since I put the same order to the face creation as in the original lesson.

    When I completed the drawElements(...), I did have a perfect rotating cube. But the cube is not colored correctly. Each vertex has a single color so only the first eight of the color array elements (out of 24) were used. Basically The top half is one color and the bottom half is another color. And the faces of the cube do not have a unique color.


    The question is : is there a way to assign color to vertex indices instead of to vertices?
    I am suspecting that I could use gl_vertexID in the shaders, but I thought I'd get some opinions first?

    Thanks...

  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    17

    Re: Simple Vertex Color Problem when using Indices

    No, the indices references the currently enabled vertex attribute arrays. Normally, you'd probably want to texture your model anyway, so this is usually of little concern..

    Also, gl_vertexID is not available using OpenGL ES shaders. The ES shaders doesnt even have integer support.

Similar Threads

  1. How does a color buffer and a vertex buffer fit together?
    By xkrja in forum Developers Coding:Beginner
    Replies: 1
    Last Post: 02-25-2011, 06:11 PM
  2. True color display problem.
    By kometes76 in forum OpenGL ES 1.X - fixed function hardware
    Replies: 1
    Last Post: 10-13-2009, 07:41 AM
  3. color transformations - problem with alpha
    By sochm in forum OpenVG and VGU
    Replies: 3
    Last Post: 04-24-2009, 07:59 AM

Posting Permissions

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