PDA

View Full Version : multitexturing not working



Johnathon332
04-27-2013, 07:49 AM
hey guys I am trying to get multitexturing to work however I am having trouble with it

When I try to texture my quad with 2 textures it changes colours to purple...it seems that it is only taking the colours of the the second texture and just multiplying it to the first texture

I have loaded both images in as GL_LINEAR as they dont have mipmaps

for(int i = 0; i < 2; ++i){
if(PVRTTextureLoadFromPVR(c_szTextureFile[i], &m_uiTexture[i]) != PVR_SUCCESS)
{
*pErrorStr = CPVRTString("texture could not be loaded ") + c_szTextureFile[i];
return false;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

also I have notified the shader that my first texture is unit 0 and second being unit 1


glUniform1i(glGetUniformLocation(m_ShaderProgram.u iId, "n_MapTex"), 0);
glUniform1i(glGetUniformLocation(m_ShaderProgram.u iId, "n_MapTex2"), 1);

and at the bottom I have used glActiveTexture when binding my textures


glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_uiTexture[0]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_uiTexture[1]);

Here is the code for my vertex and fragment shader

VERTEX

attribute highp vec3 inVertex;
attribute mediump vec3 inNormal;
attribute mediump vec2 inTexCoord;

uniform highp mat4 MVPMatrix;
uniform mediump vec3 EyePos;

varying mediump vec3 EyeDir;
varying mediump vec2 TexCoord;
varying mediump vec2 TexCoord2;

void main()
{
// Transform position
gl_Position = MVPMatrix * vec4(inVertex,1.0);

TexCoord = inTexCoord;
TexCoord2 = inTexCoord2;
}

FRAGMENT

uniform sampler2D n_mapTex;
uniform sampler2D n_mapTex2;

varying mediump vec2 TexCoord;
varying mediump vec2 TexCoord2;

//This gets updated within the main code
uniform highp float Time;

void main()
{
mediump vec4 wave1 = texture2D(n_mapTex, TexCoord);
mediump vec4 wave2 = texture2D(n_mapTex2, TexCoord2);
gl_FragColor = wave1 * wave2;

tonyo_au
04-27-2013, 08:23 PM
it seems that it is only taking the colours of the the second texture and just multiplying it to the first texture


gl_FragColor = wave1 * wave2;

That's what you asked the shader to do

mobeen
04-28-2013, 08:17 AM
Perhaps you might be looking to blend the two colours linearly in which case you should do this


gl_FragColor = mix(wave1, wave2, 0.5);