PDA

View Full Version : Colors at different heights



terickso
10-09-2002, 05:36 AM
I have received some code that displays a height map. It has two modes two display colors for the heights. Transitions from black to a color and allows different colors at different height levels. The problem is when using the different colors it will not display different colors for each of the height gradients but will take the color that matches the heighest point for that vertices and go from black to the that color. What I need is to show for example black band, red band, yellow band, blue band etc up to the heightest color.

I am new at gl. I understand that concept of color blending on a surface but how do you get different colors that stack on each other to display. What would be the easiest way to incorporate what I need.

Is there a way to apply a band of color across an already existing 3D shape.

for( int j=0; j<m_p3D->nY-1; j++ )
for( int i=0; i<m_p3D->nX-1; i++ )
{
glBegin(GL_QUADS);
ColorLevel(m_p3D->m_XYZ.w[j*m_p3D->nX+i]);
glVertex3f(m_p3D->m_XYZ.x[i], m_p3D->m_XYZ.y[j], m_p3D->m_XYZ.z[j*m_p3D->nX+i]);
ColorLevel(m_p3D->m_XYZ.w[j*m_p3D->nX+i+1]);
glVertex3f(m_p3D->m_XYZ.x[i+1], m_p3D->m_XYZ.y[j], m_p3D->m_XYZ.z[j*m_p3D->nX+i+1]);
ColorLevel(m_p3D->m_XYZ.w[(j+1)*m_p3D->nX+i+1]);
glVertex3f(m_p3D->m_XYZ.x[i+1], m_p3D->m_XYZ.y[j+1], m_p3D->m_XYZ.z[(j+1)*m_p3D->nX+i+1]);
ColorLevel(m_p3D->m_XYZ.w[(j+1)*m_p3D->nX+i]);
glVertex3f(m_p3D->m_XYZ.x[i], m_p3D->m_XYZ.y[j+1], m_p3D->m_XYZ.z[(j+1)*m_p3D->nX+i]);
glEnd();
}
}

Colorlevel uses glcolor3f to get the colors.

zen
10-09-2002, 11:57 AM
Just to clarify this:do you want each point in the rendered heightmap to have a color based solely on the height of the point,i.e. all points with common height have the same colour?
A nice way to this might be the following(never tried it so it might be completely wrong but it will give you a starting point for research):
Use a 1D texture with the desired colour range and then use txgen in contour mode to get coords based on the height of each vertex.I think the red book has an example of something like this.Just read the paragraph on texgen.
Anyway if that's what you need just read on texgen and 1d textures for details.