Moved to SDL2.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 21 Feb 2014 12:41:25 -0500
changeset 1134 be31bd0ee0a2
parent 1133 eb1eb43987b3
child 1135 780e3e4b1d4a
Moved to SDL2.
CMakeLists.txt
utils/availableprofiles.c
utils/bestprofile.c
utils/finderrors.c
utils/glcaps.c
--- a/CMakeLists.txt	Fri Feb 07 15:57:54 2014 -0500
+++ b/CMakeLists.txt	Fri Feb 21 12:41:25 2014 -0500
@@ -94,32 +94,37 @@
     )
 ENDIF(NOT RE2C)
 
-FIND_PACKAGE(SDL)
-IF(SDL_FOUND)
-    INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
+IF(APPLE)
+    find_library(CARBON_FRAMEWORK Carbon)  # Stupid Gestalt.
+ENDIF(APPLE)
+
+find_path(SDL2_INCLUDE_DIR SDL.h PATH_SUFFIXES include/SDL2)
+find_library(SDL2 NAMES SDL2 PATH_SUFFIXES lib)
+IF(SDL2)
+    INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR})
     ADD_EXECUTABLE(glcaps utils/glcaps.c)
-    TARGET_LINK_LIBRARIES(glcaps ${SDL_LIBRARY} ${LIBM})
+    TARGET_LINK_LIBRARIES(glcaps ${SDL2} ${LIBM} ${CARBON_FRAMEWORK})
     ADD_EXECUTABLE(bestprofile utils/bestprofile.c)
-    TARGET_LINK_LIBRARIES(bestprofile mojoshader ${SDL_LIBRARY} ${LIBM})
+    TARGET_LINK_LIBRARIES(bestprofile mojoshader ${SDL2} ${LIBM} ${CARBON_FRAMEWORK})
     ADD_EXECUTABLE(availableprofiles utils/availableprofiles.c)
-    TARGET_LINK_LIBRARIES(availableprofiles mojoshader ${SDL_LIBRARY} ${LIBM})
-ENDIF(SDL_FOUND)
+    TARGET_LINK_LIBRARIES(availableprofiles mojoshader ${SDL2} ${LIBM} ${CARBON_FRAMEWORK})
+ENDIF(SDL2)
 
 ADD_EXECUTABLE(finderrors utils/finderrors.c)
-TARGET_LINK_LIBRARIES(finderrors mojoshader ${SDL_LIBRARY} ${LIBM})
-IF(SDL_FOUND)
+TARGET_LINK_LIBRARIES(finderrors mojoshader ${SDL2} ${LIBM} ${CARBON_FRAMEWORK})
+IF(SDL2)
     SET_SOURCE_FILES_PROPERTIES(
         utils/finderrors.c
         PROPERTIES COMPILE_FLAGS "-DFINDERRORS_COMPILE_SHADERS=1"
     )
-ENDIF(SDL_FOUND)
+ENDIF(SDL2)
 
 ADD_EXECUTABLE(testparse utils/testparse.c)
-TARGET_LINK_LIBRARIES(testparse mojoshader ${LIBM})
+TARGET_LINK_LIBRARIES(testparse mojoshader ${LIBM} ${CARBON_FRAMEWORK})
 ADD_EXECUTABLE(testoutput utils/testoutput.c)
-TARGET_LINK_LIBRARIES(testoutput mojoshader ${LIBM})
+TARGET_LINK_LIBRARIES(testoutput mojoshader ${LIBM} ${CARBON_FRAMEWORK})
 ADD_EXECUTABLE(mojoshader-compiler utils/mojoshader-compiler.c)
