Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency

This commit is contained in:
Andreas Schiffler 2013-08-14 23:30:10 -07:00
parent 67367be019
commit 65728477af
47 changed files with 616 additions and 505 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
@ -105,7 +105,8 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"</Command> <Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"
copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav"</Command>
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent> <PostBuildEvent>
<Message>Copy SDL</Message> <Message>Copy SDL</Message>
@ -139,7 +140,8 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"</Command> <Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"
copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav"</Command>
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent> <PostBuildEvent>
<Message>Copy SDL</Message> <Message>Copy SDL</Message>
@ -174,7 +176,8 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"</Command> <Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"
copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav"</Command>
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent> <PostBuildEvent>
<Message>Copy SDL</Message> <Message>Copy SDL</Message>
@ -208,7 +211,8 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"</Command> <Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"
copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav"</Command>
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent> <PostBuildEvent>
<Message>Copy SDL</Message> <Message>Copy SDL</Message>

View File

@ -109,7 +109,8 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"</Command> <Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"
copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav"</Command>
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent> <PostBuildEvent>
<Message>Copy SDL</Message> <Message>Copy SDL</Message>
@ -143,7 +144,8 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"</Command> <Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"
copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav"</Command>
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent> <PostBuildEvent>
<Message>Copy SDL</Message> <Message>Copy SDL</Message>
@ -178,7 +180,8 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"</Command> <Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"
copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav"</Command>
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent> <PostBuildEvent>
<Message>Copy SDL</Message> <Message>Copy SDL</Message>
@ -212,7 +215,8 @@
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
</Link> </Link>
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"</Command> <Command>copy "$(SolutionDir)\SDL\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetDir)\SDL2.dll"
copy "$(SolutionDir)\..\test\sample.wav" "$(TargetDir)\sample.wav"</Command>
</PostBuildEvent> </PostBuildEvent>
<PostBuildEvent> <PostBuildEvent>
<Message>Copy SDL</Message> <Message>Copy SDL</Message>

View File

@ -117,13 +117,13 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
static void static void
PrintText(char *text) PrintText(char *text)
{ {
unsigned char *spot, expanded[1024]; char *spot, expanded[1024];
expanded[0] = '\0'; expanded[0] = '\0';
for ( spot = text; *spot; ++spot ) for ( spot = text; *spot; ++spot )
{ {
size_t length = SDL_strlen(expanded); size_t length = SDL_strlen(expanded);
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", *spot); SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
} }
SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text); SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
} }
@ -134,10 +134,13 @@ main(int argc, char *argv[])
SDL_Window *window; SDL_Window *window;
SDL_Event event; SDL_Event event;
int done; int done;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL */ /* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
@ -146,7 +149,7 @@ main(int argc, char *argv[])
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480, 0); 640, 480, 0);
if (!window) { if (!window) {
fprintf(stderr, "Couldn't create 640x480 window: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
SDL_GetError()); SDL_GetError());
quit(2); quit(2);
} }
@ -166,7 +169,7 @@ main(int argc, char *argv[])
switch (event.type) { switch (event.type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: case SDL_KEYUP:
PrintKey(&event.key.keysym, event.key.state, event.key.repeat); PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
break; break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
PrintText(event.text.text); PrintText(event.text.text);

View File

@ -80,9 +80,12 @@ main(int argc, char *argv[])
{ {
int i; int i;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) { if (SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
@ -91,7 +94,7 @@ main(int argc, char *argv[])
} }
/* Load the wave file into memory */ /* Load the wave file into memory */
if (SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL) { if (SDL_LoadWAV(argv[1], &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", argv[1], SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
quit(1); quit(1);
} }
@ -109,24 +112,19 @@ main(int argc, char *argv[])
#endif /* HAVE_SIGNAL_H */ #endif /* HAVE_SIGNAL_H */
/* Show the list of available drivers */ /* Show the list of available drivers */
printf("Available audio drivers: "); SDL_Log("Available audio drivers:");
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) { for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
if (i == 0) { SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
printf("%s", SDL_GetAudioDriver(i));
} else {
printf(", %s", SDL_GetAudioDriver(i));
}
} }
printf("\n");
/* Initialize fillerup() variables */ /* Initialize fillerup() variables */
if (SDL_OpenAudio(&wave.spec, NULL) < 0) { if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
SDL_FreeWAV(wave.sound); SDL_FreeWAV(wave.sound);
quit(2); quit(2);
} }
printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
/* Let the audio run */ /* Let the audio run */
SDL_PauseAudio(0); SDL_PauseAudio(0);

View File

@ -45,39 +45,39 @@ void RunBasicTest()
SDL_atomic_t v; SDL_atomic_t v;
SDL_bool tfret = SDL_FALSE; SDL_bool tfret = SDL_FALSE;
printf("\nspin lock---------------------------------------\n\n"); SDL_Log("\nspin lock---------------------------------------\n\n");
SDL_AtomicLock(&lock); SDL_AtomicLock(&lock);
printf("AtomicLock lock=%d\n", lock); SDL_Log("AtomicLock lock=%d\n", lock);
SDL_AtomicUnlock(&lock); SDL_AtomicUnlock(&lock);
printf("AtomicUnlock lock=%d\n", lock); SDL_Log("AtomicUnlock lock=%d\n", lock);
printf("\natomic -----------------------------------------\n\n"); SDL_Log("\natomic -----------------------------------------\n\n");
SDL_AtomicSet(&v, 0); SDL_AtomicSet(&v, 0);
tfret = SDL_AtomicSet(&v, 10) == 0; tfret = SDL_AtomicSet(&v, 10) == 0 ? SDL_TRUE : SDL_FALSE;
printf("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_Log("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = SDL_AtomicAdd(&v, 10) == 10; tfret = SDL_AtomicAdd(&v, 10) == 10 ? SDL_TRUE : SDL_FALSE;
printf("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_Log("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicSet(&v, 0); SDL_AtomicSet(&v, 0);
SDL_AtomicIncRef(&v); SDL_AtomicIncRef(&v);
tfret = (SDL_AtomicGet(&v) == 1); tfret = (SDL_AtomicGet(&v) == 1) ? SDL_TRUE : SDL_FALSE;
printf("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicIncRef(&v); SDL_AtomicIncRef(&v);
tfret = (SDL_AtomicGet(&v) == 2); tfret = (SDL_AtomicGet(&v) == 2) ? SDL_TRUE : SDL_FALSE;
printf("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE); tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE;
printf("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE); tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE;
printf("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicSet(&v, 10); SDL_AtomicSet(&v, 10);
tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE); tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE;
printf("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
value = SDL_AtomicGet(&v); value = SDL_AtomicGet(&v);
tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE); tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE;
printf("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v)); SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
} }
/**************************************************************************/ /**************************************************************************/
@ -120,7 +120,7 @@ static
int adder(void* junk) int adder(void* junk)
{ {
unsigned long N=NInter; unsigned long N=NInter;
printf("Thread subtracting %d %lu times\n",CountInc,N); SDL_Log("Thread subtracting %d %lu times\n",CountInc,N);
while (N--) { while (N--) {
SDL_AtomicAdd(&good, -CountInc); SDL_AtomicAdd(&good, -CountInc);
bad-=CountInc; bad-=CountInc;
@ -152,7 +152,7 @@ void runAdder(void)
end = SDL_GetTicks(); end = SDL_GetTicks();
printf("Finished in %f sec\n", (end - start) / 1000.f); SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
} }
static static
@ -161,28 +161,28 @@ void RunEpicTest()
int b; int b;
atomicValue v; atomicValue v;
printf("\nepic test---------------------------------------\n\n"); SDL_Log("\nepic test---------------------------------------\n\n");
printf("Size asserted to be >= 32-bit\n"); SDL_Log("Size asserted to be >= 32-bit\n");
SDL_assert(sizeof(atomicValue)>=4); SDL_assert(sizeof(atomicValue)>=4);
printf("Check static initializer\n"); SDL_Log("Check static initializer\n");
v=SDL_AtomicGet(&good); v=SDL_AtomicGet(&good);
SDL_assert(v==42); SDL_assert(v==42);
SDL_assert(bad==42); SDL_assert(bad==42);
printf("Test negative values\n"); SDL_Log("Test negative values\n");
SDL_AtomicSet(&good, -5); SDL_AtomicSet(&good, -5);
v=SDL_AtomicGet(&good); v=SDL_AtomicGet(&good);
SDL_assert(v==-5); SDL_assert(v==-5);
printf("Verify maximum value\n"); SDL_Log("Verify maximum value\n");
SDL_AtomicSet(&good, CountTo); SDL_AtomicSet(&good, CountTo);
v=SDL_AtomicGet(&good); v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo); SDL_assert(v==CountTo);
printf("Test compare and exchange\n"); SDL_Log("Test compare and exchange\n");
b=SDL_AtomicCAS(&good, 500, 43); b=SDL_AtomicCAS(&good, 500, 43);
SDL_assert(!b); /* no swap since CountTo!=500 */ SDL_assert(!b); /* no swap since CountTo!=500 */
@ -194,7 +194,7 @@ void RunEpicTest()
v=SDL_AtomicGet(&good); v=SDL_AtomicGet(&good);
SDL_assert(v==44); SDL_assert(v==44);
printf("Test Add\n"); SDL_Log("Test Add\n");
v=SDL_AtomicAdd(&good, 1); v=SDL_AtomicAdd(&good, 1);
SDL_assert(v==44); SDL_assert(v==44);
@ -206,7 +206,7 @@ void RunEpicTest()
v=SDL_AtomicGet(&good); v=SDL_AtomicGet(&good);
SDL_assert(v==55); SDL_assert(v==55);
printf("Test Add (Negative values)\n"); SDL_Log("Test Add (Negative values)\n");
v=SDL_AtomicAdd(&good, -20); v=SDL_AtomicAdd(&good, -20);
SDL_assert(v==55); SDL_assert(v==55);
@ -223,7 +223,7 @@ void RunEpicTest()
v=SDL_AtomicGet(&good); v=SDL_AtomicGet(&good);
SDL_assert(v==15); SDL_assert(v==15);
printf("Reset before count down test\n"); SDL_Log("Reset before count down test\n");
SDL_AtomicSet(&good, CountTo); SDL_AtomicSet(&good, CountTo);
v=SDL_AtomicGet(&good); v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo); SDL_assert(v==CountTo);
@ -231,11 +231,11 @@ void RunEpicTest()
bad=CountTo; bad=CountTo;
SDL_assert(bad==CountTo); SDL_assert(bad==CountTo);
printf("Counting down from %d, Expect %d remaining\n",CountTo,Expect); SDL_Log("Counting down from %d, Expect %d remaining\n",CountTo,Expect);
runAdder(); runAdder();
v=SDL_AtomicGet(&good); v=SDL_AtomicGet(&good);
printf("Atomic %d Non-Atomic %d\n",v,bad); SDL_Log("Atomic %d Non-Atomic %d\n",v,bad);
SDL_assert(v==Expect); SDL_assert(v==Expect);
SDL_assert(bad!=Expect); SDL_assert(bad!=Expect);
} }
@ -429,7 +429,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event
} else if (delta < 0) { } else if (delta < 0) {
/* We ran into an old queue entry, which means it still needs to be dequeued */ /* We ran into an old queue entry, which means it still needs to be dequeued */
} else { } else {
printf("ERROR: mutex failed!\n"); SDL_Log("ERROR: mutex failed!\n");
} }
SDL_UnlockMutex(queue->mutex); SDL_UnlockMutex(queue->mutex);
@ -462,7 +462,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
} else if (delta < 0) { } else if (delta < 0) {
/* We ran into an old queue entry, which means we've hit empty */ /* We ran into an old queue entry, which means we've hit empty */
} else { } else {
printf("ERROR: mutex failed!\n"); SDL_Log("ERROR: mutex failed!\n");
} }
SDL_UnlockMutex(queue->mutex); SDL_UnlockMutex(queue->mutex);
@ -598,9 +598,11 @@ static void RunFIFOTest(SDL_bool lock_free)
Uint32 start, end; Uint32 start, end;
int i, j; int i, j;
int grand_total; int grand_total;
char textBuffer[1024];
int len;
printf("\nFIFO test---------------------------------------\n\n"); SDL_Log("\nFIFO test---------------------------------------\n\n");
printf("Mode: %s\n", lock_free ? "LockFree" : "Mutex"); SDL_Log("Mode: %s\n", lock_free ? "LockFree" : "Mutex");
readersDone = SDL_CreateSemaphore(0); readersDone = SDL_CreateSemaphore(0);
writersDone = SDL_CreateSemaphore(0); writersDone = SDL_CreateSemaphore(0);
@ -622,7 +624,7 @@ static void RunFIFOTest(SDL_bool lock_free)
#endif #endif
/* Start the readers first */ /* Start the readers first */
printf("Starting %d readers\n", NUM_READERS); SDL_Log("Starting %d readers\n", NUM_READERS);
SDL_zero(readerData); SDL_zero(readerData);
SDL_AtomicSet(&readersRunning, NUM_READERS); SDL_AtomicSet(&readersRunning, NUM_READERS);
for (i = 0; i < NUM_READERS; ++i) { for (i = 0; i < NUM_READERS; ++i) {
@ -634,7 +636,7 @@ static void RunFIFOTest(SDL_bool lock_free)
} }
/* Start up the writers */ /* Start up the writers */
printf("Starting %d writers\n", NUM_WRITERS); SDL_Log("Starting %d writers\n", NUM_WRITERS);
SDL_zero(writerData); SDL_zero(writerData);
SDL_AtomicSet(&writersRunning, NUM_WRITERS); SDL_AtomicSet(&writersRunning, NUM_WRITERS);
for (i = 0; i < NUM_WRITERS; ++i) { for (i = 0; i < NUM_WRITERS; ++i) {
@ -668,16 +670,16 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_DestroyMutex(queue.mutex); SDL_DestroyMutex(queue.mutex);
} }
printf("Finished in %f sec\n", (end - start) / 1000.f); SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
printf("\n"); SDL_Log("\n");
for (i = 0; i < NUM_WRITERS; ++i) { for (i = 0; i < NUM_WRITERS; ++i) {
printf("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits); SDL_Log("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits);
} }
printf("Writers wrote %d total events\n", NUM_WRITERS*EVENTS_PER_WRITER); SDL_Log("Writers wrote %d total events\n", NUM_WRITERS*EVENTS_PER_WRITER);
/* Print a breakdown of which readers read messages from which writer */ /* Print a breakdown of which readers read messages from which writer */
printf("\n"); SDL_Log("\n");
grand_total = 0; grand_total = 0;
for (i = 0; i < NUM_READERS; ++i) { for (i = 0; i < NUM_READERS; ++i) {
int total = 0; int total = 0;
@ -685,17 +687,21 @@ static void RunFIFOTest(SDL_bool lock_free)
total += readerData[i].counters[j]; total += readerData[i].counters[j];
} }
grand_total += total; grand_total += total;
printf("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits); SDL_Log("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits);
printf(" { "); SDL_snprintf(textBuffer, sizeof(textBuffer), " { ");
for (j = 0; j < NUM_WRITERS; ++j) { for (j = 0; j < NUM_WRITERS; ++j) {
if (j > 0) { if (j > 0) {
printf(", "); len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
} }
printf("%d", readerData[i].counters[j]); len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", readerData[i].counters[j]);
} }
printf(" }\n"); len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
SDL_Log(textBuffer);
} }
printf("Readers read %d total events\n", grand_total); SDL_Log("Readers read %d total events\n", grand_total);
} }
/* End FIFO test */ /* End FIFO test */
@ -704,6 +710,9 @@ static void RunFIFOTest(SDL_bool lock_free)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
RunBasicTest(); RunBasicTest();
RunEpicTest(); RunEpicTest();
/* This test is really slow, so don't run it by default */ /* This test is really slow, so don't run it by default */

