I've been up working all night and not had much sleep, but I'm not having much luck with this simple function -
SETSCREEN 640,480,0
// Create white box and grab to sprite #1
DRAWRECT 0,0,64,64,RGB(255,255,255)
GRABSPRITE 1,0,0,64,64
WHILE TRUE
// Create magenta box and place sprite #1 onto it
DRAWRECT 0,0,128,128,RGB(255,0,128)
DRAWSPRITE 1,0,0
// Make the colour white transparent
SETTRANSPARENCY RGB(255,255,255)
// Grab the pink box and the white box into sprite #10
GRABSPRITE 10,0,0,128,128
DRAWSPRITE 10,200,200
SHOWSCREEN
WEND
What I want to do is grab the pink and white box from the screen, but make the white box transparent.
According to the SETTRANSPARENCY help GRABSPRITE should use the RGB value and make those portions of the sprite transparent. It doesn't seem to be doing this in my small example.
Something's obviously working as the magenta colour (RGB(255,0,128) shouldn't be visible under normal conditions, but the white isn't transparent. Am I just too tired to see the wood for the trees or is there a problem with SETTRANSPARENCY and GRABSPRITE?
Do you mean something like the included picture ?
If not, then you cant have a separate transparency for white and magenta box unless they are separate graphics.
[attachment deleted by admin]
Yep - that picture is what I was expecting/wanting. All I needed was to change the transparency colour from magenta to white.
I know you can't have separate transparency colours.
SETSCREEN 640,480,0
WHILE TRUE
// Make the colour white transparent
SETTRANSPARENCY RGB(255,255,255)
// Create magenta box
DRAWRECT 0,0,128,128,RGB(255,0,128)
// Create white box -> THIS BOX HAS ALPHA = 0 SET!!
DRAWRECT 0,0,64,64,RGB(255,255,255)
DRAWSPRITE 1,0,0
// Grab the pink box and the white box into sprite #10
GRABSPRITE 10,0,0,128,128
DRAWSPRITE 10,200,200
SHOWSCREEN
WEND
The transparent color descides on the alpha value when you DRAWRECT. The rect is drawn in that color, but also the alpha value is either 0 or 1!! Thus, you grab and you also grab the alpha pixels you drew before.
That seems odd, but it works. Why would DRAWRECT need to know about alpha colour? It doesn't use a mask (hence you can see the magenta colour).
But, like I said, it works.
Cheers chaps :)
Back again :P
Try this little example, which shows a masked image pasted onto a different coloured background and then grabbed.
The end result still shows the magenta background - the SETTRANSPARENCY setting does not appear to work at all with GRABSPRITE, despite what the online help states. I expected the magenta area to be transparent, leaving just a coloured globe.
http://www.iprice.remakes.org/my_stuff/transparency%20test.rar
I see what you mean.
I explain what I do and why:
When you draw something to the screen, and the screen has an alpha layer (not all cards can do this, mind), I draw the visible pixels and their alpha value to the back buffer.
Thus, if you draw a rectangle with the cookie colour, the alpha pixels are set to 0, but the rgb pixels are visible. This is why it's important to set the transparent colour before drawing a rect. If you draw a sprite, only the visible pixels are drawn. The alpha=0 pixels are totally ignored.
When you grab the image, I can copy the pixels with alpha information directly from the back buffer to the sprite texture. That's fast, because I don't have to read them into normal memory and upload it again to the gfx card memory. OK?
If you have no alpha layer in the back buffer (driver issue), I really have to read the pixels, then compare the RGB values to the transparent colour and "create" an alpha layer manually. Then upload to gfx card memory as a texture. Slow, but the only solution.
So, for speed issues I chose to use the alpha method described above wherever applicable.
Back to your problem. You want to create a coloured shape (drawrect or drawsprite of material) and cut a stencil off to get a shape, right?
Very hard problem. If it wasn't for speed, you "might" write the file as a BMP and then re-read it. Another option would be to draw the transparent pixels with SETPIXEL (use SPRCOLL to see where the mask has a transparent pixel). It's all not very satisfying.
Do you have a better idea how I could change GLBasic to enable what you need?
All I can say is that it works in PlayBasic, BlitzBasic and BlitzMax. I don't know how they do it, but it works. I expected something like this to be pretty easy. :(
I know I can read each pixel and "paint over" a specified colour, but that will be incredibly slow for one image, let alone the multiple images that I will require for my app.
My alternative would be to use a coloured POLYVECTOR I suppose, but I'm concerned that I won't get a clean image afterwards - I haven't tried this yet, so this is just speculation.
Ideally, I'd love the SETTRANSPARENCY command to be able to be used before DRAWSPRITE/DRAWANIM etc. This way, you could change the transparency colour on the fly. This is how BlitzMax does it. You can specify it at any point for any sprite. And it's great. And fast, in DirectX and OpenGL modes.
My app. won't be doing this in real-time BTW, all the drawing stuff is done at the start of the program and not needed again. Trouble is, it's not doing what I thought it should do. I mean, really it seems such a simple thing too. :(
OK, I'll make a command SETSPRITETRANSPARENCY id%, RGB(xxx), where I read the image and fix alpha on the RGB and then re-upload it. It's not really slow, but a lot slower than GRABSPRITE, which you might need in 120 FPS apps sometimes.
Sounds like a good solution :)
Me again.
I've used POLYVECTOR to conquer this issue, so don't go delving into code unless you really have/want to Gernot.
:)
Does it work? Fine. That's that makes a real programmer. You conquer a problem by a fix. No waiting and whining for feature requests - just make it work *somehow*.
:good:
Damn. Here was I about to whine and wait on a feature request. ;)
Mike