Hello Guest

Multiple textures for multiple shaders

  • 0 Replies
  • 4137 Views
Multiple textures for multiple shaders
« on: January 09, 2021, 04:35:21 »
I have these 2 fragment shaders:
Simple.fragment:
Code: [Select]
#version 330 core

in vec2 UV;

out vec4 color;

uniform sampler2D myTextureSamplerr;
void main(){
//use the texture
}

Unlit.fragment:
Code: [Select]
#version 330 core

in vec2 UV;

out vec4 color;

uniform sampler2D myTextureSamplerr;
void main(){
//use the texture
}
And that's how I load them:
Code: [Select]
public static int loadTexture(String imagepath) {
Image image = new Image();
IntBuffer width = BufferUtils.createIntBuffer(1);
    IntBuffer height = BufferUtils.createIntBuffer(1);
    IntBuffer comp = BufferUtils.createIntBuffer(1);

ByteBuffer data = stbi_load(imagepath, width, height, comp, 4);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);


glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width.get(), height.get(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
id = glGenTextures();




stbi_image_free(data);

return id;


}

How to send a texture to first shader and another to the unlit one? Because even if I call the loadTexture method with 1 texture for a lit object and with the 2nd texture for the unlit one the both objects will use the 2nd texture(last called)
I think the problem is this line: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width.get(), height.get(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
It searched for uniform sampler2D and give the image to all of them.
« Last Edit: January 09, 2021, 04:38:24 by Mihai_Ionut_Floares »