aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mgl/gl.h1
-rw-r--r--include/mgl/window/window.h5
-rw-r--r--src/gl.c1
-rw-r--r--src/graphics/sprite.c5
-rw-r--r--src/graphics/text.c5
-rw-r--r--src/graphics/vertex.c5
-rw-r--r--src/window/window.c13
7 files changed, 4 insertions, 31 deletions
diff --git a/include/mgl/gl.h b/include/mgl/gl.h
index 87a3ccd..4658198 100644
--- a/include/mgl/gl.h
+++ b/include/mgl/gl.h
@@ -58,6 +58,7 @@ typedef struct {
void (*glClear)(unsigned int mask);
void (*glEnable)(unsigned int cap);
void (*glBlendFunc)(unsigned int sfactor, unsigned int dfactor);
+ void (*glBlendFuncSeparate)(unsigned int sfactorRGB, unsigned int dfactorRGB, unsigned int sfactorAlpha, unsigned int dfactorAlpha);
void (*glGenTextures)(int n, unsigned int *textures);
void (*glDeleteTextures)(int n, const unsigned int *textures);
void (*glGetTexLevelParameteriv)(unsigned int target, int level, unsigned int pname, int *params);
diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h
index 77589c9..a5ccbf7 100644
--- a/include/mgl/window/window.h
+++ b/include/mgl/window/window.h
@@ -81,7 +81,7 @@ typedef struct {
mgl_window_handle parent_window; /* 0 = root window */
bool hidden; /* false by default */
bool override_redirect; /* false by default */
- bool support_alpha; /* support alpha for the window, false by default. If this is set to true then you need to call mgl_window_set_texture_blend_func before rendering textures and call mgl_window_set_render_blend_func afterwards to ensure correct alpha blending */
+ bool support_alpha; /* support alpha for the window, false by default */
bool hide_decorations; /* this is a hint, it may be ignored by the window manager, false by default */
mgl_color background_color; /* default: black */
const char *class_name;
@@ -182,9 +182,6 @@ bool mgl_window_get_clipboard(mgl_window *self, mgl_clipboard_callback callback,
bool mgl_window_get_clipboard_string(mgl_window *self, char **str, size_t *size);
void mgl_window_set_key_repeat_enabled(mgl_window *self, bool enabled);
-void mgl_window_set_texture_blend_func(mgl_window *self);
-void mgl_window_set_render_blend_func(mgl_window *self);
-
void mgl_window_flush(mgl_window *self);
void* mgl_window_get_egl_display(mgl_window *self);
diff --git a/src/gl.c b/src/gl.c
index bb2e90b..b5cb256 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -27,6 +27,7 @@ static int mgl_gl_load_gl(mgl_gl *self) {
{ (void**)&self->glClear, "glClear" },
{ (void**)&self->glEnable, "glEnable" },
{ (void**)&self->glBlendFunc, "glBlendFunc" },
+ { (void**)&self->glBlendFuncSeparate, "glBlendFuncSeparate" },
{ (void**)&self->glGenTextures, "glGenTextures" },
{ (void**)&self->glDeleteTextures, "glDeleteTextures" },
{ (void**)&self->glGetTexLevelParameteriv, "glGetTexLevelParameteriv" },
diff --git a/src/graphics/sprite.c b/src/graphics/sprite.c
index ce2566e..7ef81af 100644
--- a/src/graphics/sprite.c
+++ b/src/graphics/sprite.c
@@ -1,6 +1,5 @@
#include "../../include/mgl/graphics/sprite.h"
#include "../../include/mgl/graphics/texture.h"
-#include "../../include/mgl/window/window.h"
#include "../../include/mgl/mgl.h"
void mgl_sprite_init(mgl_sprite *self, mgl_texture *texture) {
@@ -69,8 +68,6 @@ void mgl_sprite_draw(mgl_context *context, mgl_sprite *sprite) {
if(!sprite->texture)
return;
- mgl_window_set_texture_blend_func(context->current_window);
-
float texture_right = 1.0f;
float texture_bottom = 1.0f;
if(sprite->texture->pixel_coordinates) {
@@ -97,6 +94,4 @@ void mgl_sprite_draw(mgl_context *context, mgl_sprite *sprite) {
context->gl.glEnd();
mgl_texture_use(NULL);
context->gl.glLoadIdentity(); /* TODO: Remove, but what about glRotatef above */
-
- mgl_window_set_render_blend_func(context->current_window);
}
diff --git a/src/graphics/text.c b/src/graphics/text.c
index 0280edb..2aa3bb4 100644
--- a/src/graphics/text.c
+++ b/src/graphics/text.c
@@ -1,7 +1,6 @@
#include "../../include/mgl/graphics/text.h"
#include "../../include/mgl/graphics/font.h"
#include "../../include/mgl/system/utf8.h"
-#include "../../include/mgl/window/window.h"
#include "../../include/mgl/mgl.h"
#include <stdio.h>
@@ -248,14 +247,10 @@ void mgl_text_draw(mgl_context *context, mgl_text *text) {
text_draw_userdata.text = text;
text_draw_userdata.context = context;
- mgl_window_set_texture_blend_func(context->current_window);
-
context->gl.glColor4ub(text->color.r, text->color.g, text->color.b, text->color.a);
mgl_texture_use(&text->font->texture);
context->gl.glBegin(GL_QUADS);
mgl_text_for_each_codepoint(text, text_draw_callback, &text_draw_userdata);
context->gl.glEnd();
mgl_texture_use(NULL);
-
- mgl_window_set_render_blend_func(context->current_window);
}
diff --git a/src/graphics/vertex.c b/src/graphics/vertex.c
index 92a6e93..e55c180 100644
--- a/src/graphics/vertex.c
+++ b/src/graphics/vertex.c
@@ -1,14 +1,11 @@
#include "../../include/mgl/graphics/vertex.h"
#include "../../include/mgl/graphics/texture.h"
-#include "../../include/mgl/window/window.h"
#include "../../include/mgl/mgl.h"
void mgl_vertices_draw(mgl_context *context, const mgl_vertex *vertices, size_t vertex_count, mgl_primitive_type primitive_type, mgl_vec2f position) {
if(vertex_count == 0)
return;
- mgl_window_set_texture_blend_func(context->current_window);
-
context->gl.glPushMatrix();
if(!mgl_texture_current_texture()) {
@@ -25,6 +22,4 @@ void mgl_vertices_draw(mgl_context *context, const mgl_vertex *vertices, size_t
context->gl.glDrawArrays(mgl_primitive_type_to_gl_mode(primitive_type), 0, vertex_count);
context->gl.glPopMatrix();
-
- mgl_window_set_render_blend_func(context->current_window);
}
diff --git a/src/window/window.c b/src/window/window.c
index dd91110..d931a9f 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -1017,7 +1017,7 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window
context->gl.glEnable(GL_TEXTURE_2D);
context->gl.glEnable(GL_BLEND);
context->gl.glEnable(GL_SCISSOR_TEST);
- mgl_window_set_render_blend_func(self);
+ context->gl.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
context->gl.glEnableClientState(GL_VERTEX_ARRAY);
context->gl.glEnableClientState(GL_TEXTURE_COORD_ARRAY);
context->gl.glEnableClientState(GL_COLOR_ARRAY);
@@ -2120,17 +2120,6 @@ void mgl_window_set_key_repeat_enabled(mgl_window *self, bool enabled) {
self->key_repeat_enabled = enabled;
}
-void mgl_window_set_texture_blend_func(mgl_window *self) {
- mgl_context *context = mgl_get_context();
- context->gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-void mgl_window_set_render_blend_func(mgl_window *self) {
- mgl_context *context = mgl_get_context();
- x11_context *x11_context = self->context;
- context->gl.glBlendFunc(x11_context->support_alpha ? GL_ONE : GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
void mgl_window_flush(mgl_window *self) {
mgl_context *context = mgl_get_context();
XFlush(context->connection);