PDA

View Full Version : Assigning unique color to each point



SasMaster
03-10-2011, 02:16 PM
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

_arts_
03-10-2011, 02:27 PM
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.

SasMaster
03-10-2011, 02:45 PM
I tried and it sets all the points to the same color also my display mode is RGBA

_arts_
03-10-2011, 02:59 PM
"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.

SasMaster
03-10-2011, 03:10 PM
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.

_arts_
03-10-2011, 03:23 PM
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 :)

SasMaster
03-10-2011, 03:29 PM
Thanks for advice ,I think I will return to the traditional way for this example.

SasMaster
03-13-2011, 08:21 AM
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)

Alfonse Reinheart
03-13-2011, 11:30 AM
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.

SasMaster
03-13-2011, 02:10 PM
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.