I’m trying to blend textures together in the fragment shader. I know how to do it but what I seem to be struggling on is getting these textures from my header file to the fragment shader. Here’s how my shader is set up:
out vec3 color;
in vec2 uv;
uniform sampler2D grasstexture;
uniform sampler2D rocktexture;
void main() {
vec4 grass = texture(grasstexture, uv);
vec4 rock = texture(rocktexture, uv);
And then I do my blending down below. I’m using C++ for this so my images are loaded in a header file (called mesh.h). In mesh.h here’s how I set up my images:
OpenGP::EigenImage<vec3> image;
OpenGP::imread("grass.tga", image);
glGenTextures(1, &_diffuse_tex);
glBindTexture(GL_TEXTURE_2D, _diffuse_tex);
check_error_gl();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
check_error_gl();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F,
image.cols(), image.rows(), 0,
GL_RGB, GL_FLOAT, image.data());
check_error_gl();
And that loads the image from the header file. Now I’m trying to put multiple images into the fragment shader and use them there. One thing I tried doing is adding the following:
tex_id = glGetUniformLocation(_pid, "grasstexture");
glUniform1i(tex_id, 0);
The problem is when I try to load multiple textures, it doesn’t seem to work. I’m not sure if I have to copy that entire thing for each texture I load or if I just need to say
OpenGP::imread("rock.tga", image);
for the rock texture. So how do I do this?