glColorPointer PROBLEM!!

Hi ALL!!
I am confused with how to use glColorPointer!!
this is the effect I get currently! http://homepage.ntlworld.com/robert.stuliglowa/projects/GL-Flightor/temp/red.jpg

I have eg.

float colorArray [256 * 256][3]; // color array

// loop over all vertices
for (int z = 0; z < 256; z++)
{
for (int x = 0; x < 256; x++)
{
// VERTEX - vertices are numbered left to right, top to bottom
Vertex = (z * 256) + x;

// COLOUR - set the values in the color array
// RGB] = set same colour value to all 3 colours
colorArray[Vertex][0] = terrain[x + 256 * z][1]/255.0f;
colorArray[Vertex][1] = terrain[x + 256 * z][1]/255.0f;
colorArray[Vertex][2] = terrain[x + 256 * z][1]/255.0f;
}
}

Here I am assigning RGB colour to one value which should be going from balck through grey to black depending on the heighmaps height!! Why do I have red colour only??
Strange!!!

if I for example set red to 0 and others Green and Blue to same positive value eg. 0.3 then I get colour interpolation from dark green (almost black) to bright green!!! why??
The way I understand is for example if I set Red=0.3, Green=0.3, Blue=0.3 then I get dark grey colour!
But here it looks as it only considers one colour instead of blending 3 colours!! am I right?
Any ideas how to solve the problem?

[This message has been edited by robert_s (edited 01-18-2002).]

Could you post the code for your call to glColorPointer?

This is the bit of code which belongs to the prevoius bit I posted for initialization
GLuint indexArray [256 * 256 * 6]; // vertex index array
float terrain [256 * 256][3]; // heightfield terrain data (0-255); 256x256
float colorArray [256 * 256][3]; // color array
float texcoordArray [256 * 256][2]; // texture coord array

glVertexPointer(3, GL_FLOAT, 0, terrain);
glColorPointer(3, GL_FLOAT, 0, colorArray);
glTexCoordPointer(2, GL_FLOAT, 0, texcoordArray);

then another function rendering the heightmap (see below)!

for (int z = 0; z < 200; z++)
{
// draw the triangles in this strip
glDrawElements(GL_TRIANGLE_STRIP, 200, GL_UNSIGNED_INT, &indexArray[(z * 256 * 2)]);

}

[This message has been edited by robert_s (edited 01-18-2002).]

[This message has been edited by robert_s (edited 01-18-2002).]

Try disabling textures and lights and see if you get the desired look.

kon

Ken!! you’re perfectly right!! THANKSSS!!
I disabled lighting and it works!!!

[This message has been edited by robert_s (edited 01-18-2002).]

Try setting your TexEnv to GL_DECAL (not GL_MODULATE)

kon

Great, now you have the right colours, but no lighting.
Do the following to get the right colours AND lighting:-
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

Now your lighting will work with your colours correctly.
What is happening is this:-
colours are ignored when lighting is enabled, because lighting uses materials instead. When you enable GL_COLOR_MATERIAL you are telling openGL that every time a glColor3f (or equivelent entry in your colour array) is issued, change the specified material property to that colour instead (GL_DIFFUSE, GL_AMBIENT or a convenient way of combining the two by using the GL_AMBIENT_AND_DIFFUSE constant).
That’s all it means.

[This message has been edited by knackered (edited 01-18-2002).]

ok! guys! thanks a lot!!
I did what you said and it works!!
thanks again!