Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: multitexturing not working

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    4

    multitexturing not working

    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
    Code :
    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

    Code :
    	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "n_MapTex"), 0);
    	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "n_MapTex2"), 1);

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

    Code :
    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
    Code :
    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
    Code :
    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;

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    it seems that it is only taking the colours of the the second texture and just multiplying it to the first texture
    Code :
    gl_FragColor =  wave1 * wave2;

    That's what you asked the shader to do

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    800
    Perhaps you might be looking to blend the two colours linearly in which case you should do this
    Code :
    gl_FragColor = mix(wave1, wave2, 0.5);
    Regards,
    Mobeen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •