Hello,
I have a problem of loading multiple textures and then use it in Shader(GLSL) and I am not sure what's wrong.
On my program, init function, I have something like
Code :void init() { //... glBindTexture(GL_TEXTURE_2D,myTex[0]); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,320,240,0,GL_RGB,GL_UNSIGNED_BYTE,img1->imageData); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glBindTexture(GL_TEXTURE_2D,myTex[1]); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,320,240,0,GL_RGB,GL_UNSIGNED_BYTE,img2->imageData); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); }
And after I load shader and use it(glUseProgram), I did something like
Code :void drawSquare() { //... glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,myTex[0]); GLint tex1Loc = glGetUniformLocation(program,"tex0"); glUniform1i(tex1Loc,0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,myTex[1]); GLint tex2Loc = glGetUniformLocation(program,"tex1"); glUniform1i(tex2Loc,1); }
And this did not work. It seems like one texture is empty (black) and another one is 2nd file. I know glTexImage2D lines are correct.
In fact, I am not sure how to deal with multiple textures and pass those to GLSL so can someone please help me? Like I don't know what ActiveTexture, GenTexture and others do exactly. I read API website but it still confuses me so can you tell me the process or how to deal with multiple textures?
Thank you so much for the help!



