| 1 | /** |
| 2 | * MojoShader; generate shader programs from bytecode of compiled |
| 3 | * Direct3D shaders. |
| 4 | * |
| 5 | * Please see the file LICENSE.txt in the source's root directory. |
| 6 | * |
| 7 | * This file written by Ryan C. Gordon. |
| 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include "mojoshader.h" |
| 12 | #include "SDL.h" |
| 13 | |
| 14 | static void *lookup(const char *fnname, void *unused) |
| 15 | { |
| 16 | (void) unused; |
| 17 | return SDL_GL_GetProcAddress(fnname); |
| 18 | } // lookup |
| 19 | |
| 20 | int main(int argc, char **argv) |
| 21 | { |
| 22 | int retval = 1; |
| 23 | |
| 24 | #if 0 |
| 25 | printf("MojoShader bestprofile\n"); |
| 26 | printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET); |
| 27 | printf("Linked against changeset %s\n", MOJOSHADER_changeset()); |
| 28 | printf("\n"); |
| 29 | #endif |
| 30 | |
| 31 | SDL_Window *sdlwindow = NULL; |
| 32 | if (SDL_Init(SDL_INIT_VIDEO) == -1) |
| 33 | fprintf(stderr, "SDL_Init() error: %s\n", SDL_GetError()); |
| 34 | else if (SDL_GL_LoadLibrary(NULL) == -1) |
| 35 | fprintf(stderr, "SDL_GL_LoadLibrary() error: %s\n", SDL_GetError()); |
| 36 | else if ((sdlwindow = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL)) == NULL) |
| 37 | fprintf(stderr, "SDL_CreateWindow() error: %s\n", SDL_GetError()); |
| 38 | else if (SDL_GL_CreateContext(sdlwindow) == NULL) |
| 39 | fprintf(stderr, "SDL_GL_CreateContext() error: %s\n", SDL_GetError()); |
| 40 | else |
| 41 | { |
| 42 | const char *best = MOJOSHADER_glBestProfile(lookup, NULL, NULL, NULL, NULL); |
| 43 | MOJOSHADER_glContext *ctx = MOJOSHADER_glCreateContext(best, lookup, 0, 0, 0, 0); |
| 44 | if (ctx == NULL) |
| 45 | printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError()); |
| 46 | else |
| 47 | { |
| 48 | printf("%s\n", best); |
| 49 | retval = 0; // success. |
| 50 | MOJOSHADER_glDestroyContext(ctx); |
| 51 | } // else |
| 52 | } // else |
| 53 | |
| 54 | SDL_Quit(); |
| 55 | return retval; |
| 56 | } // main |
| 57 | |
| 58 | // end of bestprofile.c ... |
| 59 |