当前位置:网站首页>OpenGL jobs - shaders

OpenGL jobs - shaders

2022-07-07 22:08:00 qq_ fifty-seven million two hundred and fifty-one thousand thre

One 、 In the vertex shader , Invert a triangle

#version 330 core
layout (location = 0) in vec3 aPos;
out vec4 ourcolor;
void main()
{
    gl_Position = vec4(aPos.x, -aPos.y, aPos.z, 1.0);
    ourcolor=vec4(1.0, 0,0.2, 1.0);
}

Two 、 Use uniform Define a horizontal offset , Use this offset in the vertex shader to move the triangle to the right of the screen

#version 330 core
layout (location = 0) in vec3 aPos;
out vec4 ourcolor;
uniform float Pianyi_x;
void main()
{
    gl_Position = vec4(aPos.x+Pianyi_x, aPos.y, aPos.z, 1.0);
    ourcolor=vec4(1.0, 0,0.2, 1.0);
}

int vertexColorLocation = glGetUniformLocation(myshader.ID, "Pianyi_x");
myshader.use();
glUniform1f(vertexColorLocation,0.7f);

3、 ... and Use out Keyword to output vertex positions to fragment shaders , And set the color of the clip to be equal to the vertex position ( Let's look at the result that even the vertex position values are interpolated in the triangle ). After that , Try to answer the following questions : Why is it black in the lower left corner of the triangle ?

I made a triangle

f

原网站

版权声明
本文为[qq_ fifty-seven million two hundred and fifty-one thousand thre]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130608249196.html