OpenGL second Texture is not showing up (OpenGL Texture Unit).

I only got first texture show up.

What’s wrong with this my code,I can’t find where’s the mistake even after two hours looking.

int main()
{
	sf::ContextSettings settings;
	settings.majorVersion = 4;
	settings.minorVersion = 5;
	settings.attributeFlags = settings.Core;

	sf::Window window;
	window.create(sf::VideoMode(1600, 900), "Texture Unit Rectangle", sf::Style::Close, settings);
	window.setActive(true);
	window.setVerticalSyncEnabled(true);

	glewExperimental = true;
	glewInit();

	GLuint shaderProgram = createShaderProgram("FX/Rectangle.vss", "FX/Rectangle.fss");

	float vertex[] =
	{
		-0.5f,0.5f,0.0f,  0.0f,0.0f,
		-0.5f,-0.5f,0.0f, 0.0f,1.0f,
		0.5f,0.5f,0.0f,   1.0f,0.0f,
		0.5,-0.5f,0.0f,   1.0f,1.0f,
	};

	GLuint indices[] =
	{
		0,1,2,
		1,2,3,
	};

	GLuint vao;
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	GLuint vbo;
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW);

	GLuint ebo;
	glGenBuffers(1, &ebo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,GL_STATIC_DRAW);

	glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(float) * 5, (void*)0);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 5, (void*)(sizeof(float) * 3));
	glEnableVertexAttribArray(1);

	GLuint texture[2];
	glGenTextures(2, texture);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, texture[0]);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	sf::Image* imageOne = new sf::Image;
	bool isImageOneLoaded = imageOne->loadFromFile("Texture/container.jpg");
	if (isImageOneLoaded)
	{
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageOne->getSize().x, imageOne->getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageOne->getPixelsPtr());
		glGenerateMipmap(GL_TEXTURE_2D);
	}

	delete imageOne;

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, texture[1]);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	sf::Image* imageTwo = new sf::Image;
	bool isImageTwoLoaded = imageTwo->loadFromFile("Texture/awesomeface.png");
	if (isImageTwoLoaded)
	{
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageTwo->getSize().x, imageTwo->getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageTwo->getPixelsPtr());
		glGenerateMipmap(GL_TEXTURE_2D);
	}

	delete imageTwo;

	glUniform1i(glGetUniformLocation(shaderProgram, "inTextureOne"), 0);
	glUniform1i(glGetUniformLocation(shaderProgram, "inTextureTwo"), 1);

	sf::Event event;

	bool isRunning = true;

	while (isRunning)
	{
		while (window.pollEvent(event))
		{
			if (event.type == event.Closed)
			{
				isRunning = false;
			}
		}

		glClear(GL_COLOR_BUFFER_BIT);

		if (isImageOneLoaded && isImageTwoLoaded)
		{
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, texture[0]);
			glActiveTexture(GL_TEXTURE1);
			glBindTexture(GL_TEXTURE_2D, texture[1]);
			glUseProgram(shaderProgram);
		}

		glBindVertexArray(vao);
		glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
		glBindVertexArray(0);

		window.display();
	}

	glDeleteVertexArrays(1, &vao);
	glDeleteBuffers(1, &vbo);
	glDeleteBuffers(1, &ebo);
	glDeleteProgram(shaderProgram);
	glDeleteTextures(2,texture);

	return 0;
}

The Vertex Shader

#version 450 core

layout(location=0) in vec3 inPos;
layout(location=1) in vec2 inTexCoord;

out vec2 TexCoord;

void main()
{
    gl_Position=vec4(inPos,1.0);
    TexCoord=inTexCoord;
}

The fragment shader

#version 450 core

in vec2 TexCoord;
uniform sampler2D inTextureOne;
uniform sampler2D inTextureTwo;

out vec4 FragmentColor;

void main()
{
    FragmentColor=mix(texture(inTextureOne,TexCoord),texture(inTextureTwo,TexCoord),0.2);
}

And this what i got [ATTACH=CONFIG]1659[/ATTACH]
I was expecting awesomeface.png on top of it.

Not only glactivetexture(GL_TEXTURE1) not working,glactivetexture(GL_TEXTURE2) ,glactivetexture(GL_TEXTURE3) and so on is not working and only show nothing.Only glactivetexture(GL_TEXTURE0) is working and drawn and show the texture.

Assuming your hardware supports multitexture - it sounds like you’re using the fixed pipeline and didn’t do glEnable (GL_TEXTURE_2D) after each glActiveTexture.

At first (and quick) glance, there’s nothing bad in your code.
Can you check these things please:

Ensure you have data sent in both the textures (what you give to glTexImage2D).
Display only the second texture in your shader.
Call glGetError after main steps, and then go to a finer grain.

Still not working.Well my spec is Intel Core i7 6700hq,nvidia GTX 960M.

Is this the same problem as here: https://www.opengl.org/discussion_boards/showthread.php/200373-OpenGL-second-Texture-is-not-showing-up-(OpenGL-Texture-Unit)

Can you confirm please, because you seem to have double-posted, and that’s just going to waste people’s time as they try to figure out what’s going on in the first place.

glGetError return 1280

I figured my problem is around glActiveTexture,so I create this thread.Sorry about the that, after I create this thread.,I can’t find delete button to delete the first thread.
Only this program return 1280 error.[ATTACH=CONFIG]1660[/ATTACH]

No need to delete the thread. However, you might post your solution for others so they can benefit from your experience.

I guess that the OP still has no answers for his issue.

Since the OP never posted his solution I figure I’ll at least post mine. I had the exact same issue while going through the learnopengl website using Rust. The two uniform textures in the fragment shader both seemed to be mapped to the same texture even though the Rust program was clearly following the same series of steps as the learnopengl tutorial. It turns out that when setting the uniform locations I was not using null-terminated strings for the uniform variable names.

Changing this:

        shader_program.use_program();
        gl::Uniform1i(
            gl::GetUniformLocation(shader_program.id(), "texture1".as_ptr() as *const i8),
            0,
        );
        gl::Uniform1i(
            gl::GetUniformLocation(shader_program.id(), "texture2".as_ptr() as *const i8),
            1,
        );

to this:

        shader_program.use_program();
        gl::Uniform1i(
            gl::GetUniformLocation(shader_program.id(), "texture1\0".as_ptr() as *const i8),
            0,
        );
        gl::Uniform1i(
            gl::GetUniformLocation(shader_program.id(), "texture2\0".as_ptr() as *const i8),
            1,
        );

fixed my issue. It may be possible that the OP had a similar solution. This is an old thread but I spent a few hours trying to figure out what happened so maybe this will help somebody else. Thanks.