font machine broke

This commit is contained in:
nullifiedcat 2017-11-14 20:56:37 +03:00
parent 25ad47a5e4
commit ad32cb9a2a
45 changed files with 262 additions and 69 deletions

View File

@ -30,8 +30,8 @@ all:
ifndef ARCH ifndef ARCH
$(MAKE) clean $(MAKE) clean
$(MAKE) $(TARGET64) -e ARCH=64 $(MAKE) $(TARGET64) -e ARCH=64
#$(MAKE) clean $(MAKE) clean
#$(MAKE) $(TARGET32) -e ARCH=32 $(MAKE) $(TARGET32) -e ARCH=32
endif endif
install: install:

BIN
bin32/liboverlay.so Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -9,6 +9,7 @@
typedef unsigned int xoverlay_font_handle_t; typedef unsigned int xoverlay_font_handle_t;
#define XOVERLAY_FONT_COUNT 64 #define XOVERLAY_FONT_COUNT 64
#define XOVERLAY_FONT_INVALID_HANDLE (xoverlay_font_handle_t)(-1)
xoverlay_font_handle_t xoverlay_font_handle_t
xoverlay_font_load(const char *path, float size); xoverlay_font_load(const char *path, float size);

View File

@ -14,12 +14,15 @@
struct fontapi_font_t struct fontapi_font_t
{ {
int init; int init;
int loaded;
int error;
texture_font_t *font; texture_font_t *font;
texture_atlas_t *atlas; texture_atlas_t *atlas;
};
struct fontapi_font_t loaded_fonts[XOVERLAY_FONT_COUNT]; char path[256];
float size;
};
texture_font_t* texture_font_t*
fontapi_get(xoverlay_font_handle_t handle); fontapi_get(xoverlay_font_handle_t handle);
@ -31,4 +34,4 @@ void
fontapi_destroy(); fontapi_destroy();
xoverlay_font_handle_t xoverlay_font_handle_t
fontapi_add_font(struct fontapi_font_t font); fontapi_add_font(struct fontapi_font_t *font);

11
include/log.h Normal file
View File

@ -0,0 +1,11 @@
/*
* log.h
*
* Created on: Nov 14, 2017
* Author: nullifiedcat
*/
#pragma once
void
log_write(const char *format, ...);

View File

