OpenGL shader渲染贴图

时间:2022-10-03 20:01:10

simple.vert

#version 400 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
layout (location = 2) 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 400 core
in vec3 ourColor;
in vec2 TexCoord;
out vec3 color;
uniform sampler2D ourTexture;

void main()
{
    color = vec3(texture(ourTexture, TexCoord));
}