Just load the images first ĭon't worry about the uniforms yet and don't bind them here. Remove the commented lines from the section above. glBindTexture(GL_TEXTURE_2D, texture1) glBindTexture(GL_TEXTURE_2D, texture0) uniform = glGetUniformLocation(program, "texture1") GLint uniform = glGetUniformLocation(program, "texture0") In this section of your code: GLuint texture0, texture1 You should either use glProgramUniform from GL 4.1+ (which takes the program it acts on) or call glUseProgram before setting the uniform value. So it should give you a GL_INVALID_OPERATION error and therefore does nothing. You don't call glUseProgram until the render loop. This function acts on the program that is currently in use. Vec4 color2 = texture(texture1, TexCoord) Vec4 color1 = texture(texture0, TexCoord) TexCoord = vec2(texCoord.x, 1.0 - texCoord.y) The associated GLSL shader files are below: GlClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) Uniform = glGetUniformLocation(program, "texture1") Image = SOIL_load_image("awesomeface.png", GlTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, Unsigned char* image = SOIL_load_image("container.jpg", GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) GlVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), GlVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, GlBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW) GlShaderSource(fragment, 1, &fragShaderCode, NULL) GlShaderSource(vertex, 1, &vertShaderCode, NULL) Ĭonst GLchar* fragShaderCode = fragmentCode.c_str() įragment = glCreateShader(GL_FRAGMENT_SHADER) Vertex = glCreateShader(GL_VERTEX_SHADER) Std::cout << "Error: Shader file not successfully read." << std::endl Ĭonst GLchar* vertShaderCode = vertexCode.c_str() Std::stringstream vShaderStream, fShaderStream VShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit) įShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit) GlfwGetFramebufferSize(display, &width, &height) GlfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE) ĭisplay = glfwCreateWindow(1280, 720, "Game Engine", nullptr, nullptr) GlfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE)
GlfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0) GlfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4)
The full C++ code is below: #define GLEW_STATIC
The texture bound first seems to be automatically bound to both uniforms. My fragment shader has two uniforms but it appears that my code sends the same image to both samplers. I am having trouble sending two textures to my fragment shader via uniform sampler2Ds. OpenGL both uniform sampler2Ds have same image