@ -47,7 +47,7 @@ struct xoverlay_library
char mapped; char mapped;
}; };
struct xoverlay_library xoverlay_library; extern struct xoverlay_library xoverlay_library;
typedef struct xoverlay_vec4_t typedef struct xoverlay_vec4_t
{ {
@ -71,6 +71,7 @@ typedef struct xoverlay_vec4_t
}; };
} xoverlay_vec4_t, xoverlay_rgba_t; } xoverlay_vec4_t, xoverlay_rgba_t;
void xoverlay_preinit();
int xoverlay_init(); int xoverlay_init();
void xoverlay_destroy(); void xoverlay_destroy();
@ -109,6 +110,14 @@ xoverlay_draw_string_with_outline(float x, float y, const char *string, xoverlay
void void
xoverlay_draw_circle(float x, float y, float radius, xoverlay_rgba_t color, float thickness, int steps); xoverlay_draw_circle(float x, float y, float radius, xoverlay_rgba_t color, float thickness, int steps);
void xoverlay_poll_events(); void
void xoverlay_draw_begin(); xoverlay_get_string_size(const char *string, xoverlay_font_handle_t font, float *out_x, float *out_y);
void xoverlay_draw_end();
void
xoverlay_poll_events();
void
xoverlay_draw_begin();
void
xoverlay_draw_end();

View File

@ -9,6 +9,7 @@
#include "overlay.h" #include "overlay.h"
#include "programs.h" #include "programs.h"
#include "vertex_structs.h" #include "vertex_structs.h"
#include "log.h"
#include <GL/gl.h> #include <GL/gl.h>
#include <math.h> #include <math.h>
@ -55,7 +56,7 @@ int glx_is_extension_supported(const char *list, const char *extension)
int xoverlay_glx_init() int xoverlay_glx_init()
{ {
glXQueryVersion(xoverlay_library.display, &glx_state.version_major, &glx_state.version_minor); glXQueryVersion(xoverlay_library.display, &glx_state.version_major, &glx_state.version_minor);
printf("GL Version: %s\n", glGetString(GL_VERSION)); log_write("GL Version: %s\n", glGetString(GL_VERSION));
return 0; return 0;
} }
@ -98,13 +99,18 @@ int xoverlay_glx_create_window()
} }
XFree(info); XFree(info);
} }
if (fbc_best == -1)
{
log_write("Could not get FB config with 32 depth\n");
return -1;
}
GLXFBConfig fbconfig = fbc[fbc_best]; GLXFBConfig fbconfig = fbc[fbc_best];
XFree(fbc); XFree(fbc);
XVisualInfo *info = glXGetVisualFromFBConfig(xoverlay_library.display, fbconfig); XVisualInfo *info = glXGetVisualFromFBConfig(xoverlay_library.display, fbconfig);
if (info == NULL) if (info == NULL)
{ {
printf("GLX initialization error\n"); log_write("GLX initialization error\n");
return -1; return -1;
} }
Window root = DefaultRootWindow(xoverlay_library.display); Window root = DefaultRootWindow(xoverlay_library.display);
@ -119,11 +125,11 @@ int xoverlay_glx_create_window()
attr.do_not_propagate_mask = (KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|ButtonMotionMask); attr.do_not_propagate_mask = (KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|ButtonMotionMask);
unsigned long mask = CWBackPixel | CWBorderPixel | CWSaveUnder | CWOverrideRedirect | CWColormap | CWEventMask | CWDontPropagate; unsigned long mask = CWBackPixel | CWBorderPixel | CWSaveUnder | CWOverrideRedirect | CWColormap | CWEventMask | CWDontPropagate;
printf("depth %d\n", info->depth); log_write("depth %d\n", info->depth);
xoverlay_library.window = XCreateWindow(xoverlay_library.display, root, 0, 0, xoverlay_library.width, xoverlay_library.height, 0, info->depth, InputOutput, info->visual, mask, &attr); xoverlay_library.window = XCreateWindow(xoverlay_library.display, root, 0, 0, xoverlay_library.width, xoverlay_library.height, 0, info->depth, InputOutput, info->visual, mask, &attr);
if (xoverlay_library.window == 0) if (xoverlay_library.window == 0)
{ {
printf("X window initialization error\n"); log_write("X window initialization error\n");
return -1; return -1;
} }
@ -145,7 +151,7 @@ int xoverlay_glx_create_window()
if (!glx_is_extension_supported(extensions, "GLX_ARB_create_context")) if (!glx_is_extension_supported(extensions, "GLX_ARB_create_context"))
{ {
printf("Falling back to glXCreateNewContext\n"); log_write("Falling back to glXCreateNewContext\n");
glx_state.context = glXCreateNewContext(xoverlay_library.display, fbconfig, GLX_RGBA_TYPE, NULL, GL_TRUE); glx_state.context = glXCreateNewContext(xoverlay_library.display, fbconfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
} }
else else
@ -160,29 +166,29 @@ int xoverlay_glx_create_window()
} }
if (glx_state.context == NULL) if (glx_state.context == NULL)
{ {
printf("OpenGL context initialization error\n"); log_write("OpenGL context initialization error\n");
return -1; return -1;
} }
if (!glXIsDirect(xoverlay_library.display, glx_state.context)) if (!glXIsDirect(xoverlay_library.display, glx_state.context))
{ {
printf("Context is indirect\n"); log_write("Context is indirect\n");
} }
else else
{ {
printf("Context is direct\n"); log_write("Context is direct\n");
} }
glXMakeCurrent(xoverlay_library.display, xoverlay_library.window, glx_state.context); glXMakeCurrent(xoverlay_library.display, xoverlay_library.window, glx_state.context);
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) if (glewInit() != GLEW_OK)
{ {
printf("GLEW initialization error: %s\n", glewGetErrorString(glGetError())); log_write("GLEW initialization error: %s\n", glewGetErrorString(glGetError()));
return -1; return -1;
} }
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glXSwapBuffers(xoverlay_library.display, xoverlay_library.window); glXSwapBuffers(xoverlay_library.display, xoverlay_library.window);
printf("Initializing DS\n"); log_write("Initializing DS\n");
ds_init(); ds_init();
program_init_everything(); program_init_everything();
@ -215,6 +221,8 @@ xoverlay_draw_line(float x, float y, float dx, float dy, xoverlay_rgba_t color,
x += 0.5f; x += 0.5f;
y += 0.5f; y += 0.5f;
dx -= 0.5f;
dy -= 0.5f;
GLuint idx = dstream.next_index; GLuint idx = dstream.next_index;
GLuint indices[6] = { idx, idx + 1, idx + 3, idx + 3, idx +2, idx }; GLuint indices[6] = { idx, idx + 1, idx + 3, idx + 3, idx +2, idx };
@ -268,6 +276,8 @@ xoverlay_draw_rect(float x, float y, float w, float h, xoverlay_rgba_t color)
x += 0.5f; x += 0.5f;
y += 0.5f; y += 0.5f;
w -= 0.5f;
h -= 0.5f;
struct vertex_v2fc4f vertices[4]; struct vertex_v2fc4f vertices[4];
GLuint indices[6] = { idx, idx + 1, idx + 2, idx + 2, idx + 3, idx }; GLuint indices[6] = { idx, idx + 1, idx + 2, idx + 2, idx + 3, idx };
@ -320,6 +330,8 @@ xoverlay_draw_rect_textured(float x, float y, float w, float h, xoverlay_rgba_t
x += 0.5f; x += 0.5f;
y += 0.5f; y += 0.5f;
w -= 0.5f;
h -= 0.5f;
GLuint idx = dstream.next_index; GLuint idx = dstream.next_index;
@ -422,9 +434,10 @@ xoverlay_draw_string(float x, float y, const char *string, xoverlay_font_handle_
ds_prepare_font(font); ds_prepare_font(font);
texture_font_t *fnt = fontapi_get(font); texture_font_t *fnt = fontapi_get(font);
if (fnt == NULL) if (fnt == NULL)
return; {
log_write("xoverlay_draw_string: INVALID FONT HANDLE %u\n", font);
}
fnt->rendermode = RENDER_NORMAL; fnt->rendermode = RENDER_NORMAL;
fnt->outline_thickness = 0.0f; fnt->outline_thickness = 0.0f;
@ -445,6 +458,8 @@ xoverlay_draw_string_with_outline(float x, float y, const char *string, xoverlay
outline_color.a = color.a; outline_color.a = color.a;
texture_font_t *fnt = fontapi_get(font); texture_font_t *fnt = fontapi_get(font);
if (fnt == NULL)
return;
fnt->rendermode = RENDER_OUTLINE_POSITIVE; fnt->rendermode = RENDER_OUTLINE_POSITIVE;
fnt->outline_thickness = outline_width; fnt->outline_thickness = outline_width;
@ -455,6 +470,43 @@ xoverlay_draw_string_with_outline(float x, float y, const char *string, xoverlay
draw_string_internal(x, y, string, fnt, *(vec4*)&color, out_x, out_y); draw_string_internal(x, y, string, fnt, *(vec4*)&color, out_x, out_y);
} }
void
xoverlay_get_string_size(const char *string, xoverlay_font_handle_t font, float *out_x, float *out_y)
{
float pen_x = 0;
float pen_y = 0;
float size_x = 0;
float size_y = 0;
texture_font_t *fnt = fontapi_get(font);
if (fnt == NULL)
return;
texture_font_load_glyphs(fnt, string);
for (size_t i = 0; i < strlen(string); ++i)
{
texture_glyph_t *glyph = texture_font_find_glyph(fnt, &string[i]);
if (glyph == NULL)
{
continue;
}
pen_x += texture_glyph_get_kerning(glyph, &string[i]);
pen_x += glyph->advance_x;
if (pen_x > size_x)
size_x = pen_x;
if (glyph->height > size_y)
size_y = glyph->height;
}
if (out_x)
*out_x = size_x;
if (out_y)
*out_y = size_y;
}
int xoverlay_glx_destroy() int xoverlay_glx_destroy()
{ {
return 0; return 0;

Binary file not shown.

View File

@ -8,6 +8,7 @@
#include "drawglx_internal.h" #include "drawglx_internal.h"
#include "vertex_structs.h" #include "vertex_structs.h"
#include "overlay.h" #include "overlay.h"
#include "log.h"
#include <memory.h> #include <memory.h>
#include <string.h> #include <string.h>
@ -297,8 +298,10 @@ ds_render_if_needed()
void void
ds_pre_render() ds_pre_render()
{ {
glXMakeContextCurrent(xoverlay_library.display, xoverlay_library.window, xoverlay_library.window, glx_state.context);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT); glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
@ -329,6 +332,7 @@ ds_post_render()
glPopAttrib(); glPopAttrib();
glFlush(); glFlush();
glXSwapBuffers(xoverlay_library.display, xoverlay_library.window); glXSwapBuffers(xoverlay_library.display, xoverlay_library.window);
glXMakeContextCurrent(xoverlay_library.display, None, None, None);
} }
void void

Binary file not shown.

View File

@ -6,14 +6,20 @@
*/ */
#include "fontapi_internal.h" #include "fontapi_internal.h"
#include "log.h"
#include <string.h> #include <string.h>
#include <memory.h> #include <memory.h>
#include <stdio.h>
struct fontapi_font_t *loaded_fonts = 0;
int int
fontapi_init() fontapi_init()
{ {
memset(loaded_fonts, 0, sizeof(loaded_fonts)); loaded_fonts = calloc(XOVERLAY_FONT_COUNT, sizeof(struct fontapi_font_t));
log_write("fontapi: init %u\n", XOVERLAY_FONT_COUNT * sizeof(struct fontapi_font_t));
fflush(stdout);
return 0; return 0;
} }
@ -28,55 +34,95 @@ xoverlay_font_load(const char *path, float size)
{ {
struct fontapi_font_t result; struct fontapi_font_t result;
memset(&result, 0, sizeof(result)); memset(&result, 0, sizeof(result));
result.atlas = texture_atlas_new(1024, 1024, 1); strncpy(result.path, path, sizeof(result.path) - 1);
result.font = texture_font_new_from_file(result.atlas, size, path); result.size = size;
xoverlay_font_handle_t handle = fontapi_add_font(&result);
return fontapi_add_font(result); log_write("fontapi: init font %u: %d %d\n", handle, loaded_fonts[handle].init, result.init);
fflush(stdout);
return handle;
} }
void void
xoverlay_font_unload(xoverlay_font_handle_t handle) xoverlay_font_unload(xoverlay_font_handle_t handle)
{ {
if (handle == 0)
return;
if (handle > XOVERLAY_FONT_COUNT) if (handle > XOVERLAY_FONT_COUNT)
return; return;
if (loaded_fonts[handle - 1].init == 0) if (loaded_fonts[handle].init == 0)
return;
if (loaded_fonts[handle].loaded == 0)
return; return;
texture_atlas_delete(loaded_fonts[handle - 1].atlas); texture_atlas_delete(loaded_fonts[handle].atlas);
texture_font_delete(loaded_fonts[handle - 1].font); texture_font_delete(loaded_fonts[handle].font);
} }
xoverlay_font_handle_t xoverlay_font_handle_t
fontapi_add_font(struct fontapi_font_t font) fontapi_add_font(struct fontapi_font_t *font)
{ {
for (xoverlay_font_handle_t i = 0; i < XOVERLAY_FONT_COUNT; ++i) for (xoverlay_font_handle_t i = 0; i < XOVERLAY_FONT_COUNT; ++i)
{ {
if (loaded_fonts[i].init == 0) if (loaded_fonts[i].init == 0)
{ {
memcpy(&loaded_fonts[i], &font, sizeof(font)); font->init = 1;
loaded_fonts[i].init = 1; memcpy(&loaded_fonts[i], font, sizeof(struct fontapi_font_t));
return i + 1; return i;
} }
} }
return 0; return XOVERLAY_FONT_INVALID_HANDLE;
}
void
fontapi_texture_load(xoverlay_font_handle_t handle)
{
log_write("fontapi: loading font %u\n", handle);
struct fontapi_font_t *font = &loaded_fonts[handle];
font->error = 1;
font->atlas = texture_atlas_new(1024, 1024, 1);
if (font->atlas != NULL)
{
font->font = texture_font_new_from_file(font->atlas, font->size, font->path);
if (font->font != NULL)
{
font->error = 0;
}
else
{
log_write("fontapi: load: could not init font\n");
}
}
else
{
log_write("fontapi: load: could not init atlas\n");
}
font->loaded = 1;
} }
texture_font_t* texture_font_t*
fontapi_get(xoverlay_font_handle_t handle) fontapi_get(xoverlay_font_handle_t handle)
{ {
if (handle == 0) log_write("fontapi: finding font %u\n", handle);
return NULL;
if (handle >= XOVERLAY_FONT_COUNT) if (handle >= XOVERLAY_FONT_COUNT)
{
log_write("fontapi: invalid handle %u\n", handle);
fflush(stdout);
return NULL; return NULL;
if (loaded_fonts[handle - 1].init == 0) }
if (loaded_fonts[handle].init == 0)
{
log_write("fontapi: font '%s' %u not init\n", loaded_fonts[handle - 1].path, handle);
fflush(stdout);
return NULL; return NULL;
return loaded_fonts[handle - 1].font; }
} if (loaded_fonts[handle].loaded == 0)
fontapi_texture_load(handle);
void if (loaded_fonts[handle].error == 1)
xoverlay_string_size(xoverlay_font_handle_t handle, const char *string, int *x, int *y) {
{ log_write("fontapi: %u loading error\n", handle);
fflush(stdout);
return NULL;
}
return loaded_fonts[handle].font;
} }

Binary file not shown.

View File

@ -6,6 +6,8 @@
*/ */
#include "input.h" #include "input.h"
#include "log.h"
#include <fcntl.h> #include <fcntl.h>
#include <dirent.h> #include <dirent.h>
#include <stdlib.h> #include <stdlib.h>

Binary file not shown.

36
src/log.c Normal file
View File

@ -0,0 +1,36 @@
/*
* log.c
*
* Created on: Nov 14, 2017
* Author: nullifiedcat
*/
#include "log.h"
#include <stdarg.h>
#include <stdio.h>
FILE *log_file = 0;
void
log_write(const char *format, ...)
{
if (log_file == 0)
{
log_file = fopen("/tmp/xoverlay.log", "w");
if (log_file == 0)
{
perror("log opening");
log_file = stderr;
}
}
va_list args;
va_start(args, format);
vfprintf(log_file, format, args);
fflush(log_file);
va_end(args);
}

BIN
src/log.o Normal file

Binary file not shown.

View File

@ -8,45 +8,69 @@
#include "overlay.h" #include "overlay.h"
#include "input.h" #include "input.h"
#include "drawglx_internal.h" #include "drawglx_internal.h"
#include "log.h"
#include <GL/glx.h> #include <GL/glx.h>
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#include <X11/extensions/Xfixes.h> #include <X11/extensions/Xfixes.h>
#include <string.h> #include <string.h>
#include <stdio.h>
int event_ShapeNotify; int event_ShapeNotify;
int event_ShapeError; int event_ShapeError;
struct xoverlay_library xoverlay_library;
int preinit_done = 0;
void xoverlay_preinit()
{
preinit_done = 1;
if (init_input() < 0)
{
perror("XOVERLAY: init_input failed");
return;
}
fontapi_init();
textureapi_init();
}
int xoverlay_init() int xoverlay_init()
{ {
memset(&xoverlay_library, 0, sizeof(struct xoverlay_library)); memset(&xoverlay_library, 0, sizeof(struct xoverlay_library));
if (init_input() < 0)
{
return -1;
}
xoverlay_library.display = XOpenDisplay(NULL); xoverlay_library.display = XOpenDisplay(NULL);
if (xoverlay_library.display == NULL) if (xoverlay_library.display == NULL)
{ {
return -1; log_write("XOVERLAY: XOpenDisplay failed\n");
return -2;
} }
if (preinit_done == 0)
xoverlay_preinit();
else
log_write("Preinit already done\n");
xoverlay_library.screen = DefaultScreen(xoverlay_library.display); xoverlay_library.screen = DefaultScreen(xoverlay_library.display);
xoverlay_library.width = DisplayWidth(xoverlay_library.display, xoverlay_library.screen); xoverlay_library.width = DisplayWidth(xoverlay_library.display, xoverlay_library.screen);
xoverlay_library.height = DisplayHeight(xoverlay_library.display, xoverlay_library.screen); xoverlay_library.height = DisplayHeight(xoverlay_library.display, xoverlay_library.screen);
if (!XShapeQueryExtension(xoverlay_library.display, &event_ShapeNotify, &event_ShapeError)) if (!XShapeQueryExtension(xoverlay_library.display, &event_ShapeNotify, &event_ShapeError))
{ {
return -1; log_write("XOVERLAY: no shape extension\n");
return -3;
} }
if (xoverlay_glx_init() < 0) if (xoverlay_glx_init() < 0)
return -1; {
log_write("XOVERLAY: xoverlay_glx_init failed\n");
return -4;
}
if (xoverlay_glx_create_window() < 0) if (xoverlay_glx_create_window() < 0)
return -1; {
log_write("XOVERLAY: xoverlay_glx_create_window failed\n");
textureapi_init(); return -5;
fontapi_init(); }
xoverlay_library.init = 1; xoverlay_library.init = 1;
@ -232,7 +256,7 @@ void xoverlay_poll_events()
/*XEvent xevt; /*XEvent xevt;
if (XCheckWindowEvent(xoverlay_library.display, xoverlay_library.window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask, &xevt)) if (XCheckWindowEvent(xoverlay_library.display, xoverlay_library.window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask, &xevt))
{ {
printf("event %d\n", xevt.type); log_write("event %d\n", xevt.type);
switch (xevt.type) switch (xevt.type)
{ {
case KeyPress: case KeyPress:

Binary file not shown.

View File

@ -11,6 +11,7 @@
#include "programs.h" #include "programs.h"
#include "texture-atlas.h" #include "texture-atlas.h"
#include "drawglx_internal.h" #include "drawglx_internal.h"
#include "log.h"
DECL_PROGRAM_INIT(freetype) DECL_PROGRAM_INIT(freetype)
{ {

Binary file not shown.

View File

@ -9,6 +9,7 @@
#include "programs.h" #include "programs.h"
#include "drawglx_internal.h" #include "drawglx_internal.h"
#include "log.h"
DECL_PROGRAM_INIT(triangles_plain) DECL_PROGRAM_INIT(triangles_plain)
{ {

Binary file not shown.

View File

@ -9,6 +9,7 @@
#include "programs.h" #include "programs.h"
#include "drawglx_internal.h" #include "drawglx_internal.h"
#include "log.h"
DECL_PROGRAM_INIT(triangles_textured) DECL_PROGRAM_INIT(triangles_textured)
{ {

Binary file not shown.

View File

@ -6,6 +6,7 @@
*/ */
#include "drawglx_internal.h" #include "drawglx_internal.h"
#include "log.h"
#include <stdio.h> #include <stdio.h>
@ -20,7 +21,7 @@ GLuint compile_shader(const char *source, GLenum type)
{ {
char error_log[256]; char error_log[256];
glGetShaderInfoLog(shader, sizeof(error_log), NULL, error_log); glGetShaderInfoLog(shader, sizeof(error_log), NULL, error_log);
printf("GL Shader compilation error:\n%s\n", error_log); log_write("GL Shader compilation error:\n%s\n", error_log);
exit(1); exit(1);
} }
return shader; return shader;
@ -65,7 +66,7 @@ program_init_inplace(struct program_t *program, const char *vertex_format, const
{ {
char error_log[256]; char error_log[256];
glGetShaderInfoLog(program->shader, sizeof(error_log), NULL, error_log); glGetShaderInfoLog(program->shader, sizeof(error_log), NULL, error_log);
printf("GL Shader linking error:\n%s\n", error_log); log_write("GL Shader linking error:\n%s\n", error_log);
exit(1); exit(1);
} }
@ -120,7 +121,7 @@ const char *shader_v2ft2fc4f_freetype_frag =
void void
program_init_everything() program_init_everything()
{ {
printf("Initializing programs\n"); log_write("Initializing programs\n");
PROGRAM_INIT_INPLACE(&programs[PROGRAM_TRIANGLES_PLAIN], "vertex:2f,color:4f", shader_v2fc4f_frag, shader_v2fc4f_vert, triangles_plain); PROGRAM_INIT_INPLACE(&programs[PROGRAM_TRIANGLES_PLAIN], "vertex:2f,color:4f", shader_v2fc4f_frag, shader_v2fc4f_vert, triangles_plain);
setup_matrices(programs[PROGRAM_TRIANGLES_PLAIN].shader, 0); setup_matrices(programs[PROGRAM_TRIANGLES_PLAIN].shader, 0);
PROGRAM_INIT_INPLACE(&programs[PROGRAM_TRIANGLES_TEXTURED], "vertex:2f,tex_coord:2f,color:4f", shader_v2ft2fc4f_frag, shader_v2ft2fc4f_vert, triangles_textured); PROGRAM_INIT_INPLACE(&programs[PROGRAM_TRIANGLES_TEXTURED], "vertex:2f,tex_coord:2f,color:4f", shader_v2ft2fc4f_frag, shader_v2ft2fc4f_vert, triangles_textured);

Binary file not shown.

View File

@ -7,6 +7,7 @@
#include "drawglx_internal.h" #include "drawglx_internal.h"
#include "textureapi_internal.h" #include "textureapi_internal.h"
#include "log.h"
#include <string.h> #include <string.h>
#include <memory.h> #include <memory.h>
@ -28,14 +29,14 @@ textureapi_load_png_rgba(const char *name, struct textureapi_texture_t *out)
fread(header, 1, 8, file); fread(header, 1, 8, file);
if (png_sig_cmp(header, 0, 8)) if (png_sig_cmp(header, 0, 8))
{ {
printf("textureapi: not a PNG file\n"); log_write("textureapi: not a PNG file\n");
fclose(file); fclose(file);
return -1; return -1;
} }
png_structp pngstr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_structp pngstr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (pngstr == NULL) if (pngstr == NULL)
{ {
printf("textureapi: png creation error\n"); log_write("textureapi: png creation error\n");
return -1; return -1;
} }
png_infop pnginfo = png_create_info_struct(pngstr); png_infop pnginfo = png_create_info_struct(pngstr);
@ -54,7 +55,7 @@ textureapi_load_png_rgba(const char *name, struct textureapi_texture_t *out)
int row_bytes; int row_bytes;
if (PNG_COLOR_TYPE_RGBA != png_get_color_type(pngstr, pnginfo)) if (PNG_COLOR_TYPE_RGBA != png_get_color_type(pngstr, pnginfo))
{ {
printf("textureapi: not RGBA PNG\n"); log_write("textureapi: not RGBA PNG\n");
png_destroy_read_struct(pngstr, pnginfo, pngend); png_destroy_read_struct(pngstr, pnginfo, pngend);
fclose(file); fclose(file);
return -1; return -1;
@ -65,7 +66,7 @@ textureapi_load_png_rgba(const char *name, struct textureapi_texture_t *out)
out->data = malloc(row_bytes * height * sizeof(png_byte)); out->data = malloc(row_bytes * height * sizeof(png_byte));
if (out->data == NULL) if (out->data == NULL)
{ {
printf("malloc error\n"); log_write("malloc error\n");
png_destroy_read_struct(pngstr, pnginfo, pngend); png_destroy_read_struct(pngstr, pnginfo, pngend);
fclose(file); fclose(file);
return -1; return -1;
@ -73,7 +74,7 @@ textureapi_load_png_rgba(const char *name, struct textureapi_texture_t *out)
row_pointers = malloc(height * sizeof(png_bytep)); row_pointers = malloc(height * sizeof(png_bytep));
if (row_pointers == NULL) if (row_pointers == NULL)
{ {
printf("malloc error\n"); log_write("malloc error\n");
png_destroy_read_struct(pngstr, pnginfo, pngend); png_destroy_read_struct(pngstr, pnginfo, pngend);
free(out->data); free(out->data);
fclose(file); fclose(file);
@ -103,7 +104,7 @@ textureapi_bind(xoverlay_texture_handle_t handle)
return; return;
if (!texture->bound) if (!texture->bound)
{ {
printf("generating texture\n"); log_write("generating texture\n");
glGenTextures(1, &texture->texture_id); glGenTextures(1, &texture->texture_id);
glBindTexture(GL_TEXTURE_2D, texture->texture_id); glBindTexture(GL_TEXTURE_2D, texture->texture_id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@ -125,7 +126,7 @@ xoverlay_texture_load_png_rgba(const char *path)
strncpy(result.filename, path, 255); strncpy(result.filename, path, 255);
if (textureapi_load_png_rgba(path, &result) != 0) if (textureapi_load_png_rgba(path, &result) != 0)
{ {
printf("textureapi: could not load texture file %s\n", path); log_write("textureapi: could not load texture file %s\n", path);
} }
return textureapi_add_texture(result); return textureapi_add_texture(result);
} }

Binary file not shown.