mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-02 09:57:40 +00:00
testprograms: parse arguments using SDLTest_CommonState
This commit is contained in:
parent
8bea41f737
commit
4a6528e3f0
71 changed files with 1516 additions and 389 deletions
|
@ -13,6 +13,9 @@
|
|||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <SDL3/SDL_test.h>
|
||||
|
||||
#include "testutils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -440,15 +443,44 @@ static void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat *texcoord)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int done;
|
||||
SDL_Window *window;
|
||||
char *filename = NULL;
|
||||
SDL_Surface *surface;
|
||||
GLuint texture;
|
||||
GLfloat texcoords[4];
|
||||
SDLTest_CommonState *state;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Parse commandline */
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (!consumed) {
|
||||
if (!filename) {
|
||||
filename = argv[i];
|
||||
consumed = 1;
|
||||
}
|
||||
}
|
||||
if (consumed <= 0) {
|
||||
static const char *options[] = { "[icon.bmp]", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
i += consumed;
|
||||
}
|
||||
|
||||
/* Initialize SDL for video output */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError());
|
||||
|
@ -469,7 +501,10 @@ int main(int argc, char **argv)
|
|||
exit(2);
|
||||
}
|
||||
|
||||
surface = SDL_LoadBMP("icon.bmp");
|
||||
filename = GetResourceFilename(NULL, "icon.bmp");
|
||||
surface = SDL_LoadBMP(filename);
|
||||
SDL_free(filename);
|
||||
|
||||
if (surface == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
|
@ -509,6 +544,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
QuitShaders();
|
||||
SDL_Quit();
|
||||
SDLTest_CommonDestroyState(state);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue