]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Add color to vertices
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 13 Jul 2021 06:52:09 +0000 (08:52 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 13 Jul 2021 06:52:09 +0000 (08:52 +0200)
shaders/fragment.glsl
shaders/vertex.glsl
src/cube.c
src/mesh.c
src/mesh.h

index 13793e95ae6acf32fae7ee486ccf2ee097b33172..7eec9ae9930932b4c1b5a07ca120db15cb1f3789 100755 (executable)
@@ -1,6 +1,7 @@
 #version 330 core
 
 in vec2 fragmentTextureCoords;
+in vec3 fragmentColor;
 
 out vec4 outColor;
 
@@ -8,7 +9,7 @@ uniform sampler2D texture0;
 
 void main()
 {
-       outColor = texture(texture0, fragmentTextureCoords);
+       outColor = texture(texture0, fragmentTextureCoords) * vec4(fragmentColor, 1.0);
        if (outColor.a == 0.0)
         discard;
 }
index 58e743a9c4f7daea8cabf213c27e881745083a23..5eccd55de0b1dc27a2d720a31f8eef70595ac557 100755 (executable)
@@ -2,8 +2,10 @@
 
 layout(location = 0) in vec3 vertexPosition;
 layout(location = 1) in vec2 vertexTextureCoords;
+layout(location = 2) in vec3 vertexColor;
 
 out vec2 fragmentTextureCoords;
+out vec3 fragmentColor;
 
 uniform mat4 model;
 uniform mat4 view;
@@ -13,5 +15,6 @@ void main()
 {
     gl_Position = projection * view * model * vec4(vertexPosition, 1.0);
     fragmentTextureCoords = vertexTextureCoords;
+       fragmentColor = vertexColor;
 }
 
index 80d6d82c79a4b651e6bd8b8a4fa22721f73a1cb4..6a32b34412fb355e05d966a017bd6172bd976239 100644 (file)
@@ -2,52 +2,52 @@
 
 Vertex cube_vertices[6][6] = {
        {
-               {-0.5, -0.5, -0.5, +0.0, +0.0},
-               {+0.5, -0.5, -0.5, +1.0, +0.0},
-               {+0.5, +0.5, -0.5, +1.0, +1.0},
-               {+0.5, +0.5, -0.5, +1.0, +1.0},
-               {-0.5, +0.5, -0.5, +0.0, +1.0},
-               {-0.5, -0.5, -0.5, +0.0, +0.0},
+               {-0.5, -0.5, -0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, -0.5, -0.5, +1.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, -0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, -0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {-0.5, +0.5, -0.5, +0.0, +1.0, +1.0, +1.0, +1.0},
+               {-0.5, -0.5, -0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
        },
        {
-               {-0.5, -0.5, +0.5, +0.0, +0.0},
-               {+0.5, +0.5, +0.5, +1.0, +1.0},
-               {+0.5, -0.5, +0.5, +1.0, +0.0},
-               {+0.5, +0.5, +0.5, +1.0, +1.0},
-               {-0.5, -0.5, +0.5, +0.0, +0.0},
-               {-0.5, +0.5, +0.5, +0.0, +1.0},
+               {-0.5, -0.5, +0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, +0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {+0.5, -0.5, +0.5, +1.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, +0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {-0.5, -0.5, +0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {-0.5, +0.5, +0.5, +0.0, +1.0, +1.0, +1.0, +1.0},
        },
        {
-               {-0.5, +0.5, +0.5, +1.0, +1.0},
-               {-0.5, -0.5, -0.5, +0.0, +0.0},
-               {-0.5, +0.5, -0.5, +0.0, +1.0},
-               {-0.5, -0.5, -0.5, +0.0, +0.0},
-               {-0.5, +0.5, +0.5, +1.0, +1.0},
-               {-0.5, -0.5, +0.5, +1.0, +0.0},
+               {-0.5, +0.5, +0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {-0.5, -0.5, -0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {-0.5, +0.5, -0.5, +0.0, +1.0, +1.0, +1.0, +1.0},
+               {-0.5, -0.5, -0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {-0.5, +0.5, +0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {-0.5, -0.5, +0.5, +1.0, +0.0, +1.0, +1.0, +1.0},
        },
        {
-               {+0.5, +0.5, +0.5, +1.0, +1.0},
-               {+0.5, +0.5, -0.5, +0.0, +1.0},
-               {+0.5, -0.5, -0.5, +0.0, +0.0},
-               {+0.5, -0.5, -0.5, +0.0, +0.0},
-               {+0.5, -0.5, +0.5, +1.0, +0.0},
-               {+0.5, +0.5, +0.5, +1.0, +1.0},
+               {+0.5, +0.5, +0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, -0.5, +0.0, +1.0, +1.0, +1.0, +1.0},
+               {+0.5, -0.5, -0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, -0.5, -0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, -0.5, +0.5, +1.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, +0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
        },
        {
-               {-0.5, -0.5, -0.5, +0.0, +1.0},
-               {+0.5, -0.5, -0.5, +1.0, +1.0},
-               {+0.5, -0.5, +0.5, +1.0, +0.0},
-               {+0.5, -0.5, +0.5, +1.0, +0.0},
-               {-0.5, -0.5, +0.5, +0.0, +0.0},
-               {-0.5, -0.5, -0.5, +0.0, +1.0},
+               {-0.5, -0.5, -0.5, +0.0, +1.0, +1.0, +1.0, +1.0},
+               {+0.5, -0.5, -0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {+0.5, -0.5, +0.5, +1.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, -0.5, +0.5, +1.0, +0.0, +1.0, +1.0, +1.0},
+               {-0.5, -0.5, +0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {-0.5, -0.5, -0.5, +0.0, +1.0, +1.0, +1.0, +1.0},
        },
        {
-               {-0.5, +0.5, -0.5, +0.0, +1.0},
-               {+0.5, +0.5, -0.5, +1.0, +1.0},
-               {+0.5, +0.5, +0.5, +1.0, +0.0},
-               {+0.5, +0.5, +0.5, +1.0, +0.0},
-               {-0.5, +0.5, +0.5, +0.0, +0.0},
-               {-0.5, +0.5, -0.5, +0.0, +1.0},
+               {-0.5, +0.5, -0.5, +0.0, +1.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, -0.5, +1.0, +1.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, +0.5, +1.0, +0.0, +1.0, +1.0, +1.0},
+               {+0.5, +0.5, +0.5, +1.0, +0.0, +1.0, +1.0, +1.0},
+               {-0.5, +0.5, +0.5, +0.0, +0.0, +1.0, +1.0, +1.0},
+               {-0.5, +0.5, -0.5, +0.0, +1.0, +1.0, +1.0, +1.0},
        },
 };
 
index c9dbff816d83ad80cd9adf07806ad19ac393b8c6..ab2f7938e8948e2774bc454c0f64b2af9b125f3c 100644 (file)
@@ -143,6 +143,9 @@ static void mesh_configure(Mesh *mesh)
        glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(Vertex), (GLvoid *) offsetof(Vertex, s));
        glEnableVertexAttribArray(1);
 
+       glVertexAttribPointer(2, 3, GL_FLOAT, false, sizeof(Vertex), (GLvoid *) offsetof(Vertex, r));
+       glEnableVertexAttribArray(2);
+
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);
 
index e4eb4b4dff900da0bb34c38d3de1e0d8db1ae69a..9271bef050545ba674397b1ad87b92921fcc2d8e 100644 (file)
@@ -14,6 +14,7 @@ typedef struct
 {
        GLfloat x, y, z;
        GLfloat s, t;
+       GLfloat r, g, b;
 } __attribute__((packed)) Vertex;
 
 typedef struct