Code:
void PutImageEx(int x,int y,BYTE far *Buffer,WORD width,WORD height,BYTE tcolor)
{
WORD BitmapStartOffsetX=0;
WORD BitmapStartOffsetY=0;
WORD ScreenOffset=0;
WORD BitmapOffset=0;
int ScreenWidth=width;
int ScreenHeight=height;
if (x<0)
{
BitmapStartOffsetX=0-x;
ScreenWidth+=x;
if (ScreenWidth<0) ScreenWidth=0;
width=ScreenWidth;
x=0;
}
if (y<0)
{
BitmapStartOffsetY=0-y;
ScreenHeight+=y;
if (ScreenHeight<0) ScreenHeight=0;
y=0;
}
ScreenOffset=ScreenAddr[y]+x;
BitmapOffset=BitmapStartOffsetY*(width)+BitmapStar
tOffsetX;
if ((x+width)>320) ScreenWidth=(320-x);
if ((y+height)>200) ScreenHeight=201-y;
ScreenHeight--;
if (ScreenWidth && ScreenHeight)
{
asm {
push ds
cld
les di,[ScreenPtr]
mov di,[ScreenOffset]
lds si,[Buffer]
mov si,[BitmapOffset]
add si,4
xor cx,cx
xor dx,dx
}
DRAWBITMAP:
asm {
inc dx
mov cx,[ScreenWidth]
}
DRAWLINE:
asm {
mov al,[ds:si]
cmp al,tcolor
jz NOBLIT
movsb
LOOP DRAWLINE
jmp NEXTLINE
}
NOBLIT:
asm {
inc si
inc di
LOOP DRAWLINE
}
NEXTLINE:
asm {
mov bx,[BitmapOffset]
add bx,[width]
add bx,[BitmapStartOffsetX]
mov [BitmapOffset],bx
mov si,bx
add si,4
mov bx,[ScreenOffset]
add bx,320
mov [ScreenOffset],bx
mov di,bx
cmp dx,[ScreenHeight]
je DONE
jmp DRAWBITMAP
}
DONE:
asm { pop ds }
}
}
void PutImage(int x,int y,BYTE far *Buffer,WORD width,WORD height)
{
WORD BitmapStartOffsetX=0;
WORD BitmapStartOffsetY=0;
WORD ScreenOffset=0;
WORD BitmapOffset=0;
int ScreenWidth=width;
int ScreenHeight=height;
if (x<0)
{
BitmapStartOffsetX=0-x;
ScreenWidth+=x;
if (ScreenWidth<0) ScreenWidth=0;
width=ScreenWidth;
x=0;
}
if (y<0)
{
BitmapStartOffsetY=0-y;
ScreenHeight+=y;
if (ScreenHeight<0) ScreenHeight=0;
y=0;
}
ScreenOffset=ScreenAddr[y]+x;
BitmapOffset=BitmapStartOffsetY*(width)+BitmapStar
tOffsetX;
if ((x+width)>320) ScreenWidth=(320-x);
if ((y+height)>200) ScreenHeight=201-y;
ScreenHeight--;
if (ScreenWidth && ScreenHeight)
{
asm {
push ds
cld
les di,[ScreenPtr]
mov di,[ScreenOffset]
lds si,[Buffer]
mov si,[BitmapOffset]
add si,4
xor cx,cx
xor dx,dx
}
DRAWBITMAP:
asm {
inc dx
mov cx,[ScreenWidth]
rep movsb
mov bx,[BitmapOffset]
add bx,[width]
add bx,[BitmapStartOffsetX]
mov [BitmapOffset],bx
mov si,bx
add si,4
mov bx,[ScreenOffset]
add bx,320
mov [ScreenOffset],bx
mov di,bx
cmp dx,[ScreenHeight]
je DONE
jmp DRAWBITMAP
}
DONE:
asm { pop ds }
}
}
Now I'm working on rotating the bitmaps. I'm going to rotate the bounding box of the bitmap, scan convert it, and then fill the bounding box from top to bottom like a polygon filler. This will allow me to rotate my bitmaps to any angle on x,y,z and will also produce complete bitmaps with no holes in them. It's essentially a linear texture map onto a 2D surface, the 2D surface being the bounding box of the bitmap (the dimensions of the bitmap).