PDA

View Full Version : ClientState & MultiTexture & Shading Language



Jedimaster
07-17-2006, 10:49 PM
void CStreamModel::Draw()
{
//glutSolidSphere(1.0,32,32);
ReBuildHeightMap();

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3,GL_FLOAT,0,Mesh);
glNormalPointer(GL_FLOAT,0,Normal);
// glEnableVertexAttribArray(::AttribTangentSlot);glV ertexAttribPointer(::AttribTangentSlot,3,GL_FLOAT, 0,0,Tangent);
// glPushMatrix();
glClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(2,GL_FLOAT,0,TexCoord);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glClientActiveTextureARB(GL_TEXTURE1);
glTexCoordPointer(2,GL_FLOAT,0,TexCoord);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,RefractMap);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,NormalMap);

glDrawElements(GL_TRIANGLE_STRIP,7936,GL_UNSIGNED_ SHORT,VertexIndex);
// glPopMatrix();

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
// glDisableVertexAttribArray(::AttribTangentSlot);

// glClientActiveTextureARB(GL_TEXTURE0_ARB);
};the texture handles "RefractMap" and "normalMap" is ok.

I just bind the RefractMap to texture unit 0,and the NormalMap to unit 1,so i can make bump mapping in my fragment shader.



attribute vec3 Tangent;
void main(void)
{
gl_Position = ftransform();
gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
}


uniform sampler2D ColorMap;
uniform sampler2D NormalMap;
void main(void)
{
gl_FragColor = texture2D(ColorMap,gl_TexCoord[0].xy);// + texture2D(NormalMap,gl_TexCoord[1].xy);
}but... even I changed the ColorMap to NormalMap,i can't see the normals map,all the same the color map.

I think maybe the problems is on the server-side or unit and client-side...

Thanks

zed
07-18-2006, 12:02 AM
i thnk u r confused normally u only need
glClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(2,GL_FLOAT,0,TexCoord);

u only need more than texcoord0 if the mesh has different texturecoords, colormaps + normalmaps normally share the same texturecoords, so u need

attribute vec3 Tangent;
void main(void)
{
gl_Position = ftransform();
gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
}


code:


uniform sampler2D ColorMap;
uniform sampler2D NormalMap;
void main(void)
{
gl_FragColor = texture2D(ColorMap,gl_TexCoord[0].xy) + texture2D(NormalMap,gl_TexCoord[0].xy);
}

of course the above will visually look wrong since youre using normalmap incorrectly

Komat
07-18-2006, 01:31 AM
Did you set the glsl sampler uniforms correctly?