Created
July 10, 2012 23:33
-
-
Save nandhp/3086941 to your computer and use it in GitHub Desktop.
Test program for emscripten bug with SDL_MapRGB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDL/SDL.h> | |
#ifdef EMSCRIPTEN | |
#include <emscripten.h> | |
// Implementation of SDL_MapRGB and SDL_MapRGBA that isn't totally broken: | |
// #define SDL_MapRGB(fmt,r,g,b) (0xff+((b)<<8)+((g)<<16)+((r)<<24)) | |
// #define SDL_MapRGBA(fmt,r,g,b,a) ((a)+((b)<<8)+((g)<<16)+((r)<<24)) | |
#endif | |
void one() { | |
SDL_Event event; | |
while (SDL_PollEvent(&event)) 1; | |
} | |
int main() { | |
Uint32 c; | |
SDL_Rect rect = {0,0,300,450}; | |
SDL_Init(SDL_INIT_VIDEO); | |
SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); | |
c = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00); // OPAQUE RED | |
SDL_FillRect(screen, &rect, c); | |
rect.x = 300; | |
c = SDL_MapRGB(screen->format, 0x7f, 0x7f, 0x00); // OPAQUE MUSTARD | |
SDL_FillRect(screen, &rect, c); | |
SDL_UpdateRect(screen, 0, 0, 600, 450); | |
#ifdef EMSCRIPTEN | |
emscripten_set_main_loop(one, 0); | |
#else | |
while (1) { one(); SDL_WaitEvent(NULL); } | |
#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment