Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easier way to build playing cards graphics?

Status
Not open for further replies.

BLT

Programmer
Nov 30, 2000
1
US
I've been working for a while now in Screen 12 mode (640x480 res, 16 colors) to draw realistic-looking standard playing cards.&nbsp;&nbsp;So far, I've had a certain amount of success--but that success has been slow.Using READ/DATA commands I've written down, pixel by pixel, the color attribute for every single dot in the design of every card based on scanned images of those cards.&nbsp;&nbsp;Not exactly fun times, especially when you have 9600 pixels per card (80x120).&nbsp;&nbsp;Now, my question is this: way back when I first programmed in BASIC on the Apple IIc, PEEK and/or POKE commands existed that automatically brought up predefined playing cards graphics.&nbsp;&nbsp;Do such commands exist on the IBM platform/in QBASIC?&nbsp;&nbsp;I would greatly appreciate anyone who could help me out here.<br><br>If such commands do not exist, does anyone have any ideas on how I could speed up the graphics building time?&nbsp;&nbsp;Sure, I can duplicate the spades graphics, the &quot;A&quot;s for the aces, etc., but I mean something besides that.&nbsp;&nbsp;In addition, the graphics use up a great deal of memory--the particular array that the graphics are stored in take up a whopping 237 KB (defined at size 30304 and as DOUBLE type)!&nbsp;&nbsp;I routinely run out of memory while dealing with the graphics.&nbsp;&nbsp;Any ideas at all would be greatly appreciated.<br><br>One idea that I have had has been to save the scanned images as bitmaps and then have them loaded in QBASIC as such.&nbsp;&nbsp;However, I do not know how to code for bitmaps, and I want this program to be as exclusively mine as possible (okay, so I've got ego problems).&nbsp;&nbsp;In addition, rendering the scanned graphics so that they all use the same set of 16, or even 256, colors would be a pain in the patootie.&nbsp;&nbsp;Any ideas?&nbsp;&nbsp;Thanks ahead of time.
 
Ever tried the BSAVE/BLOAD command?

BSAVE and BLOAD are two commands in the QBasic environment to allow
you to save graphics created using your method explained above
in a file. The file can then be loaded instantaneously from a program,
eliminating many of the delays.
Both of these commands save part of memory to a file (they don't
just have to be used for graphics).
To point BSAVE and BLOAD to the right memory address to start saving
from, you must use the DEF SEG statement in this form:

DEF SEG = VARSEG(arrayname(0))

arrayname is the name of the array you stored the graphic name
in using the GET command. After you are done BSAVEing or BLOADing,
use a solitary DEF SEG command to point memory back to where it should
be.
Its basic syntax is:

BSAVE &quot;graphic.ext&quot;, offset, length

&quot;graphic.ext&quot; is the filename of the graphic you want to save. You
can have any filename and any extension - for clarity, in my programs I
use the .PIX extension, though this is totally arbitrary.
length is the size of the array you DIMmed to store the graphic in
using the GET command. Be sure to get the EXACT number. The actual file
will be seven bytes larger than the length you specify here.
offset is the byte address of where to start saving.
You can manipulate these commands so as to save more than one graphic in a single file.
Now, for the BLOAD command, assuming you've already created and saved a graphic using BSAVE, you can BLOAD the graphic into a program. It's rather simple, really:

DIM arrayname(length)

SCREEN screenmode

DEF SEG = VARSEG(arrayname(0))
BLOAD &quot;graphic.ext&quot;, 0
DEF SEG

PUT (0, 0), arrayname

Of course, you'll need to stick your arrayname and length into this program along with the name of the file.
Be sure to use the same SCREEN mode when you BSAVE and when you BLOAD a graphic. For instance, if you BSAVEd a graphic in SCREEN 12, you *must* BLOAD the graphic in SCREEN 12, too. BSAVE files are not screen-mode interchangeable.
This should help you get around the &quot;out-of-memory&quot; problem plus it's much faster than PSETting every pixel one at a time!

Hope I helped :D
 
PZ is absolutely right.
BSAVE is the way to go.
You'll need to display the graphics
on screen from within Qbasic then
bsave them. Use either a BMP loader
or get them on screen pixel by pixel
(personally I don't see whats un-fun about that)
I have experienced weird color transition
in my BSV's. They look fine as BMP's
but hey, what do I know from dithering?
Be aware that BSAVE, while an excellent solution
is not always a cake walk. You will have to problem
solve to work it into your program.
Good Luck

 
I have to agree with Lupine that BSAVE/BLOAD isn't exactly a cake walk.

Calculating the array size with the formula:[tt]
Bytes = 4 + INT(((X2-X1+1)*(Bits/pixel/plane)+7)/8)*planes*((Y2-Y1)+1)[/tt]

can be a bit perplexing for someone who has never tried BSAVE. I have to admit <blush> that the first time I tried it I took a guess at the size and alternated between running the program and increasing the array size until I stopped receiving error messages. (A very sloppy and inefficient programming practice but it suited me well since I was a total novice and had a few minutes to spare.)

Again, BSAVE and BLOAD aren't the easiest commands to implement but your experimentation (even if it is based on trial and error) will pay off. Microsoft claims that the BLOAD file access method provides the fastest access available to a QB programmer.

There is a FAQ in this forum showing an example of BSAVE/BLOAD. Not a very good example... but it might help you get your card game up and running.
 
Lupine, if ya use BSAVE/BLOAD on bmp files and then use your BSAVEed files in a program, you have to remember 2 things:

1-You have to save the palette used for diplaying the BMPs 'cuz you need it to for your main program (otherwise you get weird colors and figures...)

2-Or, you can display BMP files saved in PAINT as a 16color BMP, this way it will not mess your palette, so you don't have to save it and your colors are always there!(even if 16 colors are very few...)

Hope I helped :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top