Page 1 of 1

Transparent color

Posted: Thu Aug 11, 2005 12:27 pm
by beeb103
Hello everyone,

I am using Screen 13 and DATA for my graphics. I am trying to make the black transparent so you can't see it. Here's is a example,

data: 000, 150, 150, 150, 000
data: 000, 150, 150, 150, 000
data: 150, 150, 150, 150, 150
data: 000, 150, 150, 150, 000

Is there a way I can get the 000 to not be seen?

Thanks

Posted: Thu Aug 11, 2005 3:01 pm
by Z!re
Yes, several ways actually:

1) Dont draw it (aka: Use your own routines instead of the built in ones)
2) Use a mask bitmap
3) Use FreeBASIC (www.FreeBASIC.net)

I dont have time to make up examples..
Maybe someone else will clarify it..

Sorry for the useless post :P

Posted: Thu Aug 11, 2005 6:49 pm
by The Awakened
Well, I assume you're using the following routine:

Code: Select all


for y = 0 to yourwidth
        for x = 0 to yourheight
                   read pixel%
                   pset x, y, pixel%
        next
next

Put this instead of the pset

Code: Select all


if pixel% > 0 then
             pset x, y, pixel
end if

That way, if the pixel is 0, the routine will just skip over it. As for PUTing, you'll have to set up a mask... check out Apester's tutorial, that's where I first got my tips. It's right here: http://petesqbsite.com/sections/tutoria ... s.shtml#11

Good luck to you! :D

Posted: Fri Aug 12, 2005 12:20 am
by Zamaster
A quick explanation o' masks... You can think of masks as holes you put down on an image that allow your sprite to fill them without messing up the background pixels or your sprites pixels. To make a mask you need to make a black cutout of your sprite and slap it on a box of white pixels that are the same size as your sprite, e.g.

The sprite 6x6 for simplicity in:

0,0,0,4,0,0
0,1,1,6,1,1
0,1,0,4,0,0
2,3,2,5,2,2
0,1,0,4,0,0
0,1,0,4,0,0

(note: the transparent pixels MUST be black!)

The Mask - F's for white(QB's color 15):

F,F,F,0,F,F
F,0,0,0,0,0
F,0,F,0,F,F
0,0,0,0,0,0
F,0,F,0,F,F
F,0,F,0,F,F

A quick way to make a mask is to scan over your sprite
and set the masks pixels to White if the color is 0 or
black if it equals anything else

Code: Select all

FOR x% = 0 TO 15
   FOR y% = 0 TO 15
      col% = sprite(x% ,y%)
      IF col% = 0 THEN 
         col% = 15
      ELSE
         col% = 0
      END IF
      mask(x%, y%) = col%
   NEXT y%
NEXT x%
The next step is to PUT(preferrable) the mask down using the AND
operrator, then PUT down the sprite with the OR operrator:

PUT (10, 10), yourmask%(0), AND

PUT (10, 10), yoursprite%(0), OR

and TADA!!!!! You have a sprite with a transparent background!
One problem with masks though, as opposed to a custom
"Dont draw the black pixels" routine. Masks take up twice as much
space cause you need to store the sprite and the mask.

Hope this helps!

Posted: Fri Aug 12, 2005 8:01 am
by Nodtveidt
This thread is definately NOT in the right forum.

Posted: Fri Aug 12, 2005 8:28 am
by Rattrapmax6
Yeah.. seems the new thing to post questions in the News forum.. oh well..

Posted: Fri Aug 12, 2005 9:49 am
by {Nathan}
Or use rellib, dqb or some other library. The sooner you learn them, the better off you are.

OOPS

Posted: Fri Aug 12, 2005 10:06 am
by beeb103
WHAT? I thought I posted in the Help forum...sorry, lol.

Thanks everyone, I will try some of your ideas.

Posted: Sat Aug 13, 2005 6:50 am
by The Walrus
There's also a tutorial on putting transperant sprites here:

http://www.qbasicnews.com/tutorials.php ... =view&id=7

Thanks

Posted: Sat Aug 13, 2005 9:09 pm
by beeb103
I used the mask and it worked.

Thanks everyone.

Posted: Sun Aug 14, 2005 9:46 am
by Rattrapmax6
It's all this work that makes FreeBasic Trans option look so nice:

Code: Select all

PUT (x, y), sprite, trans
:roll:

Posted: Sat Aug 20, 2005 10:45 pm
by Zamaster
Wait my bad, I forgot to say why the whole AND and OR thing work...
Okay so you know that a mask's background pixels are white and there is a big black spot in the middle which is your sprite. When you AND on your mask here is what happens:

the masks pixels which are white are in binary as:

11111111

the pixels under the white(the background colored pixels) are in
binary as... we'll say the qb color light red(12):

00001100

now ANDing them together ANDs each bit with the other corresponding bit in the other binary number:


11111111

AND

00001100
======
00001100


Exactly the second number(or the pixels your are ANDing the white on to)! So thats why the white pixels dont get drawn.
Now as for the black (qb color 0):


00000000

AND

00001100
======
00000000

You get 0. Thats why the black pixels show up. But the actual sprite gets ORd on so you're ORing the black and ORing the actual color:

00000000 <-- sprites transparent black

OR

00001010 <-- backgrounds green
======
00001010

You get the background color. And finally for the sprites solid pixels:

00000111 <-- sprites color grey

OR

00000000 <-- cutouts black (made when ANDing the mask)
======
00000111

So all in all, this fancy mix of opperrators creates a transparent sprite!

Posted: Tue Aug 30, 2005 9:28 am
by romassoldier
HI! My problem isn't in the DATA transparent colors. I use 8 bits .BMPs, and I wanna put the image onto the screen, but the background won't be visible.
I make a BMP file, which is the mask(I saw it in the Sonix game), and the background is 50% grey.
Image
(rehosted, this isn't the original!)
And I open this bmps, and GET dr1, and dr1mask.
BUT if I use this code

Code: Select all

PUT dr1 (1, 1), AND
PUT dr1mask (1, 1), OR
Then i don't give what i want. (Transparent backgound...)

Posted: Wed Aug 31, 2005 6:50 pm
by Zamaster
Okey pokey, now take a look at the pic on the left. That background cant be pink if your doing a mask, the background needs to be black(QB color 0). Now for the pic on the right, that grey background needs to be white(QB color 15) and all the main pixels, the colored ones that is, need to be black. So you have a sprite with a black background one the left and a white background with a black cutout of your sprite on the right.

An example sprite:

0,1,4,0
1,0,0,4
4,0,0,1
0,4,1,0

That sprites mask:

15,0,0,15
0,15,15,0
0,15,15,0
15,0,0,15


If I could post pics I would. Read my posts again till you get the
hang of it and good luck!(Nice job on those sprites!)

Posted: Thu Sep 01, 2005 11:36 am
by romassoldier
ok I will try it, and thanks.

Posted: Thu Sep 01, 2005 11:00 pm
by Dave Unit
Ummm... I'm a beginning program, but the problem I see is that the mask is coming after the original sprite. Try putting the mask first, that should fix your problem. I think. =P