Permalink
Browse files

Example: Attempt 32/16-bit colors based on response

  • Loading branch information...
endrift committed Jan 26, 2018
1 parent 3a9d77d commit 8aaa6105020f2ecae1b0cef29dbdb90c0a53cd57
Showing with 19 additions and 18 deletions.
  1. +19 −18 src/platform/example/client-server/client.c
@@ -29,35 +29,36 @@ int main() {
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)
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

0 comments on commit 8aaa610

Please sign in to comment.