summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
author0scar <qgt268@alumni.ku.dk>2024-02-12 06:57:44 +0000
committer0scar <qgt268@alumni.ku.dk>2024-02-12 08:11:17 +0000
commit63e6c8fe178082f3ab7ff46f4c7f7216626723bf (patch)
treeffabf211c1eb247cd1cf7f1adc3b88f99a3fa223 /src/core
parent82effe4e4d4a6b22f77055875d046304a86541eb (diff)
Enable textures (?)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/src/loop.c136
1 files changed, 32 insertions, 104 deletions
diff --git a/src/core/src/loop.c b/src/core/src/loop.c
index 642f771..f9c100c 100644
--- a/src/core/src/loop.c
+++ b/src/core/src/loop.c
@@ -5,6 +5,9 @@
#include <cglm/cglm.h>
+#define STB_IMAGE_IMPLEMENTATION
+#include <stb/stb_image.h>
+
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
/* include winapi */
#include <Windows.h>
@@ -36,6 +39,12 @@ Platform* GLOBAL_PLATFORM = NULL;
input_callback_t* callbacks[128];
usize callbacks_len;
+/* TODO: MOVE ME */
+#include <glad/gl.h>
+char *img_filename = "test.png";
+unsigned char *test_image = NULL;
+GLuint img_texture;
+
i32 nproc(void) {
return get_nprocs();
}
@@ -95,109 +104,6 @@ Platform* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight
// Dont forget to init the renderer
init_render_opengl(w);
- //const GladGLContext *gl = w->context;
-
- //struct RenderObject *testobject = malloc(sizeof(struct RenderObject));
-
- //gl->GenVertexArrays(1, &(testobject->vao));
- //gl->BindVertexArray(testobject->vao);
-
- //p->testobject = testobject;
-
- //testobject->g_vertex_buffer_data[0] = -1.0f;
- //testobject->g_vertex_buffer_data[1] = -1.0f;
- //testobject->g_vertex_buffer_data[2] = 0.0f;
-
- //testobject->g_vertex_buffer_data[3] = 1.0f;
- //testobject->g_vertex_buffer_data[4] = -1.0f;
- //testobject->g_vertex_buffer_data[5] = 0.0f;
-
- //testobject->g_vertex_buffer_data[6] = 0.0f;
- //testobject->g_vertex_buffer_data[7] = 1.0f;
- //testobject->g_vertex_buffer_data[8] = 0.0f;
-
- //static const float bufdata[] = {
- // -1.0f,-1.0f,-1.0f, // triangle 1 : begin
- // -1.0f,-1.0f, 1.0f,
- // -1.0f, 1.0f, 1.0f, // triangle 1 : end
- // 1.0f, 1.0f,-1.0f, // triangle 2 : begin
- // -1.0f,-1.0f,-1.0f,
- // -1.0f, 1.0f,-1.0f, // triangle 2 : end
- // 1.0f,-1.0f, 1.0f,
- // -1.0f,-1.0f,-1.0f,
- // 1.0f,-1.0f,-1.0f,
- // 1.0f, 1.0f,-1.0f,
- // 1.0f,-1.0f,-1.0f,
- // -1.0f,-1.0f,-1.0f,
- // -1.0f,-1.0f,-1.0f,
- // -1.0f, 1.0f, 1.0f,
- // -1.0f, 1.0f,-1.0f,
- // 1.0f,-1.0f, 1.0f,
- // -1.0f,-1.0f, 1.0f,
- // -1.0f,-1.0f,-1.0f,
- // -1.0f, 1.0f, 1.0f,
- // -1.0f,-1.0f, 1.0f,
- // 1.0f,-1.0f, 1.0f,
- // 1.0f, 1.0f, 1.0f,
- // 1.0f,-1.0f,-1.0f,
- // 1.0f, 1.0f,-1.0f,
- // 1.0f,-1.0f,-1.0f,
- // 1.0f, 1.0f, 1.0f,
- // 1.0f,-1.0f, 1.0f,
- // 1.0f, 1.0f, 1.0f,
- // 1.0f, 1.0f,-1.0f,
- // -1.0f, 1.0f,-1.0f,
- // 1.0f, 1.0f, 1.0f,
- // -1.0f, 1.0f,-1.0f,
- // -1.0f, 1.0f, 1.0f,
- // 1.0f, 1.0f, 1.0f,
- // -1.0f, 1.0f, 1.0f,
- // 1.0f,-1.0f, 1.0f
- //};
-
- //static const GLfloat g_color_buffer_data[] = {
- // 0.583f, 0.771f, 0.014f,
- // 0.609f, 0.115f, 0.436f,
- // 0.327f, 0.483f, 0.844f,
- // 0.822f, 0.569f, 0.201f,
- // 0.435f, 0.602f, 0.223f,
- // 0.310f, 0.747f, 0.185f,
- // 0.597f, 0.770f, 0.761f,
- // 0.559f, 0.436f, 0.730f,
- // 0.359f, 0.583f, 0.152f,
- // 0.483f, 0.596f, 0.789f,
- // 0.559f, 0.861f, 0.639f,
- // 0.195f, 0.548f, 0.859f,
- // 0.014f, 0.184f, 0.576f,
- // 0.771f, 0.328f, 0.970f,
- // 0.406f, 0.615f, 0.116f,
- // 0.676f, 0.977f, 0.133f,
- // 0.971f, 0.572f, 0.833f,
- // 0.140f, 0.616f, 0.489f,
- // 0.997f, 0.513f, 0.064f,
- // 0.945f, 0.719f, 0.592f,
- // 0.543f, 0.021f, 0.978f,
- // 0.279f, 0.317f, 0.505f,
- // 0.167f, 0.620f, 0.077f,
- // 0.347f, 0.857f, 0.137f,
- // 0.055f, 0.953f, 0.042f,
- // 0.714f, 0.505f, 0.345f,
- // 0.783f, 0.290f, 0.734f,
- // 0.722f, 0.645f, 0.174f,
- // 0.302f, 0.455f, 0.848f,
- // 0.225f, 0.587f, 0.040f,
- // 0.517f, 0.713f, 0.338f,
- // 0.053f, 0.959f, 0.120f,
- // 0.393f, 0.621f, 0.362f,
- // 0.673f, 0.211f, 0.457f,
- // 0.820f, 0.883f, 0.371f,
- // 0.982f, 0.099f, 0.879f
- //};
-
-
-//// LOG("sizeof(bufdata) = %lu", sizeof(bufdata));
-//// LOG("sizeof(g_vertex_buffer_data) = %lu", sizeof(testobject->g_vertex_buffer_data));
-////
//// Generate 1 buffer, put the resulting identifier in vertexbuffer
//gl->GenBuffers(1, &(testobject->vbo));
@@ -339,6 +245,29 @@ Platform* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight
p->bindings_sz = 0;
p->bindings_len = 0;
+ {
+ int x,y,n;
+ test_image = stbi_load(img_filename, &x, &y, &n, 0);
+ if (test_image == NULL) {
+ ERROR("Failed to load image %s", img_filename);
+ } else {
+ //
+ const GladGLContext *gl = w->context;
+ gl->GenTextures(1, &img_texture);
+ gl->BindTexture(GL_TEXTURE_2D, img_texture);
+
+ gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, test_image);
+
+ gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+ stbi_image_free(test_image);
+ }
+// // ... process data if not NULL ...
+// // ... x = width, y = height, n = # 8-bit components per pixel ...
+// // ... replace '0' with '1'..'4' to force that many components per pixel
+// // ... but 'n' will always be the number that it would have been if you said 0
+ }
// TODO: Add global bindings
INFO("Available cores: %d", nproc());
@@ -543,7 +472,6 @@ void engine_stop(Platform* p) {
// }
//}
-
destroy_window(p->window);
}