This is a multi-part message in MIME format.
--------------EBA6C974CF47D7E826FD9CDA
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Mattias Engdeg?rd wrote:
I am currently porting an amiga game to linux/sdl.Yesterday I compiled
the whole thing new and realized that some blittings
doesn’t succeed anymore, which befor I installed SDL 1.2.0 was okay.
please write a minimal compilable example that shows the problem
Attached you will fin the example.Sorry for the delay.Was on tour for my
company.
Best regards
Anes
--------------EBA6C974CF47D7E826FD9CDA
Content-Type: text/plain; charset=us-ascii;
name="main.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename=“main.c”
#include <string.h>
#include <SDL/SDL.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
static SDL_Surface *screen;
char *data;
char *palette;
int opengfx()
{
screen=NULL;
if(SDL_Init(SDL_INIT_VIDEO)<0)
{
fprintf(stderr,"Sorry unable to Init SDL. SDL: %s\n",SDL_GetError());
return -1;
}
screen=SDL_SetVideoMode(640,480,8,SDL_HWSURFACE|SDL_HWPALETTE);
atexit(SDL_Quit);
if(!screen)
{
fprintf(stderr,"Sorry.Unable to desired Video Mode.SDL: %s\n",SDL_GetError());
return -1;
}
return 0;
}
void closegfx()
{
SDL_Quit();
}
int LoadPic(char *name)
{
int fin=-1;
fin=open(name,O_RDONLY);
if(!fin)
{
fprintf(stderr,"Sorry.Unable to open file %s.\n",name);
return -1;
}
data=(char*)malloc(64000);
palette=(char*)malloc(768);
if(data && palette)
{
char temp[310];
read(fin,temp,310);
read(fin,palette,768);
read(fin,data,64000);
}else
{
fprintf(stderr,"Sorry unable to get enough memory.\n");
close(fin);
return -1;
}
close(fin);
return 0;
}
int main(int argc,char *argv[])
{
SDL_Event event;
int done;
int rc1=-1,rc2=-1;
int i,j;
int bpp;
Uint8 *ptr,*ptr2;
SDL_Surface *picture=NULL;
SDL_Rect rect;
SDL_Color *colors;
int ncolors=256;
opengfx();
rc1=LoadPic("pinguin");
if(rc1!=0)
fprintf(stderr,"Error with Reading File.\n");
//Direct draw to surface, which works
//to enable replace #if 0 with #if 1
//and comment the Blit a bit down
#if 0
SDL_LockSurface(screen);
bpp=screen->format->BytesPerPixel;
ptr=(Uint8*)screen->pixels;
for(i=0;i<320;i++)
for(j=0;j<200;j++)
ptr[j*screen->pitch+i*bpp]=data[j*320+i];
SDL_UnlockSurface(screen);
#endif
picture=SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWPALETTE,320,200,8,0,0,0,0);
if(!picture)
{
fprintf(stderr,"Sorry. Unable to make Picture Surface.SDL: %s\n",SDL_GetError());
goto end;
}
colors=(SDL_Color*)malloc(ncolors*sizeof(SDL_Color));
for(i=0;i<256;i++)
{
colors[i].r=data[i*3];
colors[i].g=data[i*3+1];
colors[i].b=data[i*3+2];
}
rc2=SDL_SetColors(picture,colors,0,256);
rc1=SDL_SetColors(screen,colors,0,256);
fprintf(stderr,"Color setting for screen was %d and for picture was %d.\n",rc1,rc2);
//Preparing the blit
//not sure if i made this correct
SDL_LockSurface(picture);
ptr2=(Uint8*)picture->pixels;
for(i=0;i<200;++i)
{
//Funny, with this it works !!!
// memset(ptr2,(i*255)/200,320);
memcpy(ptr,data,320);
ptr2+=320;
data+=320;
}
SDL_UnlockSurface(picture);
rect.x=0;
rect.y=0;
rect.w=320;
rect.h=200;
rc1=SDL_BlitSurface(picture,NULL,screen,&rect);
fprintf(stderr,"Blitting was %d.\n",rc1);
SDL_UpdateRects(screen,1,&rect);
done=0;
while(!done)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYUP:
case SDL_KEYDOWN:
{
Uint8* keys;
keys=SDL_GetKeyState(NULL);
if(keys[SDLK_ESCAPE]==SDL_PRESSED)
{
done=1;
break;
}
}
}
}
}
end:
SDL_FreeSurface(picture);
free(data);
free(palette);
closegfx();
return 0;
}
--------------EBA6C974CF47D7E826FD9CDA–