-TARGET_LINK_LIBRARIES(mojoshader-compiler mojoshader ${LIBM})
+TARGET_LINK_LIBRARIES(mojoshader-compiler mojoshader ${LIBM} ${CARBON_FRAMEWORK})
 
 # Unit tests...
 ADD_CUSTOM_TARGET(
--- a/utils/availableprofiles.c	Fri Feb 07 15:57:54 2014 -0500
+++ b/utils/availableprofiles.c	Fri Feb 21 12:41:25 2014 -0500
@@ -54,18 +54,19 @@
     printf("\n");
     #endif
 
+    SDL_Window *sdlwindow = NULL;
     if (SDL_Init(SDL_INIT_VIDEO) == -1)
-        fprintf(stderr, "SDL_Init(SDL_INIT_VIDEO) error: %s\n", SDL_GetError());
+        fprintf(stderr, "SDL_Init() error: %s\n", SDL_GetError());
+    else if (SDL_GL_LoadLibrary(NULL) == -1)
+        fprintf(stderr, "SDL_GL_LoadLibrary() error: %s\n", SDL_GetError());
+    else if ((sdlwindow = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL)) == NULL)
+        fprintf(stderr, "SDL_CreateWindow() error: %s\n", SDL_GetError());
+    else if (SDL_GL_CreateContext(sdlwindow) == NULL)
+        fprintf(stderr, "SDL_GL_CreateContext() error: %s\n", SDL_GetError());
     else
-    {
-        SDL_GL_LoadLibrary(NULL);
-        if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL)
-            fprintf(stderr, "SDL_SetVideoMode() error: %s\n", SDL_GetError());
-        else
-            retval = check_available();
-        SDL_Quit();
-    } // else
+        retval = check_available();
 
+    SDL_Quit();
     return retval;
 } // main
 
--- a/utils/bestprofile.c	Fri Feb 07 15:57:54 2014 -0500
+++ b/utils/bestprofile.c	Fri Feb 21 12:41:25 2014 -0500
@@ -28,30 +28,30 @@
     printf("\n");
     #endif
 
+    SDL_Window *sdlwindow = NULL;
     if (SDL_Init(SDL_INIT_VIDEO) == -1)
-        fprintf(stderr, "SDL_Init(SDL_INIT_VIDEO) error: %s\n", SDL_GetError());
+        fprintf(stderr, "SDL_Init() error: %s\n", SDL_GetError());
+    else if (SDL_GL_LoadLibrary(NULL) == -1)
+        fprintf(stderr, "SDL_GL_LoadLibrary() error: %s\n", SDL_GetError());
+    else if ((sdlwindow = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL)) == NULL)
+        fprintf(stderr, "SDL_CreateWindow() error: %s\n", SDL_GetError());
+    else if (SDL_GL_CreateContext(sdlwindow) == NULL)
+        fprintf(stderr, "SDL_GL_CreateContext() error: %s\n", SDL_GetError());
     else
     {
-        SDL_GL_LoadLibrary(NULL);
-        if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL)
-            fprintf(stderr, "SDL_SetVideoMode() error: %s\n", SDL_GetError());
+        const char *best = MOJOSHADER_glBestProfile(lookup, NULL, NULL, NULL, NULL);
+        MOJOSHADER_glContext *ctx = MOJOSHADER_glCreateContext(best, lookup, 0, 0, 0, 0);
+        if (ctx == NULL)
+            printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
         else
         {
-            const char *best = MOJOSHADER_glBestProfile(lookup, NULL, NULL, NULL, NULL);
-            MOJOSHADER_glContext *ctx;
-            ctx = MOJOSHADER_glCreateContext(best, lookup, 0, 0, 0, 0);
-            if (ctx == NULL)
-                printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
-            else
-            {
-                printf("%s\n", best);
-                retval = 0;  // success.
-                MOJOSHADER_glDestroyContext(ctx);
-            } // else
+            printf("%s\n", best);
+            retval = 0;  // success.
+            MOJOSHADER_glDestroyContext(ctx);
         } // else
-        SDL_Quit();
     } // else
 
+    SDL_Quit();
     return retval;
 } // main
 
--- a/utils/finderrors.c	Fri Feb 07 15:57:54 2014 -0500
+++ b/utils/finderrors.c	Fri Feb 21 12:41:25 2014 -0500
@@ -18,6 +18,7 @@
 
 #if FINDERRORS_COMPILE_SHADERS
 #include "SDL.h"
+static SDL_Window *sdlwindow = NULL;
 static void *lookup(const char *fnname, void *unused)
 {
     (void) unused;
@@ -47,7 +48,7 @@
         if (e.type == SDL_QUIT)
             do_quit = 1;
     } // while
-    SDL_GL_SwapBuffers();
+    SDL_GL_SwapWindow(sdlwindow);
     #endif
 
     if (do_quit)