View File

@ -18,18 +18,18 @@ print_devices(int iscapture)
const char *typestr = ((iscapture) ? "capture" : "output"); const char *typestr = ((iscapture) ? "capture" : "output");
int n = SDL_GetNumAudioDevices(iscapture); int n = SDL_GetNumAudioDevices(iscapture);
printf("%s devices:\n", typestr); SDL_Log("%s devices:\n", typestr);
if (n == -1) if (n == -1)
printf(" Driver can't detect specific %s devices.\n\n", typestr); SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
else if (n == 0) else if (n == 0)
printf(" No %s devices found.\n\n", typestr); SDL_Log(" No %s devices found.\n\n", typestr);
else { else {
int i; int i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
printf(" %s\n", SDL_GetAudioDeviceName(i, iscapture)); SDL_Log(" %s\n", SDL_GetAudioDeviceName(i, iscapture));
} }
printf("\n"); SDL_Log("\n");
} }
} }
@ -38,26 +38,29 @@ main(int argc, char **argv)
{ {
int n; int n;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) { if (SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
/* Print available audio drivers */ /* Print available audio drivers */
n = SDL_GetNumAudioDrivers(); n = SDL_GetNumAudioDrivers();
if (n == 0) { if (n == 0) {
printf("No built-in audio drivers\n\n"); SDL_Log("No built-in audio drivers\n\n");
} else { } else {
int i; int i;
printf("Built-in audio drivers:\n"); SDL_Log("Built-in audio drivers:\n");
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
printf(" %s\n", SDL_GetAudioDriver(i)); SDL_Log(" %s\n", SDL_GetAudioDriver(i));
} }
printf("\n"); SDL_Log("\n");
} }
printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver()); SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
print_devices(0); print_devices(0);
print_devices(1); print_devices(1);

View File

@ -80,8 +80,7 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
"Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
argv[0], SDLTest_CommonUsage(state)); argv[0], SDLTest_CommonUsage(state));
quit(1); quit(1);
} }

View File

@ -360,8 +360,6 @@ surface_testCompleteSurfaceConversion(void *arg)
for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) { for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) { for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
/*printf("Converting %s -> %s\n", SDL_GetPixelFormatName(pixel_formats[i]), SDL_GetPixelFormatName(pixel_formats[j]));*/
fmt1 = SDL_AllocFormat(pixel_formats[i]); fmt1 = SDL_AllocFormat(pixel_formats[i]);
SDL_assert(fmt1 != NULL); SDL_assert(fmt1 != NULL);
cvt1 = SDL_ConvertSurface(face, fmt1, 0); cvt1 = SDL_ConvertSurface(face, fmt1, 0);

View File

@ -176,6 +176,9 @@ main(int argc, char *argv[])
SDL_Event event; SDL_Event event;
Uint32 then, now, frames; Uint32 then, now, frames;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */ /* Initialize parameters */
num_objects = NUM_OBJECTS; num_objects = NUM_OBJECTS;
@ -218,8 +221,7 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
"Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
argv[0], SDLTest_CommonUsage(state)); argv[0], SDLTest_CommonUsage(state));
return 1; return 1;
} }
@ -268,7 +270,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
double fps = ((double) frames * 1000) / (now - then); double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps); SDL_Log("%2.2f frames per second\n", fps);
} }
return 0; return 0;
} }

View File

@ -54,10 +54,13 @@ main(int argc, char *argv[])
SDL_Surface *surface; SDL_Surface *surface;
SDL_Renderer *renderer; SDL_Renderer *renderer;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL */ /* Initialize SDL */
if(SDL_Init(SDL_INIT_VIDEO) != 0) if(SDL_Init(SDL_INIT_VIDEO) != 0)
{ {
fprintf(stderr,"SDL_Init fail : %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
return 1; return 1;
} }
@ -66,14 +69,14 @@ main(int argc, char *argv[])
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
if(!window) if(!window)
{ {
fprintf(stderr,"Window creation fail : %s\n",SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
return 1; return 1;
} }
surface = SDL_GetWindowSurface(window); surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface); renderer = SDL_CreateSoftwareRenderer(surface);
if(!renderer) if(!renderer)
{ {
fprintf(stderr,"Render creation for surface fail : %s\n",SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
return 1; return 1;
} }

View File

@ -36,10 +36,10 @@ ThreadFunc(void *data)
SDL_SetError("Thread %s (%lu) had a problem: %s", SDL_SetError("Thread %s (%lu) had a problem: %s",
(char *) data, SDL_ThreadID(), "nevermind"); (char *) data, SDL_ThreadID(), "nevermind");
while (alive) { while (alive) {
printf("Thread '%s' is alive!\n", (char *) data); SDL_Log("Thread '%s' is alive!\n", (char *) data);
SDL_Delay(1 * 1000); SDL_Delay(1 * 1000);
} }
printf("Child thread error string: %s\n", SDL_GetError()); SDL_Log("Child thread error string: %s\n", SDL_GetError());
return (0); return (0);
} }
@ -48,9 +48,12 @@ main(int argc, char *argv[])
{ {
SDL_Thread *thread; SDL_Thread *thread;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(0) < 0) { if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
@ -60,15 +63,15 @@ main(int argc, char *argv[])
alive = 1; alive = 1;
thread = SDL_CreateThread(ThreadFunc, NULL, "#1"); thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
if (thread == NULL) { if (thread == NULL) {
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1); quit(1);
} }
SDL_Delay(5 * 1000); SDL_Delay(5 * 1000);
printf("Waiting for thread #1\n"); SDL_Log("Waiting for thread #1\n");
alive = 0; alive = 0;
SDL_WaitThread(thread, NULL); SDL_WaitThread(thread, NULL);
printf("Main thread error string: %s\n", SDL_GetError()); SDL_Log("Main thread error string: %s\n", SDL_GetError());
SDL_Quit(); SDL_Quit();
return (0); return (0);

View File

@ -44,7 +44,6 @@
static void static void
cleanup(void) cleanup(void)
{ {
unlink(FBASENAME1); unlink(FBASENAME1);
unlink(FBASENAME2); unlink(FBASENAME2);
} }
@ -52,8 +51,7 @@ cleanup(void)
static void static void
rwops_error_quit(unsigned line, SDL_RWops * rwops) rwops_error_quit(unsigned line, SDL_RWops * rwops)
{ {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
printf("testfile.c(%d): failed\n", line);
if (rwops) { if (rwops) {
rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */ rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
} }
@ -71,6 +69,9 @@ main(int argc, char *argv[])
SDL_RWops *rwops = NULL; SDL_RWops *rwops = NULL;
char test_buf[30]; char test_buf[30];
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
cleanup(); cleanup();
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */ /* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
@ -90,7 +91,7 @@ main(int argc, char *argv[])
rwops = SDL_RWFromFile("something", NULL); rwops = SDL_RWFromFile("something", NULL);
if (rwops) if (rwops)
RWOP_ERR_QUIT(rwops); RWOP_ERR_QUIT(rwops);
printf("test1 OK\n"); SDL_Log("test1 OK\n");
/* test 2 : check that inexistent file is not successfully opened/created when required */ /* test 2 : check that inexistent file is not successfully opened/created when required */
/* modes : r, r+ imply that file MUST exist /* modes : r, r+ imply that file MUST exist
@ -123,7 +124,7 @@ main(int argc, char *argv[])
RWOP_ERR_QUIT(rwops); RWOP_ERR_QUIT(rwops);
rwops->close(rwops); rwops->close(rwops);
unlink(FBASENAME2); unlink(FBASENAME2);
printf("test2 OK\n"); SDL_Log("test2 OK\n");
/* test 3 : creation, writing , reading, seeking, /* test 3 : creation, writing , reading, seeking,
test : w mode, r mode, w+ mode test : w mode, r mode, w+ mode
@ -201,7 +202,7 @@ main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "12345678901234567890", 20)) if (SDL_memcmp(test_buf, "12345678901234567890", 20))
RWOP_ERR_QUIT(rwops); RWOP_ERR_QUIT(rwops);
rwops->close(rwops); rwops->close(rwops);
printf("test3 OK\n"); SDL_Log("test3 OK\n");
/* test 4: same in r+ mode */ /* test 4: same in r+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */ rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
@ -236,7 +237,7 @@ main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "12345678901234567890", 20)) if (SDL_memcmp(test_buf, "12345678901234567890", 20))
RWOP_ERR_QUIT(rwops); RWOP_ERR_QUIT(rwops);
rwops->close(rwops); rwops->close(rwops);
printf("test4 OK\n"); SDL_Log("test4 OK\n");
/* test5 : append mode */ /* test5 : append mode */
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */ rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
@ -277,7 +278,7 @@ main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30)) if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30))
RWOP_ERR_QUIT(rwops); RWOP_ERR_QUIT(rwops);
rwops->close(rwops); rwops->close(rwops);
printf("test5 OK\n"); SDL_Log("test5 OK\n");
cleanup(); cleanup();
return 0; /* all ok */ return 0; /* all ok */
} }

View File

@ -91,7 +91,7 @@ WatchGameController(SDL_GameController * gamecontroller)
const char *name = SDL_GameControllerName(gamecontroller); const char *name = SDL_GameControllerName(gamecontroller);
const char *basetitle = "Game Controller Test: "; const char *basetitle = "Game Controller Test: ";
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1; const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
char *title = SDL_malloc(titlelen); char *title = (char *)SDL_malloc(titlelen);
SDL_Window *window = NULL; SDL_Window *window = NULL;
SDL_Renderer *screen = NULL; SDL_Renderer *screen = NULL;
int done = 0; int done = 0;
@ -107,13 +107,13 @@ WatchGameController(SDL_GameController * gamecontroller)
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0); SCREEN_HEIGHT, 0);
if (window == NULL) { if (window == NULL) {
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return; return;
} }
screen = SDL_CreateRenderer(window, -1, 0); screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) { if (screen == NULL) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
return; return;
} }
@ -124,7 +124,7 @@ WatchGameController(SDL_GameController * gamecontroller)
SDL_RaiseWindow(window); SDL_RaiseWindow(window);
/* Print info about the controller we are watching */ /* Print info about the controller we are watching */
printf("Watching controller %s\n", name ? name : "Unknown Controller"); SDL_Log("Watching controller %s\n", name ? name : "Unknown Controller");
/* Loop, getting controller events! */ /* Loop, getting controller events! */
while (!done) { while (!done) {
@ -135,21 +135,21 @@ WatchGameController(SDL_GameController * gamecontroller)
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
switch (event.type) { switch (event.type) {
case SDL_CONTROLLERAXISMOTION: case SDL_CONTROLLERAXISMOTION:
printf("Controller %d axis %d ('%s') value: %d\n", SDL_Log("Controller %d axis %d ('%s') value: %d\n",
event.caxis.which, event.caxis.which,
event.caxis.axis, event.caxis.axis,
ControllerAxisName(event.caxis.axis), ControllerAxisName((SDL_GameControllerAxis)event.caxis.axis),
event.caxis.value); event.caxis.value);
break; break;
case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONDOWN:
printf("Controller %d button %d ('%s') down\n", SDL_Log("Controller %d button %d ('%s') down\n",
event.cbutton.which, event.cbutton.button, event.cbutton.which, event.cbutton.button,
ControllerButtonName(event.cbutton.button)); ControllerButtonName((SDL_GameControllerButton)event.cbutton.button));
break; break;
case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONUP:
printf("Controller %d button %d ('%s') up\n", SDL_Log("Controller %d button %d ('%s') up\n",
event.cbutton.which, event.cbutton.button, event.cbutton.which, event.cbutton.button,
ControllerButtonName(event.cbutton.button)); ControllerButtonName((SDL_GameControllerButton)event.cbutton.button));
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (event.key.keysym.sym != SDLK_ESCAPE) { if (event.key.keysym.sym != SDLK_ESCAPE) {
@ -167,7 +167,7 @@ WatchGameController(SDL_GameController * gamecontroller)
/* Update visual controller state */ /* Update visual controller state */
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE); SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
for (i = 0; i <SDL_CONTROLLER_BUTTON_MAX; ++i) { for (i = 0; i <SDL_CONTROLLER_BUTTON_MAX; ++i) {
if (SDL_GameControllerGetButton(gamecontroller, i) == SDL_PRESSED) { if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32); DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32);
} }
} }
@ -176,7 +176,7 @@ WatchGameController(SDL_GameController * gamecontroller)
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX / 2; ++i) { for (i = 0; i < SDL_CONTROLLER_AXIS_MAX / 2; ++i) {
/* Draw the X/Y axis */ /* Draw the X/Y axis */
int x, y; int x, y;
x = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 0)) + 32768); x = (((int) SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i * 2 + 0))) + 32768);
x *= SCREEN_WIDTH; x *= SCREEN_WIDTH;
x /= 65535; x /= 65535;
if (x < 0) { if (x < 0) {
@ -184,7 +184,7 @@ WatchGameController(SDL_GameController * gamecontroller)
} else if (x > (SCREEN_WIDTH - 16)) { } else if (x > (SCREEN_WIDTH - 16)) {
x = SCREEN_WIDTH - 16; x = SCREEN_WIDTH - 16;
} }
y = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 1)) + 32768); y = (((int) SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i * 2 + 1))) + 32768);
y *= SCREEN_HEIGHT; y *= SCREEN_HEIGHT;
y /= 65535; y /= 65535;
if (y < 0) { if (y < 0) {
@ -217,9 +217,12 @@ main(int argc, char *argv[])
char guid[64]; char guid[64];
SDL_GameController *gamecontroller; SDL_GameController *gamecontroller;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL (Note: video is required to start event loop) */ /* Initialize SDL (Note: video is required to start event loop) */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1; return 1;
} }
@ -238,22 +241,22 @@ main(int argc, char *argv[])
} else { } else {
name = SDL_JoystickNameForIndex(i); name = SDL_JoystickNameForIndex(i);
} }
printf("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid); SDL_Log("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid);
} }
printf("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks()); SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks());
if (argv[1]) { if (argv[1]) {
int device = atoi(argv[1]); int device = atoi(argv[1]);
if (device >= SDL_NumJoysticks()) { if (device >= SDL_NumJoysticks()) {
printf("%i is an invalid joystick index.\n", device); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%i is an invalid joystick index.\n", device);
retcode = 1; retcode = 1;
} else { } else {
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device), SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device),
guid, sizeof (guid)); guid, sizeof (guid));
printf("Attempting to open device %i, guid %s\n", device, guid); SDL_Log("Attempting to open device %i, guid %s\n", device, guid);
gamecontroller = SDL_GameControllerOpen(device); gamecontroller = SDL_GameControllerOpen(device);
if (gamecontroller == NULL) { if (gamecontroller == NULL) {
printf("Couldn't open joystick %d: %s\n", device, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open joystick %d: %s\n", device, SDL_GetError());
retcode = 1; retcode = 1;
} else { } else {
WatchGameController(gamecontroller); WatchGameController(gamecontroller);
@ -272,7 +275,7 @@ main(int argc, char *argv[])
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
fprintf(stderr, "SDL compiled without Joystick support.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
exit(1); exit(1);
} }

View File

@ -207,6 +207,9 @@ int main(int argc, char* argv[])
SDL_bool quitting = SDL_FALSE; SDL_bool quitting = SDL_FALSE;
SDL_RWops *src; SDL_RWops *src;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
//gesture variables //gesture variables
knob.r = .1f; knob.r = .1f;
knob.ang = 0; knob.ang = 0;

View File

@ -181,6 +181,9 @@ main(int argc, char *argv[])
Uint32 then, now, frames; Uint32 then, now, frames;
int status; int status;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */ /* Initialize parameters */
fsaa = 0; fsaa = 0;
accel = -1; accel = -1;
@ -206,7 +209,7 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, "Usage: %s %s [--fsaa n] [--accel n]\n", argv[0], SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
SDLTest_CommonUsage(state)); SDLTest_CommonUsage(state));
quit(1); quit(1);
} }
@ -235,7 +238,7 @@ main(int argc, char *argv[])
/* Create OpenGL context */ /* Create OpenGL context */
context = SDL_GL_CreateContext(state->windows[0]); context = SDL_GL_CreateContext(state->windows[0]);
if (!context) { if (!context) {
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2); quit(2);
} }
@ -249,63 +252,63 @@ main(int argc, char *argv[])
} }
SDL_GetCurrentDisplayMode(0, &mode); SDL_GetCurrentDisplayMode(0, &mode);
printf("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format)); SDL_Log("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format));
printf("Swap Interval : %d\n", SDL_GL_GetSwapInterval()); SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
printf("\n"); SDL_Log("\n");
printf("Vendor : %s\n", glGetString(GL_VENDOR)); SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
printf("Renderer : %s\n", glGetString(GL_RENDERER)); SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
printf("Version : %s\n", glGetString(GL_VERSION)); SDL_Log("Version : %s\n", glGetString(GL_VERSION));
printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
printf("\n"); SDL_Log("\n");
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
} }
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
} }
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
} }
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
} else { } else {
printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
} }
if (fsaa) { if (fsaa) {
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else { } else {
printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError()); SDL_GetError());
} }
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value); value);
} else { } else {
printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError()); SDL_GetError());
} }
} }
if (accel >= 0) { if (accel >= 0) {
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
if (!status) { if (!status) {
printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel, SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
value); value);
} else { } else {
printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError()); SDL_GetError());
} }
} }
@ -343,7 +346,7 @@ main(int argc, char *argv[])
/* Print out some timing information */ /* Print out some timing information */
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
printf("%2.2f frames per second\n", SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then)); ((double) frames * 1000) / (now - then));
} }
quit(0); quit(0);
@ -355,7 +358,7 @@ main(int argc, char *argv[])
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
printf("No OpenGL support on this system\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
return 1; return 1;
} }

