Problem Loading multiple textures using multiple shaders with GLSL

Posted by paj777 on Stack Overflow See other posts from Stack Overflow or by paj777
Published on 2010-04-14T12:19:36Z Indexed on 2010/04/14 12:23 UTC
Read the original article Hit count: 289

Filed under:
|
|

I am trying to use multiple textures in the same scene but no matter what I try the same texture is loaded for each object. So this what I am doing at the moment, I initialise each shader:

rightWall.SendShaders("wall.vert","wall.frag","brick3.bmp", "wallTex", 0);
demoFloor.SendShaders("floor.vert","floor.frag","dirt1.bmp", "floorTex", 1);

The code in SendShaders is:

GLuint vert,frag; glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D);

            char *vs = NULL,*fs = NULL;

            vert = glCreateShader(GL_VERTEX_SHADER);
            frag = glCreateShader(GL_FRAGMENT_SHADER);

            vs = textFileRead(vertFile);
            fs = textFileRead(fragFile);
            const char * ff = fs;
            const char * vv = vs;

            glShaderSource(vert, 1, &vv, NULL);
            glShaderSource(frag, 1, &ff, NULL);

            free(vs); free(fs);

            glCompileShader(vert);
            glCompileShader(frag);

            program = glCreateProgram();
            glAttachShader(program, frag);
            glAttachShader(program, vert);

            glLinkProgram(program);
            glUseProgram(program);

        LoadGLTexture(textureImage, texture);

        GLint location = glGetUniformLocation(program, textureName);

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

        glUniform1i(location, 0);

And then in the main loop:

     rightWall.UseShader();
rightWall.Draw();   

demoFloor.UseShader();
demoFloor.Draw();

Which ever shader is initialised last is the texture which is used for both objects. Thank you for your time and I appreciate any comments.

© Stack Overflow or respective owner

Related posts about opengl

Related posts about glsl