@@ -196,33 +197,43 @@
         printf("\n\nUSAGE: %s <profile> [dir1] ... [dirN]\n\n", argv[0]);
     else
     {
+        int okay = 0;
         int total = 0;
         int i;
         const char *profile = argv[1];
 
         #if FINDERRORS_COMPILE_SHADERS
-        SDL_Init(SDL_INIT_VIDEO);
-        SDL_GL_LoadLibrary(NULL);
-        SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
-        printf("Best profile is '%s'\n", MOJOSHADER_glBestProfile(lookup, 0, NULL, NULL, NULL));
-        MOJOSHADER_glContext *ctx;
-        ctx = MOJOSHADER_glCreateContext(profile, lookup, 0, 0, 0, 0);
-        if (ctx == NULL)
+        MOJOSHADER_glContext *ctx = NULL;
+        if (SDL_Init(SDL_INIT_VIDEO) == -1)
+            fprintf(stderr, "SDL_Init() error: %s\n", SDL_GetError());
+        else if (SDL_GL_LoadLibrary(NULL) == -1)
+            fprintf(stderr, "SDL_GL_LoadLibrary() error: %s\n", SDL_GetError());
+        else if ((sdlwindow = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL)) == NULL)
+            fprintf(stderr, "SDL_CreateWindow() error: %s\n", SDL_GetError());
+        else if (SDL_GL_CreateContext(sdlwindow) == NULL)
+            fprintf(stderr, "SDL_GL_CreateContext() error: %s\n", SDL_GetError());
+        else if ((ctx = MOJOSHADER_glCreateContext(profile, lookup, 0, 0, 0, 0)) == NULL)
+            fprintf(stderr, "MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
+        else
         {
-            printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
-            SDL_Quit();
-            return 1;
-        } // if
-        MOJOSHADER_glMakeContextCurrent(ctx);
+            printf("Best profile is '%s'\n", MOJOSHADER_glBestProfile(lookup, 0, NULL, NULL, NULL));
+            MOJOSHADER_glMakeContextCurrent(ctx);
+            okay = 1;
+        }
+        #else
+        okay = 1;
         #endif
 
-        for (i = 2; i < argc; i++)
-            total += do_dir(argv[i], profile);
-
-        printf("Saw %d files.\n", total);
+        if (okay)
+        {
+            for (i = 2; i < argc; i++)
+                total += do_dir(argv[i], profile);
+            printf("Saw %d files.\n", total);
+        } // if
 
         #if FINDERRORS_COMPILE_SHADERS
-        MOJOSHADER_glDestroyContext(ctx);
+        if (ctx)
+            MOJOSHADER_glDestroyContext(ctx);
         SDL_Quit();
         #endif
     } // else
--- a/utils/glcaps.c	Fri Feb 07 15:57:54 2014 -0500
+++ b/utils/glcaps.c	Fri Feb 21 12:41:25 2014 -0500
@@ -32,12 +32,27 @@
 
 int main(int argc, char **argv)
 {
+    int retval = 1;
     GLint val = 0;
     const char *str = NULL;
+    SDL_Window *sdlwindow = NULL;
 
-    SDL_Init(SDL_INIT_VIDEO);
-    SDL_GL_LoadLibrary(NULL);
-    SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
+    if (SDL_Init(SDL_INIT_VIDEO) == -1)
+        fprintf(stderr, "SDL_Init() error: %s\n", SDL_GetError());
+    else if (SDL_GL_LoadLibrary(NULL) == -1)
+        fprintf(stderr, "SDL_GL_LoadLibrary() error: %s\n", SDL_GetError());
+    else if ((sdlwindow = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL)) == NULL)
+        fprintf(stderr, "SDL_CreateWindow() error: %s\n", SDL_GetError());
+    if (SDL_GL_CreateContext(sdlwindow) == NULL)
+        fprintf(stderr, "SDL_GL_CreateContext() error: %s\n", SDL_GetError());
+    else
+        retval = 0;
+
+    if (retval != 0)
+    {
+        SDL_Quit();
+        return retval;
+    } // if
 
     PFNGLGETSTRINGPROC pglGetString = (PFNGLGETSTRINGPROC) SDL_GL_GetProcAddress("glGetString");
     PFNGLGETINTEGERVPROC pglGetIntegerv = (PFNGLGETINTEGERVPROC) SDL_GL_GetProcAddress("glGetIntegerv");