Primer programčka v SDL - nalaganje slike
Primer programčka, ki naloži in skopira slikico. Poiščite napake in grde programerske prijeme!
Koda:
Uint32 x,y,i, minw; short int c; Uint8 *pimage, *pdisplay; SDL_Init(SDL_INIT_VIDEO); display = SDL_SetVideoMode( 450, 480, 32, SDL_HWSURFACE); /*for (i=0; i!=255; i++){*/ if (SDL_MUSTLOCK(display)) SDL_LockSurface(display); temp = SDL_LoadBMP("lenna.bmp"); if (temp == NULL) { printf("Unable to load bitmap: %s\n", SDL_GetError()); return 1; } image = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); /* for(y=0; y<(display->h); y++) { for(x=0; x<(display->w); x++) { c = (x%256)*256 + (y%256)*65536; *((Uint32*)display->pixels + (y * display->w + x)) = c; } } */ /* SDL_BlitSurface(image, 0, display, 0); */ minw = display->w; if (image->w < minw) minw = image->w; for(y=0; y<(display->h); y++) { for(x=0; x< (4*minw); x++) { pdisplay = (Uint8*)display->pixels + (4*y * display->w + x); pimage = (Uint8*)image->pixels + (4*y * image->w + x); c = *pimage; c = c - 100; if (c > 255) c = 255; if (c < 0) c = 0; *pdisplay = c; } } if ( SDL_MUSTLOCK(display) ) SDL_UnlockSurface(display); SDL_UpdateRect(display, 0, 0, display->w, display->h); /*}*/ SDL_Delay(5000); return 0; }