Qbasicnews.com

Full Version: PUT "transparent" graphics?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I want to be able to PUT a cursor image on the screen. The problem is that the picture has to be a rectangle - and I don't want a completely square picture. Is there a way to PUT a graphic on the screen without PUTting the black pixels, leaving text or colors beneath it untouched?

Thanks for any help!
SuperPut and SetVideoSeg by plasma

Do a search.
or you can search the net for sprite tutorials, or routines.
(There's a million or so.)
You can also check out Video13h v1.3, I just posted the source code in the projects index. (For SCREEN 13)
The source contains routines that'll make sprite manipulation much easier, you might even learn some things Big Grin


Cya!
use a library, such as rellib, blast, cosmox, etc. etc. They contain many functions that you may want, including what you are asking for.
Quote:I want to be able to PUT a cursor image on the screen. The problem is that the picture has to be a rectangle - and I don't want a completely square picture. Is there a way to PUT a graphic on the screen without PUTting the black pixels, leaving text or colors beneath it untouched?
Since there are already 3 replies referring you to something else, I'll just explain it to you... Wink

For Mode 13h a.s.:
The trick is to know how the image is stored in memory. Suppose you have an integer array Mouse() and GET a picture in it.
Now:
Mouse(0) = WidthOfImage * 8
Mouse(1) = HeightOfImage
The first index will contain the width of the image, multiplied by eigth. The second index will contain the height of the image.
Then, the image data begins, one byte per pixel. Since you have the width and height of the image, you can calculate how many bytes there are after the 2nd index.
To read from memory, here's an example:
[syntax="qbasic"]DIM Mouse(51) AS INTEGER
SCREEN 13
GET (0, 0) - (9, 9), Mouse

'Look:
PRINT Mouse(0), Mouse(0) \ 8
PRINT Mouse(1)

'to read from memory:
Wid% = Mouse(0) \ 8
Hei% = Mouse(1)
pixels& = CLNG(Wid%) * CLNG(Hei%)
DEF SEG = VARSEG(Mouse(0))
offs% = VARPTR(Mouse(0))
FOR i& = 1 TO pixels&
pixelcolor = PEEK(offs% + 3 + i&)

'############
'now you can see if the pixel color equals zero, and if it's not,
'you can put it to screen (DEF SEG = &HA000)
'############
NEXT i&
DEF SEG[/syntax]

If you want the full code, you can also take a look at NeoLib v1.6b, it should be available at Pete's QB Site.
Big Grin
You have two choices:
1. Code using pure QB routines(dont like 'em personally)
2. Use a library like Future.Lib(personal favorite), Rellib or uGL....
assuming SCREEN 13

make 2 images of the cursor 1 normal Image, 1 mask. the mask is the same as the cursor image except that what has palette attribute 0 now has palette attribute 255.

example:
0,0,0
0,1,0
0,0,0 <- image
get(0,0)-(2,2), img

255,255,255
255,1,255
255,255,255 <- mask
get(0,0)(2,2), mask

Draw a background

PUT(10,10), mask, AND
PUT(10,10), img, OR

just look at the truth tables of the logical AND and logical OR if you find this code strange.
The bad thing is that that way requires twice as much memory as a routine that simply just ignores the color 0.
Quote:The bad thing is that that way requires twice as much memory as a routine that simply just ignores the color 0.

I agree. but there is no function as fast as put that ignores the 0 you could make your own put, with PEEK. but it'll never have the same speed. or you should do it in ASM (I don't know much ASM therefore never tried to do this)
Like I said, SetVideoSeg and SuperPut made by Plasma

If you want to know exactly what it does, just PM him and he'll (probably) tell =)


I havent even noticed any speed difference when using SuperPut compared to regular put, and SetVideoSeg is just... awesome.
Pages: 1 2