• Advertisement
Sign in to follow this  

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

This topic is 2688 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
Hi Brother Bob,

So is there anyway I can index my spectrum instead of duplicating the color over all vertices?

Share this post


Link to post
Share on other sites
You could use a vertex shader with your color index as an integer attribute, which you use to pick from a 1-D texture lookup table.

Share this post


Link to post
Share on other sites
@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
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
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
@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
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
Sign in to follow this  

  • Advertisement