all repos — mgba @ 8aaa6105020f2ecae1b0cef29dbdb90c0a53cd57

mGBA Game Boy Advance Emulator

Example: Attempt 32/16-bit colors based on response
Vicki Pfau vi@endrift.com
Thu, 25 Jan 2018 18:40:22 -0800
commit

8aaa6105020f2ecae1b0cef29dbdb90c0a53cd57

parent

3a9d77d9e0fe59d488a538474381a564b1c061d3

1 files changed, 19 insertions(+), 18 deletions(-)

jump to
M src/platform/example/client-server/client.csrc/platform/example/client-server/client.c

@@ -29,19 +29,19 @@ SocketRecv(server, &height, sizeof(height));

SocketRecv(server, &bpp, sizeof(bpp)); width = ntohl(width); height = ntohl(height); - if (ntohl(bpp) != BYTES_PER_PIXEL) { + bpp = ntohl(bpp); + ssize_t bufferSize = width * height * bpp; + +#if !SDL_VERSION_ATLEAST(2, 0, 0) + if (bpp == 2) { + SDL_SetVideoMode(width, height, 16, SDL_DOUBLEBUF | SDL_HWSURFACE); + } else if (bpp == 4) { + SDL_SetVideoMode(width, height, 32, SDL_DOUBLEBUF | SDL_HWSURFACE); + } else { SocketClose(server); SocketSubsystemDeinit(); return 1; } - ssize_t bufferSize = width * height * BYTES_PER_PIXEL; - -#if !SDL_VERSION_ATLEAST(2, 0, 0) -#ifdef COLOR_16_BIT - SDL_SetVideoMode(width, height, 16, SDL_DOUBLEBUF | SDL_HWSURFACE); -#else - SDL_SetVideoMode(width, height, 32, SDL_DOUBLEBUF | SDL_HWSURFACE); -#endif #endif #if SDL_VERSION_ATLEAST(2, 0, 0)

@@ -49,15 +49,16 @@ SDL_Window* window = SDL_CreateWindow(projectName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);

SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); Uint32 pixfmt; -#ifdef COLOR_16_BIT -#ifdef COLOR_5_6_5 - pixfmt = SDL_PIXELFORMAT_RGB565; -#else - pixfmt = SDL_PIXELFORMAT_ABGR1555; -#endif -#else - pixfmt = SDL_PIXELFORMAT_ABGR8888; -#endif + if (bpp == 2) { + pixfmt = SDL_PIXELFORMAT_RGB565; + } else if (bpp == 4) { + pixfmt = SDL_PIXELFORMAT_ABGR8888; + } else { + SocketClose(server); + SocketSubsystemDeinit(); + return 1; + } + SDL_Texture* sdlTex = SDL_CreateTexture(renderer, pixfmt, SDL_TEXTUREACCESS_STREAMING, width, height); #endif