aboutsummaryrefslogtreecommitdiff
path: root/src/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/backend/egl.c24
-rw-r--r--src/graphics/backend/glx.c17
-rw-r--r--src/graphics/backend/graphics.c16
-rw-r--r--src/graphics/font.c2
4 files changed, 37 insertions, 22 deletions
diff --git a/src/graphics/backend/egl.c b/src/graphics/backend/egl.c
index f92e2fc..cabbf04 100644
--- a/src/graphics/backend/egl.c
+++ b/src/graphics/backend/egl.c
@@ -32,7 +32,7 @@ static bool xvisual_match_alpha(Display *dpy, XVisualInfo *visual_info, bool alp
return (alpha && pict_format->direct.alphaMask > 0) || (!alpha && pict_format->direct.alphaMask == 0);
}
-static bool mgl_graphics_context_choose(mgl_graphics_egl *self, mgl_context *context, bool alpha) {
+static bool mgl_graphics_egl_choose_config(mgl_graphics_egl *self, mgl_context *context, bool alpha) {
self->configs = NULL;
self->ecfg = NULL;
self->visual_info = NULL;
@@ -40,13 +40,13 @@ static bool mgl_graphics_context_choose(mgl_graphics_egl *self, mgl_context *con
int32_t num_configs = 0;
context->gl.eglGetConfigs(self->display, NULL, 0, &num_configs);
if(num_configs == 0) {
- fprintf(stderr, "mgl error: no configs found\n");
+ fprintf(stderr, "mgl error: mgl_graphics_egl_choose_config: no configs found\n");
return false;
}
self->configs = (EGLConfig*)calloc(num_configs, sizeof(EGLConfig));
if(!self->configs) {
- fprintf(stderr, "mgl error: failed to allocate %d configs\n", (int)num_configs);
+ fprintf(stderr, "mgl error: mgl_graphics_egl_choose_config: failed to allocate %d configs\n", (int)num_configs);
return false;
}
@@ -54,6 +54,9 @@ static bool mgl_graphics_context_choose(mgl_graphics_egl *self, mgl_context *con
for(int i = 0; i < num_configs; i++) {
self->ecfg = self->configs[i];
+ //if(mgl_graphics_egl_get_config_attrib(self, self->ecfg, EGL_RENDERABLE_TYPE) != EGL_OPENGL_ES2_BIT)
+ // continue;
+
if(mgl_graphics_egl_get_config_attrib(self, self->ecfg, EGL_COLOR_BUFFER_TYPE) != EGL_RGB_BUFFER)
continue;
@@ -94,14 +97,13 @@ static bool mgl_graphics_context_choose(mgl_graphics_egl *self, mgl_context *con
}
}
- if(context->window_system == MGL_WINDOW_SYSTEM_X11 && !self->visual_info) {
- if(self->configs) {
- free(self->configs);
- self->configs = NULL;
- }
- self->ecfg = NULL;
+ if(!self->ecfg) {
+ fprintf(stderr, "mgl error: mgl_graphics_egl_choose_config: no appropriate glx config found\n");
+ return false;
+ }
- fprintf(stderr, "mgl error: mgl_graphics_context_choose: no appropriate visual found\n");
+ if(context->window_system == MGL_WINDOW_SYSTEM_X11 && !self->visual_info) {
+ fprintf(stderr, "mgl error: mgl_graphics_egl_choose_config: no appropriate visual found\n");
return false;
}
@@ -188,7 +190,7 @@ bool mgl_graphics_egl_init(mgl_graphics *self) {
return false;
}
- if(!mgl_graphics_context_choose(impl, context, self->alpha)) {
+ if(!mgl_graphics_egl_choose_config(impl, context, self->alpha)) {
mgl_graphics_egl_deinit(self);
return false;
}
diff --git a/src/graphics/backend/glx.c b/src/graphics/backend/glx.c
index 548b0a0..70836e3 100644
--- a/src/graphics/backend/glx.c
+++ b/src/graphics/backend/glx.c
@@ -23,7 +23,7 @@ static bool xvisual_match_alpha(Display *dpy, XVisualInfo *visual_info, bool alp
return (alpha && pict_format->direct.alphaMask > 0) || (!alpha && pict_format->direct.alphaMask == 0);
}
-static bool mgl_graphics_glx_context_choose(mgl_graphics_glx *self, mgl_context *context, bool alpha) {
+static bool mgl_graphics_glx_choose_config(mgl_graphics_glx *self, mgl_context *context, bool alpha) {
const int attr[] = {
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
@@ -58,14 +58,13 @@ static bool mgl_graphics_glx_context_choose(mgl_graphics_glx *self, mgl_context
}
}
- if(!self->visual_info) {
- if(self->fbconfigs) {
- XFree(self->fbconfigs);
- self->fbconfigs = NULL;
- }
- self->fbconfig = NULL;
+ if(!self->fbconfig) {
+ fprintf(stderr, "mgl error: mgl_graphics_glx_choose_config: no appropriate glx config found\n");
+ return false;
+ }
- fprintf(stderr, "mgl error: no appropriate visual found\n");
+ if(!self->visual_info) {
+ fprintf(stderr, "mgl error: mgl_graphics_glx_choose_config: no appropriate visual found\n");
return false;
}
@@ -129,7 +128,7 @@ bool mgl_graphics_glx_init(mgl_graphics *self) {
self->impl = impl;
mgl_context *context = mgl_get_context();
- if(!mgl_graphics_glx_context_choose(impl, context, self->alpha)) {
+ if(!mgl_graphics_glx_choose_config(impl, context, self->alpha)) {
mgl_graphics_glx_deinit(self);
return false;
}
diff --git a/src/graphics/backend/graphics.c b/src/graphics/backend/graphics.c
index 792894e..201b9e3 100644
--- a/src/graphics/backend/graphics.c
+++ b/src/graphics/backend/graphics.c
@@ -1,6 +1,7 @@
#include "../../../include/mgl/graphics/backend/graphics.h"
#include "../../../include/mgl/graphics/backend/glx.h"
#include "../../../include/mgl/graphics/backend/egl.h"
+#include "../../../include/mgl/mgl.h"
#include <string.h>
@@ -24,7 +25,20 @@ void mgl_graphics_deinit(mgl_graphics *self) {
}
bool mgl_graphics_make_context_current(mgl_graphics *self, mgl_window_handle window) {
- return self->make_context_current(self, window);
+ const bool result = self->make_context_current(self, window);
+ if(result) {
+ mgl_context *context = mgl_get_context();
+ context->gl.glEnable(GL_TEXTURE_2D);
+ context->gl.glEnable(GL_BLEND);
+ context->gl.glEnable(GL_SCISSOR_TEST);
+ 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);
+ context->gl.glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ context->gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ }
+ return result;
}
void mgl_graphics_swap_buffers(mgl_graphics *self, mgl_window_handle window) {
diff --git a/src/graphics/font.c b/src/graphics/font.c
index 12235f6..671d8a1 100644
--- a/src/graphics/font.c
+++ b/src/graphics/font.c
@@ -210,7 +210,7 @@ int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph
/* TODO: Use stbtt_MakeGlyphBitmapSubpixelPrefilter instead for better text quality */
const size_t pixels_width = (width + GLYPH_PADDING * 2);
const size_t pixels_height = (height + GLYPH_PADDING * 2);
- const size_t pixels_size = pixels_width * pixels_height;
+ const size_t pixels_size = pixels_width * pixels_height * 2; // *2 required for opengl glTexSubImage2D
unsigned char *pixels = calloc(pixels_size, 1);
if(pixels) {
const int top_padding = GLYPH_PADDING;