diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-18 20:25:40 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-06-18 20:25:40 -0700 |
commit | ad01a1896200d9ab8eff3f8485a99e70e72530c4 (patch) | |
tree | e204d6cde21933e39981f5ddd09cef4eb4cd3018 /tests/hello_world_sdl.cpp | |
parent | 3963031492acab163f8fa440aaf50661d954506b (diff) | |
parent | 9ee4ca4af663921dace9aa6bcdd206825adf145e (diff) |
Merge pull request #1304 from int3/sdl
Fix SDL color encoding
Diffstat (limited to 'tests/hello_world_sdl.cpp')
-rw-r--r-- | tests/hello_world_sdl.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/tests/hello_world_sdl.cpp b/tests/hello_world_sdl.cpp index b6401995..eeaad0cd 100644 --- a/tests/hello_world_sdl.cpp +++ b/tests/hello_world_sdl.cpp @@ -2,7 +2,7 @@ #include <SDL/SDL.h> -int main() { +extern "C" int main(int argc, char** argv) { printf("hello, world!\n"); SDL_Init(SDL_INIT_VIDEO); @@ -11,10 +11,8 @@ int main() { if (SDL_MUSTLOCK(screen)) SDL_LockSurface(screen); for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { - *((char*)screen->pixels + i*256*4 + j*4 + 0) = i; - *((char*)screen->pixels + i*256*4 + j*4 + 1) = j; - *((char*)screen->pixels + i*256*4 + j*4 + 2) = 255-i; - *((char*)screen->pixels + i*256*4 + j*4 + 3) = (i+j)%255; // actually ignored, since this is to the screen + // alpha component is actually ignored, since this is to the screen + *((Uint32*)screen->pixels + i * 256 + j) = SDL_MapRGBA(screen->format, i, j, 255-i, (i+j) % 255); } } if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); |