Multiple vertex color sets in OpenGL

Started by
31 comments, last by convert 1 year, 4 months ago

I have a C++ Mesh class which looks like this:

//Vector3F is float[3]
    class Mesh{
        Vector3F* positions;
        ...
        Vector3F* colors1;
        Vector3F* colors2;
        
        public:
        
        void draw();
        
    };
    
    
    void Mesh::draw()
    {
       .....
        glVertexPointer(3, GL_FLOAT, 0, positions);
        if(colors1) glColorPointer(3, GL_FLOAT, 0, colors1);
        if(colors2) ?
        ...
    }

So how can I use both vertex color sets colors1 and colors2?

Advertisement

How do you use both sets of vertex colors?

You can pass whatever data you want into your vertex shader (including multiple sets of UV data, or various sets of vertex colors). How you code your shaders will determine how that data gets used.

@Warp9 I am not using any shaders. Just triing to visualize some generic mesh with good old OpenGL. While for passing multiple sets of UV data there seems to be a solution, which I also still can´t understand I have not find any similar solution for multiple sets of vertex colors.

Fair enough. Although it seems like having multiple sets of vertex colors is pretty unusual, so it may not be available in old OpenGL.

If I may ask, why is it that you want two sets of colors for the same vertex?

@Warp9 I personaly don´t want two sets of colors, but something like this seems to be posible similar like multiple Uv map sets. In 3ds max for example there are 3 standard sets of colors. In asimp there is even something like 4 sets of colors posible, if I remember right.

Not shure, but posibly glSecondaryColorPointer could solve this problem.

@convert : Good luck with your problem. Hopefully somebody else can give you the info you need.

I will add this though. . . Back in the day, when I was using old style OpenGL, I did have situations when one vertex would essentially have multiple normals or uvs on it. For example, the corner of a cube, where the same corner would have 3 different normals, depending on which face we were dealing with (and I still wanted it to act as one vertex for editing purposes). However I never had OpenGL deal with this stuff directly, instead I tracked the data on the CPU and told OpenGL what it needed to know at the time. So, if I had multiple sets of colors for the same vertex, then I'd just store the data myself, and hand OpenGL the color set that was relevant at the time (in modern times, I do try to get more stuff done on the GPU, but that was then and this is now). Not sure that helps, but that is definitely how I would have dealt with your problem in old school OpenGL.

Warp9 said:

@convert : Good luck with your problem. Hopefully somebody else can give you the info you need.

I will add this though. . . Back in the day, when I was using old style OpenGL, I did have situations when one vertex would essentially have multiple normals or uvs on it. For example, the corner of a cube, where the same corner would have 3 different normals, depending on which face we were dealing with (and I still wanted it to act as one vertex for editing purposes). However I never had OpenGL deal with this stuff directly, instead I tracked the data on the CPU and told OpenGL what it needed to know at the time. So, if I had multiple sets of colors for the same vertex, then I'd just store the data myself, and hand OpenGL the color set that was relevant at the time (in modern times, I do try to get more stuff done on the GPU, but that was then and this is now). Not sure that helps, but that is definitely how I would have dealt with your problem in old school OpenGL.

What you tallking about is diferent thing. Also you mean by vertex just position, while the term stands for all values: position, normal, uv coord, posibly second uv coord, color and eventual some other values. So your example is about a number of vetices with the same position but diferent normals and/or uv coords. To be honest I have also no idea what the second color value for a vertex should be good for. In 3ds max the second color set is often refered as ilumination, so posibly this is an explanation.

convert said:

So your example is about a number of vetices with the same position but diferent normals and/or uv coords.

I suppose it comes down to your specific technical definition of exactly what a vertex is. But, if you look at how 3DS Max Does things, or how vertices are stored in a format like OBJ files or DAE files, a given vertex can have multiple uvs, normals, etc. So, the corner of a cube can be one vertex, even if the different faces have their own uvs.

Here is a screen shot from 3DS max proves this point. I've ripped apart the UVs so that each of the 6 faces of the box has different UVs (as seen on the window to the left). But, according the 3DS Max, that is still only 8 vertices. Which means that each of those 8 vertices has multiple uvs (at least according to 3DS Max).

Added on edit : after a bit of consideration, I don't think my argument here holds up. How 3DS Max does things doesn't really say that much about what the technical definition of a vertex is in OpenGL, so feel free to disregard this post.

You really should use OpenGL 4. With the help of GLM, it's not much harder than OpenGL 1. There you can upload any kind of data you want into the shader, including data representing multiple colours. It is so much better.

P.S. I still use OpenGL 1 for some smaller projects… prototypes mostly.

This topic is closed to new replies.

Advertisement