Sign in to follow this  
jakesee

How to use glIndexPointer ? Yes yes... I know it's for color.

Recommended Posts

jakesee    100
Hi,

I cannot find a single glIndexPointer example. I wish to know how is it used exactly.

I have a real world terrain model and a color spectrum array for visually indicating the height of the terrain.

The spectrum has just 56 colors (float, float, float) and the terrain has 1200x1200 vertices. I figured that it will be good if i can store just an index into the spectrum in each Vertex.

Is glIndexPointer for this purpose? If so, how do I use it?

my current code crashes on glDrawElements():


struct Vertex3
{
Vector3 position;
Vector3 normal;
int spectrum_index; // if this were Color color;
// and index pointer not used, it will run correct.
};

class Spectrum { public: const static Colors[]; }

Vertex3 terrain[1200x1200];

..
glColorArray(3, GL_FLOAT, 0, Spectrum::Colors);
glIndexPointer(GL_INT, sizeof(Vertex3), &(terrain[0].spectrum_index));
...






Thanks!

Share this post


Link to post
Share on other sites
Brother Bob    10344
glIndexPointer is only used if you have a paletted pixel format. If you have an RGB pixel format, you use glColorPointer. The two are mutually exclusive, and one or the others presence (as in, one is working and the other one is effectively ignored) is exclusively determined by the color mode of the pixel format.

SO in short, it has nothing to do with your spectrum. To OpenGL, your spectrum is just another array, and your index is just another attribute that you happen to use as a lookup into the spectrum. That is orthogonal to whether you use an indexed or RGB pixel format.

Share this post


Link to post
Share on other sites
jakesee    100
@karwosts

Sadly, I have no idea what a "vertex shader" is. Usually definition states "..a program that modifies the vertex properties before rendering.. " or something to that effect but it still doesn't explain very much to me.

I have the impression that it's some new scripting langauge (GLSL?) which I have no time to learn at the moment.

Maybe you help me kick start by telling me which opengl function I am suppose to look at?

Share this post


Link to post
Share on other sites
karwosts    840
Yes you need to learn a new language (GLSL) to use them. Shaders in general are the heart of all modern rendering, they give full flexibility to program the GPU to do whatever you want, in special cases like yours.

Unfortunately they do have a small bit of learning curve to setup right, so if you can't/won't spend the time to learn it, than I'd just suggest that you just go ahead and send the colors with your vertices.

Share this post


Link to post
Share on other sites
V-man    813
I believe you need to use glColorTableEXT which is part of GL_EXT_palette_texture. You're going to find that there are no graphics cards that support it. The only solution is to use a shader and you can do it in a vertex or fragment shader.
It is a GLSL world these days.

Share this post


Link to post
Share on other sites
jakesee    100
@v-man
thanks for the definitive reply. i'll stop wasting time trying to do this. could have used my wasted time to read up the vertex shader thingy...

thanks all!

Share this post


Link to post
Share on other sites
karwosts    840
If you're interested I find this to be a good source for getting started with GLSL:

http://www.lighthouse3d.com/opengl/glsl/index.php?intro

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this