Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <SDL2/SDL.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. Uint16 CreateHiColorPixel(SDL_PixelFormat * fmt, Uint8 red,
  6. Uint8 green, Uint8 blue)
  7. {
  8.     Uint16 value;
  9.    
  10.     value = ((red >> fmt->Rloss)<< fmt->Rshift) +
  11.     ((green >> fmt->Gloss) << fmt->Gshift) +
  12.     ((blue >> fmt->Bloss) << fmt->Bshift );
  13.    
  14.     return value;
  15. }
  16.  
  17. int main()
  18. {
  19.     SDL_Surface *screen;
  20.     Uint16 *raw_pixels;
  21.     int x,y;
  22.    
  23.     if (SDL_Init(SDL_INIT_VIDEO) != 0) {
  24.         printf("Unable to initialize SDL: %s\n", SDL_GetError());
  25.         return -1;
  26.     }
  27.    
  28.     atexit(SDL_Quit);
  29.    
  30.     screen = SDL_SetVideoMode(256, 256, 16, 0);
  31.     if (screen == NULL) {
  32.         printf("Unable to set video mode: %s\n", SDL_GetError());
  33.         return -1;
  34.     }
  35.  
  36.     SDL_LockSurface(screen);
  37.    
  38.     raw_pixels = (Uint16 *) screen->pixels;
  39.    
  40.     for (x=0; x < 256; x++)
  41.         for (y=0; y < 256; y++) {
  42.             Uint16 pixel_color;
  43.             int offset;
  44.             pixel_color = CreateHicolorPixel(screen->format, x, 0, y);
  45.             offset = (screen->pitch / 2 * y + x);
  46.             raw_pixels[offset] = pixel_color;
  47.     }
  48.  
  49.  
  50.  
  51. SDL_UnlockSurface(screen);
  52.  
  53. SDL_UpdateRect(screen, 0, 0, 0, 0);
  54.  
  55. SDL_Delay(3000);
  56.  
  57. return 0;
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement