Assigning unique color to each point

Hi all .I am new to OpenGL. I am learning with the book OpenGL SuperBible. What I would like to to is to create a sphere of point whereas each point has a different color. Till no I managed to create a sphere of points but I can only change the color for all of them .
The author supplies a tool kit with a very nice class GLBatch which speeds much drawing of geometry.
It has methods Color4f and Color4fv which I think are responsible for coloring the points, But I can’t get them work. When I apply one of these methods or even a regular glColor4f for each set of vertices the sphere becomes invisible. Any help will be appreciated.
Thanks

If you set-up RGBA attributes to your window, and the last value of your glColor4f tends to 0 then you will have full transparent color. Use glColor3f for start.

I tried and it sets all the points to the same color also my display mode is RGBA

Simply” set the color before any vertex.

If you can’t do that, do your own code for the sphere where each vertex will have its own color.

I completely understand what you say .This would be easy to do if I made it a traditional way.Just like you say: vertex color and then vertex. BUT I am using the examples from SuperBible 5 .The author makes use of high level utility GLTools which wrap such a stuff.I make the following I fill an array with the vertices.Then I do this:
pointBatch.Begin(GL_POINTS, VertexCount);
pointBatch.CopyColorData4f(vColors);
pointBatch.CopyVertexData3f(sphereVerts);
pointBatch.End();
This block builds the geomtry in the batch ; no need to write each vertex and color just as you said. The problem is that the second line doesn’t work.It doesn’t assign a color from the color array to each point. Also I process it with a prebuilt shader program.May be the problem is there.

I understand your question now. And I suppose you can’t access the code of this class.

Yes, try without shaders to see if there is any difference.

If not, try to see the website of this book and see if there’s any code update you can download.

If still not, you know what you’ll have to do :slight_smile:

Thanks for advice ,I think I will return to the traditional way for this example.

But really guys ! With the fixed “Old testament” pipeline this is not a problem.But how I paint each point into different color using Shader program in the "new testament "? ( the approach that SuperBible 5 edition uses)

BUT I am using the examples from SuperBible 5 .The author makes use of high level utility GLTools which wrap such a stuff.

And this thread is why if you’re going to teach people how to use OpenGL 3.x, you should actually teach people how to use it instead of hiding the details.

Per-vertex attributes like colors and positions are stored in buffer objects and assigned to a particular rendering call via a combination of glBindBuffer and glVertexAttribPointer. If these commands are unknown to you, then I would suggest following the link in my signature.

Alfonse ,thanks a lot .In fact I am quite disappointed from the 5th edition of the book.The author writes as if he assumes that the reader had already learn by heart 4th edition which is far better (I know it because I started now with it instead). All that shader programming pipeline seems really more convenient from some aspects but from the other side he doesn’t explain well all the essential details.