mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-05 01:16:26 +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:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user