Render game graphics using OpenGL
[mercenary-reloaded.git] / src / libsdl / sdl.c
index e6a34e6..b0f464b 100644 (file)
@@ -43,7 +43,7 @@ static void audio_cb(void __attribute__((unused)) *userdata, Uint8 *stream, int
        SDL_MixAudio(stream, (Uint8 *)audio_data, len, SDL_MIX_MAXVOLUME);
 }
 
-int init_sdl(const char *progname, int width, int height, int sound_samplerate, int sound_chunk, void (*keyboard)(int down, SDL_Keycode sym), void (*audio)(float *data, int len))
+int init_sdl(const char *progname, int width, int height, int sound_samplerate, int sound_chunk, void (*keyboard)(int down, SDL_Keycode sym), void (*audio)(float *data, int len), int multisampling)
 {
        int rc;
 
@@ -58,6 +58,16 @@ int init_sdl(const char *progname, int width, int height, int sound_samplerate,
        }
        sdl_initialized = 1;
 
+       if (multisampling) {
+               SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+               SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+               SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+               SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+               SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, multisampling);
+       }
+
        /* open window */
        gl_window = SDL_CreateWindow(progname, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
        if (!gl_window) {
@@ -114,6 +124,8 @@ int init_sdl(const char *progname, int width, int height, int sound_samplerate,
        /* just in case */
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_CULL_FACE);
+       if (multisampling)
+               glEnable(GL_MULTISAMPLE);
 
        /* open audio */
        SDL_AudioSpec want, have;
@@ -175,8 +187,10 @@ int event_sdl(void)
                                        if (fullscreen) {
                                                fullscreen = 0;
                                                SDL_SetWindowFullscreen(gl_window, 0);
+                                               SDL_ShowCursor(SDL_ENABLE);
                                        } else {
                                                SDL_SetWindowFullscreen(gl_window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+                                               SDL_ShowCursor(SDL_DISABLE);
                                                fullscreen = 1;
                                        }
                                }