PDA

View Full Version : Colors on terrain, glcolorpointer ?



artariel
05-03-2012, 02:13 AM
glcolorpointer doesn't work. i mean, it changes nothing on the tiles.. what is missing ?


init loop :


keslan[z * TERRAIN_SIZE + x].x=x - TERRAIN_SIZE/2;
keslan[z * TERRAIN_SIZE + x].y=heightmap[z * TERRAIN_SIZE + x] / SCALE_FACTOR ;
keslan[z * TERRAIN_SIZE + x].z=z - TERRAIN_SIZE/2;
keslan[z * TERRAIN_SIZE + x].u=(GLfloat)x/TERRAIN_SIZE*16;
keslan[z * TERRAIN_SIZE + x].v=(GLfloat)z/TERRAIN_SIZE*16;
keslan[z * TERRAIN_SIZE + x].r=0.5f + 0.5f * keslan[z * TERRAIN_SIZE + x].y / MAX_HEIGHT;
keslan[z * TERRAIN_SIZE + x].g=0.5f + 0.5f * keslan[z * TERRAIN_SIZE + x].y / MAX_HEIGHT;
keslan[z * TERRAIN_SIZE + x].b=0.5f + 0.5f * keslan[z * TERRAIN_SIZE + x].y / MAX_HEIGHT;
keslan[z * TERRAIN_SIZE + x].a=1.0f;



draw code :


glBindBuffer(GL_ARRAY_BUFFER,m_vert);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vrt), NULL);
glTexCoordPointer(2,GL_FLOAT,sizeof(vrt),(char*)NU LL + 12);
glColorPointer(4,GL_FLOAT,sizeof(vrt),(char*)NULL + 20);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_ind);
glDrawElements(GL_TRIANGLE_STRIP,indices.size(),GL _UNSIGNED_INT,0);
glBindBuffer(GL_ARRAY_BUFFER,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

BionicBytes
05-03-2012, 02:56 AM
I can't see anything wrong with the array setup code.
How are you shading the terrain, where's the rest of the draw code and state?

artariel
05-03-2012, 03:48 AM
void CGfxOpenGL::Render()
{
glClearColor(0.0f, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
gluLookAt(cameraX, cameraY, cameraZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);


m_skybox.Render(cameraX, cameraY, cameraZ);

DrawTerrain();
}

drawterrain is the above one

Dan Bartlett
05-03-2012, 04:02 AM
Are you using shaders, or the fixed function? If you are using shaders you will need to use gl_Color for colors to have any effect.

artariel
05-03-2012, 04:15 AM
shaders ? i don't think i use them. what do you mean by fixed function ?

BionicBytes
05-03-2012, 04:26 AM
I think we need to see what's inside DrawTerrain();

artariel
05-03-2012, 04:30 AM
void CGfxOpenGL::DrawTerrain()
{
static float ze = 2.00f;

glBindTexture(GL_TEXTURE_2D, m_grassTexture);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glBindBuffer(GL_ARRAY_BUFFER,m_vert);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vrt), NULL);
glTexCoordPointer(2,GL_FLOAT,sizeof(vrt),(char*)NU LL + 12);
glColorPointer(4,GL_FLOAT,sizeof(vrt),(char*)NULL + 20);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_ind);
glDrawElements(GL_TRIANGLE_STRIP,indices.size(),GL _UNSIGNED_INT,0);
glBindBuffer(GL_ARRAY_BUFFER,0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);



//water
glBindTexture(GL_TEXTURE_2D, m_waterTexture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(-TERRAIN_SIZE/2.1f, WATER_HEIGHT, TERRAIN_SIZE/2.1f);

glTexCoord2f(TERRAIN_SIZE/4.0f, 0.0);
glVertex3f(TERRAIN_SIZE/2.1f, WATER_HEIGHT, TERRAIN_SIZE/2.1f);

glTexCoord2f(TERRAIN_SIZE/4.0f, TERRAIN_SIZE/4.0f);
glVertex3f(TERRAIN_SIZE/2.1f, WATER_HEIGHT, -TERRAIN_SIZE/2.1f);

glTexCoord2f(0.0, TERRAIN_SIZE/4.0f);
glVertex3f(-TERRAIN_SIZE/2.1f, WATER_HEIGHT, -TERRAIN_SIZE/2.1f);
glEnd();

}

BionicBytes
05-03-2012, 04:42 AM
Your Terrain render isn't doing anything with the colours in the vertex array because you have enabled texturing. What you need to do is combine the texture colour with the per-vertex colour.
This is usually done via glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, pname);
where pname is either GL_DECAL, GL_ADD, GL_MODULATE, GL_BLEND, GL_REPLACE or GL_COMBINE

Basic per-vertex colour * Texture colour is achieved via GL_MODULATE.

GL_COMBINE uses Texture Combiner Functions which has been superceeded by shaders which will allow you to perform a custom wizzy function on your terrain instead of some rather limited math.

Perhaps you have set the textEnv to GL_REPLACE elsewhere in your code which means the final colour is only the texture colour and the vertex colour is ingored.

artariel
05-03-2012, 04:49 AM
thank you so much, it works now. I think i have to learn about textures more :P

artariel
05-03-2012, 05:31 AM
Your Terrain render isn't doing anything with the colours in the vertex array because you have enabled texturing. What you need to do is combine the texture colour with the per-vertex colour.
This is usually done via glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, pname);
where pname is either GL_DECAL, GL_ADD, GL_MODULATE, GL_BLEND, GL_REPLACE or GL_COMBINE

Basic per-vertex colour * Texture colour is achieved via GL_MODULATE.

GL_COMBINE uses Texture Combiner Functions which has been superceeded by shaders which will allow you to perform a custom wizzy function on your terrain instead of some rather limited math.

Perhaps you have set the textEnv to GL_REPLACE elsewhere in your code which means the final colour is only the texture colour and the vertex colour is ingored.

by the way i have to ask

what is "normal" for a mesh/model ? i got texture coords, vertex, color thing but what is a normal ?

Rosario Leonardi
05-04-2012, 05:13 PM
On a plane the normal is the vector perpendicular to the plane. Cause in openGL we send information on the vertex the normal vector is issued as vertex attribute, the normal of the point on the triangle is the (linear) interpolation of the normal on the vertexes.
Normal is usually combined with light direction to shade the surface.

Normal map for example is a technique that use a texture to disturb the surface normal by sampling another vector from a texture.

artariel
05-04-2012, 11:12 PM
On a plane the normal is the vector perpendicular to the plane. Cause in openGL we send information on the vertex the normal vector is issued as vertex attribute, the normal of the point on the triangle is the (linear) interpolation of the normal on the vertexes.
Normal is usually combined with light direction to shade the surface.

Normal map for example is a technique that use a texture to disturb the surface normal by sampling another vector from a texture.

so normals are used only for lights (?)

nothing else ?

BionicBytes
05-05-2012, 06:53 AM
Correct. Normals are used as part of the lighting equation.
On a terrain, you could read the normal at ang given triangle and use that to work out the best postion to place vegetation, etc but this is more of a specialist use of 'normals'.

artariel
05-05-2012, 09:18 AM
it's actually useful as you said. think of a train and rail system and their angle according to the normals :P