aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-21 07:14:46 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-21 07:14:46 +0200
commitf02a283c06c51cb29f79e89754b31ffd6952d2e6 (patch)
tree2eb691e105b65d3ca0464ed00628dd0b0974955a /include
parent2d4457a5ee926eca221102ee70f118b305ea2670 (diff)
Add vertex buffer
Diffstat (limited to 'include')
-rw-r--r--include/mgl/gl.h14
-rw-r--r--include/mgl/gl_macro.h20
-rw-r--r--include/mgl/graphics/vertex.h13
-rw-r--r--include/mgl/graphics/vertex_buffer.h44
4 files changed, 91 insertions, 0 deletions
diff --git a/include/mgl/gl.h b/include/mgl/gl.h
index 6de98d9..8a09e3e 100644
--- a/include/mgl/gl.h
+++ b/include/mgl/gl.h
@@ -3,6 +3,7 @@
#include "gl_macro.h"
#include <stdint.h>
+#include <sys/types.h>
typedef struct _XVisualInfo _XVisualInfo;
typedef struct _XDisplay Display;
@@ -37,7 +38,20 @@ typedef struct {
void (*glTexCoord2f)(float s, float t);
void (*glOrtho)(double left, double right, double bottom, double top, double near_val, double far_val);
void (*glMatrixMode)(unsigned int mode);
+ void (*glPushMatrix)(void);
+ void (*glPopMatrix)(void);
void (*glLoadIdentity)(void);
+ void (*glTranslatef)(float x, float y, float z);
+ void (*glGenBuffers)(int n, unsigned int *buffers);
+ void (*glBindBuffer)(unsigned int target, unsigned int buffer);
+ void (*glDeleteBuffers)(int n, const unsigned int *buffers);
+ void (*glBufferData)(unsigned int target, ssize_t size, const void *data, unsigned int usage);
+ void (*glBufferSubData)(unsigned int target, ssize_t offset, ssize_t size, const void *data);
+ void (*glDrawArrays)(unsigned int mode, int first, int count);
+ void (*glEnableClientState)(unsigned int cap);
+ void (*glVertexPointer)(int size, unsigned int type, int stride, const void *ptr);
+ void (*glColorPointer)(int size, unsigned int type, int stride, const void *ptr);
+ void (*glTexCoordPointer)(int size, unsigned int type, int stride, const void *ptr);
/* Optional*/
void (*glXSwapIntervalEXT)(Display * dpy, GLXDrawable drawable, int interval);
diff --git a/include/mgl/gl_macro.h b/include/mgl/gl_macro.h
index a0bb16c..a3be960 100644
--- a/include/mgl/gl_macro.h
+++ b/include/mgl/gl_macro.h
@@ -49,8 +49,28 @@
#define GL_CLAMP_TO_EDGE 0x812F
#define GL_LINEAR 0x2601
+#define GL_POINTS 0x0000
+#define GL_LINES 0x0001
+#define GL_LINE_STRIP 0x0003
+#define GL_TRIANGLES 0x0004
+#define GL_TRIANGLE_STRIP 0x0005
+#define GL_TRIANGLE_FAN 0x0006
#define GL_QUADS 0x0007
+#define GL_QUAD_STRIP 0x0008
+#define GL_POLYGON 0x0009
#define GL_PROJECTION 0x1701
+#define GL_STREAM_DRAW 0x88E0
+#define GL_STATIC_DRAW 0x88E4
+#define GL_DYNAMIC_DRAW 0x88E8
+
+#define GL_ARRAY_BUFFER 0x8892
+
+#define GL_FLOAT 0x1406
+
+#define GL_VERTEX_ARRAY 0x8074
+#define GL_COLOR_ARRAY 0x8076
+#define GL_TEXTURE_COORD_ARRAY 0x8078
+
#endif /* MGL_GL_MACRO_H */
diff --git a/include/mgl/graphics/vertex.h b/include/mgl/graphics/vertex.h
new file mode 100644
index 0000000..b4a5830
--- /dev/null
+++ b/include/mgl/graphics/vertex.h
@@ -0,0 +1,13 @@
+#ifndef MGL_VERTEX_H
+#define MGL_VERTEX_H
+
+#include "color.h"
+#include "../system/vec.h"
+
+typedef struct {
+ mgl_vec2f position;
+ mgl_color color;
+ mgl_vec2f texcoords;
+} mgl_vertex;
+
+#endif /* MGL_VERTEX_H */
diff --git a/include/mgl/graphics/vertex_buffer.h b/include/mgl/graphics/vertex_buffer.h
new file mode 100644
index 0000000..c1e4af1
--- /dev/null
+++ b/include/mgl/graphics/vertex_buffer.h
@@ -0,0 +1,44 @@
+#ifndef MGL_VERTEX_BUFFER_H
+#define MGL_VERTEX_BUFFER_H
+
+#include "vertex.h"
+#include <stddef.h>
+
+typedef struct mgl_context mgl_context;
+typedef struct mgl_texture mgl_texture;
+
+typedef enum {
+ MGL_PRIMITIVE_POINTS,
+ MGL_PRIMITIVE_LINES,
+ MGL_PRIMITIVE_LINE_STRIP,
+ MGL_PRIMITIVE_TRIANGLES,
+ MGL_PRIMITIVE_TRIANGLE_STRIP,
+ MGL_PRIMITIVE_TRIANGLE_FAN,
+ MGL_PRIMITIVE_QUADS,
+ MGL_PRIMITIVE_QUAD_STRIP,
+ MGL_PRIMITIVE_POLYGON,
+} mgl_primitive_type;
+
+typedef enum {
+ MGL_USAGE_STREAM,
+ MGL_USAGE_DYNAMIC,
+ MGL_USAGE_STATIC
+} mgl_vertex_buffer_usage;
+
+typedef struct {
+ unsigned int id;
+ size_t vertex_count;
+ mgl_primitive_type primitive_type;
+ mgl_vertex_buffer_usage usage;
+ mgl_vec2f position;
+} mgl_vertex_buffer;
+
+int mgl_vertex_buffer_init(mgl_vertex_buffer *self, mgl_primitive_type primitive_type, mgl_vertex_buffer_usage usage);
+void mgl_vertex_buffer_deinit(mgl_vertex_buffer *self);
+
+void mgl_vertex_buffer_set_position(mgl_vertex_buffer *self, mgl_vec2f position);
+int mgl_vertex_buffer_update(mgl_vertex_buffer *self, mgl_vertex *vertices, size_t vertex_count);
+/* |texture| can be NULL to not use any texture */
+void mgl_vertex_buffer_draw(mgl_context *context, mgl_vertex_buffer *self, mgl_texture *texture);
+
+#endif /* MGL_VERTEX_BUFFER_H */