pull/2/head
E. Almqvist 2 years ago
parent 8fa8b95246
commit 25a0f13ba2
  1. 4
      shaders/fragment.glsl
  2. 10
      shaders/vertex.glsl
  3. 7
      src/main.cpp
  4. 2
      src/shaders.cpp

@ -1,6 +1,8 @@
#version 330 core
out vec4 FragColor;
uniform vec4 inputColor;
void main() {
FragColor = vec4(1.0f, 1.0f, 1.0f, 0.0f);
FragColor = inputColor;
}

@ -1,7 +1,9 @@
#version 330 core
layout (location = 0) in vec3 aPos;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
out vec4 vertexColor;
void main() {
gl_Position = vec4(aPos, 1.0);
vertexColor = vec4(1.0f, 1.0f, 1.0f, 0.0f);
}

@ -2,6 +2,7 @@
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <vector>
#include <math.h>
#include "shaders.cpp"
@ -81,7 +82,13 @@ void renderCallback(RenderObj ro) {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
float time = glfwGetTime();
float gVal = (sin(time) / 1.5f) + 0.5f;
int vertColLocation = glGetUniformLocation(ro.shaderProg, "inputColor");
glUseProgram(ro.shaderProg);
glUniform4f(vertColLocation, gVal, gVal, gVal, 1.0f);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ro.EBO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}

@ -25,8 +25,6 @@ namespace Shader {
}
unsigned int compile(GLenum shadertype, const char* shaderSource) {
printf("--------------SRC-PREVIEW--------------\n%s\n---------------------------------------\n", shaderSource);
unsigned int shader;
shader = glCreateShader(shadertype);
glShaderSource(shader, 1, &shaderSource, NULL);

Loading…
Cancel
Save