More boilerplate code

This commit is contained in:
hiimgoodpack 2021-01-28 21:49:11 -05:00
parent f4fe28e0ab
commit bbb8e397d3
Signed by: hiimgoodpack
GPG key ID: 4E0E62733C14AE69
3 changed files with 45 additions and 3 deletions

View file

@ -147,6 +147,8 @@ void onGLFWError(int errorCode, const char* error) {
std::cerr << "GLFW error: " << error << " (error code: " << errorCode << ")\n"; std::cerr << "GLFW error: " << error << " (error code: " << errorCode << ")\n";
} }
Shader::Program shader;
int main() { int main() {
glfwSetErrorCallback(onGLFWError); glfwSetErrorCallback(onGLFWError);
glfwInit(); glfwInit();
@ -161,10 +163,13 @@ int main() {
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
Mesh::InstancedElements sphere = processMesh("../meshes/sphere.obj"); Mesh::InstancedElements sphere = processMesh("../meshes/sphere.obj");
Shader::Program shader;
shader.add(readExternalFile("../shaders/vertex.glsl").c_str(), -1, GL_VERTEX_SHADER); {
shader.add(readExternalFile("../shaders/fragment.glsl").c_str(), -1, GL_FRAGMENT_SHADER); std::string vertexCode = readExternalFile("../shaders/vertex.glsl");
shader.add(vertexCode.c_str(), -1, GL_VERTEX_SHADER);
std::string fragmentCode = readExternalFile("../shaders/fragment.glsl");
shader.add(fragmentCode.c_str(), -1, GL_FRAGMENT_SHADER);
}
shader.link(); shader.link();
shader.use(); shader.use();
} }

9
shaders/fragment.glsl Normal file
View file

@ -0,0 +1,9 @@
#version 330 core
in vec2 vTexCoord;
unfirom sampler2D aTexture0;
void main() {
gl_FragColor = texture(aTexture0, vTexCoord);
}

28
shaders/vertex.glsl Normal file
View file

@ -0,0 +1,28 @@
/*
Copyright (C) 2021 hiimgoodpack
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#version 330 core
layout (location = 0) in vec3 aPosition;
layout (location = 1) in vec3 aTexCoord;
out vec2 vTexCoord;
uniform mat4 aTransform;
void main() {
gl_Position = aTransform * vec4(aPosition, 1);
vTexCoordd = aTexCoord;
}