Switch to GLib logging
This commit is contained in:
+10
-10
@@ -21,12 +21,12 @@ shader_fail (int shader)
|
||||
{
|
||||
char *info = malloc (sizeof (char) * info_len);
|
||||
glGetShaderInfoLog (shader, info_len, NULL, info);
|
||||
WARN ("Compiling %s shader failed:\n%s", type, info);
|
||||
g_warning ("Compiling %s shader failed:\n%s", type, info);
|
||||
free (info);
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN ("Compiling %s shader failed without information.", type);
|
||||
g_warning ("Compiling %s shader failed without information.", type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ program_fail (int program)
|
||||
{
|
||||
char *info = malloc (sizeof (char) * info_len);
|
||||
glGetProgramInfoLog (program, info_len, NULL, info);
|
||||
WARN ("Linking program failed:\n%s", info);
|
||||
g_warning ("Linking program failed:\n%s", info);
|
||||
free (info);
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN ("Linking program failed without information.");
|
||||
g_warning ("Linking program failed without information.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ program_create (const char *v_src, const char *f_src)
|
||||
glLinkProgram (program);
|
||||
glGetProgramiv (program, GL_LINK_STATUS, &success);
|
||||
if (!success) program_fail (program);
|
||||
else INFO ("Compiled shaders and linked program %d successfuly.", program);
|
||||
else g_info ("Compiled shaders and linked program %d successfuly.", program);
|
||||
|
||||
glDeleteShader (vertex);
|
||||
glDeleteShader (fragment);
|
||||
@@ -144,7 +144,7 @@ void
|
||||
program_print (int program)
|
||||
/* This function assumes that `program' is the active program. */
|
||||
{
|
||||
INFO ("== Program %d ==", program);
|
||||
g_info ("== Program %d ==", program);
|
||||
|
||||
int attr_len;
|
||||
glGetProgramiv (program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attr_len);
|
||||
@@ -157,7 +157,7 @@ program_print (int program)
|
||||
|
||||
for (GLint i = 0; i < attribute_no; i++) {
|
||||
glGetActiveAttrib (program, i, attr_len, NULL, NULL, &type, attr);
|
||||
INFO ("Attribute #%d: %s %s", i, gl_type_to_string (type), attr);
|
||||
g_info ("Attribute #%d: %s %s", i, gl_type_to_string (type), attr);
|
||||
}
|
||||
|
||||
int uniform_len;
|
||||
@@ -176,16 +176,16 @@ program_print (int program)
|
||||
{
|
||||
case GL_FLOAT_VEC3:
|
||||
glGetUniformfv (program, glGetUniformLocation (program, uniform), vec);
|
||||
INFO ("Uniform #%d: %s %s = (%5.1f,%5.1f,%5.1f)", i, gl_type_to_string (type),
|
||||
g_info ("Uniform #%d: %s %s = (%5.1f,%5.1f,%5.1f)", i, gl_type_to_string (type),
|
||||
uniform, vec[0], vec[1], vec[2]);
|
||||
break;
|
||||
case GL_FLOAT_VEC4:
|
||||
glGetUniformfv (program, glGetUniformLocation (program, uniform), vec);
|
||||
INFO ("Uniform #%d: %s %s = (%5.1f,%5.1f,%5.1f,%5.1f)", i, gl_type_to_string (type),
|
||||
g_info ("Uniform #%d: %s %s = (%5.1f,%5.1f,%5.1f,%5.1f)", i, gl_type_to_string (type),
|
||||
uniform, vec[0], vec[1], vec[2], vec[3]);
|
||||
break;
|
||||
default:
|
||||
INFO ("Uniform #%d: %s %s", i, gl_type_to_string (type), uniform);
|
||||
g_info ("Uniform #%d: %s %s", i, gl_type_to_string (type), uniform);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL_opengles2.h>
|
||||
#include <cglm/cglm.h>
|
||||
|
||||
#include "../util.h"
|
||||
#include <glib-2.0/glib.h>
|
||||
|
||||
unsigned int program_use (int program);
|
||||
void shader_fail (int shader);
|
||||
|
||||
+8
-8
@@ -20,14 +20,14 @@ graphics_init ()
|
||||
{
|
||||
if (!SDL_Init (SDL_INIT_VIDEO))
|
||||
{
|
||||
FATAL ("Couldn't initialize SDL: %s", SDL_GetError ());
|
||||
g_error ("Couldn't initialize SDL: %s", SDL_GetError ());
|
||||
}
|
||||
|
||||
sdl_window = SDL_CreateWindow (GAME_NAME, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL);
|
||||
|
||||
if (!sdl_window)
|
||||
{
|
||||
FATAL ("Couldn't create window: %s", SDL_GetError ());
|
||||
g_error ("Couldn't create window: %s", SDL_GetError ());
|
||||
}
|
||||
|
||||
/* We use OpenGL ES 2.0. It should support everything, and it's more
|
||||
@@ -42,16 +42,16 @@ graphics_init ()
|
||||
|
||||
if (!gl_context)
|
||||
{
|
||||
FATAL ("Couldn't create OpenGL context: %s", SDL_GetError ());
|
||||
g_error ("Couldn't create OpenGL context: %s", SDL_GetError ());
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent (sdl_window, gl_context);
|
||||
SDL_SetWindowRelativeMouseMode (sdl_window, true);
|
||||
|
||||
INFO ("Renderer: %s", glGetString (GL_RENDERER));
|
||||
INFO ("OpenGL version: %s", glGetString (GL_VERSION));
|
||||
INFO ("GLSL version: %s", glGetString (GL_SHADING_LANGUAGE_VERSION));
|
||||
INFO ("Max vertex attributes: %d", GL_MAX_VERTEX_ATTRIBS);
|
||||
g_info ("Renderer: %s", glGetString (GL_RENDERER));
|
||||
g_info ("OpenGL version: %s", glGetString (GL_VERSION));
|
||||
g_info ("GLSL version: %s", glGetString (GL_SHADING_LANGUAGE_VERSION));
|
||||
g_info ("Max vertex attributes: %d", GL_MAX_VERTEX_ATTRIBS);
|
||||
|
||||
glViewport (0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
glClearColor (0, 0.3, 0.8, 1);
|
||||
@@ -119,7 +119,7 @@ graphics_render ()
|
||||
avg_elapsed = 0;
|
||||
avg_counter = 0;
|
||||
last_check_perf = now;
|
||||
INFO ("Dynamic render distance check: render distance %d, average ms: %.2f", render_distance, avg / 10000.0);
|
||||
g_debug ("Dynamic render distance check: render distance %d, average ms: %.2f", render_distance, avg / 10000.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ resources_load_program (const char *v_path, const char *f_path)
|
||||
|
||||
if (v_file == NULL)
|
||||
{
|
||||
WARN ("File `%s' does not exist.", v_path);
|
||||
g_warning ("File `%s' does not exist.", v_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ resources_load_program (const char *v_path, const char *f_path)
|
||||
size_t v_len = ftell (v_file) + 1;
|
||||
char *v_src = calloc (v_len, sizeof (char));
|
||||
rewind (v_file);
|
||||
INFO ("Read %zu bytes from vertex source.", fread (v_src, sizeof (char), v_len, v_file));
|
||||
g_debug ("Read %zu bytes from vertex source.", fread (v_src, sizeof (char), v_len, v_file));
|
||||
|
||||
FILE *f_file = fopen (f_path, "r");
|
||||
|
||||
if (f_file == NULL)
|
||||
{
|
||||
WARN ("File `%s' does not exist.", f_path);
|
||||
g_warning ("File `%s' does not exist.", f_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ resources_load_program (const char *v_path, const char *f_path)
|
||||
size_t f_len = ftell (f_file) + 1;
|
||||
char *f_src = calloc (f_len, sizeof (char));
|
||||
rewind (f_file);
|
||||
INFO ("Read %zu bytes from fragment source.", fread (f_src, sizeof (char), f_len, f_file));
|
||||
g_debug ("Read %zu bytes from fragment source.", fread (f_src, sizeof (char), f_len, f_file));
|
||||
|
||||
unsigned int program = program_create (v_src, f_src);
|
||||
free (v_src);
|
||||
@@ -49,7 +49,7 @@ resources_load_texture (const char *path)
|
||||
|
||||
if (surface == NULL)
|
||||
{
|
||||
WARN ("Failed to load texture from path %s: %s", path, SDL_GetError ());
|
||||
g_warning ("Failed to load texture from path %s: %s", path, SDL_GetError ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ resources_get_program (char *key)
|
||||
{
|
||||
if (!g_hash_table_contains (programs, key))
|
||||
{
|
||||
WARN ("Program `%s' does not exist. Careful!", key);
|
||||
g_warning ("Program `%s' does not exist. Careful!", key);
|
||||
}
|
||||
|
||||
return GPOINTER_TO_INT (g_hash_table_lookup (programs, key));
|
||||
@@ -91,7 +91,7 @@ resources_get_texture (char *key)
|
||||
{
|
||||
if (!g_hash_table_contains (textures, key))
|
||||
{
|
||||
WARN ("Texture `%s' does not exist. Careful!", key);
|
||||
g_warning ("Texture `%s' does not exist. Careful!", key);
|
||||
}
|
||||
|
||||
return GPOINTER_TO_INT (g_hash_table_lookup (textures, key));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "gl/program.h"
|
||||
#include "gl/texture.h"
|
||||
#include "util.h"
|
||||
|
||||
#define RESPRG(key) (resources_get_program (key))
|
||||
#define RESTEX(key) (resources_get_texture (key))
|
||||
|
||||
@@ -321,9 +321,9 @@ uicb_flag_switch (UIElement *element, void *userdata)
|
||||
}
|
||||
|
||||
void
|
||||
uicb_debug_print (UIElement *element, void *userdata)
|
||||
uicb_debug (UIElement *element, void *userdata)
|
||||
{
|
||||
UNUSED (element);
|
||||
char *text = userdata;
|
||||
INFO ("%s", text);
|
||||
g_debug ("%s", text);
|
||||
}
|
||||
|
||||
@@ -85,4 +85,4 @@ void uicb_label_show_int (UIElement *element, void *userdata);
|
||||
void uicb_label_show_float (UIElement *element, void *userdata);
|
||||
|
||||
void uicb_flag_switch (UIElement *element, void *userdata);
|
||||
void uicb_debug_print (UIElement *element, void *userdata);
|
||||
void uicb_debug (UIElement *element, void *userdata);
|
||||
|
||||
+13
-9
@@ -6,16 +6,20 @@
|
||||
#define GAME_NAME "Wschód"
|
||||
#define GAME_VERSION "0.2"
|
||||
|
||||
#define COLOR_BLUE "\x1B[34m"
|
||||
#define COLOR_RED "\x1B[31m"
|
||||
#define COLOR_YELLOW "\x1B[33m"
|
||||
#define COLOR_RESET "\x1B[0m"
|
||||
|
||||
#define INFO(fmt, args...) (fprintf (stderr, COLOR_BLUE "[I] %s:%d:%s(): " COLOR_RESET fmt "\n", __FILE__, __LINE__, __func__, ##args))
|
||||
#define WARN(fmt, args...) (fprintf (stderr, COLOR_YELLOW "[W] %s:%d:%s(): " COLOR_RESET fmt "\n", __FILE__, __LINE__, __func__, ##args))
|
||||
#define FATAL(fmt, args...) (fprintf (stderr, COLOR_RED "[!] %s:%d:%s(): " COLOR_RESET fmt "\n", __FILE__, __LINE__, __func__, ##args), exit (-1))
|
||||
|
||||
#define UNUSED(...) (UNUSED_1 (__VA_ARGS__, 0))
|
||||
#define UNUSED_1(arg, ...) (void) arg, UNUSED_2 (__VA_ARGS__, 0)
|
||||
#define UNUSED_2(arg, ...) (void) arg, UNUSED_3 (__VA_ARGS__, 0)
|
||||
#define UNUSED_3(arg, ...) (void) arg
|
||||
|
||||
/*
|
||||
|
||||
GLib log levels:
|
||||
|
||||
g_debug
|
||||
g_info
|
||||
g_message
|
||||
g_warning
|
||||
g_critical
|
||||
g_error
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user