aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-10 14:54:53 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-10 14:54:53 +0200
commitb81aff95e7924c38dbd1cf639011be1848af6967 (patch)
treec86ecf98fe0f2366473fc2f6cd84b3c7daf85bf9
parent54b2376adad98d91d32378efc3f241f120ba970f (diff)
Enable alpha blending
-rw-r--r--include/mgl/gl.h2
-rw-r--r--src/gl.c4
-rw-r--r--src/window.c5
-rw-r--r--tests/main.c7
4 files changed, 17 insertions, 1 deletions
diff --git a/include/mgl/gl.h b/include/mgl/gl.h
index b5b6ca1..745e69d 100644
--- a/include/mgl/gl.h
+++ b/include/mgl/gl.h
@@ -18,6 +18,8 @@ typedef struct {
void (*glViewport)(int x, int y, int width, int height);
void (*glClearColor)(float red, float green, float blue, float alpha);
void (*glClear)(unsigned int mask);
+ void (*glEnable)(unsigned int cap);
+ void (*glBlendFunc)(unsigned int sfactor, unsigned int dfactor);
/* Optional*/
void (*glXSwapIntervalEXT)(Display * dpy, GLXDrawable drawable, int interval);
diff --git a/src/gl.c b/src/gl.c
index 023ffbb..282046c 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -1,6 +1,6 @@
#include "../include/mgl/gl.h"
#include <dlfcn.h>
-/*#include <GL/glx.h>*/
+/*#include <GL/gl.h>*/
#include <stdio.h>
typedef struct {
@@ -37,6 +37,8 @@ int mgl_gl_load(mgl_gl *self) {
{ &self->glViewport, "glViewport" },
{ &self->glClearColor, "glClearColor" },
{ &self->glClear, "glClear" },
+ { &self->glEnable, "glEnable" },
+ { &self->glBlendFunc, "glBlendFunc" },
{ NULL, NULL }
};
diff --git a/src/window.c b/src/window.c
index bdbcd6f..4d877d7 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4,6 +4,9 @@
#include <stdio.h>
#define GL_COLOR_BUFFER_BIT 0x00004000
+#define GL_BLEND 0x0BE2
+#define GL_SRC_ALPHA 0x0302
+#define GL_ONE_MINUS_SRC_ALPHA 0x0303
int mgl_window_create(mgl_window *self, const char *title, int width, int height, mgl_window_callback *callback, void *userdata) {
return mgl_window_create_with_params(self, title, width, height, DefaultRootWindow(mgl_get_context()->connection), callback, userdata);
@@ -80,6 +83,8 @@ void mgl_window_show(mgl_window *self) {
/* TODO: Switch current when rendering to another window, and set current to NULL when destroying the currently selected context */
context->gl.glXMakeCurrent(context->connection, self->window, context->glx_context);
set_vertical_sync_enabled(self->window, 1);
+ context->gl.glEnable(GL_BLEND);
+ context->gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
mgl_window_draw(self);
}
diff --git a/tests/main.c b/tests/main.c
index dfea218..c16a68e 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -11,6 +11,13 @@ static void draw(mgl_window *window, void *userdata) {
glColor3f(0., 0., 1.); glVertex3f( .75, .75, 0.);
glColor3f(1., 1., 0.); glVertex3f(-.75, .75, 0.);
glEnd();
+
+ glBegin(GL_QUADS);
+ glColor4f(1., 0., 0., 0.5); glVertex3f(0.1 + -.75, 0.1 + -.75, 0.);
+ glColor4f(1., 0., 0., 0.5); glVertex3f(0.1 + .75, 0.1 + -.75, 0.);
+ glColor4f(1., 0., 0., 0.5); glVertex3f(0.1 + .75, 0.1 + .75, 0.);
+ glColor4f(1., 0., 0., 0.5); glVertex3f(0.1 + -.75, 0.1 + .75, 0.);
+ glEnd();
}
int main(int argc, char **argv) {