Texture exercises

This commit is contained in:
Joseph Ferano 2023-10-17 22:49:33 +07:00
parent 65c81c4c58
commit afd31d361b
2 changed files with 9 additions and 15 deletions

20
main.c
View File

@ -87,10 +87,10 @@ int main(void) {
float v1[] = {
// Position // Color // UV
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 2.0f, 2.0f,
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 2.0f, 0.0f,
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f
-0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 2.0f
};
unsigned int indices[] = {
@ -135,12 +135,10 @@ int main(void) {
glClear(GL_COLOR_BUFFER_BIT);
float timeValue = glfwGetTime();
float green = (sin(timeValue) / 2.0f) + 0.5f;
float mix = (sin(timeValue) / 2.0f) + 0.5f;
glUseProgram(shaderProgram);
int ourColorLoc = glGetUniformLocation(shaderProgram, "ourColor");
glUniform4f(ourColorLoc, 0.0f, green, 0.0f, 1.0f);
int offsetLoc = glGetUniformLocation(shaderProgram, "offset");
glUniform1f(offsetLoc, 0.5f);
int offsetLoc = glGetUniformLocation(shaderProgram, "mixAmount");
glUniform1f(offsetLoc, mix);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture1);
@ -150,12 +148,6 @@ int main(void) {
glBindVertexArray(vaos[0]);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
// glBindVertexArray(vaos[1]);
// glDrawArrays(GL_TRIANGLES, 0, 3);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glfwSwapBuffers(window);
glfwPollEvents();
}

View File

@ -7,7 +7,9 @@ out vec4 FragColor;
uniform sampler2D t1;
uniform sampler2D t2;
uniform float mixAmount;
void main() {
FragColor = mix(texture(t1, tCoord), texture(t2, tCoord), 0.2);
vec2 flipped = vec2(-tCoord.x, tCoord.y);
FragColor = mix(texture(t1, tCoord), texture(t2, flipped), mixAmount);
}