View File

@ -110,6 +110,9 @@ main(int argc, char *argv[])
Uint32 then, now, frames; Uint32 then, now, frames;
int status; int status;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */ /* Initialize parameters */
fsaa = 0; fsaa = 0;
accel = 0; accel = 0;
@ -143,7 +146,7 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, "Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0], SDL_Log("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
SDLTest_CommonUsage(state)); SDLTest_CommonUsage(state));
quit(1); quit(1);
} }
@ -169,7 +172,7 @@ main(int argc, char *argv[])
context = SDL_calloc(state->num_windows, sizeof(context)); context = SDL_calloc(state->num_windows, sizeof(context));
if (context == NULL) { if (context == NULL) {
fprintf(stderr, "Out of memory!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2); quit(2);
} }
@ -177,7 +180,7 @@ main(int argc, char *argv[])
for (i = 0; i < state->num_windows; i++) { for (i = 0; i < state->num_windows; i++) {
context[i] = SDL_GL_CreateContext(state->windows[i]); context[i] = SDL_GL_CreateContext(state->windows[i]);
if (!context[i]) { if (!context[i]) {
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2); quit(2);
} }
} }
@ -189,65 +192,65 @@ main(int argc, char *argv[])
} }
SDL_GetCurrentDisplayMode(0, &mode); SDL_GetCurrentDisplayMode(0, &mode);
printf("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format)); SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
printf("\n"); SDL_Log("\n");
printf("Vendor : %s\n", glGetString(GL_VENDOR)); SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
printf("Renderer : %s\n", glGetString(GL_RENDERER)); SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
printf("Version : %s\n", glGetString(GL_VERSION)); SDL_Log("Version : %s\n", glGetString(GL_VERSION));
printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
printf("\n"); SDL_Log("\n");
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_GetError()); SDL_GetError());
} }
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_GetError()); SDL_GetError());
} }
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_GetError()); SDL_GetError());
} }
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value); SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_GetError()); SDL_GetError());
} }
if (fsaa) { if (fsaa) {
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError()); SDL_GetError());
} }
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value); value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError()); SDL_GetError());
} }
} }
if (accel) { if (accel) {
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
if (!status) { if (!status) {
printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError()); SDL_GetError());
} }
} }
@ -258,7 +261,7 @@ main(int argc, char *argv[])
status = SDL_GL_MakeCurrent(state->windows[i], context[i]); status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) { if (status) {
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
/* Continue for next window */ /* Continue for next window */
continue; continue;
@ -292,7 +295,7 @@ main(int argc, char *argv[])
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) { if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
status = SDL_GL_MakeCurrent(state->windows[i], context[i]); status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) { if (status) {
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
break; break;
} }
/* Change view port to the new window dimensions */ /* Change view port to the new window dimensions */
@ -311,7 +314,7 @@ main(int argc, char *argv[])
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
status = SDL_GL_MakeCurrent(state->windows[i], context[i]); status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) { if (status) {
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
/* Continue for next window */ /* Continue for next window */
continue; continue;
@ -324,7 +327,7 @@ main(int argc, char *argv[])
/* Print out some timing information */ /* Print out some timing information */
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
printf("%2.2f frames per second\n", SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then)); ((double) frames * 1000) / (now - then));
} }
quit(0); quit(0);
@ -336,7 +339,7 @@ main(int argc, char *argv[])
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
printf("No OpenGL ES support on this system\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL ES support on this system\n");
return 1; return 1;
} }

View File

@ -26,7 +26,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* includes * includes
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> /* printf */
#include <string.h> /* strstr */ #include <string.h> /* strstr */
#include <ctype.h> /* isdigit */ #include <ctype.h> /* isdigit */
@ -62,12 +61,15 @@ main(int argc, char **argv)
int nefx; int nefx;
unsigned int supported; unsigned int supported;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
name = NULL; name = NULL;
index = -1; index = -1;
if (argc > 1) { if (argc > 1) {
name = argv[1]; name = argv[1];
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) { if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
printf("USAGE: %s [device]\n" SDL_Log("USAGE: %s [device]\n"
"If device is a two-digit number it'll use it as an index, otherwise\n" "If device is a two-digit number it'll use it as an index, otherwise\n"
"it'll use it as if it were part of the device's name.\n", "it'll use it as if it were part of the device's name.\n",
argv[0]); argv[0]);
@ -84,7 +86,7 @@ main(int argc, char **argv)
/* Initialize the force feedbackness */ /* Initialize the force feedbackness */
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
SDL_INIT_HAPTIC); SDL_INIT_HAPTIC);
printf("%d Haptic devices detected.\n", SDL_NumHaptics()); SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
if (SDL_NumHaptics() > 0) { if (SDL_NumHaptics() > 0) {
/* We'll just use index or the first force feedback device found */ /* We'll just use index or the first force feedback device found */
if (name == NULL) { if (name == NULL) {
@ -98,7 +100,7 @@ main(int argc, char **argv)
} }
if (i >= SDL_NumHaptics()) { if (i >= SDL_NumHaptics()) {
printf("Unable to find device matching '%s', aborting.\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
name); name);
return 1; return 1;
} }
@ -106,14 +108,14 @@ main(int argc, char **argv)
haptic = SDL_HapticOpen(i); haptic = SDL_HapticOpen(i);
if (haptic == NULL) { if (haptic == NULL) {
printf("Unable to create the haptic device: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
SDL_GetError()); SDL_GetError());
return 1; return 1;
} }
printf("Device: %s\n", SDL_HapticName(i)); SDL_Log("Device: %s\n", SDL_HapticName(i));
HapticPrintSupported(haptic); HapticPrintSupported(haptic);
} else { } else {
printf("No Haptic devices found!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
return 1; return 1;
} }
@ -125,10 +127,10 @@ main(int argc, char **argv)
nefx = 0; nefx = 0;
supported = SDL_HapticQuery(haptic); supported = SDL_HapticQuery(haptic);
printf("\nUploading effects\n"); SDL_Log("\nUploading effects\n");
/* First we'll try a SINE effect. */ /* First we'll try a SINE effect. */
if (supported & SDL_HAPTIC_SINE) { if (supported & SDL_HAPTIC_SINE) {
printf(" effect %d: Sine Wave\n", nefx); SDL_Log(" effect %d: Sine Wave\n", nefx);
efx[nefx].type = SDL_HAPTIC_SINE; efx[nefx].type = SDL_HAPTIC_SINE;
efx[nefx].periodic.period = 1000; efx[nefx].periodic.period = 1000;
efx[nefx].periodic.magnitude = 0x4000; efx[nefx].periodic.magnitude = 0x4000;
@ -137,14 +139,14 @@ main(int argc, char **argv)
efx[nefx].periodic.fade_length = 1000; efx[nefx].periodic.fade_length = 1000;
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) { if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution(); abort_execution();
} }
nefx++; nefx++;
} }
/* Now we'll try a SAWTOOTHUP */ /* Now we'll try a SAWTOOTHUP */
if (supported & SDL_HAPTIC_SAWTOOTHUP) { if (supported & SDL_HAPTIC_SAWTOOTHUP) {
printf(" effect %d: Sawtooth Up\n", nefx); SDL_Log(" effect %d: Sawtooth Up\n", nefx);
efx[nefx].type = SDL_HAPTIC_SAWTOOTHUP; efx[nefx].type = SDL_HAPTIC_SAWTOOTHUP;
efx[nefx].periodic.period = 500; efx[nefx].periodic.period = 500;
efx[nefx].periodic.magnitude = 0x5000; efx[nefx].periodic.magnitude = 0x5000;
@ -153,14 +155,14 @@ main(int argc, char **argv)
efx[nefx].periodic.fade_length = 1000; efx[nefx].periodic.fade_length = 1000;
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) { if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution(); abort_execution();
} }
nefx++; nefx++;
} }
/* Now the classical constant effect. */ /* Now the classical constant effect. */
if (supported & SDL_HAPTIC_CONSTANT) { if (supported & SDL_HAPTIC_CONSTANT) {
printf(" effect %d: Constant Force\n", nefx); SDL_Log(" effect %d: Constant Force\n", nefx);
efx[nefx].type = SDL_HAPTIC_CONSTANT; efx[nefx].type = SDL_HAPTIC_CONSTANT;
efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR; efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */ efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
@ -170,14 +172,14 @@ main(int argc, char **argv)
efx[nefx].constant.fade_length = 1000; efx[nefx].constant.fade_length = 1000;
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) { if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution(); abort_execution();
} }
nefx++; nefx++;
} }
/* The cute spring effect. */ /* The cute spring effect. */
if (supported & SDL_HAPTIC_SPRING) { if (supported & SDL_HAPTIC_SPRING) {
printf(" effect %d: Condition Spring\n", nefx); SDL_Log(" effect %d: Condition Spring\n", nefx);
efx[nefx].type = SDL_HAPTIC_SPRING; efx[nefx].type = SDL_HAPTIC_SPRING;
efx[nefx].condition.length = 5000; efx[nefx].condition.length = 5000;
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) { for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
@ -189,14 +191,14 @@ main(int argc, char **argv)
} }
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) { if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution(); abort_execution();
} }
nefx++; nefx++;
} }
/* The pretty awesome inertia effect. */ /* The pretty awesome inertia effect. */
if (supported & SDL_HAPTIC_INERTIA) { if (supported & SDL_HAPTIC_INERTIA) {
printf(" effect %d: Condition Inertia\n", nefx); SDL_Log(" effect %d: Condition Inertia\n", nefx);
efx[nefx].type = SDL_HAPTIC_SPRING; efx[nefx].type = SDL_HAPTIC_SPRING;
efx[nefx].condition.length = 5000; efx[nefx].condition.length = 5000;
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) { for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
@ -207,7 +209,7 @@ main(int argc, char **argv)
} }
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) { if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution(); abort_execution();
} }
nefx++; nefx++;
@ -215,24 +217,24 @@ main(int argc, char **argv)
/* Finally we'll try a left/right effect. */ /* Finally we'll try a left/right effect. */
if (supported & SDL_HAPTIC_LEFTRIGHT) { if (supported & SDL_HAPTIC_LEFTRIGHT) {
printf(" effect %d: Left/Right\n", nefx); SDL_Log(" effect %d: Left/Right\n", nefx);
efx[nefx].type = SDL_HAPTIC_LEFTRIGHT; efx[nefx].type = SDL_HAPTIC_LEFTRIGHT;
efx[nefx].leftright.length = 5000; efx[nefx].leftright.length = 5000;
efx[nefx].leftright.large_magnitude = 0x3000; efx[nefx].leftright.large_magnitude = 0x3000;
efx[nefx].leftright.small_magnitude = 0xFFFF; efx[nefx].leftright.small_magnitude = 0xFFFF;
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]); id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) { if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution(); abort_execution();
} }
nefx++; nefx++;
} }
printf SDL_Log
("\nNow playing effects for 5 seconds each with 1 second delay between\n"); ("\nNow playing effects for 5 seconds each with 1 second delay between\n");
for (i = 0; i < nefx; i++) { for (i = 0; i < nefx; i++) {
printf(" Playing effect %d\n", i); SDL_Log(" Playing effect %d\n", i);
SDL_HapticRunEffect(haptic, id[i], 1); SDL_HapticRunEffect(haptic, id[i], 1);
SDL_Delay(6000); /* Effects only have length 5000 */ SDL_Delay(6000); /* Effects only have length 5000 */
} }
@ -252,7 +254,7 @@ main(int argc, char **argv)
static void static void
abort_execution(void) abort_execution(void)
{ {
printf("\nAborting program execution.\n"); SDL_Log("\nAborting program execution.\n");
SDL_HapticClose(haptic); SDL_HapticClose(haptic);
SDL_Quit(); SDL_Quit();
@ -270,42 +272,42 @@ HapticPrintSupported(SDL_Haptic * haptic)
unsigned int supported; unsigned int supported;
supported = SDL_HapticQuery(haptic); supported = SDL_HapticQuery(haptic);
printf(" Supported effects [%d effects, %d playing]:\n", SDL_Log(" Supported effects [%d effects, %d playing]:\n",
SDL_HapticNumEffects(haptic), SDL_HapticNumEffectsPlaying(haptic)); SDL_HapticNumEffects(haptic), SDL_HapticNumEffectsPlaying(haptic));
if (supported & SDL_HAPTIC_CONSTANT) if (supported & SDL_HAPTIC_CONSTANT)
printf(" constant\n"); SDL_Log(" constant\n");
if (supported & SDL_HAPTIC_SINE) if (supported & SDL_HAPTIC_SINE)
printf(" sine\n"); SDL_Log(" sine\n");
/* !!! FIXME: put this back when we have more bits in 2.1 */ /* !!! FIXME: put this back when we have more bits in 2.1 */
/*if (supported & SDL_HAPTIC_SQUARE) /*if (supported & SDL_HAPTIC_SQUARE)
printf(" square\n");*/ SDL_Log(" square\n");*/
if (supported & SDL_HAPTIC_TRIANGLE) if (supported & SDL_HAPTIC_TRIANGLE)
printf(" triangle\n"); SDL_Log(" triangle\n");
if (supported & SDL_HAPTIC_SAWTOOTHUP) if (supported & SDL_HAPTIC_SAWTOOTHUP)
printf(" sawtoothup\n"); SDL_Log(" sawtoothup\n");
if (supported & SDL_HAPTIC_SAWTOOTHDOWN) if (supported & SDL_HAPTIC_SAWTOOTHDOWN)
printf(" sawtoothdown\n"); SDL_Log(" sawtoothdown\n");
if (supported & SDL_HAPTIC_RAMP) if (supported & SDL_HAPTIC_RAMP)
printf(" ramp\n"); SDL_Log(" ramp\n");
if (supported & SDL_HAPTIC_FRICTION) if (supported & SDL_HAPTIC_FRICTION)
printf(" friction\n"); SDL_Log(" friction\n");
if (supported & SDL_HAPTIC_SPRING) if (supported & SDL_HAPTIC_SPRING)
printf(" spring\n"); SDL_Log(" spring\n");
if (supported & SDL_HAPTIC_DAMPER) if (supported & SDL_HAPTIC_DAMPER)
printf(" damper\n"); SDL_Log(" damper\n");
if (supported & SDL_HAPTIC_INERTIA) if (supported & SDL_HAPTIC_INERTIA)
printf(" intertia\n"); SDL_Log(" inertia\n");
if (supported & SDL_HAPTIC_CUSTOM) if (supported & SDL_HAPTIC_CUSTOM)
printf(" custom\n"); SDL_Log(" custom\n");
if (supported & SDL_HAPTIC_LEFTRIGHT) if (supported & SDL_HAPTIC_LEFTRIGHT)
printf(" left/right\n"); SDL_Log(" left/right\n");
printf(" Supported capabilities:\n"); SDL_Log(" Supported capabilities:\n");
if (supported & SDL_HAPTIC_GAIN) if (supported & SDL_HAPTIC_GAIN)
printf(" gain\n"); SDL_Log(" gain\n");
if (supported & SDL_HAPTIC_AUTOCENTER) if (supported & SDL_HAPTIC_AUTOCENTER)
printf(" autocenter\n"); SDL_Log(" autocenter\n");
if (supported & SDL_HAPTIC_STATUS) if (supported & SDL_HAPTIC_STATUS)
printf(" status\n"); SDL_Log(" status\n");
} }
#else #else
@ -313,7 +315,7 @@ HapticPrintSupported(SDL_Haptic * haptic)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
fprintf(stderr, "SDL compiled without Haptic support.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");
exit(1); exit(1);
} }

