mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-02 04:37:54 +08:00
Fix several texture/shader exercises to use updated code viewer.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
|
||||
out vec3 ourColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos.x, -aPos.y, aPos.z, 1.0); // just add a - to the y position
|
||||
ourColor = aColor;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// In your CPP file:
|
||||
// ======================
|
||||
float offset = 0.5f;
|
||||
ourShader.setFloat("xOffset", offset);
|
||||
|
||||
// In your vertex shader:
|
||||
// ======================
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
|
||||
out vec3 ourColor;
|
||||
|
||||
uniform float xOffset;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos.x + xOffset, aPos.y, aPos.z, 1.0); // add the xOffset to the x position of the vertex position
|
||||
ourColor = aColor;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Vertex shader:
|
||||
// ==============
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
|
||||
// out vec3 ourColor;
|
||||
out vec3 ourPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos, 1.0);
|
||||
// ourColor = aColor;
|
||||
ourPosition = aPos;
|
||||
}
|
||||
|
||||
// Fragment shader:
|
||||
// ================
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
// in vec3 ourColor;
|
||||
in vec3 ourPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(ourPosition, 1.0); // note how the position value is linearly interpolated to get all the different colors
|
||||
}
|
||||
|
||||
/*
|
||||
Answer to the question: Do you know why the bottom-left side is black?
|
||||
-- --------------------------------------------------------------------
|
||||
Think about this for a second: the output of our fragment's color is equal to the (interpolated) coordinate of
|
||||
the triangle. What is the coordinate of the bottom-left point of our triangle? This is (-0.5f, -0.5f, 0.0f). Since the
|
||||
xy values are negative they are clamped to a value of 0.0f. This happens all the way to the center sides of the
|
||||
triangle since from that point on the values will be interpolated positively again. Values of 0.0f are of course black
|
||||
and that explains the black side of the triangle.
|
||||
*/
|
||||
@@ -0,0 +1,13 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D ourTexture1;
|
||||
uniform sampler2D ourTexture2;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = mix(texture(ourTexture1, TexCoord), texture(ourTexture2, vec2(1.0 - TexCoord.x, TexCoord.y)), 0.2);
|
||||
}
|
||||
Reference in New Issue
Block a user