I’m drawing some meshes from polylines using tessellateToMesh().
After doing that, I want to iterate to all the vertices and set their color according to some calculated value (i.e.: the distance to the next vertex), but I’m constantly getting what I think is a bad pointer error:
The mesh you create doesn’t necessarily have any colors yet. You can call ofMesh::getNumColors() to find out how many colors there are stored, and you can add new ones with ofMesh::addColor() or ofMesh::addColors().
The fact that there are vertices doesn’t imply there’s the same number of colors, indices, normals or texCoords.
Thanks @hamoid, now it’s a bit clearer.
Sorry to chain in with a question that is only just partially related. but do you know how to pass vertices colors to a vert shader?
If you draw the mesh, and the mesh has vertex colors, they should be passed to the shader, right?
Yes, that’s true. I had a very complicated idea involving interpolation modes in the frag shader. But I think I have to set that aside for now and go back to the basics!
The color get linearly interpolated during the rasterisation process.
Let’s say that you create a mesh composed by 3 vertices, and that you set as mode OF_PRIMITIVE_TRIANGLES. Let’s say that you also want to add the attribute color for each vertex, using “addColor” as you were doing. Let’s assume that vertex is red, one is green and one is blue. That means that each angle of the triangle will have a different color.
During the rasterisation process, the triangle originally composed by 3 vertices connected together becomes pixels on the screen. The attributes (and therefore the colors) of each vertex get interpolated. If a pixel, for example, end up being in the middle between the blue angle and the red angle, its color will be violet.
If you look for “rendering pipeline” you can find way more detailed information about what’s going on.