View File

@ -49,12 +49,15 @@ main(int argc, char *argv[])
FILE *file; FILE *file;
int errors = 0; int errors = 0;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!argv[1]) { if (!argv[1]) {
argv[1] = "utf8.txt"; argv[1] = "utf8.txt";
} }
file = fopen(argv[1], "rb"); file = fopen(argv[1], "rb");
if (!file) { if (!file) {
fprintf(stderr, "Unable to open %s\n", argv[1]); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", argv[1]);
return (1); return (1);
} }
@ -69,7 +72,7 @@ main(int argc, char *argv[])
test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len); test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len); test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
if (!test[1] || SDL_memcmp(test[1], ucs4, len) != 0) { if (!test[1] || SDL_memcmp(test[1], ucs4, len) != 0) {
fprintf(stderr, "FAIL: %s\n", formats[i]); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "FAIL: %s\n", formats[i]);
++errors; ++errors;
} }
if (test[0]) { if (test[0]) {

View File

@ -80,7 +80,7 @@ char *utf8_advance(char *p, size_t distance)
void usage() void usage()
{ {
printf("usage: testime [--font fontfile]\n"); SDL_Log("usage: testime [--font fontfile]\n");
exit(0); exit(0);
} }
@ -210,6 +210,9 @@ int main(int argc, char *argv[]) {
SDL_Event event; SDL_Event event;
const char *fontname = DEFAULT_FONT; const char *fontname = DEFAULT_FONT;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) { if (!state) {
@ -251,12 +254,12 @@ int main(int argc, char *argv[]) {
font = TTF_OpenFont(fontname, DEFAULT_PTSIZE); font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
if (! font) if (! font)
{ {
fprintf(stderr, "Failed to find font: %s\n", TTF_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError());
exit(-1); exit(-1);
} }
#endif #endif
printf("Using font: %s\n", fontname); SDL_Log("Using font: %s\n", fontname);
atexit(SDL_Quit); atexit(SDL_Quit);
InitInput(); InitInput();
@ -321,8 +324,7 @@ int main(int argc, char *argv[]) {
break; break;
} }
fprintf(stderr, SDL_Log("Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
"Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
event.key.keysym.scancode, event.key.keysym.scancode,
SDL_GetScancodeName(event.key.keysym.scancode), SDL_GetScancodeName(event.key.keysym.scancode),
event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym)); event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym));
@ -333,12 +335,12 @@ int main(int argc, char *argv[]) {
markedRect.w < 0) markedRect.w < 0)
break; break;
fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text); SDL_Log("Keyboard: text input \"%s\"\n", event.text.text);
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
SDL_strlcat(text, event.text.text, sizeof(text)); SDL_strlcat(text, event.text.text, sizeof(text));
fprintf(stderr, "text inputed: %s\n", text); SDL_Log("text inputed: %s\n", text);
// After text inputed, we can clear up markedText because it // After text inputed, we can clear up markedText because it
// is committed // is committed
@ -347,7 +349,7 @@ int main(int argc, char *argv[]) {
break; break;
case SDL_TEXTEDITING: case SDL_TEXTEDITING:
fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n", SDL_Log("text editing \"%s\", selected range (%d, %d)\n",
event.edit.text, event.edit.start, event.edit.length); event.edit.text, event.edit.start, event.edit.length);
strcpy(markedText, event.edit.text); strcpy(markedText, event.edit.text);

View File

@ -84,7 +84,7 @@ add_line(int x1, int y1, int x2, int y2)
if ((x1 == x2) && (y1 == y2)) if ((x1 == x2) && (y1 == y2))
return 0; return 0;
printf("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2); SDL_Log("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2);
lines[num_lines].x = x1; lines[num_lines].x = x1;
lines[num_lines].y = y1; lines[num_lines].y = y1;
lines[num_lines].w = x2; lines[num_lines].w = x2;
@ -133,7 +133,7 @@ add_rect(int x1, int y1, int x2, int y2)
if (y1 > y2) if (y1 > y2)
SWAP(int, y1, y2); SWAP(int, y1, y2);
printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, SDL_Log("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2,
x2 - x1, y2 - y1); x2 - x1, y2 - y1);
rects[num_rects].x = x1; rects[num_rects].x = x1;
@ -199,6 +199,9 @@ main(int argc, char *argv[])
SDL_Event event; SDL_Event event;
Uint32 then, now, frames; Uint32 then, now, frames;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */ /* Initialize parameters */
num_objects = NUM_OBJECTS; num_objects = NUM_OBJECTS;
@ -241,8 +244,7 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
"Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
argv[0], SDLTest_CommonUsage(state)); argv[0], SDLTest_CommonUsage(state));
return 1; return 1;
} }
@ -327,7 +329,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
double fps = ((double) frames * 1000) / (now - then); double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps); SDL_Log("%2.2f frames per second\n", fps);
} }
return 0; return 0;
} }

View File

@ -52,13 +52,13 @@ WatchJoystick(SDL_Joystick * joystick)
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0); SCREEN_HEIGHT, 0);
if (window == NULL) { if (window == NULL) {
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return SDL_FALSE; return SDL_FALSE;
} }
screen = SDL_CreateRenderer(window, -1, 0); screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) { if (screen == NULL) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
return SDL_FALSE; return SDL_FALSE;
} }
@ -70,9 +70,9 @@ WatchJoystick(SDL_Joystick * joystick)
/* Print info about the joystick we are watching */ /* Print info about the joystick we are watching */
name = SDL_JoystickName(joystick); name = SDL_JoystickName(joystick);
printf("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick), SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
name ? name : "Unknown Joystick"); name ? name : "Unknown Joystick");
printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n", SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick), SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick)); SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
@ -85,36 +85,36 @@ WatchJoystick(SDL_Joystick * joystick)
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
switch (event.type) { switch (event.type) {
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
printf("Joystick %d axis %d value: %d\n", SDL_Log("Joystick %d axis %d value: %d\n",
event.jaxis.which, event.jaxis.which,
event.jaxis.axis, event.jaxis.value); event.jaxis.axis, event.jaxis.value);
break; break;
case SDL_JOYHATMOTION: case SDL_JOYHATMOTION:
printf("Joystick %d hat %d value:", SDL_Log("Joystick %d hat %d value:",
event.jhat.which, event.jhat.hat); event.jhat.which, event.jhat.hat);
if (event.jhat.value == SDL_HAT_CENTERED) if (event.jhat.value == SDL_HAT_CENTERED)
printf(" centered"); SDL_Log(" centered");
if (event.jhat.value & SDL_HAT_UP) if (event.jhat.value & SDL_HAT_UP)
printf(" up"); SDL_Log(" up");
if (event.jhat.value & SDL_HAT_RIGHT) if (event.jhat.value & SDL_HAT_RIGHT)
printf(" right"); SDL_Log(" right");
if (event.jhat.value & SDL_HAT_DOWN) if (event.jhat.value & SDL_HAT_DOWN)
printf(" down"); SDL_Log(" down");
if (event.jhat.value & SDL_HAT_LEFT) if (event.jhat.value & SDL_HAT_LEFT)
printf(" left"); SDL_Log(" left");
printf("\n"); SDL_Log("\n");
break; break;
case SDL_JOYBALLMOTION: case SDL_JOYBALLMOTION:
printf("Joystick %d ball %d delta: (%d,%d)\n", SDL_Log("Joystick %d ball %d delta: (%d,%d)\n",
event.jball.which, event.jball.which,
event.jball.ball, event.jball.xrel, event.jball.yrel); event.jball.ball, event.jball.xrel, event.jball.yrel);
break; break;
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
printf("Joystick %d button %d down\n", SDL_Log("Joystick %d button %d down\n",
event.jbutton.which, event.jbutton.button); event.jbutton.which, event.jbutton.button);
break; break;
case SDL_JOYBUTTONUP: case SDL_JOYBUTTONUP:
printf("Joystick %d button %d up\n", SDL_Log("Joystick %d button %d up\n",
event.jbutton.which, event.jbutton.button); event.jbutton.which, event.jbutton.button);
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
@ -211,31 +211,34 @@ main(int argc, char *argv[])
int i; int i;
SDL_Joystick *joystick; SDL_Joystick *joystick;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL (Note: video is required to start event loop) */ /* Initialize SDL (Note: video is required to start event loop) */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1); exit(1);
} }
/* Print information about the joysticks */ /* Print information about the joysticks */
printf("There are %d joysticks attached\n", SDL_NumJoysticks()); SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks());
for (i = 0; i < SDL_NumJoysticks(); ++i) { for (i = 0; i < SDL_NumJoysticks(); ++i) {
name = SDL_JoystickNameForIndex(i); name = SDL_JoystickNameForIndex(i);
printf("Joystick %d: %s\n", i, name ? name : "Unknown Joystick"); SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
joystick = SDL_JoystickOpen(i); joystick = SDL_JoystickOpen(i);
if (joystick == NULL) { if (joystick == NULL) {
fprintf(stderr, "SDL_JoystickOpen(%d) failed: %s\n", i, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
SDL_GetError()); SDL_GetError());
} else { } else {
char guid[64]; char guid[64];
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
guid, sizeof (guid)); guid, sizeof (guid));
printf(" axes: %d\n", SDL_JoystickNumAxes(joystick)); SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
printf(" balls: %d\n", SDL_JoystickNumBalls(joystick)); SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
printf(" hats: %d\n", SDL_JoystickNumHats(joystick)); SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
printf(" buttons: %d\n", SDL_JoystickNumButtons(joystick)); SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
printf("instance id: %d\n", SDL_JoystickInstanceID(joystick)); SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
printf(" guid: %s\n", guid); SDL_Log(" guid: %s\n", guid);
SDL_JoystickClose(joystick); SDL_JoystickClose(joystick);
} }
} }
@ -256,7 +259,7 @@ main(int argc, char *argv[])
while ( keepGoing ) { while ( keepGoing ) {
if (joystick == NULL) { if (joystick == NULL) {
if ( !reportederror ) { if ( !reportederror ) {
printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError()); SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
keepGoing = SDL_FALSE; keepGoing = SDL_FALSE;
reportederror = SDL_TRUE; reportederror = SDL_TRUE;
} }
@ -268,7 +271,7 @@ main(int argc, char *argv[])
joystick = NULL; joystick = NULL;
if (keepGoing) { if (keepGoing) {
printf("Waiting for attach\n"); SDL_Log("Waiting for attach\n");
} }
while (keepGoing) { while (keepGoing) {
SDL_WaitEvent(&event); SDL_WaitEvent(&event);
@ -296,7 +299,7 @@ main(int argc, char *argv[])
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
fprintf(stderr, "SDL compiled without Joystick support.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
exit(1); exit(1);
} }

View File

@ -24,12 +24,15 @@ main(int argc, char *argv[])
{ {
SDL_Scancode scancode; SDL_Scancode scancode;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1); exit(1);
} }
for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) { for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
printf("Scancode #%d, \"%s\"\n", scancode, SDL_Log("Scancode #%d, \"%s\"\n", scancode,
SDL_GetScancodeName(scancode)); SDL_GetScancodeName(scancode));
} }
SDL_Quit(); SDL_Quit();

View File

@ -33,14 +33,14 @@ main(int argc, char *argv[])
if (argc != 3) { if (argc != 3) {
const char *app = argv[0]; const char *app = argv[0];
fprintf(stderr, "USAGE: %s <library> <functionname>\n", app); SDL_Log("USAGE: %s <library> <functionname>\n", app);
fprintf(stderr, " %s --hello <lib with puts()>\n", app); SDL_Log(" %s --hello <lib with puts()>\n", app);
return 1; return 1;
} }
/* Initialize SDL */ /* Initialize SDL */
if (SDL_Init(0) < 0) { if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 2; return 2;
} }
@ -55,23 +55,23 @@ main(int argc, char *argv[])
lib = SDL_LoadObject(libname); lib = SDL_LoadObject(libname);
if (lib == NULL) { if (lib == NULL) {
fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n",
libname, SDL_GetError()); libname, SDL_GetError());
retval = 3; retval = 3;
} else { } else {
fn = (fntype) SDL_LoadFunction(lib, symname); fn = (fntype) SDL_LoadFunction(lib, symname);
if (fn == NULL) { if (fn == NULL) {
fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n",
symname, SDL_GetError()); symname, SDL_GetError());
retval = 4; retval = 4;
} else { } else {
printf("Found %s in %s at %p\n", symname, libname, fn); SDL_Log("Found %s in %s at %p\n", symname, libname, fn);
if (hello) { if (hello) {
printf("Calling function...\n"); SDL_Log("Calling function...\n");
fflush(stdout); fflush(stdout);
fn(" HELLO, WORLD!\n"); fn(" HELLO, WORLD!\n");
printf("...apparently, we survived. :)\n"); SDL_Log("...apparently, we survived. :)\n");
printf("Unloading library...\n"); SDL_Log("Unloading library...\n");
fflush(stdout); fflush(stdout);
} }
} }

