feat: unlit shader program

This commit is contained in:
Cat Flynn 2023-08-06 13:08:49 +02:00
parent c161f3e54a
commit 1f217971fd
6 changed files with 27 additions and 12 deletions

View File

@ -52,8 +52,10 @@ endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vert.glsl
${CMAKE_CURRENT_BINARY_DIR}/vert.glsl COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/frag.glsl
${CMAKE_CURRENT_BINARY_DIR}/frag.glsl COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/frag_lit.glsl
${CMAKE_CURRENT_BINARY_DIR}/frag_lit.glsl COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/frag_unlit.glsl
${CMAKE_CURRENT_BINARY_DIR}/frag_unlit.glsl COPYONLY)
# Append Git version to built executable after it has been built
find_package(Git)

9
frag_unlit.glsl Normal file
View File

@ -0,0 +1,9 @@
#version 330 core
out vec4 FragColor;
void main()
{
vec3 objectColor = vec3(1.0, 1.0, 1.0);
FragColor = vec4(objectColor, 1.0);
}

View File

@ -28,10 +28,10 @@ GLuint compileShader(const std::string& shaderPath, GLenum shaderType)
return shader;
}
GLuint compileShaderProgram()
GLuint compileShaderProgram(const std::string& fragShaderPath)
{
GLuint vertShader = compileShader("./vert.glsl", GL_VERTEX_SHADER);
GLuint fragShader = compileShader("./frag.glsl", GL_FRAGMENT_SHADER);
GLuint fragShader = compileShader(fragShaderPath, GL_FRAGMENT_SHADER);
GLuint shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertShader);

View File

@ -4,5 +4,5 @@
#include "GL/glew.h"
GLuint compileShaderProgram();
GLuint compileShaderProgram(const std::string& fragShaderPath);
GLuint compileShader(const std::string& shaderPath, GLenum shaderType);

View File

@ -149,7 +149,9 @@ int main()
if (initGraphics(&window) != 0)
return -1;
GLuint shaderProgram = compileShaderProgram();
GLuint litProgram = compileShaderProgram("./frag_lit.glsl");
GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl");
Icosphere sphere(0.5, 2);
Orbit orbit(30, glm::vec3(.5, .5, 0));
@ -161,14 +163,16 @@ int main()
glClearColor(0.2, 0.3, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Render everything with the same shaders
glUseProgram(shaderProgram);
float time = glfwGetTime();
// Update uniforms
updateModelViewProjectionMatrix(shaderProgram, glfwGetTime());
// Render objects
// Render lit objects
glUseProgram(litProgram);
updateModelViewProjectionMatrix(litProgram, time);
sphere.render();
// Render unlit objects
glUseProgram(unlitProgram);
updateModelViewProjectionMatrix(unlitProgram, time);
orbit.render();
glfwSwapBuffers(window);