diff --git a/native/main.cpp b/native/main.cpp index 04d94b0..a5d259f 100644 --- a/native/main.cpp +++ b/native/main.cpp @@ -147,6 +147,8 @@ void onGLFWError(int errorCode, const char* error) { std::cerr << "GLFW error: " << error << " (error code: " << errorCode << ")\n"; } +Shader::Program shader; + int main() { glfwSetErrorCallback(onGLFWError); glfwInit(); @@ -161,10 +163,13 @@ int main() { glfwMakeContextCurrent(window); 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.use(); } diff --git a/shaders/fragment.glsl b/shaders/fragment.glsl new file mode 100644 index 0000000..92759c7 --- /dev/null +++ b/shaders/fragment.glsl @@ -0,0 +1,9 @@ +#version 330 core + +in vec2 vTexCoord; + +unfirom sampler2D aTexture0; + +void main() { + gl_FragColor = texture(aTexture0, vTexCoord); +} diff --git a/shaders/vertex.glsl b/shaders/vertex.glsl new file mode 100644 index 0000000..5e8d6d5 --- /dev/null +++ b/shaders/vertex.glsl @@ -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 . +*/ +#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; +}