OpenGL shader渲染贴图

时间:2024-10-02 19:35:38

simple.vert

#version  core
layout (location = ) in vec3 position;
layout (location = ) in vec3 color;
layout (location = ) in vec2 texCoord;
out vec3 ourColor;
out vec2 TexCoord;
//out vec3 FragPos;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projection;
void main()
{
//gl_Position = projection*viewMatrix*modelMatrix*vec4(position, 1.0f);
gl_Position = vec4(position, 1.0f);
ourColor = color;
TexCoord = texCoord;
// if non-uniform transfrom is applied
//FragPos = vec3(modelMatrix * vec4(position, 1.0f));
}

simple.frag

#version  core
in vec3 ourColor;
in vec2 TexCoord;
out vec3 color;
uniform sampler2D ourTexture; void main()
{
color = vec3(texture(ourTexture, TexCoord));
}