View File

@ -40,7 +40,7 @@ SDL_Quit_Wrapper(void)
void void
printid(void) printid(void)
{ {
printf("Process %lu: exiting\n", SDL_ThreadID()); SDL_Log("Process %lu: exiting\n", SDL_ThreadID());
} }
void void
@ -55,7 +55,7 @@ closemutex(int sig)
{ {
SDL_threadID id = SDL_ThreadID(); SDL_threadID id = SDL_ThreadID();
int i; int i;
printf("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id); SDL_Log("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id);
doterminate = 1; doterminate = 1;
for (i = 0; i < 6; ++i) for (i = 0; i < 6; ++i)
SDL_WaitThread(threads[i], NULL); SDL_WaitThread(threads[i], NULL);
@ -69,23 +69,23 @@ Run(void *data)
if (SDL_ThreadID() == mainthread) if (SDL_ThreadID() == mainthread)
signal(SIGTERM, closemutex); signal(SIGTERM, closemutex);
while (!doterminate) { while (!doterminate) {
printf("Process %lu ready to work\n", SDL_ThreadID()); SDL_Log("Process %lu ready to work\n", SDL_ThreadID());
if (SDL_LockMutex(mutex) < 0) { if (SDL_LockMutex(mutex) < 0) {
fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock mutex: %s", SDL_GetError());
exit(1); exit(1);
} }
printf("Process %lu, working!\n", SDL_ThreadID()); SDL_Log("Process %lu, working!\n", SDL_ThreadID());
SDL_Delay(1 * 1000); SDL_Delay(1 * 1000);
printf("Process %lu, done!\n", SDL_ThreadID()); SDL_Log("Process %lu, done!\n", SDL_ThreadID());
if (SDL_UnlockMutex(mutex) < 0) { if (SDL_UnlockMutex(mutex) < 0) {
fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't unlock mutex: %s", SDL_GetError());
exit(1); exit(1);
} }
/* If this sleep isn't done, then threads may starve */ /* If this sleep isn't done, then threads may starve */
SDL_Delay(10); SDL_Delay(10);
} }
if (SDL_ThreadID() == mainthread && doterminate) { if (SDL_ThreadID() == mainthread && doterminate) {
printf("Process %lu: raising SIGTERM\n", SDL_ThreadID()); SDL_Log("Process %lu: raising SIGTERM\n", SDL_ThreadID());
raise(SIGTERM); raise(SIGTERM);
} }
return (0); return (0);
@ -97,26 +97,29 @@ main(int argc, char *argv[])
int i; int i;
int maxproc = 6; int maxproc = 6;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(0) < 0) { if (SDL_Init(0) < 0) {
fprintf(stderr, "%s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
exit(1); exit(1);
} }
atexit(SDL_Quit_Wrapper); atexit(SDL_Quit_Wrapper);
if ((mutex = SDL_CreateMutex()) == NULL) { if ((mutex = SDL_CreateMutex()) == NULL) {
fprintf(stderr, "Couldn't create mutex: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError());
exit(1); exit(1);
} }
mainthread = SDL_ThreadID(); mainthread = SDL_ThreadID();
printf("Main thread: %lu\n", mainthread); SDL_Log("Main thread: %lu\n", mainthread);
atexit(printid); atexit(printid);
for (i = 0; i < maxproc; ++i) { for (i = 0; i < maxproc; ++i) {
char name[64]; char name[64];
SDL_snprintf(name, sizeof (name), "Worker%d", i); SDL_snprintf(name, sizeof (name), "Worker%d", i);
if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL) if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
fprintf(stderr, "Couldn't create thread!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
} }
signal(SIGINT, terminate); signal(SIGINT, terminate);
Run(NULL); Run(NULL);

View File

@ -62,7 +62,7 @@ button_messagebox(void *eventNumber)
success = SDL_ShowMessageBox(&data, &button); success = SDL_ShowMessageBox(&data, &button);
if (success == -1) { if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
if (eventNumber) { if (eventNumber) {
SDL_UserEvent event; SDL_UserEvent event;
event.type = (intptr_t)eventNumber; event.type = (intptr_t)eventNumber;
@ -72,7 +72,7 @@ button_messagebox(void *eventNumber)
quit(2); quit(2);
} }
} }
printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK"); SDL_Log("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
if (eventNumber) { if (eventNumber) {
SDL_UserEvent event; SDL_UserEvent event;
@ -88,12 +88,15 @@ main(int argc, char *argv[])
{ {
int success; int success;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Simple MessageBox", "Simple MessageBox",
"This is a simple error MessageBox", "This is a simple error MessageBox",
NULL); NULL);
if (success == -1) { if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1); quit(1);
} }
@ -102,7 +105,7 @@ main(int argc, char *argv[])
"This is a simple MessageBox with a newline:\r\nHello world!", "This is a simple MessageBox with a newline:\r\nHello world!",
NULL); NULL);
if (success == -1) { if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1); quit(1);
} }
@ -112,7 +115,7 @@ main(int argc, char *argv[])
"Unicode text: '牛肉西蘭花' ...", "Unicode text: '牛肉西蘭花' ...",
NULL); NULL);
if (success == -1) { if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1); quit(1);
} }
@ -122,7 +125,7 @@ main(int argc, char *argv[])
"Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'", "Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
NULL); NULL);
if (success == -1) { if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1); quit(1);
} }
@ -135,7 +138,7 @@ main(int argc, char *argv[])
subsystem on the main thread. subsystem on the main thread.
*/ */
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
return (1); return (1);
} }
{ {
@ -153,7 +156,7 @@ main(int argc, char *argv[])
SDL_WaitThread(thread, &status); SDL_WaitThread(thread, &status);
printf("Message box thread return %i\n", status); SDL_Log("Message box thread return %i\n", status);
} }
/* Test showing a message box with a parent window */ /* Test showing a message box with a parent window */
@ -166,7 +169,7 @@ main(int argc, char *argv[])
"This is a simple error MessageBox with a parent window", "This is a simple error MessageBox with a parent window",
window); window);
if (success == -1) { if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1); quit(1);
} }

View File

