PDA

View Full Version : glColorPointer PROBLEM!!

robert_s
01-18-2002, 06:15 AM
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).]

pallindo
01-18-2002, 06:18 AM
Could you post the code for your call to glColorPointer?

robert_s
01-18-2002, 07:26 AM
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).]

kon
01-18-2002, 07:37 AM
Try disabling textures and lights and see if you get the desired look.

kon

robert_s
01-18-2002, 08:04 AM
Ken!! you're perfectly right!! THANKSSS!!
I disabled lighting and it works!!!

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

kon
01-18-2002, 08:06 AM
Try setting your TexEnv to GL_DECAL (not GL_MODULATE)

kon

knackered
01-18-2002, 08:49 AM
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);