Replace printf/fprintf with own print_info() / print_error() using SDL_log
[mercenary-reloaded.git] / src / libsdl / sdl.c
index d310791..50af2a8 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <errno.h>
+#include "print.h"
 #include "sdl.h"
 #include "opengl.h"
 
@@ -52,7 +53,7 @@ int init_sdl(const char *progname, int width, int height, int sound_samplerate,
        /* init SDL library */
        rc = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
        if (rc < 0) {
-               fprintf(stderr, "Failed to init SDL\n");
+               print_error("Failed to init SDL\n");
                goto error;
        }
        sdl_initialized = 1;
@@ -60,7 +61,7 @@ int init_sdl(const char *progname, int width, int height, int sound_samplerate,
        /* open window */
        gl_window = SDL_CreateWindow(progname, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
        if (!gl_window) {
-               fprintf(stderr, "Failed to open SDL window: %s\n", SDL_GetError());
+               print_error("Failed to open SDL window: %s\n", SDL_GetError());
                rc = EIO;
                goto error;
        }
@@ -68,44 +69,44 @@ int init_sdl(const char *progname, int width, int height, int sound_samplerate,
        /* create GL context */
        gl_context = SDL_GL_CreateContext(gl_window);
        if (!gl_context) {
-               fprintf(stderr, "Failed to create SDL's OpenGL context: %s\n", SDL_GetError());
+               print_error("Failed to create SDL's OpenGL context: %s\n", SDL_GetError());
                rc = EIO;
                goto error;
        }
 
        rc = SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
        if (rc < 0) {
-               fprintf(stderr, "Failed to set SDL's OpenGL context profile\n");
+               print_error("Failed to set SDL's OpenGL context profile\n");
                goto error;
        }
 
        rc = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
        if (rc < 0) {
-               fprintf(stderr, "Failed to set SDL's OpenGL major version\n");
+               print_error("Failed to set SDL's OpenGL major version\n");
                goto error;
        }
        rc = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
        if (rc < 0) {
-               fprintf(stderr, "Failed to set SDL's OpenGL minor version\n");
+               print_error("Failed to set SDL's OpenGL minor version\n");
                goto error;
        }
 
        rc = SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        if (rc < 0) {
-               fprintf(stderr, "Failed to set SDL's OpenGL doublebuffer\n");
+               print_error("Failed to set SDL's OpenGL doublebuffer\n");
                goto error;
        }
 
        rc = SDL_GL_SetSwapInterval(1);
        if (rc < 0) {
-               fprintf(stderr, "Failed to set SDL's OpenGL swap interval to VBLANK\n");
+               print_error("Failed to set SDL's OpenGL swap interval to VBLANK\n");
                goto error;
        }
 
 #ifndef __APPLE__
        glewExperimental = GL_TRUE;
        if (glewInit() != GLEW_OK) {
-               fprintf(stderr, "Failed to init GLEW\n");
+               print_error("Failed to init GLEW\n");
                goto error;
        }
 #endif
@@ -124,15 +125,15 @@ int init_sdl(const char *progname, int width, int height, int sound_samplerate,
        want.callback = audio_cb;
        rc = SDL_OpenAudio(&want, &have);
        if (rc < 0) {
-               fprintf(stderr, "Failed to open audio\n");
+               print_error("Failed to open audio\n");
                goto error;
        } else if (have.format != want.format) {
-               fprintf(stderr, "Failed to open audio with desired audio format\n");
+               print_error("Failed to open audio with desired audio format\n");
                SDL_CloseAudio();
                rc = -EIO;
                goto error;
        } else if (have.freq != want.freq) {
-               fprintf(stderr, "Failed to open audio with desired sample rate\n");
+               print_error("Failed to open audio with desired sample rate\n");
                SDL_CloseAudio();
                rc = -EIO;
                goto error;