mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-04 19:07:40 +00:00
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!)
This commit is contained in:
parent
a228b67d88
commit
fe40a17224
61 changed files with 4047 additions and 600 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue