Initial merge of Emscripten port!
With this commit, you can compile SDL2 with Emscripten ( http://emscripten.org/ ), and make your SDL-based C/C++ program into a web app. This port was due to the efforts of several people, including: Charlie Birks, Sathyanarayanan Gunasekaran, Jukka Jylänki, Alon Zakai, Edward Rudd, Bruce Mitchener, and Martin Gerhardy. (Thanks, everyone!) --HG-- extra : rebase_source : 97af74c8a5121e926ebe89f123536b5dd6681695
This commit is contained in:
parent
c2ebb6b09f
commit
de88474dda
61 changed files with 4047 additions and 600 deletions
|
@ -38,6 +38,7 @@ TARGETS = \
|
|||
testloadso$(EXE) \
|
||||
testlock$(EXE) \
|
||||
testmultiaudio$(EXE) \
|
||||
testmultiaudio2$(EXE) \
|
||||
testnative$(EXE) \
|
||||
testoverlay2$(EXE) \
|
||||
testplatform$(EXE) \
|
||||
|
@ -105,6 +106,9 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
|
|||
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testmultiaudio2$(EXE): $(srcdir)/testmultiaudio2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testatomic$(EXE): $(srcdir)/testatomic.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
@ -196,6 +200,15 @@ testnative$(EXE): $(srcdir)/testnative.c \
|
|||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @XLIB@
|
||||
endif
|
||||
|
||||
#there's probably a better way of doing this
|
||||
ifeq (@ISMACOSX@,false)
|
||||
ifeq (@ISWINDOWS@,false)
|
||||
ifeq (@ISUNIX@,false)
|
||||
testnative$(EXE): ;
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
testoverlay2$(EXE): $(srcdir)/testoverlay2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
|
|
@ -19,8 +19,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
@ -128,12 +134,37 @@ PrintText(char *text)
|
|||
SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
/* Check for events */
|
||||
/*SDL_WaitEvent(&event); emscripten does not like waiting*/
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
//case SDL_KEYUP:
|
||||
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
PrintText(event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Any button press quits the app... */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Event event;
|
||||
int done;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -163,26 +194,14 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Watch keystrokes */
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
SDL_WaitEvent(&event);
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
PrintText(event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Any button press quits the app... */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
|
|
5
test/configure
vendored
5
test/configure
vendored
|
@ -2980,6 +2980,11 @@ fi
|
|||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGLES_CM"
|
||||
;;
|
||||
*-*-emscripten* )
|
||||
EXE=".bc"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*)
|
||||
ISUNIX="true"
|
||||
EXE=""
|
||||
|
|
|
@ -65,6 +65,12 @@ case "$host" in
|
|||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGLES_CM"
|
||||
;;
|
||||
*-*-emscripten* )
|
||||
dnl This should really be .js, but we need to specify extra flags when compiling to js
|
||||
EXE=".bc"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*)
|
||||
dnl Oh well, call it Unix...
|
||||
ISUNIX="true"
|
||||
|
|
25
test/emscripten/joystick-pre.js
Normal file
25
test/emscripten/joystick-pre.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
Module['arguments'] = ['0'];
|
||||
//Gamepads don't appear until a button is pressed and the joystick/gamepad tests expect one to be connected
|
||||
Module['preRun'].push(function()
|
||||
{
|
||||
Module['print']("Waiting for gamepad...");
|
||||
Module['addRunDependency']("gamepad");
|
||||
window.addEventListener('gamepadconnected', function()
|
||||
{
|
||||
//OK, got one
|
||||
Module['removeRunDependency']("gamepad");
|
||||
}, false);
|
||||
|
||||
//chrome
|
||||
if(!!navigator.webkitGetGamepads)
|
||||
{
|
||||
var timeout = function()
|
||||
{
|
||||
if(navigator.webkitGetGamepads()[0] !== undefined)
|
||||
Module['removeRunDependency']("gamepad");
|
||||
else
|
||||
setTimeout(timeout, 100);
|
||||
}
|
||||
setTimeout(timeout, 100);
|
||||
}
|
||||
});
|
|
@ -24,6 +24,10 @@
|
|||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_audio.h"
|
||||
|
||||
|
@ -75,6 +79,13 @@ poked(int sig)
|
|||
done = 1;
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
if(done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING))
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -131,8 +142,13 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudio(0);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
SDL_Delay(1000);
|
||||
#endif
|
||||
|
||||
/* Clean up on signal */
|
||||
SDL_CloseAudio();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define NUM_OBJECTS 100
|
||||
|
@ -29,6 +33,8 @@ static int current_alpha = 255;
|
|||
static int current_color = 255;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawPoints(SDL_Renderer * renderer)
|
||||
{
|
||||
|
@ -169,11 +175,35 @@ DrawRects(SDL_Renderer * renderer)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawPoints(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
Uint32 then, now, frames;
|
||||
|
||||
/* Enable standard application logging */
|
||||
|
@ -245,26 +275,16 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
loop();
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
#endif
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawPoints(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
|
||||
|
|
|
@ -14,8 +14,19 @@
|
|||
|
||||
/* Sample program: Draw a Chess Board by using SDL_CreateSoftwareRenderer API */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawChessBoard(SDL_Renderer * renderer)
|
||||
{
|
||||
|
@ -44,12 +55,33 @@ DrawChessBoard(SDL_Renderer * renderer)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event e;
|
||||
if (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if(e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DrawChessBoard(renderer);
|
||||
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Surface *surface;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -83,24 +115,14 @@ main(int argc, char *argv[])
|
|||
|
||||
|
||||
/* Draw the Image on rendering surface */
|
||||
while(1)
|
||||
{
|
||||
SDL_Event e;
|
||||
if (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT)
|
||||
break;
|
||||
|
||||
if(e.key.keysym.sym == SDLK_ESCAPE)
|
||||
break;
|
||||
}
|
||||
|
||||
DrawChessBoard(renderer);
|
||||
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
SDL_UpdateWindowSurface(window);
|
||||
|
||||
done = 0;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,25 @@ main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
char *base_path = SDL_GetBasePath();
|
||||
if(base_path == NULL){
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
|
||||
SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Log("base path: '%s'\n", SDL_GetBasePath());
|
||||
SDL_free(base_path);
|
||||
|
||||
char *pref_path = SDL_GetPrefPath("libsdl", "testfilesystem");
|
||||
if(pref_path == NULL){
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
|
||||
SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));
|
||||
SDL_free(pref_path);
|
||||
|
||||
SDL_Log("base path: '%s'\n", SDL_GetBasePath());
|
||||
SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
|
@ -28,6 +32,40 @@
|
|||
#define SCREEN_HEIGHT 317
|
||||
#endif
|
||||
|
||||
/* This is indexed by SDL_GameControllerButton. */
|
||||
static const struct { int x; int y; } button_positions[] = {
|
||||
{387, 167}, /* A */
|
||||
{431, 132}, /* B */
|
||||
{342, 132}, /* X */
|
||||
{389, 101}, /* Y */
|
||||
{174, 132}, /* BACK */
|
||||
{233, 132}, /* GUIDE */
|
||||
{289, 132}, /* START */
|
||||
{75, 154}, /* LEFTSTICK */
|
||||
{305, 230}, /* RIGHTSTICK */
|
||||
{77, 40}, /* LEFTSHOULDER */
|
||||
{396, 36}, /* RIGHTSHOULDER */
|
||||
{154, 188}, /* DPAD_UP */
|
||||
{154, 249}, /* DPAD_DOWN */
|
||||
{116, 217}, /* DPAD_LEFT */
|
||||
{186, 217}, /* DPAD_RIGHT */
|
||||
};
|
||||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{75, 154, 0.0}, /* LEFTX */
|
||||
{75, 154, 90.0}, /* LEFTY */
|
||||
{305, 230, 0.0}, /* RIGHTX */
|
||||
{305, 230, 90.0}, /* RIGHTY */
|
||||
{91, 0, 90.0}, /* TRIGGERLEFT */
|
||||
{375, 0, 90.0}, /* TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Texture *background, *button, *axis;
|
||||
|
||||
static SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
|
||||
{
|
||||
|
@ -60,50 +98,71 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
|
|||
return texture;
|
||||
}
|
||||
|
||||
void
|
||||
loop(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
SDL_GameController *gamecontroller = (SDL_GameController *)arg;
|
||||
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update visual controller state */
|
||||
for (i = 0; i < SDL_CONTROLLER_BUTTON_MAX; ++i) {
|
||||
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
|
||||
const SDL_Rect dst = { button_positions[i].x, button_positions[i].y, 50, 50 };
|
||||
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
|
||||
if (value < -deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, 0);
|
||||
} else if (value > deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle + 180.0;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (!SDL_GameControllerGetAttached(gamecontroller)) {
|
||||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
WatchGameController(SDL_GameController * gamecontroller)
|
||||
{
|
||||
/* This is indexed by SDL_GameControllerButton. */
|
||||
static const struct { int x; int y; } button_positions[] = {
|
||||
{387, 167}, /* A */
|
||||
{431, 132}, /* B */
|
||||
{342, 132}, /* X */
|
||||
{389, 101}, /* Y */
|
||||
{174, 132}, /* BACK */
|
||||
{233, 132}, /* GUIDE */
|
||||
{289, 132}, /* START */
|
||||
{75, 154}, /* LEFTSTICK */
|
||||
{305, 230}, /* RIGHTSTICK */
|
||||
{77, 40}, /* LEFTSHOULDER */
|
||||
{396, 36}, /* RIGHTSHOULDER */
|
||||
{154, 188}, /* DPAD_UP */
|
||||
{154, 249}, /* DPAD_DOWN */
|
||||
{116, 217}, /* DPAD_LEFT */
|
||||
{186, 217}, /* DPAD_RIGHT */
|
||||
};
|
||||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{75, 154, 0.0}, /* LEFTX */
|
||||
{75, 154, 90.0}, /* LEFTY */
|
||||
{305, 230, 0.0}, /* RIGHTX */
|
||||
{305, 230, 90.0}, /* RIGHTY */
|
||||
{91, 0, 90.0}, /* TRIGGERLEFT */
|
||||
{375, 0, 90.0}, /* TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
const char *name = SDL_GameControllerName(gamecontroller);
|
||||
const char *basetitle = "Game Controller Test: ";
|
||||
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
|
||||
char *title = (char *)SDL_malloc(titlelen);
|
||||
SDL_Texture *background, *button, *axis;
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
||||
if (title) {
|
||||
SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
|
||||
}
|
||||
|
@ -151,56 +210,13 @@ WatchGameController(SDL_GameController * gamecontroller)
|
|||
SDL_Log("Watching controller %s\n", name ? name : "Unknown Controller");
|
||||
|
||||
/* Loop, getting controller events! */
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop_arg(loop, gamecontroller, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update visual controller state */
|
||||
for (i = 0; i < SDL_CONTROLLER_BUTTON_MAX; ++i) {
|
||||
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
|
||||
const SDL_Rect dst = { button_positions[i].x, button_positions[i].y, 50, 50 };
|
||||
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
|
||||
if (value < -deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, 0);
|
||||
} else if (value > deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle + 180.0;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (!SDL_GameControllerGetAttached(gamecontroller)) {
|
||||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
loop(gamecontroler);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#define WIDTH 640
|
||||
#define HEIGHT 480
|
||||
#define BPP 4
|
||||
|
@ -34,6 +38,9 @@ static int eventWrite;
|
|||
|
||||
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
|
||||
|
||||
SDL_Surface *screen;
|
||||
SDL_bool quitting = SDL_FALSE;
|
||||
|
||||
typedef struct {
|
||||
float x,y;
|
||||
} Point;
|
||||
|
@ -161,33 +168,13 @@ SDL_Window* initWindow(SDL_Window *window, int width,int height)
|
|||
return window;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
void loop()
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Surface *screen;
|
||||
SDL_Event event;
|
||||
SDL_bool quitting = SDL_FALSE;
|
||||
SDL_RWops *stream;
|
||||
SDL_Event event;
|
||||
SDL_RWops *stream;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* gesture variables */
|
||||
knob.r = .1f;
|
||||
knob.ang = 0;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
|
||||
|
||||
if (!(window = initWindow(window, WIDTH, HEIGHT)) ||
|
||||
!(screen = SDL_GetWindowSurface(window)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
while(!quitting) {
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
{
|
||||
/* Record _all_ events */
|
||||
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
|
||||
eventWrite++;
|
||||
|
@ -233,7 +220,7 @@ int main(int argc, char* argv[])
|
|||
!(screen = SDL_GetWindowSurface(window)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -278,9 +265,36 @@ int main(int argc, char* argv[])
|
|||
SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
DrawScreen(screen, window);
|
||||
}
|
||||
DrawScreen(screen);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* gesture variables */
|
||||
knob.r = .1f;
|
||||
knob.ang = 0;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
|
||||
|
||||
if (!(screen = initScreen(WIDTH,HEIGHT)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while(!quitting) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
|
117
test/testgles2.c
117
test/testgles2.c
|
@ -14,6 +14,10 @@
|
|||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__NACL__)
|
||||
|
@ -408,17 +412,72 @@ Render(unsigned int width, unsigned int height, shader_data* data)
|
|||
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLES, 0, 36));
|
||||
}
|
||||
|
||||
int done;
|
||||
Uint32 frames;
|
||||
shader_data *datas;
|
||||
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
int status;
|
||||
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event) && !done) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
|
||||
int w, h;
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
break;
|
||||
}
|
||||
/* Change view port to the new window dimensions */
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
state->window_w = event.window.data1;
|
||||
state->window_h = event.window.data2;
|
||||
/* Update window content */
|
||||
Render(event.window.data1, event.window.data2, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
if (!done) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
int i, done;
|
||||
int i;
|
||||
SDL_DisplayMode mode;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
Uint32 then, now;
|
||||
int status;
|
||||
shader_data *datas, *data;
|
||||
shader_data *data;
|
||||
|
||||
/* Initialize parameters */
|
||||
fsaa = 0;
|
||||
|
@ -581,6 +640,7 @@ main(int argc, char *argv[])
|
|||
/* Set rendering settings for each context */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
|
||||
int w, h;
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
@ -588,7 +648,8 @@ main(int argc, char *argv[])
|
|||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
ctx.glViewport(0, 0, state->window_w, state->window_h);
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
|
||||
data = &datas[i];
|
||||
data->angle_x = 0; data->angle_y = 0; data->angle_z = 0;
|
||||
|
@ -630,48 +691,14 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event) && !done) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
break;
|
||||
}
|
||||
/* Change view port to the new window dimensions */
|
||||
ctx.glViewport(0, 0, event.window.data1, event.window.data2);
|
||||
/* Update window content */
|
||||
Render(event.window.data1, event.window.data2, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
if (!done) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while(0)
|
||||
|
@ -30,6 +34,9 @@ static int current_alpha = 255;
|
|||
static int current_color = 255;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
|
||||
int mouse_begin_x = -1, mouse_begin_y = -1;
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawPoints(SDL_Renderer * renderer)
|
||||
{
|
||||
|
@ -191,12 +198,71 @@ DrawRectRectIntersections(SDL_Renderer * renderer)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mouse_begin_x = event.button.x;
|
||||
mouse_begin_y = event.button.y;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (event.button.button == 3)
|
||||
add_line(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
if (event.button.button == 1)
|
||||
add_rect(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case 'l':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
num_lines = 0;
|
||||
else
|
||||
add_line(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
break;
|
||||
case 'r':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
num_rects = 0;
|
||||
else
|
||||
add_rect(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawPoints(renderer);
|
||||
DrawRectRectIntersections(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawRectLineIntersections(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int mouse_begin_x = -1, mouse_begin_y = -1;
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
Uint32 then, now, frames;
|
||||
|
||||
/* Enable standard application logging */
|
||||
|
@ -268,62 +334,15 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mouse_begin_x = event.button.x;
|
||||
mouse_begin_y = event.button.y;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (event.button.button == 3)
|
||||
add_line(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
if (event.button.button == 1)
|
||||
add_rect(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case 'l':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
num_lines = 0;
|
||||
else
|
||||
add_line(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
break;
|
||||
case 'r':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
num_rects = 0;
|
||||
else
|
||||
add_rect(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawPoints(renderer);
|
||||
DrawRectRectIntersections(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawRectLineIntersections(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
|
@ -28,6 +32,9 @@
|
|||
#define SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
|
||||
static void
|
||||
DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
||||
|
@ -36,50 +43,15 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
|||
SDL_RenderFillRect(r, &area);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
void
|
||||
loop(void *arg)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
const char *name = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
SDL_Joystick *joystick = (SDL_Joystick *)arg;
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderPresent(screen);
|
||||
SDL_RaiseWindow(window);
|
||||
|
||||
/* Print info about the joystick we are watching */
|
||||
name = SDL_JoystickName(joystick);
|
||||
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
|
||||
name ? name : "Unknown Joystick");
|
||||
SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
|
||||
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
|
||||
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
while (!done) {
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_SetRenderDrawColor(screen, 0x0, 0x0, 0x0, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
|
@ -197,8 +169,53 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
const char *name = NULL;
|
||||
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderPresent(screen);
|
||||
SDL_RaiseWindow(window);
|
||||
|
||||
/* Print info about the joystick we are watching */
|
||||
name = SDL_JoystickName(joystick);
|
||||
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
|
||||
name ? name : "Unknown Joystick");
|
||||
SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
|
||||
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
|
||||
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop_arg(loop, joystick, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop(joystick);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return retval;
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
#include <stdio.h> /* for fflush() and stdout */
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
static SDL_AudioSpec spec;
|
||||
static Uint8 *sound = NULL; /* Pointer to wave data */
|
||||
static Uint32 soundlen = 0; /* Length of wave data */
|
||||
|
@ -24,6 +28,8 @@ typedef struct
|
|||
volatile int done;
|
||||
} callback_data;
|
||||
|
||||
callback_data cbd[64];
|
||||
|
||||
void SDLCALL
|
||||
play_through_once(void *arg, Uint8 * stream, int len)
|
||||
{
|
||||
|
@ -44,10 +50,21 @@ play_through_once(void *arg, Uint8 * stream, int len)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
if(cbd[0].done) {
|
||||
emscripten_cancel_main_loop();
|
||||
SDL_PauseAudioDevice(cbd[0].dev, 1);
|
||||
SDL_CloseAudioDevice(cbd[0].dev);
|
||||
SDL_FreeWAV(sound);
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_multi_audio(int devcount)
|
||||
{
|
||||
callback_data cbd[64];
|
||||
int keep_going = 1;
|
||||
int i;
|
||||
|
||||
|
@ -78,14 +95,19 @@ test_multi_audio(int devcount)
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device failed: %s\n", SDL_GetError());
|
||||
} else {
|
||||
SDL_PauseAudioDevice(cbd[0].dev, 0);
|
||||
while (!cbd[0].done) {
|
||||
#ifdef __ANDROID__
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!cbd[0].done)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
/* Empty queue, some application events would prevent pause. */
|
||||
while (SDL_PollEvent(&event)){}
|
||||
#endif
|
||||
#endif
|
||||
SDL_Delay(100);
|
||||
}
|
||||
SDL_PauseAudioDevice(cbd[0].dev, 1);
|
||||
#endif
|
||||
SDL_Log("done.\n");
|
||||
SDL_CloseAudioDevice(cbd[0].dev);
|
||||
}
|
||||
|
@ -116,21 +138,13 @@ test_multi_audio(int devcount)
|
|||
keep_going = 1;
|
||||
}
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
#ifdef __ANDROID__
|
||||
/* Empty queue, some application events would prevent pause. */
|
||||
while (SDL_PollEvent(&event)){}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SDL_Delay(100);
|
||||
}
|
||||
|
||||
for (i = 0; i < devcount; i++) {
|
||||
if (cbd[i].dev) {
|
||||
SDL_PauseAudioDevice(cbd[i].dev, 1);
|
||||
SDL_CloseAudioDevice(cbd[i].dev);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Log("All done!\n");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#define MOOSEPIC_W 64
|
||||
|
@ -135,6 +139,18 @@ SDL_Color MooseColors[84] = {
|
|||
, {239, 206, 173}
|
||||
};
|
||||
|
||||
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE*2];
|
||||
SDL_Texture *MooseTexture;
|
||||
SDL_Rect displayrect;
|
||||
int window_w;
|
||||
int window_h;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
int paused = 0;
|
||||
int i;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
Uint32 pixel_format = SDL_PIXELFORMAT_YV12;
|
||||
int fpsdelay;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
|
@ -246,21 +262,65 @@ PrintUsage(char *argv0)
|
|||
SDL_Log("\n");
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
SDL_RenderSetViewport(renderer, NULL);
|
||||
displayrect.w = window_w = event.window.data1;
|
||||
displayrect.h = window_h = event.window.data2;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
displayrect.x = event.button.x - window_w / 2;
|
||||
displayrect.y = event.button.y - window_h / 2;
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if (event.motion.state) {
|
||||
displayrect.x = event.motion.x - window_w / 2;
|
||||
displayrect.y = event.motion.y - window_h / 2;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
paused = !paused;
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
SDL_Delay(fpsdelay);
|
||||
#endif
|
||||
|
||||
if (!paused) {
|
||||
i = (i + 1) % MOOSEFRAMES_COUNT;
|
||||
|
||||
SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W*SDL_BYTESPERPIXEL(pixel_format));
|
||||
}
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, MooseTexture, NULL, &displayrect);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
Uint8 *RawMooseData;
|
||||
SDL_RWops *handle;
|
||||
int window_w;
|
||||
int window_h;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE*2];
|
||||
SDL_Texture *MooseTexture;
|
||||
SDL_Rect displayrect;
|
||||
SDL_Event event;
|
||||
int paused = 0;
|
||||
int i, j;
|
||||
int j;
|
||||
int fps = 12;
|
||||
int fpsdelay;
|
||||
int nodelay = 0;
|
||||
|
@ -270,7 +330,6 @@ main(int argc, char **argv)
|
|||
Uint32 pixel_format = SDL_PIXELFORMAT_YV12;
|
||||
#endif
|
||||
int scale = 5;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -430,50 +489,14 @@ main(int argc, char **argv)
|
|||
SDL_EventState(SDL_KEYUP, SDL_IGNORE);
|
||||
|
||||
/* Loop, waiting for QUIT or RESIZE */
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, nodelay ? 0 : fps, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
SDL_RenderSetViewport(renderer, NULL);
|
||||
displayrect.w = window_w = event.window.data1;
|
||||
displayrect.h = window_h = event.window.data2;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
displayrect.x = event.button.x - window_w / 2;
|
||||
displayrect.y = event.button.y - window_h / 2;
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if (event.motion.state) {
|
||||
displayrect.x = event.motion.x - window_w / 2;
|
||||
displayrect.y = event.motion.y - window_h / 2;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
paused = !paused;
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
loop();
|
||||
}
|
||||
}
|
||||
SDL_Delay(fpsdelay);
|
||||
#endif
|
||||
|
||||
if (!paused) {
|
||||
i = (i + 1) % MOOSEFRAMES_COUNT;
|
||||
|
||||
SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W*SDL_BYTESPERPIXEL(pixel_format));
|
||||
}
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, MooseTexture, NULL, &displayrect);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
quit(0);
|
||||
return 0;
|
||||
|
|
|
@ -18,8 +18,14 @@
|
|||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
int i, done;
|
||||
SDL_Rect rect;
|
||||
SDL_Event event;
|
||||
|
||||
static void
|
||||
DrawRects(SDL_Renderer * renderer, SDL_Rect * rect)
|
||||
|
@ -28,12 +34,36 @@ DrawRects(SDL_Renderer * renderer, SDL_Rect * rect)
|
|||
SDL_RenderFillRect(renderer, rect);
|
||||
}
|
||||
|
||||
static void
|
||||
loop(){
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
switch(event.type) {
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
rect.x += event.motion.xrel;
|
||||
rect.y += event.motion.yrel;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer, &rect);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Rect rect;
|
||||
SDL_Event event;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -69,32 +99,13 @@ main(int argc, char *argv[])
|
|||
rect.h = 10;
|
||||
/* Main render loop */
|
||||
done = 0;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
switch(event.type) {
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
rect.x += event.motion.xrel;
|
||||
rect.y += event.motion.yrel;
|
||||
}
|
||||
break;
|
||||
}
|
||||
loop();
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer, &rect);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
SDLTest_CommonQuit(state);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
|
||||
|
@ -29,6 +33,9 @@ typedef struct {
|
|||
int scale_direction;
|
||||
} DrawState;
|
||||
|
||||
DrawState *drawstates;
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
@ -130,12 +137,27 @@ Draw(DrawState *s)
|
|||
/* SDL_Delay(10); */
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
Draw(&drawstates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
DrawState *drawstates;
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
int frames;
|
||||
Uint32 then, now;
|
||||
|
||||
|
@ -181,19 +203,15 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
Draw(&drawstates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
++frames;
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
|
||||
|
@ -29,6 +33,10 @@ typedef struct {
|
|||
int scale_direction;
|
||||
} DrawState;
|
||||
|
||||
DrawState *drawstates;
|
||||
int done;
|
||||
SDL_bool test_composite = SDL_FALSE;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
@ -214,15 +222,33 @@ Draw(DrawState *s)
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
if (test_composite) {
|
||||
if (!DrawComposite(&drawstates[i])) done = 1;
|
||||
} else {
|
||||
if (!Draw(&drawstates[i])) done = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
DrawState *drawstates;
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
int frames;
|
||||
Uint32 then, now;
|
||||
SDL_bool test_composite = SDL_FALSE;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -278,22 +304,15 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
if (test_composite) {
|
||||
if (!DrawComposite(&drawstates[i])) done = 1;
|
||||
} else {
|
||||
if (!Draw(&drawstates[i])) done = 1;
|
||||
}
|
||||
}
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define WINDOW_WIDTH 640
|
||||
|
@ -31,6 +35,9 @@ typedef struct {
|
|||
int scale_direction;
|
||||
} DrawState;
|
||||
|
||||
DrawState *drawstates;
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
@ -120,12 +127,27 @@ Draw(DrawState *s)
|
|||
SDL_RenderPresent(s->renderer);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
Draw(&drawstates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
DrawState *drawstates;
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
int frames;
|
||||
Uint32 then, now;
|
||||
|
||||
|
@ -171,18 +193,15 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
Draw(&drawstates[i]);
|
||||
}
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test.h"
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
|
@ -38,6 +42,8 @@ static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
|
|||
/* -1: infinite random moves (default); >=0: enables N deterministic moves */
|
||||
static int iterations = -1;
|
||||
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
@ -230,11 +236,27 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
MoveSprites(state->renderers[i], sprites[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
Uint32 then, now, frames;
|
||||
Uint64 seed;
|
||||
const char *icon = "icon.bmp";
|
||||
|
@ -351,18 +373,15 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
MoveSprites(state->renderers[i], sprites[i]);
|
||||
}
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#define WINDOW_WIDTH 640
|
||||
|
@ -27,6 +31,9 @@ static SDL_Rect positions[NUM_SPRITES];
|
|||
static SDL_Rect velocities[NUM_SPRITES];
|
||||
static int sprite_w, sprite_h;
|
||||
|
||||
SDL_Renderer *renderer;
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
@ -118,13 +125,25 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN) {
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
MoveSprites(renderer, sprite);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -154,16 +173,14 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Main render loop */
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN) {
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
MoveSprites(renderer, sprite);
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
quit(0);
|
||||
|
||||
return 0; /* to prevent compiler warning */
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#define MOOSEPIC_W 64
|
||||
|
@ -52,6 +56,11 @@ SDL_Color MooseColors[84] = {
|
|||
|
||||
Uint8 MooseFrames[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE];
|
||||
|
||||
SDL_Renderer *renderer;
|
||||
int frame;
|
||||
SDL_Texture *MooseTexture;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
|
||||
void quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
|
@ -82,16 +91,37 @@ void UpdateTexture(SDL_Texture *texture, int frame)
|
|||
SDL_UnlockTexture(texture);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
frame = (frame + 1) % MOOSEFRAMES_COUNT;
|
||||
UpdateTexture(MooseTexture, frame);
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, MooseTexture, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_RWops *handle;
|
||||
SDL_Texture *MooseTexture;
|
||||
SDL_Event event;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
int frame;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -136,27 +166,15 @@ main(int argc, char **argv)
|
|||
|
||||
/* Loop, waiting for QUIT or the escape key */
|
||||
frame = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
frame = (frame + 1) % MOOSEFRAMES_COUNT;
|
||||
UpdateTexture(MooseTexture, frame);
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, MooseTexture, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
|
||||
quit(0);
|
||||
|
|
|
@ -15,12 +15,23 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test.h"
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
|
||||
SDL_Rect viewport;
|
||||
int done, j;
|
||||
SDL_bool use_target = SDL_FALSE;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
Uint32 wait_start;
|
||||
#endif
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
@ -77,14 +88,54 @@ DrawOnViewport(SDL_Renderer * renderer, SDL_Rect viewport)
|
|||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
/* Avoid using delays */
|
||||
if(SDL_GetTicks() - wait_start < 1000)
|
||||
return;
|
||||
wait_start = SDL_GetTicks();
|
||||
#endif
|
||||
SDL_Event event;
|
||||
int i;
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
|
||||
/* Move a viewport box in steps around the screen */
|
||||
viewport.x = j * 100;
|
||||
viewport.y = viewport.x;
|
||||
viewport.w = 100 + j * 50;
|
||||
viewport.h = 100 + j * 50;
|
||||
j = (j + 1) % 4;
|
||||
SDL_Log("Current Viewport x=%i y=%i w=%i h=%i", viewport.x, viewport.y, viewport.w, viewport.h);
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
|
||||
/* Draw using viewport */
|
||||
DrawOnViewport(state->renderers[i], viewport);
|
||||
|
||||
/* Update the screen! */
|
||||
if (use_target) {
|
||||
SDL_SetRenderTarget(state->renderers[i], NULL);
|
||||
SDL_RenderCopy(state->renderers[i], state->targets[i], NULL, NULL);
|
||||
SDL_RenderPresent(state->renderers[i]);
|
||||
SDL_SetRenderTarget(state->renderers[i], state->targets[i]);
|
||||
} else {
|
||||
SDL_RenderPresent(state->renderers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, j, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
Uint32 then, now, frames;
|
||||
SDL_Rect viewport;
|
||||
SDL_bool use_target = SDL_FALSE;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
|
@ -135,41 +186,17 @@ main(int argc, char *argv[])
|
|||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
j = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
|
||||
/* Move a viewport box in steps around the screen */
|
||||
viewport.x = j * 100;
|
||||
viewport.y = viewport.x;
|
||||
viewport.w = 100 + j * 50;
|
||||
viewport.h = 100 + j * 50;
|
||||
j = (j + 1) % 4;
|
||||
SDL_Log("Current Viewport x=%i y=%i w=%i h=%i", viewport.x, viewport.y, viewport.w, viewport.h);
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
|
||||
/* Draw using viewport */
|
||||
DrawOnViewport(state->renderers[i], viewport);
|
||||
|
||||
/* Update the screen! */
|
||||
if (use_target) {
|
||||
SDL_SetRenderTarget(state->renderers[i], NULL);
|
||||
SDL_RenderCopy(state->renderers[i], state->targets[i], NULL, NULL);
|
||||
SDL_RenderPresent(state->renderers[i]);
|
||||
SDL_SetRenderTarget(state->renderers[i], state->targets[i]);
|
||||
} else {
|
||||
SDL_RenderPresent(state->renderers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
wait_start = SDL_GetTicks();
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
++frames;
|
||||
loop();
|
||||
SDL_Delay(1000);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
|
|
111
test/testwm2.c
111
test/testwm2.c
|
@ -13,22 +13,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
static const char *cursorNames[] = {
|
||||
static const char *cursorNames[] = {
|
||||
"arrow",
|
||||
"ibeam",
|
||||
"wait",
|
||||
|
@ -41,44 +35,22 @@ main(int argc, char *argv[])
|
|||
"sizeALL",
|
||||
"NO",
|
||||
"hand",
|
||||
};
|
||||
};
|
||||
int system_cursor = -1;
|
||||
SDL_Cursor *cursor = NULL;
|
||||
|
||||
int i, done;
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
int system_cursor = -1;
|
||||
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);
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
state->skip_renderer = SDL_TRUE;
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
|
||||
quit(1);
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
|
@ -128,7 +100,50 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
state->skip_renderer = SDL_TRUE;
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
}
|
||||
if (consumed < 0) {
|
||||
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
|
||||
quit(1);
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
done = 0;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
SDL_FreeCursor(cursor);
|
||||
|
||||
quit(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue