Shaders_ Exercise II: using a uniform definition of horizontal offset, using the vertex shader to offset the triangle to the right of the screen

2019/11/27

 1 // In your CPP file:
 2 // ======================
 3 float offset = 0.5f;
 4 ourShader.setFloat("xOffset", offset);
 5 
 6 // In your vertex shader:
 7 // ======================
 8 #version 330 core
 9 layout (location = 0) in vec3 aPos;
10 layout (location = 1) in vec3 aColor;
11 
12 out vec3 ourColor;
13 
14 uniform float xOffset;
15 
16 void main()
17 {
18     gl_Position = vec4(aPos.x + xOffset, aPos.y, aPos.z, 1.0); // add the xOffset to the x position of the vertex position
19     ourColor = aColor;
20 }
View Code

note:

Note that the query does not require uniform address before you used the shader programs, but a uniform update before you need to use the program (call glUseProgram), because it is set uniform in the currently active shader program.

Guess you like

Origin www.cnblogs.com/ljy08163268/p/11943491.html