Ok, here is some code to draw single images, and animimages. The loading i've kept the same.
I havent tested the following code, as I dont have the images you are using to hand. And appologies if it looks messy. Btw, Im not a wizard to all things bitmapy.
Option Explicit
'Windowed
#define PTC_WIN
'-------------------------------------
' Includes.
'-------------------------------------
#Include Once "tinyptc.bi"
'
' Screen constants
'
Const XRES=640 'Screen Width
Const YRES=480 'Screen Height
Const ARES=XRES * YRES 'Array Width
'
' BitmapFont constants
'
Const FontW=32 'Font Width
Const FontH=32 'Font Height
Const FontL=60 'Number Of Letters In The Font
Const MAXIMAGES=2
'
' Sub Routines
'
Declare Sub BitmapText(byval message as string,_
byval xpos as integer,_
byval ypos as integer,_
byval inc as integer)
Declare Sub LoadAnimImage( ByVal stringFilename As string,_
ByVal FrameW As Integer,_
byval FrameH As Integer,_
ByVal Num As Integer=0)
Declare Sub DrawAnimImage(byval xpos as integer,_
byval ypos as integer,_
byval Frame as integer,_
byval FrameW as integer,_
byval FrameH as integer)
Declare Sub Load_Bitmap(byval filename as string, ByVal Num As Integer )
Declare Sub ClearScreen()
'
' Variables
'
Dim Shared Buffer(ARES) as integer 'Tinyptc buffer
Dim Shared BitmapFont( FontW, FontH, FontL ) as integer ' Font buffer
Dim Shared Background( XRES, YRES )
'
' Bitmap (256 color palette) loader variables
'
ReDim Shared img_buffer(1) as ubyte ' Bitmap Image buffer
Dim Shared As Ubyte img_r(256), img_g(256), img_b(256) ' RGB color palette buffer
Dim Shared As Short img_w(MAXIMAGES), img_h(MAXIMAGES) ' Image Width / Height
'
' Image file names
'
Dim file_name as string
Dim file_name2 as string
file_name="Media\rsigold2.bmp"
file_name2="Media\BACKGROUND.bmp"
'
' Load our images
'
LoadAnimImage( file_name,FontW,FontH )
LoadAnimImage( file_name2,XRES,YRES,1) ' presuming the background is the same size as the screen resolution,
'
' Open TinyPTC window
'
If( ptc_open( "Bitmap Text + Font Loader", XRES, YRES ) = 0 ) Then
End -1
End if
'
' Main Loop
'
While Inkey$() <> Chr$( 27 )
ClearScreen()
DrawImage(0,0,1) ; Background Image
BitmapText("BITMAP TEXT",132,150,FontW)
BitmapText("+",290,190,FontW)
BitmapText("FONT LOADER",132,230,FontW)
BitmapText("BY RBRAZ - 2006",90,320,FontW)
Ptc_Update @Buffer(0)
Wend
'Close TinyPTC window
ptc_close()
'Draw text on screen
Sub BitmapText(byval message as string, byval xpos as integer, byval ypos as integer, byval inc as integer)
Dim As Integer a,i
Dim As Integer character
Dim As String char
For a=1 To Len(message)
char = Mid$(message,a,1)
character = Asc(char)-32 'Make sure that your font are into this range
If (character>-1) And (character<FontL) then
DrawAnimImage(xpos,ypos,character,FontW,FontH)
End If
xpos=xpos+inc
Next
End Sub
'Load frame images
Sub LoadAnimImage( ByVal Filename As string, byval FrameW As Integer, byval FrameH as Integer, ByVal Num As Integer=0 )
Dim intX, intY, FrameWidth, FrameHeight, FrameNum
Dim rect_x1, rect_x2, rect_y1, rect_y2, a, b
Dim pixel
'Load bitmap 256 color palette
Load_Bitmap(Filename)
FrameWidth = img_w(Num)/FrameW
FrameHeight = img_h(Num)/FrameH
FrameNum = 0
rect_x1 = 0
rect_x2 = FrameW
rect_y1 = 0
rect_y2 = FrameH
Dim As UInteger Col
For b = 0 to FrameHeight-1
For a = 0 to FrameWidth-1
For intY = rect_y1 to rect_y2-1
For intX = rect_x1 to rect_x2-1
pixel= img_buffer( intX + ( intY * img_w(Num) ) )
Col=(img_r(pixel) Shl 16 ) Or (img_g(pixel) Shl 8) Or (img_b(pixel)
Select Case As Const Num
Case 0
BitmapFont( intX Mod FrameW, intY Mod FrameH, FrameNum ) = Col
Case 1
Background( intx Mod FrameW, inty Mod FrameH )= Col
End Select
Next
Next
rect_x1 = rect_x2
rect_x2 = rect_x2 + FrameW
FrameNum = FrameNum + 1
Next
rect_x1 = 0
rect_x2 = FrameW
rect_y1 = rect_y2
rect_y2 = rect_y2 + FrameH
Next
End Sub
Sub DrawAnimImage(byval xpos as integer,_
byval ypos as integer,_
byval Frame as integer,_
byval FrameW as integer,_
byval FrameH as integer)
Dim As Integer intX, intY
For intY=0 to FrameH-1
For intX=0 to FrameW-1
if (xpos+intX) < (XRES - 1) and (xpos+intX) > 0 then
Buffer( ((intY+ypos) * XRES) + (intX+xpos)) = BitmapFont(intX, intY, Frame )
end if
Next
Next
end sub
Sub DrawImage( ByVal XPos As Integer, ByVal YPos As Integer, ByVal Num As Integer=0 )
Dim As Integer x,y
For Y=0 to img_h( Num )-1
For X=0 to img_w( Num )-1
if (xpos+X) < (XRES - 1) and (xpos+X) > 0 then
Select Case As Const Num
Case 0
Buffer( ((Y+ypos) * XRES) + (X+xpos)) = Background( X, Y )
End Select
end if
Next
Next
End Sub
'----------------------------------------
' For 256 color palette image only
'----------------------------------------
Sub Load_Bitmap(byval filename as string, ByVal Num As Integer )
Dim i,j,n,k,l,cnt as integer
Dim Bmp_len, file as integer
Dim byt as ubyte
file = FreeFile
OPEN filename FOR BINARY AS #file
Get #file,19,img_w(num) ' bmp width
Get #file,23,img_h(num) ' bmp height
Bmp_len = img_w(num) * img_h(num) ' Bmp size
ReDim img_buffer(Bmp_len)
Dim temp(Bmp_len)
'Color palette
cnt = 55
For i = 0 To 255
Get #file,cnt,byt
img_b(i) = byt
cnt+=1
Get #file,cnt,byt
img_g(i) = byt
cnt+=1
Get #file,cnt,byt
img_r(i) = byt
cnt+=2
Next
'Image pixels
cnt = 1079
For i = 0 To Bmp_len-1
Get #file,cnt,byt
img_buffer(i) = byt
cnt+=1
Next
Close #file
For i = -(Bmp_len-1) To 0
temp(j) = img_buffer(Abs(i))
j = j + 1
Next
'Flip image
Do
For j = 0 To img_w(num)
k = (j + (n * img_w(num)))
l = ((img_w(num) - j) + (n * img_w(num)))
img_buffer(l) = temp(k)
Next
n = n + 1
Loop Until n = img_h(num)
End Sub
What ive done is use case, to choose which image array to contain the relevant data. Add more to taste. You could if you wanted have an array called ImageData( MaxWidth, MaxHeight, MaxImages ) if you catch my drift.
I hope that you can see and understand what the code is doing. And if for any reason the code doesnt work, let me know in a reply please dude, as like I say I havent fully tested it.
Cheers,
Clyde.