Why this code doesn’t blit on the screen all the bits contained in 'buffer’
but only ~1/4
Thanks a lot
I think it must be a problem in Uint formats or someting like this
Logarno
void loadbmp(char *filename, unsigned char *bitmap)
{
FILE *f;
int line;
unsigned char *ptr;
f = fopen(filename,“rb”);
fseek(f,1078,SEEK_SET);
for(line=199;line>=0;line–)
{
ptr=(unsigned char )bitmap+line320;
fread(ptr,320,1,f);
}
fclose(f);
}
int main()
{
SDL_Surface *screen;
int i;
Uint8 *bits, *buffer, **bufptr;
/* Initialisation de la SDL */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Problem: %s\n", SDL_GetError());
exit(1);
}
/* S?lectionne le mode vid?o */
screen = SDL_SetVideoMode(320, 200, 0, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Problem: %s\n", SDL_GetError());
exit(1);
}
buffer=(Uint8 )malloc(screen->hscreen->w*screen->format->BytesPerPixel);
loadbmp(“img.bmp”,buffer);
SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
while (SDL_PollEvent(NULL)==0){
/* Dessine des bandes de couleurs sur la surface brute */
if ( SDL_MUSTLOCK(screen) ) {
if ( SDL_LockSurface(screen) < 0 ) {
fprintf(stderr, “Problem: %s\n”, SDL_GetError());
exit(1);
}
}
bits=(Uint32 *)screen->pixels;
bufptr=(Uint8 )buffer;
for ( i=0; ih; i++ ) {
memcpy(bits,bufptr,screen->wscreen->format->BytesPerPixel);
bits += screen->pitch;
bufptr += 320;
}
if ( SDL_MUSTLOCK(screen) ) {
SDL_UnlockSurface(screen);
}
SDL_Flip(screen);
}
exit(0);
}