summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-05-20 23:03:42 -0500
committersanine-a <sanine.not@pm.me>2020-05-20 23:03:42 -0500
commita09b5a72d365f10e35b012e04b95891abf0b8313 (patch)
tree8c233b15f5592371dde867abc62e31193b442c97
parentc3a41085272644709d891bf04137a6c2bd901230 (diff)
add cube primitive
-rw-r--r--CMakeLists.txt2
-rw-r--r--demo.c14
-rw-r--r--demo.fs8
-rw-r--r--demo.vs8
-rw-r--r--include/honey.h1
-rw-r--r--include/mesh.h3
-rw-r--r--include/primitives.h24
-rw-r--r--src/primitives.c49
8 files changed, 86 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c78eafa..9222cc3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,7 +9,7 @@ add_executable(honey_engine_demo demo.c)
set(CMAKE_C_FLAGS "-g")
-add_library(honey src/honey.c src/texture.c src/shader.c src/mesh.c)
+add_library(honey src/honey.c src/mesh.c src/primitives.c src/shader.c src/texture.c)
add_library(glad src/glad.c)
add_library(stb_image src/stb_image.c)
diff --git a/demo.c b/demo.c
index 94fdd66..2213dc7 100644
--- a/demo.c
+++ b/demo.c
@@ -165,8 +165,8 @@ int main() {
}
/* create triangle */
- float vertices[] = {
- /* positions colors tex coords */
+ /*float vertices[] = {
+ /* positions colors tex coords /
-0.5, -0.5, 0.5, 1.0, 0.0, 0.0, 0.0, 0.0,
0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0, 0.0,
-0.5, 0.5, 0.5, 0.0, 0.0, 1.0, 0.0, 1.0,
@@ -189,18 +189,18 @@ int main() {
0, 1, 4,
1, 4, 5 };
- unsigned int attribute_sizes[] = { 3, 3, 2 }; /* position, color, texture coordinate */
+ unsigned int attribute_sizes[] = { 3, 3, 2 }; /* position, color, texture coordinate /
enum honey_mesh_result result = honey_mesh_new(&cube,
vertices, 8, 3, attribute_sizes,
indices,
- sizeof(indices)/sizeof(unsigned int));
- if (result != MESH_OK) {
+ sizeof(indices)/sizeof(unsigned int)); */
+ if (honey_mesh_new_cube(&cube, 1, 1, 1) != MESH_OK) {
fprintf(stderr, "Failed to load cube\n");
return 1;
}
- honey_shader_set_int(shader, "boxTexture", 0);
- honey_shader_set_int(shader, "happyTexture", 1);
+ /*honey_shader_set_int(shader, "boxTexture", 0);
+ honey_shader_set_int(shader, "happyTexture", 1);*/
glm_mat4_identity(model);
glm_rotate_x(model, glm_rad(-55), model);
diff --git a/demo.fs b/demo.fs
index ddfc235..e43d761 100644
--- a/demo.fs
+++ b/demo.fs
@@ -1,14 +1,10 @@
#version 330 core
-in vec3 outColor;
-in vec2 outTexCoord;
+in vec4 color;
out vec4 FragColor;
-uniform sampler2D boxTexture;
-uniform sampler2D happyTexture;
-
void main()
{
- FragColor = mix(texture(boxTexture, outTexCoord), texture(happyTexture, outTexCoord), 0.1);
+ FragColor = color;
}
diff --git a/demo.vs b/demo.vs
index 3ed0556..2c62f90 100644
--- a/demo.vs
+++ b/demo.vs
@@ -1,10 +1,7 @@
#version 330 core
layout (location = 0) in vec3 position;
-layout (location = 1) in vec3 color;
-layout (location = 2) in vec2 texCoord;
-out vec3 outColor;
-out vec2 outTexCoord;
+out vec4 color;
uniform mat4 model;
uniform mat4 view;
@@ -13,6 +10,5 @@ uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(position.xyz, 1.0);
- outColor = color;
- outTexCoord = texCoord;
+ color = vec4(0, 1, 1, 1);
} \ No newline at end of file
diff --git a/include/honey.h b/include/honey.h
index 7ae7789..bea21c4 100644
--- a/include/honey.h
+++ b/include/honey.h
@@ -4,6 +4,7 @@
/** @file Defines the basic loading and callback functions. */
#include "common.h"
#include "mesh.h"
+#include "primitives.h"
#include "shader.h"
#include "texture.h"
diff --git a/include/mesh.h b/include/mesh.h
index 2040f44..24aec26 100644
--- a/include/mesh.h
+++ b/include/mesh.h
@@ -1,4 +1,5 @@
-/** @brief Defines the honey_mesh struct and related basic mesh functions. */
+/** @file Defines the honey_mesh struct and related basic mesh functions.
+*/
#ifndef HONEY_MESH_H
#define HONEY_MESH_H
diff --git a/include/primitives.h b/include/primitives.h
new file mode 100644
index 0000000..81dc16f
--- /dev/null
+++ b/include/primitives.h
@@ -0,0 +1,24 @@
+#ifndef HONEY_PRIMITIVES_H
+#define HONEY_PRIMITIVES H
+
+/** @file Define various common primitive objects.
+ */
+
+#include "common.h"
+#include "mesh.h"
+
+/** @brief Create a cube.
+ *
+ * @param[out] mesh Pointer to the destination mesh
+ * @param[in] width Desired width of the cube (x-axis)
+ * @param[in] height Desired height of the cube (y-axis)
+ * @param[in] depth Desired depth of the cube (z-axis)
+ *
+ * @return Success or failure code
+ */
+enum honey_mesh_result honey_mesh_new_cube(honey_mesh* mesh,
+ float width,
+ float height,
+ float depth);
+
+#endif
diff --git a/src/primitives.c b/src/primitives.c
index 798a691..7cbea07 100644
--- a/src/primitives.c
+++ b/src/primitives.c
@@ -1,3 +1,48 @@
-#ifndef HONEY_PRIMITIVE_OBJECTS
-#define HONEY_PRIMITIVE_OBJECTS
+#include "include/primitives.h"
+
+enum honey_mesh_result honey_mesh_new_cube(honey_mesh* mesh,
+ float width,
+ float height,
+ float depth) {
+ float x0 = 0;
+ float y0 = 0;
+ float z0 = 0;
+
+ float x1 = width;
+ float y1 = height;
+ float z1 = depth;
+
+ float vertices[] = {
+ x0, y0, z0,
+ x1, y0, z0,
+ x0, y1, z0,
+ x1, y1, z0,
+ x0, y0, z1,
+ x1, y0, z1,
+ x0, y1, z1,
+ x1, y1, z1 };
+
+ unsigned int indices[] = { 0, 1, 2,
+ 1, 2, 3,
+ 4, 5, 6,
+ 5, 6, 7,
+ 0, 2, 4,
+ 2, 4, 6,
+ 1, 3, 5,
+ 3, 5, 7,
+ 2, 3, 6,
+ 3, 6, 7,
+ 0, 1, 4,
+ 1, 4, 5 };
+
+ unsigned int attrib_sizes[] = { 3 };
+
+ enum honey_mesh_result result = honey_mesh_new(mesh,
+ vertices,
+ 8, 1, attrib_sizes,
+ indices, 36);
+
+ return result;
+}
+