Advertisement

glError 1282

Started by January 18, 2018 12:18 PM
2 comments, last by NubDevice 7 years ago

i got error 1282 in my code.


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);

	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);

	GLenum error = glGetError();
	std::cout << error << std::endl;

	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;
}

and this is 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;
} 

and 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);
}

I was expecting awesomeface.png on top of container.jpg

failed texture unit.jpg

I'm just a noob

50 minutes ago, Balma Alparisi said:

i got error 1282 in my code.

Sorry to be a bit rude, but...

You already posted in another forum, plus in this another forum you posted twice in the same section. You started to have answers from this another forums, from people willing to help you solve your problems. And you posted here in this forum after the answers from this another forum. This is not that respectful, plus this will spread answers instead of focusing on them.

Also, please consider how to ask questions. Telling that you have a certain error (which I, to say, gave to you on the other forum) and spitting your code after will not make people willing to help you.

Thank you.

Advertisement

Well, my guess would be re-position your vbo and ebo genBuffer calls ahead of your vao bind. After that, unbind your vao during initialization before you start with the texture loads.

edit: The other thing we don't see is when you do your useProgram call before you set your shader uniforms.

Dev careful. Pixel on board.

This topic is closed to new replies.

Advertisement