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

Started by
8 comments, last by jakesee 13 years, 6 months ago
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!
==============================================Rage - Really Amateurish Graphics EngineCollada Parser / Serializer
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.
Hi Brother Bob,

So is there anyway I can index my spectrum instead of duplicating the color over all vertices?
==============================================Rage - Really Amateurish Graphics EngineCollada Parser / Serializer
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.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
@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?
==============================================Rage - Really Amateurish Graphics EngineCollada Parser / Serializer
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.

[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
@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!
==============================================Rage - Really Amateurish Graphics EngineCollada Parser / Serializer
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
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Definitely interested. Very much appreciated. =)
==============================================Rage - Really Amateurish Graphics EngineCollada Parser / Serializer

This topic is closed to new replies.

Advertisement