Pixmaps can have any dimensions whatsoever. Now on to the main event!
Animated Images 101:
So you want to load an image strip? Well, BlitzMax has you covered for that, but if you want to load a strip of images, and then get the Pixmaps, you'll need to know how the TImage Class works. First use this to load the strip:
Local myanimation:TImage=LoadAnimImage(myurl:Object,width,height,first,count,flags=-1)
Now you must extract the pixmaps. You'll need to access the pixmap field of the TImage Class on the instance 'myanimation' you created previously. This is the BRL code used to define a TImage (DO NOT INCORPORATE IN TO YOUR OWN CODE, IT'S AUTOMATICALLY DONE FOR YOU):
Strict
Import "driver.bmx"
Import BRL.Data
Type TImage Extends TData
Field width,height,flags
Field mask_r,mask_g,mask_b
Field handle_x#,handle_y#
Field pixmaps:TPixmap[]
Field frames:TImageFrame[]
Field seqs[]
Method DataType:TImageDataType()
Return ImageDataType
End Method
Method Frame:TImageFrame( index )
If seqs[index]=GraphicsSeq Return frames[index]
frames[index]=_max2dDriver.CreateFrameFromPixmap( Lock(index,True,False),flags )
If frames[index] seqs[index]=GraphicsSeq Else seqs[index]=0
Return frames[index]
End Method
Method Lock:TPixmap( index,read,write )
If write
seqs[index]=0
frames[index]=Null
EndIf
If Not pixmaps[index]
pixmaps[index]=CreatePixmap( width,height,PF_RGBA8888 )
EndIf
Return pixmaps[index]
End Method
Method SetPixmap( index,pixmap:TPixmap )
If (flags & MASKEDIMAGE) And AlphaBitsPerPixel[pixmap.format]=0
pixmap=MaskPixmap( pixmap,mask_r,mask_g,mask_b )
EndIf
pixmaps[index]=pixmap
seqs[index]=0
frames[index]=Null
End Method
Function Create:TImage( width,height,frames,flags,mr,mg,mb )
Local t:TImage=New TImage
t.width=width
t.height=height
t.flags=flags
t.mask_r=mr
t.mask_g=mg
t.mask_b=mb
t.pixmaps=New TPixmap[frames]
t.frames=New TImageFrame[frames]
t.seqs=New Int[frames]
Return t
End Function
Function Load:TImage( url:Object,flags,mr,mg,mb )
Local pixmap:TPixmap=TPixmap(url)
If Not pixmap pixmap=LoadPixmap(url)
If Not pixmap Return
Local t:TImage=Create( pixmap.width,pixmap.height,1,flags,mr,mg,mb )
t.SetPixmap 0,pixmap
Return t
End Function
Function LoadAnim:TImage( url:Object,cell_width,cell_height,first,count,flags,mr,mg,mb )
Local pixmap:TPixmap=TPixmap(url)
If Not pixmap pixmap=LoadPixmap(url)
If Not pixmap Return
Local x_cells=pixmap.width/cell_width
Local y_cells=pixmap.height/cell_height
If first+count>x_cells*y_cells Return
Local t:TImage=Create( cell_width,cell_height,count,flags,mr,mg,mb )
For Local cell=first To first+count-1
Local x=cell Mod x_cells * cell_width
Local y=cell / x_cells * cell_height
Local window:TPixmap=pixmap.Window( x,y,cell_width,cell_height )
t.SetPixmap cell-first,window.Copy()
Next
Return t
End Function
End Type
Type TImageDataType Extends TDataType
Method Tag$()
Return "brl.max2d.TImage"
End Method
Method ReadObject:Object( stream:TStream )
Local image:TImage=New TImage
image.width=stream.ReadInt()
image.height=stream.ReadInt()
image.flags=stream.ReadInt()
image.mask_r=stream.ReadInt()
image.mask_g=stream.ReadInt()
image.mask_b=stream.ReadInt()
image.handle_x=stream.ReadFloat()
image.handle_y=stream.ReadFloat()
Local count=stream.ReadInt()
image.pixmaps=New TPixmap[count]
For Local i=0 Until count
image.pixmaps[i]=TPixmap( stream.ReadObject() )
Next
image.frames=New TImageFrame[count]
image.seqs=New Int[count]
End Method
Method WriteObject( o:Object,stream:TStream )
Local image:TImage=TImage(o)
stream.WriteInt image.width
stream.WriteInt image.height
stream.WriteInt image.flags
stream.WriteInt image.mask_r
stream.WriteInt image.mask_g
stream.WriteInt image.mask_b
stream.WriteFloat image.handle_x
stream.WriteFloat image.handle_y
stream.WriteInt image.pixmaps.length
For Local pixmap:TPixmap=EachIn image.pixmaps
stream.WriteObject pixmap
Next
End Method
End Type
Global ImageDataType:TImageDataType=New TImageDataType
As you can see, one of the field vars is 'pixmaps', a TPixmap Array. You'll need to get these manually. Ahem, Mark, ahem, Simon, there needs to be a BRL function for returning that. Or maybe not. Your program will look something like this now:
Local myanimation:TImage=LoadAnimImage(myurl:Object,width,height,first,count,flags=-1)
Local pixmaps:TPixmap[]=myanimation.pixmaps
There! Pixmaps loaded! All you have to do now, is do whatever you want with the resulting pixmaps. You can additionally turn each one in to a TImage for all the special rendering features that are provided with it. Like this:
Local myanimation:TImage=LoadAnimImage(myurl:Object,width,height,first,count,flags=-1)
Local pixmaps:TPixmap[]=myanimation.pixmaps
Local images:TImage[pixmaps.length]
For j=0 to pixmaps.length-1
images[j]=LoadImage(pixmaps[j])
Next
Hope this helps! Now, as for loading them specifically with OpenGL, I dunno, but I know that OpenGL is much easier to understand than DirectX, so keep trying. You'll get it. ;)