@ -10,7 +10,6 @@
freely. freely.
*/ */
#include "SDL.h" #include "SDL.h"
#include <stdio.h>
static SDL_AudioSpec spec; static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */ static Uint8 *sound = NULL; /* Pointer to wave data */
@ -51,7 +50,7 @@ test_multi_audio(int devcount)
int i; int i;
if (devcount > 64) { if (devcount > 64) {
fprintf(stderr, "Too many devices (%d), clamping to 64...\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Too many devices (%d), clamping to 64...\n",
devcount); devcount);
devcount = 64; devcount = 64;
} }
@ -60,33 +59,33 @@ test_multi_audio(int devcount)
for (i = 0; i < devcount; i++) { for (i = 0; i < devcount; i++) {
const char *devname = SDL_GetAudioDeviceName(i, 0); const char *devname = SDL_GetAudioDeviceName(i, 0);
printf("playing on device #%d: ('%s')...", i, devname); SDL_Log("playing on device #%d: ('%s')...", i, devname);
fflush(stdout); fflush(stdout);
SDL_memset(&cbd[0], '\0', sizeof(callback_data)); SDL_memset(&cbd[0], '\0', sizeof(callback_data));
spec.userdata = &cbd[0]; spec.userdata = &cbd[0];
cbd[0].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0); cbd[0].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
if (cbd[0].dev == 0) { if (cbd[0].dev == 0) {
printf("\nOpen device failed: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device failed: %s\n", SDL_GetError());
} else { } else {
SDL_PauseAudioDevice(cbd[0].dev, 0); SDL_PauseAudioDevice(cbd[0].dev, 0);
while (!cbd[0].done) while (!cbd[0].done)
SDL_Delay(100); SDL_Delay(100);
SDL_PauseAudioDevice(cbd[0].dev, 1); SDL_PauseAudioDevice(cbd[0].dev, 1);
printf("done.\n"); SDL_Log("done.\n");
SDL_CloseAudioDevice(cbd[0].dev); SDL_CloseAudioDevice(cbd[0].dev);
} }
} }
SDL_memset(cbd, '\0', sizeof(cbd)); SDL_memset(cbd, '\0', sizeof(cbd));
printf("playing on all devices...\n"); SDL_Log("playing on all devices...\n");
for (i = 0; i < devcount; i++) { for (i = 0; i < devcount; i++) {
const char *devname = SDL_GetAudioDeviceName(i, 0); const char *devname = SDL_GetAudioDeviceName(i, 0);
spec.userdata = &cbd[i]; spec.userdata = &cbd[i];
cbd[i].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0); cbd[i].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
if (cbd[i].dev == 0) { if (cbd[i].dev == 0) {
printf("Open device %d failed: %s\n", i, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device %d failed: %s\n", i, SDL_GetError());
} }
} }
@ -113,7 +112,7 @@ test_multi_audio(int devcount)
} }
} }
printf("All done!\n"); SDL_Log("All done!\n");
} }
@ -122,17 +121,20 @@ main(int argc, char **argv)
{ {
int devcount = 0; int devcount = 0;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) { if (SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
devcount = SDL_GetNumAudioDevices(0); devcount = SDL_GetNumAudioDevices(0);
if (devcount < 1) { if (devcount < 1) {
fprintf(stderr, "Don't see any specific audio devices!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
} else { } else {
if (argv[1] == NULL) { if (argv[1] == NULL) {
argv[1] = "sample.wav"; argv[1] = "sample.wav";
@ -140,7 +142,7 @@ main(int argc, char **argv)
/* Load the wave file into memory */ /* Load the wave file into memory */
if (SDL_LoadWAV(argv[1], &spec, &sound, &soundlen) == NULL) { if (SDL_LoadWAV(argv[1], &spec, &sound, &soundlen) == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", argv[1], SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1],
SDL_GetError()); SDL_GetError());
} else { } else {
test_multi_audio(devcount); test_multi_audio(devcount);

View File

@ -58,7 +58,7 @@ LoadSprite(SDL_Renderer *renderer, char *file)
/* Load the sprite image */ /* Load the sprite image */
temp = SDL_LoadBMP(file); temp = SDL_LoadBMP(file);
if (temp == NULL) { if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return 0; return 0;
} }
@ -70,7 +70,7 @@ LoadSprite(SDL_Renderer *renderer, char *file)
/* Create textures from the image */ /* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp); sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) { if (!sprite) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp); SDL_FreeSurface(temp);
return 0; return 0;
} }
@ -131,8 +131,11 @@ main(int argc, char *argv[])
int sprite_w, sprite_h; int sprite_w, sprite_h;
SDL_Event event; SDL_Event event;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_VideoInit(NULL) < 0) { if (SDL_VideoInit(NULL) < 0) {
fprintf(stderr, "Couldn't initialize SDL video: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video: %s\n",
SDL_GetError()); SDL_GetError());
exit(1); exit(1);
} }
@ -146,19 +149,19 @@ main(int argc, char *argv[])
} }
} }
if (!factory) { if (!factory) {
fprintf(stderr, "Couldn't find native window code for %s driver\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n",
driver); driver);
quit(2); quit(2);
} }
printf("Creating native window for %s driver\n", driver); SDL_Log("Creating native window for %s driver\n", driver);
native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H); native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H);
if (!native_window) { if (!native_window) {
fprintf(stderr, "Couldn't create native window\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n");
quit(3); quit(3);
} }
window = SDL_CreateWindowFrom(native_window); window = SDL_CreateWindowFrom(native_window);
if (!window) { if (!window) {
fprintf(stderr, "Couldn't create SDL window: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError());
quit(4); quit(4);
} }
SDL_SetWindowTitle(window, "SDL Native Window Test"); SDL_SetWindowTitle(window, "SDL Native Window Test");
@ -166,7 +169,7 @@ main(int argc, char *argv[])
/* Create the renderer */ /* Create the renderer */
renderer = SDL_CreateRenderer(window, -1, 0); renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) { if (!renderer) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
quit(5); quit(5);
} }
@ -185,7 +188,7 @@ main(int argc, char *argv[])
positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect)); positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
if (!positions || !velocities) { if (!positions || !velocities) {
fprintf(stderr, "Out of memory!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2); quit(2);
} }
srand(time(NULL)); srand(time(NULL));

View File

@ -209,19 +209,18 @@ ConvertRGBtoYV12(Uint8 *rgb, Uint8 *out, int w, int h,
static void static void
PrintUsage(char *argv0) PrintUsage(char *argv0)
{ {
fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0); SDL_Log("Usage: %s [arg] [arg] [arg] ...\n", argv0);
fprintf(stderr, "\n"); SDL_Log("\n");
fprintf(stderr, "Where 'arg' is any of the following options:\n"); SDL_Log("Where 'arg' is any of the following options:\n");
fprintf(stderr, "\n"); SDL_Log("\n");
fprintf(stderr, " -fps <frames per second>\n"); SDL_Log(" -fps <frames per second>\n");
fprintf(stderr, " -nodelay\n"); SDL_Log(" -nodelay\n");
fprintf(stderr, " -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n"); SDL_Log(" -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
fprintf(stderr, " -scale <scale factor> (initial scale of the overlay)\n"); SDL_Log(" -scale <scale factor> (initial scale of the overlay)\n");
fprintf(stderr, " -help (shows this help)\n"); SDL_Log(" -help (shows this help)\n");
fprintf(stderr, "\n"); SDL_Log("\n");
fprintf(stderr, SDL_Log("Press ESC to exit, or SPACE to freeze the movie while application running.\n");
"Press ESC to exit, or SPACE to freeze the movie while application running.\n"); SDL_Log("\n");
fprintf(stderr, "\n");
} }
int int
@ -246,8 +245,11 @@ main(int argc, char **argv)
int scale = 5; int scale = 5;
SDL_bool done = SDL_FALSE; SDL_bool done = SDL_FALSE;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 3; return 3;
} }
@ -256,19 +258,19 @@ main(int argc, char **argv)
if (argv[2]) { if (argv[2]) {
fps = atoi(argv[2]); fps = atoi(argv[2]);
if (fps == 0) { if (fps == 0) {
fprintf(stderr, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n"); "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10); quit(10);
} }
if ((fps < 0) || (fps > 1000)) { if ((fps < 0) || (fps > 1000)) {
fprintf(stderr, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option must be in range from 1 to 1000, default is 12.\n"); "The -fps option must be in range from 1 to 1000, default is 12.\n");
quit(10); quit(10);
} }
argv += 2; argv += 2;
argc -= 2; argc -= 2;
} else { } else {
fprintf(stderr, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n"); "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10); quit(10);
} }
@ -280,19 +282,19 @@ main(int argc, char **argv)
if (argv[2]) { if (argv[2]) {
scale = atoi(argv[2]); scale = atoi(argv[2]);
if (scale == 0) { if (scale == 0) {
fprintf(stderr, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -scale option requires an argument [from 1 to 50], default is 5.\n"); "The -scale option requires an argument [from 1 to 50], default is 5.\n");
quit(10); quit(10);
} }
if ((scale < 0) || (scale > 50)) { if ((scale < 0) || (scale > 50)) {
fprintf(stderr, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -scale option must be in range from 1 to 50, default is 5.\n"); "The -scale option must be in range from 1 to 50, default is 5.\n");
quit(10); quit(10);
} }
argv += 2; argv += 2;
argc -= 2; argc -= 2;
} else { } else {
fprintf(stderr, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n"); "The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10); quit(10);
} }
@ -301,7 +303,7 @@ main(int argc, char **argv)
PrintUsage(argv[0]); PrintUsage(argv[0]);
quit(0); quit(0);
} else { } else {
fprintf(stderr, "Unrecognized option: %s.\n", argv[1]); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized option: %s.\n", argv[1]);
quit(10); quit(10);
} }
break; break;
@ -309,7 +311,7 @@ main(int argc, char **argv)
RawMooseData = (Uint8 *) malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT); RawMooseData = (Uint8 *) malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
if (RawMooseData == NULL) { if (RawMooseData == NULL) {
fprintf(stderr, "Can't allocate memory for movie !\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
free(RawMooseData); free(RawMooseData);
quit(1); quit(1);
} }
@ -317,7 +319,7 @@ main(int argc, char **argv)
/* load the trojan moose images */ /* load the trojan moose images */
handle = SDL_RWFromFile("moose.dat", "rb"); handle = SDL_RWFromFile("moose.dat", "rb");
if (handle == NULL) { if (handle == NULL) {
fprintf(stderr, "Can't find the file moose.dat !\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
free(RawMooseData); free(RawMooseData);
quit(2); quit(2);
} }
@ -335,21 +337,21 @@ main(int argc, char **argv)
window_w, window_h, window_w, window_h,
SDL_WINDOW_RESIZABLE); SDL_WINDOW_RESIZABLE);
if (!window) { if (!window) {
fprintf(stderr, "Couldn't set create window: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
free(RawMooseData); free(RawMooseData);
quit(4); quit(4);
} }
renderer = SDL_CreateRenderer(window, -1, 0); renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) { if (!renderer) {
fprintf(stderr, "Couldn't set create renderer: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
free(RawMooseData); free(RawMooseData);
quit(4); quit(4);
} }
MooseTexture = SDL_CreateTexture(renderer, pixel_format, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H); MooseTexture = SDL_CreateTexture(renderer, pixel_format, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
if (!MooseTexture) { if (!MooseTexture) {
fprintf(stderr, "Couldn't set create texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
free(RawMooseData); free(RawMooseData);
quit(5); quit(5);
} }

View File

@ -35,30 +35,30 @@ TestTypes(SDL_bool verbose)
if (badsize(sizeof(Uint8), 1)) { if (badsize(sizeof(Uint8), 1)) {
if (verbose) if (verbose)
printf("sizeof(Uint8) != 1, instead = %u\n", SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
(unsigned int)sizeof(Uint8)); (unsigned int)sizeof(Uint8));
++error; ++error;
} }
if (badsize(sizeof(Uint16), 2)) { if (badsize(sizeof(Uint16), 2)) {
if (verbose) if (verbose)
printf("sizeof(Uint16) != 2, instead = %u\n", SDL_Log("sizeof(Uint16) != 2, instead = %u\n",
(unsigned int)sizeof(Uint16)); (unsigned int)sizeof(Uint16));
++error; ++error;
} }
if (badsize(sizeof(Uint32), 4)) { if (badsize(sizeof(Uint32), 4)) {
if (verbose) if (verbose)
printf("sizeof(Uint32) != 4, instead = %u\n", SDL_Log("sizeof(Uint32) != 4, instead = %u\n",
(unsigned int)sizeof(Uint32)); (unsigned int)sizeof(Uint32));
++error; ++error;
} }
if (badsize(sizeof(Uint64), 8)) { if (badsize(sizeof(Uint64), 8)) {
if (verbose) if (verbose)
printf("sizeof(Uint64) != 8, instead = %u\n", SDL_Log("sizeof(Uint64) != 8, instead = %u\n",
(unsigned int)sizeof(Uint64)); (unsigned int)sizeof(Uint64));
++error; ++error;
} }
if (verbose && !error) if (verbose && !error)
printf("All data types are the expected size.\n"); SDL_Log("All data types are the expected size.\n");
return (error ? 1 : 0); return (error ? 1 : 0);
} }
@ -83,7 +83,7 @@ TestEndian(SDL_bool verbose)
swapped64 |= 0xDEADBEEF; swapped64 |= 0xDEADBEEF;
if (verbose) { if (verbose) {
printf("Detected a %s endian machine.\n", SDL_Log("Detected a %s endian machine.\n",
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big"); (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
} }
if ((*((char *) &value) >> 4) == 0x1) { if ((*((char *) &value) >> 4) == 0x1) {
@ -93,44 +93,44 @@ TestEndian(SDL_bool verbose)
} }
if (real_byteorder != SDL_BYTEORDER) { if (real_byteorder != SDL_BYTEORDER) {
if (verbose) { if (verbose) {
printf("Actually a %s endian machine!\n", SDL_Log("Actually a %s endian machine!\n",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big"); (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
} }
++error; ++error;
} }
if (verbose) { if (verbose) {
printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16,
SDL_Swap16(value16)); SDL_Swap16(value16));
} }
if (SDL_Swap16(value16) != swapped16) { if (SDL_Swap16(value16) != swapped16) {
if (verbose) { if (verbose) {
printf("16 bit value swapped incorrectly!\n"); SDL_Log("16 bit value swapped incorrectly!\n");
} }
++error; ++error;
} }
if (verbose) { if (verbose) {
printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Log("Value 32 = 0x%X, swapped = 0x%X\n", value32,
SDL_Swap32(value32)); SDL_Swap32(value32));
} }
if (SDL_Swap32(value32) != swapped32) { if (SDL_Swap32(value32) != swapped32) {
if (verbose) { if (verbose) {
printf("32 bit value swapped incorrectly!\n"); SDL_Log("32 bit value swapped incorrectly!\n");
} }
++error; ++error;
} }
if (verbose) { if (verbose) {
#ifdef _MSC_VER #ifdef _MSC_VER
printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64, SDL_Log("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
SDL_Swap64(value64)); SDL_Swap64(value64));
#else #else
printf("Value 64 = 0x%llX, swapped = 0x%llX\n", SDL_Log("Value 64 = 0x%llX, swapped = 0x%llX\n",
(unsigned long long) value64, (unsigned long long) value64,
(unsigned long long) SDL_Swap64(value64)); (unsigned long long) SDL_Swap64(value64));
#endif #endif
} }
if (SDL_Swap64(value64) != swapped64) { if (SDL_Swap64(value64) != swapped64) {
if (verbose) { if (verbose) {
printf("64 bit value swapped incorrectly!\n"); SDL_Log("64 bit value swapped incorrectly!\n");
} }
++error; ++error;
} }
@ -142,17 +142,17 @@ int
TestCPUInfo(SDL_bool verbose) TestCPUInfo(SDL_bool verbose)
{ {
if (verbose) { if (verbose) {
printf("CPU count: %d\n", SDL_GetCPUCount()); SDL_Log("CPU count: %d\n", SDL_GetCPUCount());
printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize()); SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected"); SDL_Log("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
printf("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected"); SDL_Log("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected"); SDL_Log("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
printf("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected"); SDL_Log("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected"); SDL_Log("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected"); SDL_Log("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
printf("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected"); SDL_Log("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
printf("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected"); SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
printf("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected"); SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
} }
return (0); return (0);
} }
@ -176,7 +176,7 @@ TestAssertions(SDL_bool verbose)
{ {
const SDL_assert_data *item = SDL_GetAssertionReport(); const SDL_assert_data *item = SDL_GetAssertionReport();
while (item) { while (item) {
printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n", SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
item->condition, item->function, item->filename, item->condition, item->function, item->filename,
item->linenum, item->trigger_count, item->linenum, item->trigger_count,
item->always_ignore ? "yes" : "no"); item->always_ignore ? "yes" : "no");
@ -192,11 +192,14 @@ main(int argc, char *argv[])
SDL_bool verbose = SDL_TRUE; SDL_bool verbose = SDL_TRUE;
int status = 0; int status = 0;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) { if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
verbose = SDL_FALSE; verbose = SDL_FALSE;
} }
if (verbose) { if (verbose) {
printf("This system is running %s\n", SDL_GetPlatform()); SDL_Log("This system is running %s\n", SDL_GetPlatform());
} }
status += TestTypes(verbose); status += TestTypes(verbose);

View File

@ -21,7 +21,7 @@ report_power(void)
const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent); const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
char *statestr = NULL; char *statestr = NULL;
printf("SDL-reported power info...\n"); SDL_Log("SDL-reported power info...\n");
switch (state) { switch (state) {
case SDL_POWERSTATE_UNKNOWN: case SDL_POWERSTATE_UNKNOWN:
statestr = "Unknown"; statestr = "Unknown";
@ -43,18 +43,18 @@ report_power(void)
break; break;
} }
printf("State: %s\n", statestr); SDL_Log("State: %s\n", statestr);
if (percent == -1) { if (percent == -1) {
printf("Percent left: unknown\n"); SDL_Log("Percent left: unknown\n");
} else { } else {
printf("Percent left: %d%%\n", percent); SDL_Log("Percent left: %d%%\n", percent);
} }
if (seconds == -1) { if (seconds == -1) {
printf("Time left: unknown\n"); SDL_Log("Time left: unknown\n");
} else { } else {
printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60), SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
(int) (seconds % 60)); (int) (seconds % 60));
} }
} }
@ -63,8 +63,11 @@ report_power(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(0) == -1) { if (SDL_Init(0) == -1) {
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
return 1; return 1;
} }

View File

@ -35,6 +35,8 @@ main(int argc, char *argv[])
int i, done; int i, done;
SDL_Event event; SDL_Event event;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
@ -74,10 +76,8 @@ main(int argc, char *argv[])
switch(event.type) { switch(event.type) {
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
{ {
/*printf("mouse motion ABS x %d y %d REL x %d y %d\n",event.motion.x,event.motion.y,event.motion.xrel,event.motion.yrel);*/
rect.x += event.motion.xrel; rect.x += event.motion.xrel;
rect.y += event.motion.yrel; rect.y += event.motion.yrel;
} }
break; break;
} }

View File

