Playing around with cards

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Playing around with cards

Post by paul doe »

D.J.Peters wrote:I posted it at 2005 up's we are 13 years older now :-)
Funny how time goes by =D
jj2007 wrote:Did you get inspiration from the Masm32 thread started 5 days ago?

On Windows, you can use Cards.dll ...[/url].
If you're asking me, I'm afraid not. I don't follow that forum since I'm not interested in assembler. Of course you can use cards.dll on Windows, but there's two problems: first, the cards look like absolute crap and are low-res, and second, it's Windows only. The idea is making portable software, so Linux (and Mac) folks can also run it, no? ;)
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: Playing around with cards

Post by lizard »

paul doe wrote:No excuses needed, of course. I'll create a decent PNG with the deck so you'll be able to use it if you want. Or I can post the raw SVG file if you prefer. Your call.
For me personal it would not be necessary, because i dont believe i will realize a playing part. Have done this long ago. But there are few people here who are interested.
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Playing around with cards

Post by paul doe »

lizard wrote:For me personal it would not be necessary, because i dont believe i will realize a playing part. Have done this long ago. But there are few people here who are interested.
Very well. Let those that are interested speak for themselves then ;)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Playing around with cards

Post by D.J.Peters »

2005 it's a lie :-(

I posted it at 2010 ups we are 8 years older now :-)

Joshy
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Playing around with cards

Post by paul doe »

D.J.Peters wrote:2005 it's a lie :-(

I posted it at 2010 ups we are 8 years older now :-)
Yeah, I noticed. But I assumed it was just senile dementia LOL ;)
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Playing around with cards

Post by paul doe »

>> On Windows, you can use Cards.dll <<
It doesn't even come with Win10.

So I packed the crappy old cards in a binary file to use in FB. To load them, use code like this one:

Code: Select all

#include once "fbgfx.bi"

screenRes( 800, 600, 32 )

dim as ulong w, h
dim as integer numCards
dim as integer fileHandle = freeFile()

'' Load all the cards from file
open "cards.res" for binary access read as fileHandle
	get #fileHandle, , numCards
	
	dim as fb.image ptr img( 0 to numCards - 1 )
	
	for i as integer = 0 to numCards - 1
		get #fileHandle, , w
		get #fileHandle, , h
		
		img( i ) = imageCreate( w, h )
		
		get #fileHandle, , *( cast( ubyte ptr, img( i ) ) + sizeOf( fb.image ) ), img( i )->pitch * h
	next
close( fileHandle )

'' Show them
for i as integer = 0 to numCards - 1
	put( i * 10, 100 ), img( i ), pset
next

sleep()

'' Don't forget to release the resources
for i as integer = 0 to numCards - 1
	imageDestroy( img( i ) )
next
Image

Get the binary from here:
https://github.com/glasyalabolas/fb-card-library
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: Playing around with cards

Post by lizard »

Works here on Mint 18 64. Never tried .res in FB. Then you could link it in the .exe to have all in one file, i suppose.
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Playing around with cards

Post by paul doe »

lizard wrote:Works here on Mint 18 64. Never tried .res in FB. Then you could link it in the .exe to have all in one file, i suppose.
The .res extension is arbitrary but yeah, you could. But it's not such a good idea, for several reasons. The technique could be used to avoid, for example, having hundreds of files, each with a small bitmap. Of course, you can also use it to pack all the textures you need, ready to be used by OpenGL, for example.

The file format is rather dull, as the header only consist in the number of images found in the file. You can create your own custom binary file, or you custom .pak file (to have several file types in one, like Quake-era games did) if you wish.
Post Reply