From 15fa2a78f24e18a76e5292791a1e7d0726491cc9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 8 Oct 2024 21:46:13 -0500 Subject: [PATCH] Some cleanup and comments for clarity (for future self sake) --- res/shaders/Basic.shader | 5 +++-- src/Application.cpp | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/res/shaders/Basic.shader b/res/shaders/Basic.shader index db31f70..53bba99 100644 --- a/res/shaders/Basic.shader +++ b/res/shaders/Basic.shader @@ -1,10 +1,11 @@ #shader vertex #version 330 core +//Receiving vertex attribute data layout(location = 0) in vec4 position; layout(location = 1) in vec2 texCoord; -//Varying to pass data from vertex shader to fragment shader. +//'Varying' variable to pass data from vertex shader to fragment shader. out vec2 v_TexCoord; void main() @@ -17,9 +18,9 @@ void main() #version 330 core out vec4 color; - in vec2 v_TexCoord; +//Uniforms get data from CPU into the shader (GPU) uniform vec4 u_Color; uniform sampler2D u_Texture; diff --git a/src/Application.cpp b/src/Application.cpp index 6df9f7c..4b70390 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -47,7 +47,7 @@ int main(void) //Vertex buffer data //Position x, Position y, tex coord x, tex coord y - float positions[] = { + float vertexData[] = { -0.5f, -0.5f, 0.0f, 0.0f, //0 0.5f, -0.5f, 1.0f, 0.0f, //1 0.5f, 0.5f, 1.0f, 1.0f, //2 @@ -60,17 +60,16 @@ int main(void) 2, 3, 0 }; - //Blending - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - - VertexBuffer vb(positions, 4 * 4 * sizeof(float)); + unsigned int vertexCount = 4; + unsigned int elementsInVertex = 4; + VertexBuffer vb(vertexData, vertexCount * elementsInVertex * sizeof(float)); - VertexArray va; VertexBufferLayout layout; layout.Push(2); layout.Push(2); + + VertexArray va; va.AddBuffer(vb, layout); IndexBuffer ib(indices, 6); @@ -79,9 +78,11 @@ int main(void) shader.Bind(); shader.SetUniform4f("u_Color", 0.8f, 0.3f, 0.8f, 1.0f); + //Creating texture from path and binding it as the active texture Texture texture("res/textures/ship.png"); - texture.Bind(); - shader.SetUniform1i("u_Texture", 0); + unsigned int textureSlot = 0; + texture.Bind(textureSlot); + shader.SetUniform1i("u_Texture", textureSlot); va.Unbind(); vb.Unbind(); @@ -90,6 +91,11 @@ int main(void) Renderer renderer; + //Blending config + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + float redValue = 0.0f; float redIncrement = 0.05f; //Set the value of the 'u_Color' uniform variable in the shader. Thus passing data from the CPU to the GPU.