diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d0bd41..ead21fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,10 @@ set(SOURCE src/main.cpp ) +set(SHADERS + src/shader/main.frag +) + ######################################################### # FIND OpenGL ######################################################### @@ -48,6 +52,15 @@ if(NOT GLFW_FOUND) message(ERROR " GLFW not found!") endif(NOT GLFW_FOUND) +######################################################## +# COPY SHADER +######################################################## + +foreach(SHADER ${SHADERS}) + message(STATUS "copy shader " ${SHADER}) + file(COPY ${SHADER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/shader/) +endforeach(SHADER) + add_executable(medievalSomething ${SOURCE}) target_link_libraries(medievalSomething ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} ${GLFW_LIBRARIES}) diff --git a/src/engine/shader/Shader.h b/src/engine/shader/Shader.h index 047cf01..e785214 100644 --- a/src/engine/shader/Shader.h +++ b/src/engine/shader/Shader.h @@ -1,3 +1,6 @@ +#ifndef SHADER_H +#define SHADER_H + #include #include @@ -24,3 +27,5 @@ namespace Engine { GLuint getShaderId() { return this->shaderId; } }; } + +#endif diff --git a/src/engine/shader/ShaderLoader.cpp b/src/engine/shader/ShaderLoader.cpp index 1b9551d..359b3a6 100644 --- a/src/engine/shader/ShaderLoader.cpp +++ b/src/engine/shader/ShaderLoader.cpp @@ -5,7 +5,7 @@ using namespace Engine; -ShaderLoader::ShaderLoader(GLenum shaderType, std::string& path) : shaderType(shaderType) { +ShaderLoader::ShaderLoader(GLenum shaderType, std::string&& path) : shaderType(shaderType) { std::ifstream fileStream(path.c_str(), std::ios::in); diff --git a/src/engine/shader/ShaderLoader.h b/src/engine/shader/ShaderLoader.h index d7967ef..08c1d57 100644 --- a/src/engine/shader/ShaderLoader.h +++ b/src/engine/shader/ShaderLoader.h @@ -1,5 +1,9 @@ +#ifndef SHADERLOADER_H +#define SHADERLOADER_H + #include #include +#include namespace Engine { @@ -9,7 +13,8 @@ namespace Engine { const GLenum shaderType; std::string source; - ShaderLoader(GLenum shaderType, std::string& path); - ~ShaderLoader(); + ShaderLoader(GLenum shaderType, std::string&& path); }; } + +#endif diff --git a/src/engine/shader/ShaderProgram.h b/src/engine/shader/ShaderProgram.h index 747de5b..21eef7a 100644 --- a/src/engine/shader/ShaderProgram.h +++ b/src/engine/shader/ShaderProgram.h @@ -10,9 +10,10 @@ namespace Engine { class ShaderProgram { private: GLuint programId = 0; - - std::vector> shaders; + public: + std::vector> shaders; + ShaderProgram(); virtual ~ShaderProgram(); diff --git a/src/main.cpp b/src/main.cpp index 3f9e3ba..e492a46 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,21 +3,30 @@ #include "engine/Window.h" #include "engine/Object.h" +#include "engine/shader/ShaderProgram.h" +#include "engine/shader/ShaderLoader.h" -void render() { - static const GLfloat color[] = {.0f, .0f, .5f, 1.0f}; - glClearBufferfv(GL_COLOR, 0, color); -} +using namespace Engine; int main(int argc, char** argv) { - Engine::Window* win = new Engine::Window(); + Window* win = new Window(); win->create(); + + ShaderProgram p1; + ShaderLoader sl(GL_FRAGMENT_SHADER, "shader/main.frag"); + Shader s(sl); + p1.shaders.push_back(std::make_shared(s)); + p1.link(); - Engine::Object* o = new Engine::Object(); - - while(win->loop()); + while (win->loop()) { + glClear(GL_COLOR_BUFFER_BIT || GL_DEPTH_BUFFER_BIT); + + p1.use(); + + p1.end(); + } win->close(); return 0; diff --git a/src/shader/main.frag b/src/shader/main.frag new file mode 100644 index 0000000..c5fceca --- /dev/null +++ b/src/shader/main.frag @@ -0,0 +1,4 @@ +#version 450 + +void main { +} diff --git a/src/shader/main.vert b/src/shader/main.vert new file mode 100644 index 0000000..e69de29