debuxar3.c (1259B)
1 /* 2 * Debuxar sen render, modificando a superficie da xanela 3 * Autor: G. Xoel Otero 4 */ 5 6 #include <SDL2/SDL.h> 7 #include <stdio.h> 8 #define DIMX 400 9 #define DIMY 300 10 11 12 // Igual que memset pero copia 4 bytes de value tantas veces como 13 // indique size na direccion de memoria indicada polo punteiro dest 14 // A funcion orixinal de memset so copia 1 byte x veces nunha direccion 15 void memset32( void * dest, Uint32 value, uintptr_t size ) { 16 uintptr_t i; 17 for( i = 0; i < (size & (~3)); i+=4 ) 18 memcpy( ((char*)dest) + i, &value, 4 ); 19 } 20 21 22 int main() { 23 SDL_Init(SDL_INIT_EVERYTHING); 24 SDL_Window *win = SDL_CreateWindow("debuxar", SDL_WINDOWPOS_UNDEFINED, 25 SDL_WINDOWPOS_UNDEFINED, 400, 300, 0); 26 SDL_Surface *window_surface = SDL_GetWindowSurface(win); 27 Uint32* buffer = (Uint32*) window_surface->pixels; 28 //Uint32 cor = SDL_MapRGBA(window_surface->format, 255, 0, 0, 255); 29 Uint32 cor = 0x00ff0000; 30 for (int i=0; i<1000; i++) { 31 cor += 0x00000001; 32 cor -= 0x00010000; 33 cor &= 0x00ffffff; 34 memset32(buffer, cor, 400 * 300 * 4); 35 SDL_UpdateWindowSurface(win); 36 SDL_Delay(10); 37 printf("Cor: %x\n", cor); 38 } 39 SDL_DestroyWindow(win); 40 SDL_Quit(); 41 return 0; 42 }