Skip to content

Commit

Permalink
Some cleanup and comments for clarity (for future self sake)
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsell committed Oct 9, 2024
1 parent e1726e7 commit 15fa2a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions res/shaders/Basic.shader
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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;

Expand Down
24 changes: 15 additions & 9 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<float>(2);
layout.Push<float>(2);

VertexArray va;
va.AddBuffer(vb, layout);

IndexBuffer ib(indices, 6);
Expand All @@ -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();
Expand All @@ -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.
Expand Down

0 comments on commit 15fa2a7

Please sign in to comment.