@ -46,7 +46,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Load the sprite image */ /* Load the sprite image */
temp = SDL_LoadBMP(file); temp = SDL_LoadBMP(file);
if (temp == NULL) { if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL; return NULL;
} }
@ -77,7 +77,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Create textures from the image */ /* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp); texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) { if (!texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp); SDL_FreeSurface(temp);
return NULL; return NULL;
} }
@ -139,6 +139,9 @@ main(int argc, char *argv[])
int frames; int frames;
Uint32 then, now; Uint32 then, now;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) { if (!state) {
@ -149,7 +152,7 @@ main(int argc, char *argv[])
consumed = SDLTest_CommonArg(state, i); consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) { if (consumed == 0) {
fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
return 1; return 1;
} }
i += consumed; i += consumed;
@ -193,7 +196,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
double fps = ((double) frames * 1000) / (now - then); double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps); SDL_Log("%2.2f frames per second\n", fps);
} }
SDL_stack_free(drawstates); SDL_stack_free(drawstates);

View File

@ -46,7 +46,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Load the sprite image */ /* Load the sprite image */
temp = SDL_LoadBMP(file); temp = SDL_LoadBMP(file);
if (temp == NULL) { if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL; return NULL;
} }
@ -77,7 +77,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Create textures from the image */ /* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp); texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) { if (!texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp); SDL_FreeSurface(temp);
return NULL; return NULL;
} }
@ -114,7 +114,7 @@ DrawComposite(DrawState *s)
SDL_RenderCopy(s->renderer, A, NULL, NULL); SDL_RenderCopy(s->renderer, A, NULL, NULL);
SDL_RenderReadPixels(s->renderer, NULL, SDL_PIXELFORMAT_ARGB8888, &P, sizeof(P)); SDL_RenderReadPixels(s->renderer, NULL, SDL_PIXELFORMAT_ARGB8888, &P, sizeof(P));
printf("Blended pixel: 0x%8.8X\n", P); SDL_Log("Blended pixel: 0x%8.8X\n", P);
SDL_DestroyTexture(A); SDL_DestroyTexture(A);
SDL_DestroyTexture(B); SDL_DestroyTexture(B);
@ -218,6 +218,9 @@ main(int argc, char *argv[])
Uint32 then, now; Uint32 then, now;
SDL_bool test_composite = SDL_FALSE; SDL_bool test_composite = SDL_FALSE;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) { if (!state) {
@ -235,8 +238,7 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, SDL_Log("Usage: %s %s [--composite]\n",
"Usage: %s %s [--composite]\n",
argv[0], SDLTest_CommonUsage(state)); argv[0], SDLTest_CommonUsage(state));
quit(1); quit(1);
} }
@ -289,7 +291,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
double fps = ((double) frames * 1000) / (now - then); double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps); SDL_Log("%2.2f frames per second\n", fps);
} }
SDL_stack_free(drawstates); SDL_stack_free(drawstates);

View File

@ -9,7 +9,7 @@
including commercial applications, and to alter it and redistribute it including commercial applications, and to alter it and redistribute it
freely. freely.
*/ */
#include <stdio.h>
#include "SDL.h" #include "SDL.h"
int int
@ -25,27 +25,30 @@ main(int argc, char **argv)
int avgbytes = 0; int avgbytes = 0;
SDL_RWops *io = NULL; SDL_RWops *io = NULL;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (argc != 4) { if (argc != 4) {
fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]); SDL_Log("USAGE: %s in.wav out.wav newfreq\n", argv[0]);
return 1; return 1;
} }
cvtfreq = SDL_atoi(argv[3]); cvtfreq = SDL_atoi(argv[3]);
if (SDL_Init(SDL_INIT_AUDIO) == -1) { if (SDL_Init(SDL_INIT_AUDIO) == -1) {
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
return 2; return 2;
} }
if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) { if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) {
fprintf(stderr, "failed to load %s: %s\n", argv[1], SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", argv[1], SDL_GetError());
SDL_Quit(); SDL_Quit();
return 3; return 3;
} }
if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq, if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq,
spec.format, spec.channels, cvtfreq) == -1) { spec.format, spec.channels, cvtfreq) == -1) {
fprintf(stderr, "failed to build CVT: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to build CVT: %s\n", SDL_GetError());
SDL_FreeWAV(data); SDL_FreeWAV(data);
SDL_Quit(); SDL_Quit();
return 4; return 4;
@ -54,7 +57,7 @@ main(int argc, char **argv)
cvt.len = len; cvt.len = len;
cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult); cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult);
if (cvt.buf == NULL) { if (cvt.buf == NULL) {
fprintf(stderr, "Out of memory.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory.\n");
SDL_FreeWAV(data); SDL_FreeWAV(data);
SDL_Quit(); SDL_Quit();
return 5; return 5;
@ -62,7 +65,7 @@ main(int argc, char **argv)
SDL_memcpy(cvt.buf, data, len); SDL_memcpy(cvt.buf, data, len);
if (SDL_ConvertAudio(&cvt) == -1) { if (SDL_ConvertAudio(&cvt) == -1) {
fprintf(stderr, "Conversion failed: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Conversion failed: %s\n", SDL_GetError());
SDL_free(cvt.buf); SDL_free(cvt.buf);
SDL_FreeWAV(data); SDL_FreeWAV(data);
SDL_Quit(); SDL_Quit();
@ -72,7 +75,7 @@ main(int argc, char **argv)
/* write out a WAV header... */ /* write out a WAV header... */
io = SDL_RWFromFile(argv[2], "wb"); io = SDL_RWFromFile(argv[2], "wb");
if (io == NULL) { if (io == NULL) {
fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
SDL_free(cvt.buf); SDL_free(cvt.buf);
SDL_FreeWAV(data); SDL_FreeWAV(data);
SDL_Quit(); SDL_Quit();
@ -99,7 +102,7 @@ main(int argc, char **argv)
SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1); SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
if (SDL_RWclose(io) == -1) { if (SDL_RWclose(io) == -1) {
fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
SDL_free(cvt.buf); SDL_free(cvt.buf);
SDL_FreeWAV(data); SDL_FreeWAV(data);
SDL_Quit(); SDL_Quit();

View File

@ -26,7 +26,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* includes * includes
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> /* printf */
#include <string.h> /* strstr */ #include <string.h> /* strstr */
#include <ctype.h> /* isdigit */ #include <ctype.h> /* isdigit */
@ -51,12 +50,15 @@ main(int argc, char **argv)
char *name; char *name;
int index; int index;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
name = NULL; name = NULL;
index = -1; index = -1;
if (argc > 1) { if (argc > 1) {
name = argv[1]; name = argv[1];
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) { if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
printf("USAGE: %s [device]\n" SDL_Log("USAGE: %s [device]\n"
"If device is a two-digit number it'll use it as an index, otherwise\n" "If device is a two-digit number it'll use it as an index, otherwise\n"
"it'll use it as if it were part of the device's name.\n", "it'll use it as if it were part of the device's name.\n",
argv[0]); argv[0]);
@ -73,7 +75,7 @@ main(int argc, char **argv)
/* Initialize the force feedbackness */ /* Initialize the force feedbackness */
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
SDL_INIT_HAPTIC); SDL_INIT_HAPTIC);
printf("%d Haptic devices detected.\n", SDL_NumHaptics()); SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
if (SDL_NumHaptics() > 0) { if (SDL_NumHaptics() > 0) {
/* We'll just use index or the first force feedback device found */ /* We'll just use index or the first force feedback device found */
if (name == NULL) { if (name == NULL) {
@ -87,7 +89,7 @@ main(int argc, char **argv)
} }
if (i >= SDL_NumHaptics()) { if (i >= SDL_NumHaptics()) {
printf("Unable to find device matching '%s', aborting.\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
name); name);
return 1; return 1;
} }
@ -95,13 +97,13 @@ main(int argc, char **argv)
haptic = SDL_HapticOpen(i); haptic = SDL_HapticOpen(i);
if (haptic == NULL) { if (haptic == NULL) {
printf("Unable to create the haptic device: %s\n", SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
SDL_GetError()); SDL_GetError());
return 1; return 1;
} }
printf("Device: %s\n", SDL_HapticName(i)); SDL_Log("Device: %s\n", SDL_HapticName(i));
} else { } else {
printf("No Haptic devices found!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
return 1; return 1;
} }
@ -109,25 +111,25 @@ main(int argc, char **argv)
SDL_ClearError(); SDL_ClearError();
if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) { if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) {
printf("\nRumble not supported!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n");
return 1; return 1;
} }
if (SDL_HapticRumbleInit(haptic) != 0) { if (SDL_HapticRumbleInit(haptic) != 0) {
printf("\nFailed to initialize rumble: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError());
return 1; return 1;
} }
printf("Playing 2 second rumble at 0.5 magnitude.\n"); SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) { if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) {
printf("\nFailed to play rumble: %s\n", SDL_GetError() ); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
return 1; return 1;
} }
SDL_Delay(2000); SDL_Delay(2000);
printf("Stopping rumble.\n"); SDL_Log("Stopping rumble.\n");
SDL_HapticRumbleStop(haptic); SDL_HapticRumbleStop(haptic);
SDL_Delay(2000); SDL_Delay(2000);
printf("Playing 2 second rumble at 0.3 magnitude.\n"); SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) { if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) {
printf("\nFailed to play rumble: %s\n", SDL_GetError() ); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
return 1; return 1;
} }
SDL_Delay(2000); SDL_Delay(2000);
@ -145,7 +147,7 @@ main(int argc, char **argv)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
fprintf(stderr, "SDL compiled without Haptic support.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");
exit(1); exit(1);
} }

View File

@ -48,7 +48,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Load the sprite image */ /* Load the sprite image */
temp = SDL_LoadBMP(file); temp = SDL_LoadBMP(file);
if (temp == NULL) { if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL; return NULL;
} }
@ -79,7 +79,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Create textures from the image */ /* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp); texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) { if (!texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp); SDL_FreeSurface(temp);
return NULL; return NULL;
} }
@ -129,6 +129,9 @@ main(int argc, char *argv[])
int frames; int frames;
Uint32 then, now; Uint32 then, now;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */ /* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) { if (!state) {
@ -139,7 +142,7 @@ main(int argc, char *argv[])
consumed = SDLTest_CommonArg(state, i); consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) { if (consumed == 0) {
fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
return 1; return 1;
} }
i += consumed; i += consumed;
@ -183,7 +186,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
double fps = ((double) frames * 1000) / (now - then); double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps); SDL_Log("%2.2f frames per second\n", fps);
} }
SDL_stack_free(drawstates); SDL_stack_free(drawstates);

View File

@ -30,17 +30,15 @@ ThreadFunc(void *data)
int threadnum = (int) (uintptr_t) data; int threadnum = (int) (uintptr_t) data;
while (alive) { while (alive) {
SDL_SemWait(sem); SDL_SemWait(sem);
fprintf(stderr, SDL_Log("Thread number %d has got the semaphore (value = %d)!\n",
"Thread number %d has got the semaphore (value = %d)!\n",
threadnum, SDL_SemValue(sem)); threadnum, SDL_SemValue(sem));
SDL_Delay(200); SDL_Delay(200);
SDL_SemPost(sem); SDL_SemPost(sem);
fprintf(stderr, SDL_Log("Thread number %d has released the semaphore (value = %d)!\n",
"Thread number %d has released the semaphore (value = %d)!\n",
threadnum, SDL_SemValue(sem)); threadnum, SDL_SemValue(sem));
SDL_Delay(1); /* For the scheduler */ SDL_Delay(1); /* For the scheduler */
} }
printf("Thread number %d exiting.\n", threadnum); SDL_Log("Thread number %d exiting.\n", threadnum);
return 0; return 0;
} }
@ -59,7 +57,7 @@ TestWaitTimeout(void)
int retval; int retval;
sem = SDL_CreateSemaphore(0); sem = SDL_CreateSemaphore(0);
printf("Waiting 2 seconds on semaphore\n"); SDL_Log("Waiting 2 seconds on semaphore\n");
start_ticks = SDL_GetTicks(); start_ticks = SDL_GetTicks();
retval = SDL_SemWaitTimeout(sem, 2000); retval = SDL_SemWaitTimeout(sem, 2000);
@ -69,13 +67,13 @@ TestWaitTimeout(void)
/* Accept a little offset in the effective wait */ /* Accept a little offset in the effective wait */
if (duration > 1900 && duration < 2050) if (duration > 1900 && duration < 2050)
printf("Wait done.\n"); SDL_Log("Wait done.\n");
else else
fprintf(stderr, "Wait took %d milliseconds\n", duration); SDL_Log("Wait took %d milliseconds\n", duration);
/* Check to make sure the return value indicates timed out */ /* Check to make sure the return value indicates timed out */
if (retval != SDL_MUTEX_TIMEDOUT) if (retval != SDL_MUTEX_TIMEDOUT)
fprintf(stderr, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
} }
int int
@ -85,14 +83,17 @@ main(int argc, char **argv)
uintptr_t i; uintptr_t i;
int init_sem; int init_sem;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (argc < 2) { if (argc < 2) {
fprintf(stderr, "Usage: %s init_value\n", argv[0]); SDL_Log("Usage: %s init_value\n", argv[0]);
return (1); return (1);
} }
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(0) < 0) { if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
signal(SIGTERM, killed); signal(SIGTERM, killed);
@ -101,7 +102,7 @@ main(int argc, char **argv)
init_sem = atoi(argv[1]); init_sem = atoi(argv[1]);
sem = SDL_CreateSemaphore(init_sem); sem = SDL_CreateSemaphore(init_sem);
printf("Running %d threads, semaphore value = %d\n", NUM_THREADS, SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS,
init_sem); init_sem);
/* Create all the threads */ /* Create all the threads */
for (i = 0; i < NUM_THREADS; ++i) { for (i = 0; i < NUM_THREADS; ++i) {
@ -114,12 +115,12 @@ main(int argc, char **argv)
SDL_Delay(10 * 1000); SDL_Delay(10 * 1000);
/* Wait for all threads to finish */ /* Wait for all threads to finish */
printf("Waiting for threads to finish\n"); SDL_Log("Waiting for threads to finish\n");
alive = 0; alive = 0;
for (i = 0; i < NUM_THREADS; ++i) { for (i = 0; i < NUM_THREADS; ++i) {
SDL_WaitThread(threads[i], NULL); SDL_WaitThread(threads[i], NULL);
} }
printf("Finished waiting for threads\n"); SDL_Log("Finished waiting for threads\n");
SDL_DestroySemaphore(sem); SDL_DestroySemaphore(sem);

View File

@ -11,7 +11,6 @@
*/ */
/* This is a simple example of using GLSL shaders with SDL */ /* This is a simple example of using GLSL shaders with SDL */
#include <stdio.h> /* for printf() */
#include "SDL.h" #include "SDL.h"
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
@ -139,7 +138,7 @@ static SDL_bool CompileShader(GLhandleARB shader, const char *source)
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = SDL_stack_alloc(char, length+1); info = SDL_stack_alloc(char, length+1);
glGetInfoLogARB(shader, length, NULL, info); glGetInfoLogARB(shader, length, NULL, info);
fprintf(stderr, "Failed to compile shader:\n%s\n%s", source, info); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
SDL_stack_free(info); SDL_stack_free(info);
return SDL_FALSE; return SDL_FALSE;
@ -245,7 +244,7 @@ static SDL_bool InitShaders()
/* Compile all the shaders */ /* Compile all the shaders */
for (i = 0; i < NUM_SHADERS; ++i) { for (i = 0; i < NUM_SHADERS; ++i) {
if (!CompileShaderProgram(&shaders[i])) { if (!CompileShaderProgram(&shaders[i])) {
fprintf(stderr, "Unable to compile shader!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to compile shader!\n");
return SDL_FALSE; return SDL_FALSE;
} }
} }
@ -422,29 +421,32 @@ int main(int argc, char **argv)
GLuint texture; GLuint texture;
GLfloat texcoords[4]; GLfloat texcoords[4];
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL for video output */ /* Initialize SDL for video output */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError());
exit(1); exit(1);
} }
/* Create a 640x480 OpenGL screen */ /* Create a 640x480 OpenGL screen */
window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL ); window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );
if ( !window ) { if ( !window ) {
fprintf(stderr, "Unable to create OpenGL window: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError());
SDL_Quit(); SDL_Quit();
exit(2); exit(2);
} }
if ( !SDL_GL_CreateContext(window)) { if ( !SDL_GL_CreateContext(window)) {
fprintf(stderr, "Unable to create OpenGL context: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL context: %s\n", SDL_GetError());
SDL_Quit(); SDL_Quit();
exit(2); exit(2);
} }
surface = SDL_LoadBMP("icon.bmp"); surface = SDL_LoadBMP("icon.bmp");
if ( ! surface ) { if ( ! surface ) {
fprintf(stderr, "Unable to load icon.bmp: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError());
SDL_Quit(); SDL_Quit();
exit(3); exit(3);
} }
@ -454,9 +456,9 @@ int main(int argc, char **argv)
/* Loop, drawing and checking events */ /* Loop, drawing and checking events */
InitGL(640, 480); InitGL(640, 480);
if (InitShaders()) { if (InitShaders()) {
printf("Shaders supported, press SPACE to cycle them.\n"); SDL_Log("Shaders supported, press SPACE to cycle them.\n");
} else { } else {
printf("Shaders not supported!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Shaders not supported!\n");
} }
done = 0; done = 0;
while ( ! done ) { while ( ! done ) {
@ -489,7 +491,7 @@ int main(int argc, char **argv)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
printf("No OpenGL support on this system\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
return 1; return 1;
} }

View File

@ -68,13 +68,16 @@ int main(int argc,char** argv)
int access = 0; int access = 0;
SDL_Rect texture_dimensions;; SDL_Rect texture_dimensions;;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if(argc < 2) { if(argc < 2) {
printf("SDL_Shape requires at least one bitmap file as argument.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Shape requires at least one bitmap file as argument.");
exit(-1); exit(-1);
} }
if(SDL_VideoInit(NULL) == -1) { if(SDL_VideoInit(NULL) == -1) {
printf("Could not initialize SDL video.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL video.");
exit(-2); exit(-2);
} }
@ -91,7 +94,7 @@ int main(int argc,char** argv)
SDL_FreeSurface(pictures[j].surface); SDL_FreeSurface(pictures[j].surface);
SDL_free(pictures); SDL_free(pictures);
SDL_VideoQuit(); SDL_VideoQuit();
printf("Could not load surface from named bitmap file.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file.");
exit(-3); exit(-3);
} }
@ -112,7 +115,7 @@ int main(int argc,char** argv)
SDL_FreeSurface(pictures[i].surface); SDL_FreeSurface(pictures[i].surface);
SDL_free(pictures); SDL_free(pictures);
SDL_VideoQuit(); SDL_VideoQuit();
printf("Could not create shaped window for SDL_Shape.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create shaped window for SDL_Shape.");
exit(-4); exit(-4);
} }
renderer = SDL_CreateRenderer(window,-1,0); renderer = SDL_CreateRenderer(window,-1,0);
@ -122,7 +125,7 @@ int main(int argc,char** argv)
SDL_FreeSurface(pictures[i].surface); SDL_FreeSurface(pictures[i].surface);
SDL_free(pictures); SDL_free(pictures);
SDL_VideoQuit(); SDL_VideoQuit();
printf("Could not create rendering context for SDL_Shape window.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create rendering context for SDL_Shape window.");
exit(-5); exit(-5);
} }
@ -141,7 +144,7 @@ int main(int argc,char** argv)
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
SDL_VideoQuit(); SDL_VideoQuit();
printf("Could not create texture for SDL_shape.\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create texture for SDL_shape.");
exit(-6); exit(-6);
} }
} }

