Skip to content

Commit

Permalink
add shader loader
Browse files Browse the repository at this point in the history
  • Loading branch information
mohlek committed Aug 2, 2017
1 parent 7209ed0 commit b0be191
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 13 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ set(SOURCE
src/main.cpp
)

set(SHADERS
src/shader/main.frag
)

#########################################################
# FIND OpenGL
#########################################################
Expand Down Expand Up @@ -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})
5 changes: 5 additions & 0 deletions src/engine/shader/Shader.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef SHADER_H
#define SHADER_H

#include <GL/glew.h>

#include <string>
Expand All @@ -24,3 +27,5 @@ namespace Engine {
GLuint getShaderId() { return this->shaderId; }
};
}

#endif
2 changes: 1 addition & 1 deletion src/engine/shader/ShaderLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 7 additions & 2 deletions src/engine/shader/ShaderLoader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#ifndef SHADERLOADER_H
#define SHADERLOADER_H

#include <GL/glew.h>
#include <string>
#include <memory>

namespace Engine {

Expand All @@ -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
5 changes: 3 additions & 2 deletions src/engine/shader/ShaderProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ namespace Engine {
class ShaderProgram {
private:
GLuint programId = 0;

std::vector<std::shared_ptr<Shader>> shaders;

public:
std::vector<std::shared_ptr<Shader>> shaders;

ShaderProgram();
virtual ~ShaderProgram();

Expand Down
25 changes: 17 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Shader>(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;
Expand Down
4 changes: 4 additions & 0 deletions src/shader/main.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#version 450

void main {
}
Empty file added src/shader/main.vert
Empty file.

0 comments on commit b0be191

Please sign in to comment.