но исходное изображение ниже:
Код :
Код: Выделить всё
app::Shader cube_shader{ "Cube" };
float vertices[] = {
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
... ...
};
unsigned int cube_VAO, cube_VBO, cube_texture;
//vao,vbo id generate and bind buffer data code
...
glGenTextures(1, &cube_texture);
glBindTexture(GL_TEXTURE_2D, cube_texture);
...
unsigned char* data = stbi_load(pic_path.c_str(), &width, &height, &nrChannels, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
cube_shader.load();
cube_shader.setInt("texture1", 0);
//event loop code
glClearColor(0.3f, 0.3f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, cube_texture);
cube_shader.load();
//set the model,view, projection matrix
...
glBindVertexArray(cube_VAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glfwSwapBuffers(mainWindow);
glfwPollEvents();
Код: Выделить всё
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
out vec2 TexCoord;
void main()
{
gl_Position = projection * view * model*vec4(aPos, 1.0);
//gl_Position = vec4(aPos, 1.0);
TexCoord = vec2(aTexCoord.x, aTexCoord.y);
}
Код: Выделить всё
#version 330 core
out vec4 FragColor;
in vec2 TexCoord;
uniform sampler2D texture1;
void main()
{
FragColor = texture(texture1, TexCoord);
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... e-unnormal