View File

@ -64,7 +64,7 @@ LoadSprite(const char *file)
/* Load the sprite image */ /* Load the sprite image */
temp = SDL_LoadBMP(file); temp = SDL_LoadBMP(file);
if (temp == NULL) { if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return (-1); return (-1);
} }
sprite_w = temp->w; sprite_w = temp->w;
@ -95,7 +95,7 @@ LoadSprite(const char *file)
SDL_Renderer *renderer = state->renderers[i]; SDL_Renderer *renderer = state->renderers[i];
sprites[i] = SDL_CreateTextureFromSurface(renderer, temp); sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprites[i]) { if (!sprites[i]) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp); SDL_FreeSurface(temp);
return (-1); return (-1);
} }
@ -299,8 +299,7 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
"Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
argv[0], SDLTest_CommonUsage(state)); argv[0], SDLTest_CommonUsage(state));
quit(1); quit(1);
} }
@ -314,7 +313,7 @@ main(int argc, char *argv[])
sprites = sprites =
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites)); (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
if (!sprites) { if (!sprites) {
fprintf(stderr, "Out of memory!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2); quit(2);
} }
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
@ -330,7 +329,7 @@ main(int argc, char *argv[])
positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect)); velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
if (!positions || !velocities) { if (!positions || !velocities) {
fprintf(stderr, "Out of memory!\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2); quit(2);
} }
@ -375,7 +374,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks(); now = SDL_GetTicks();
if (now > then) { if (now > then) {
double fps = ((double) frames * 1000) / (now - then); double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps); SDL_Log("%2.2f frames per second\n", fps);
} }
quit(0); quit(0);
return 0; return 0;

View File

@ -42,7 +42,7 @@ LoadSprite(char *file, SDL_Renderer *renderer)
/* Load the sprite image */ /* Load the sprite image */
temp = SDL_LoadBMP(file); temp = SDL_LoadBMP(file);
if (temp == NULL) { if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file, SDL_GetError());
return (-1); return (-1);
} }
sprite_w = temp->w; sprite_w = temp->w;
@ -73,7 +73,7 @@ LoadSprite(char *file, SDL_Renderer *renderer)
/* Create textures from the image */ /* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp); sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) { if (!sprite) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp); SDL_FreeSurface(temp);
return (-1); return (-1);
} }
@ -126,6 +126,9 @@ main(int argc, char *argv[])
int i, done; int i, done;
SDL_Event event; SDL_Event event;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) { if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) {
quit(2); quit(2);
} }

View File

@ -68,7 +68,7 @@ void UpdateTexture(SDL_Texture *texture, int frame)
int pitch; int pitch;
if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) { if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) {
fprintf(stderr, "Couldn't lock texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError());
quit(5); quit(5);
} }
src = MooseFrames[frame]; src = MooseFrames[frame];
@ -93,15 +93,18 @@ main(int argc, char **argv)
SDL_bool done = SDL_FALSE; SDL_bool done = SDL_FALSE;
int frame; int frame;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1; return 1;
} }
/* load the moose images */ /* load the moose images */
handle = SDL_RWFromFile("moose.dat", "rb"); handle = SDL_RWFromFile("moose.dat", "rb");
if (handle == NULL) { if (handle == NULL) {
fprintf(stderr, "Can't find the file moose.dat !\n"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
quit(2); quit(2);
} }
SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT); SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
@ -115,19 +118,19 @@ main(int argc, char **argv)
MOOSEPIC_W*4, MOOSEPIC_H*4, MOOSEPIC_W*4, MOOSEPIC_H*4,
SDL_WINDOW_RESIZABLE); SDL_WINDOW_RESIZABLE);
if (!window) { if (!window) {
fprintf(stderr, "Couldn't set create window: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
quit(3); quit(3);
} }
renderer = SDL_CreateRenderer(window, -1, 0); renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) { if (!renderer) {
fprintf(stderr, "Couldn't set create renderer: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
quit(4); quit(4);
} }
MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H); MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
if (!MooseTexture) { if (!MooseTexture) {
fprintf(stderr, "Couldn't set create texture: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
quit(5); quit(5);
} }

View File

@ -34,20 +34,20 @@ int SDLCALL
ThreadFunc(void *data) ThreadFunc(void *data)
{ {
SDL_TLSSet(tls, "baby thread", NULL); SDL_TLSSet(tls, "baby thread", NULL);
printf("Started thread %s: My thread id is %lu, thread data = %s\n", SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls)); (char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
while (alive) { while (alive) {
printf("Thread '%s' is alive!\n", (char *) data); SDL_Log("Thread '%s' is alive!\n", (char *) data);
SDL_Delay(1 * 1000); SDL_Delay(1 * 1000);
} }
printf("Thread '%s' exiting!\n", (char *) data); SDL_Log("Thread '%s' exiting!\n", (char *) data);
return (0); return (0);
} }
static void static void
killed(int sig) killed(int sig)
{ {
printf("Killed with SIGTERM, waiting 5 seconds to exit\n"); SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
SDL_Delay(5 * 1000); SDL_Delay(5 * 1000);
alive = 0; alive = 0;
quit(0); quit(0);
@ -58,35 +58,38 @@ main(int argc, char *argv[])
{ {
SDL_Thread *thread; SDL_Thread *thread;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(0) < 0) { if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
tls = SDL_TLSCreate(); tls = SDL_TLSCreate();
SDL_assert(tls); SDL_assert(tls);
SDL_TLSSet(tls, "main thread", NULL); SDL_TLSSet(tls, "main thread", NULL);
printf("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls)); SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1; alive = 1;
thread = SDL_CreateThread(ThreadFunc, "One", "#1"); thread = SDL_CreateThread(ThreadFunc, "One", "#1");
if (thread == NULL) { if (thread == NULL) {
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1); quit(1);
} }
SDL_Delay(5 * 1000); SDL_Delay(5 * 1000);
printf("Waiting for thread #1\n"); SDL_Log("Waiting for thread #1\n");
alive = 0; alive = 0;
SDL_WaitThread(thread, NULL); SDL_WaitThread(thread, NULL);
printf("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls)); SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1; alive = 1;
signal(SIGTERM, killed); signal(SIGTERM, killed);
thread = SDL_CreateThread(ThreadFunc, "Two", "#2"); thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
if (thread == NULL) { if (thread == NULL) {
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1); quit(1);
} }
raise(SIGTERM); raise(SIGTERM);

View File

@ -33,7 +33,7 @@ ticktock(Uint32 interval, void *param)
static Uint32 SDLCALL static Uint32 SDLCALL
callback(Uint32 interval, void *param) callback(Uint32 interval, void *param)
{ {
printf("Timer %d : param = %d\n", interval, (int) (uintptr_t) param); SDL_Log("Timer %d : param = %d\n", interval, (int) (uintptr_t) param);
return interval; return interval;
} }
@ -45,8 +45,11 @@ main(int argc, char *argv[])
Uint32 start32, now32; Uint32 start32, now32;
Uint64 start, now; Uint64 start, now;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_TIMER) < 0) { if (SDL_Init(SDL_INIT_TIMER) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
@ -61,7 +64,7 @@ main(int argc, char *argv[])
t1 = SDL_AddTimer(desired, ticktock, NULL); t1 = SDL_AddTimer(desired, ticktock, NULL);
/* Wait 10 seconds */ /* Wait 10 seconds */
printf("Waiting 10 seconds\n"); SDL_Log("Waiting 10 seconds\n");
SDL_Delay(10 * 1000); SDL_Delay(10 * 1000);
/* Stop the timer */ /* Stop the timer */
@ -69,28 +72,27 @@ main(int argc, char *argv[])
/* Print the results */ /* Print the results */
if (ticks) { if (ticks) {
fprintf(stderr, SDL_Log("Timer resolution: desired = %d ms, actual = %f ms\n",
"Timer resolution: desired = %d ms, actual = %f ms\n",
desired, (double) (10 * 1000) / ticks); desired, (double) (10 * 1000) / ticks);
} }
/* Test multiple timers */ /* Test multiple timers */
printf("Testing multiple timers...\n"); SDL_Log("Testing multiple timers...\n");
t1 = SDL_AddTimer(100, callback, (void *) 1); t1 = SDL_AddTimer(100, callback, (void *) 1);
if (!t1) if (!t1)
fprintf(stderr, "Could not create timer 1: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 1: %s\n", SDL_GetError());
t2 = SDL_AddTimer(50, callback, (void *) 2); t2 = SDL_AddTimer(50, callback, (void *) 2);
if (!t2) if (!t2)
fprintf(stderr, "Could not create timer 2: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 2: %s\n", SDL_GetError());
t3 = SDL_AddTimer(233, callback, (void *) 3); t3 = SDL_AddTimer(233, callback, (void *) 3);
if (!t3) if (!t3)
fprintf(stderr, "Could not create timer 3: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 3: %s\n", SDL_GetError());
/* Wait 10 seconds */ /* Wait 10 seconds */
printf("Waiting 10 seconds\n"); SDL_Log("Waiting 10 seconds\n");
SDL_Delay(10 * 1000); SDL_Delay(10 * 1000);
printf("Removing timer 1 and waiting 5 more seconds\n"); SDL_Log("Removing timer 1 and waiting 5 more seconds\n");
SDL_RemoveTimer(t1); SDL_RemoveTimer(t1);
SDL_Delay(5 * 1000); SDL_Delay(5 * 1000);
@ -103,15 +105,15 @@ main(int argc, char *argv[])
ticktock(0, NULL); ticktock(0, NULL);
} }
now = SDL_GetPerformanceCounter(); now = SDL_GetPerformanceCounter();
printf("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency()); SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
printf("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency()); SDL_Log("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency());
start32 = SDL_GetTicks(); start32 = SDL_GetTicks();
start = SDL_GetPerformanceCounter(); start = SDL_GetPerformanceCounter();
SDL_Delay(1000); SDL_Delay(1000);
now = SDL_GetPerformanceCounter(); now = SDL_GetPerformanceCounter();
now32 = SDL_GetTicks(); now32 = SDL_GetTicks();
printf("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency()); SDL_Log("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
SDL_Quit(); SDL_Quit();
return (0); return (0);

View File

@ -26,17 +26,20 @@ main(int argc, char *argv[])
SDL_version compiled; SDL_version compiled;
SDL_version linked; SDL_version linked;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
printf("Compiled with SDL 2.0 or newer\n"); SDL_Log("Compiled with SDL 2.0 or newer\n");
#else #else
printf("Compiled with SDL older than 2.0\n"); SDL_Log("Compiled with SDL older than 2.0\n");
#endif #endif
SDL_VERSION(&compiled); SDL_VERSION(&compiled);
printf("Compiled version: %d.%d.%d.%d (%s)\n", SDL_Log("Compiled version: %d.%d.%d.%d (%s)\n",
compiled.major, compiled.minor, compiled.patch, compiled.major, compiled.minor, compiled.patch,
SDL_REVISION_NUMBER, SDL_REVISION); SDL_REVISION_NUMBER, SDL_REVISION);
SDL_GetVersion(&linked); SDL_GetVersion(&linked);
printf("Linked version: %d.%d.%d.%d (%s)\n", SDL_Log("Linked version: %d.%d.%d.%d (%s)\n",
linked.major, linked.minor, linked.patch, linked.major, linked.minor, linked.patch,
SDL_GetRevisionNumber(), SDL_GetRevision()); SDL_GetRevisionNumber(), SDL_GetRevision());
SDL_Quit(); SDL_Quit();

View File

@ -48,6 +48,9 @@ main(int argc, char *argv[])
int system_cursor = -1; int system_cursor = -1;
SDL_Cursor *cursor = NULL; SDL_Cursor *cursor = NULL;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS); SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
/* Initialize test framework */ /* Initialize test framework */
@ -64,7 +67,7 @@ main(int argc, char *argv[])
consumed = -1; consumed = -1;
} }
if (consumed < 0) { if (consumed < 0) {
fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
quit(1); quit(1);
} }
i += consumed; i += consumed;
@ -84,7 +87,7 @@ main(int argc, char *argv[])
if (event.window.event == SDL_WINDOWEVENT_RESIZED) { if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID); SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) { if (window) {
printf("Window %d resized to %dx%d\n", SDL_Log("Window %d resized to %dx%d\n",
event.window.windowID, event.window.windowID,
event.window.data1, event.window.data1,
event.window.data2); event.window.data2);
@ -93,7 +96,7 @@ main(int argc, char *argv[])
if (event.window.event == SDL_WINDOWEVENT_MOVED) { if (event.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID); SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) { if (window) {
printf("Window %d moved to %d,%d (display %s)\n", SDL_Log("Window %d moved to %d,%d (display %s)\n",
event.window.windowID, event.window.windowID,
event.window.data1, event.window.data1,
event.window.data2, event.window.data2,

View File

@ -49,7 +49,7 @@ ThreadFunc(void *data)
int i; int i;
int tid = (int) (uintptr_t) data; int tid = (int) (uintptr_t) data;
fprintf(stderr, "Creating Thread %d\n", tid); SDL_Log("Creating Thread %d\n", tid);
for (i = 0; i < NUMTHREADS; i++) { for (i = 0; i < NUMTHREADS; i++) {
char name[64]; char name[64];
@ -58,18 +58,18 @@ ThreadFunc(void *data)
sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]); sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]);
} }
printf("Thread '%d' waiting for signal\n", tid); SDL_Log("Thread '%d' waiting for signal\n", tid);
while (time_for_threads_to_die[tid] != 1) { while (time_for_threads_to_die[tid] != 1) {
; /* do nothing */ ; /* do nothing */
} }
printf("Thread '%d' sending signals to subthreads\n", tid); SDL_Log("Thread '%d' sending signals to subthreads\n", tid);
for (i = 0; i < NUMTHREADS; i++) { for (i = 0; i < NUMTHREADS; i++) {
flags[i] = 1; flags[i] = 1;
SDL_WaitThread(sub_threads[i], NULL); SDL_WaitThread(sub_threads[i], NULL);
} }
printf("Thread '%d' exiting!\n", tid); SDL_Log("Thread '%d' exiting!\n", tid);
return 0; return 0;
} }
@ -80,9 +80,12 @@ main(int argc, char *argv[])
SDL_Thread *threads[NUMTHREADS]; SDL_Thread *threads[NUMTHREADS];
int i; int i;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */ /* Load the SDL library */
if (SDL_Init(0) < 0) { if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1); return (1);
} }
@ -94,7 +97,7 @@ main(int argc, char *argv[])
threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i); threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i);
if (threads[i] == NULL) { if (threads[i] == NULL) {
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1); quit(1);
} }
} }