Moved shaders to standalone source file
This commit is contained in:
@@ -47,16 +47,7 @@ App::App():
|
||||
if(glewInit() != GLEW_OK) {
|
||||
error_callback_s(GLFW_NO_ERROR, "glewInit() failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
App::~App() {
|
||||
glfwTerminate();
|
||||
glfwSetErrorCallback(NULL);
|
||||
}
|
||||
|
||||
|
||||
void App::game_loop() {
|
||||
float vertices[] = {
|
||||
.0f, .5f, 1.f, 0.f, 0.f,
|
||||
.5f, -.5f, 0.f, 1.f, 0.f,
|
||||
@@ -67,25 +58,10 @@ void App::game_loop() {
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
auto vertexSource = R"glsl(
|
||||
#version 150 core
|
||||
in vec2 position;
|
||||
in vec3 color;
|
||||
out vec3 _color;
|
||||
void main() { _color = color; gl_Position = vec4(position, 0.0, 1.0); }
|
||||
)glsl";
|
||||
|
||||
auto fragmentSource = R"glsl(
|
||||
#version 150 core
|
||||
in vec3 _color;
|
||||
out vec4 color;
|
||||
void main() { color = vec4(_color, 1.0); }
|
||||
)glsl";
|
||||
|
||||
GLuint shaderProgram = ugly::ShaderProgramBuilder{}
|
||||
.attachFromMemory(GL_VERTEX_SHADER, vertexSource)
|
||||
.attachFromMemory(GL_FRAGMENT_SHADER, fragmentSource)
|
||||
.attachFromFile(GL_VERTEX_SHADER, "assets/shaders/shader.vert")
|
||||
.attachFromFile(GL_FRAGMENT_SHADER, "assets/shaders/shader.frag")
|
||||
.link();
|
||||
glUseProgram(shaderProgram);
|
||||
|
||||
@@ -96,7 +72,16 @@ void App::game_loop() {
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void*)(2*sizeof(float)));
|
||||
glEnableVertexAttribArray(1);
|
||||
}
|
||||
|
||||
|
||||
App::~App() {
|
||||
glfwTerminate();
|
||||
glfwSetErrorCallback(NULL);
|
||||
}
|
||||
|
||||
|
||||
void App::game_loop() {
|
||||
while(!glfwWindowShouldClose(mpWindow)) {
|
||||
glfwPollEvents();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user