feat: unlit shader program
This commit is contained in:
parent
c161f3e54a
commit
1f217971fd
|
@ -52,8 +52,10 @@ endif()
|
||||||
|
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vert.glsl
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vert.glsl
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/vert.glsl COPYONLY)
|
${CMAKE_CURRENT_BINARY_DIR}/vert.glsl COPYONLY)
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/frag.glsl
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/frag_lit.glsl
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/frag.glsl COPYONLY)
|
${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
|
# Append Git version to built executable after it has been built
|
||||||
find_package(Git)
|
find_package(Git)
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -28,10 +28,10 @@ GLuint compileShader(const std::string& shaderPath, GLenum shaderType)
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint compileShaderProgram()
|
GLuint compileShaderProgram(const std::string& fragShaderPath)
|
||||||
{
|
{
|
||||||
GLuint vertShader = compileShader("./vert.glsl", GL_VERTEX_SHADER);
|
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();
|
GLuint shaderProgram = glCreateProgram();
|
||||||
glAttachShader(shaderProgram, vertShader);
|
glAttachShader(shaderProgram, vertShader);
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
|
|
||||||
#include "GL/glew.h"
|
#include "GL/glew.h"
|
||||||
|
|
||||||
GLuint compileShaderProgram();
|
GLuint compileShaderProgram(const std::string& fragShaderPath);
|
||||||
GLuint compileShader(const std::string& shaderPath, GLenum shaderType);
|
GLuint compileShader(const std::string& shaderPath, GLenum shaderType);
|
|
@ -149,7 +149,9 @@ int main()
|
||||||
if (initGraphics(&window) != 0)
|
if (initGraphics(&window) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
GLuint shaderProgram = compileShaderProgram();
|
GLuint litProgram = compileShaderProgram("./frag_lit.glsl");
|
||||||
|
GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl");
|
||||||
|
|
||||||
Icosphere sphere(0.5, 2);
|
Icosphere sphere(0.5, 2);
|
||||||
Orbit orbit(30, glm::vec3(.5, .5, 0));
|
Orbit orbit(30, glm::vec3(.5, .5, 0));
|
||||||
|
|
||||||
|
@ -161,14 +163,16 @@ int main()
|
||||||
glClearColor(0.2, 0.3, 0.3, 1.0);
|
glClearColor(0.2, 0.3, 0.3, 1.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Render everything with the same shaders
|
float time = glfwGetTime();
|
||||||
glUseProgram(shaderProgram);
|
|
||||||
|
|
||||||
// Update uniforms
|
// Render lit objects
|
||||||
updateModelViewProjectionMatrix(shaderProgram, glfwGetTime());
|
glUseProgram(litProgram);
|
||||||
|
updateModelViewProjectionMatrix(litProgram, time);
|
||||||
// Render objects
|
|
||||||
sphere.render();
|
sphere.render();
|
||||||
|
|
||||||
|
// Render unlit objects
|
||||||
|
glUseProgram(unlitProgram);
|
||||||
|
updateModelViewProjectionMatrix(unlitProgram, time);
|
||||||
orbit.render();
|
orbit.render();
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|
Loading…
Reference in New Issue