Skip to content

Commit

Permalink
fix shader
Browse files Browse the repository at this point in the history
  • Loading branch information
mohlek committed Aug 2, 2017
1 parent b0be191 commit 712d40f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(SOURCE

set(SHADERS
src/shader/main.frag
src/shader/main.vert
)

#########################################################
Expand Down
4 changes: 4 additions & 0 deletions src/engine/shader/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Shader::~Shader() {
}

void Shader::compile() {
if (shaderId) {
return;
}

this->shaderId = glCreateShader(this->shaderType);
const char* s = this->source.c_str();
glShaderSource(this->shaderId, 1, &s, 0);
Expand Down
1 change: 1 addition & 0 deletions src/engine/shader/ShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void ShaderProgram::link() {
this->programId = glCreateProgram();

for (auto& s : this->shaders) {
s->compile();
glAttachShader(this->programId, s->getShaderId());
}

Expand Down
12 changes: 9 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ int main(int argc, char** argv) {
win->create();

ShaderProgram p1;
ShaderLoader sl(GL_FRAGMENT_SHADER, "shader/main.frag");
Shader s(sl);
p1.shaders.push_back(std::make_shared<Shader>(s));

ShaderLoader loadMainVertex(GL_VERTEX_SHADER, "shader/main.vert");
Shader mainVertex(loadMainVertex);
p1.shaders.push_back(std::make_shared<Shader>(mainVertex));

ShaderLoader loadMainFrag(GL_FRAGMENT_SHADER, "shader/main.frag");
Shader mainFrag(loadMainFrag);
p1.shaders.push_back(std::make_shared<Shader>(mainFrag));

p1.link();

while (win->loop()) {
Expand Down
7 changes: 5 additions & 2 deletions src/shader/main.frag
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#version 450
#version 450 core

void main {
out vec4 color;

void main() {
color = vec4(0.5, 0.0, 0.0, 1.0);
}
7 changes: 7 additions & 0 deletions src/shader/main.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#version 450 core

layout (location = 0) in vec3 aPos;

void main() {
gl_Position = vec4(aPos, 1.0);
}

0 comments on commit 712d40f

Please sign in to comment.