Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / semi-trasparent box

Author
Message
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th Apr 2005 04:51
I have read a couple of threads after searching and I've just given it a go..

In the thread here, the_winch managed to get the text to go semi-transparent BUT I cat get a box to do the same thing.

I CAN do this from a memblock - but I'd much rather do it from 2D boxes right now..

Does ANYONE know of a way of drawing a semi transparent box without using a PNG, Sprite or memblock?

Cheers,
Nick

My Website:
Ric
21
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th Apr 2005 05:26 Edited at: 5th Apr 2005 05:28
You could use a 3d plane instead of a box - write the text to a bitmap, grab an image, texture the plane then ghost the plane - I know it's not 2d, but planes give you a whole lot more flexibility.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th Apr 2005 07:47
cheer ric - not a bad idea.. Thing is, I can actually do semi transparent text Hehe..

The reason I want this is for the ants sim in the comp thread. I want the health/reproduction bars to be semi-transparent. Ideally I dont want to use anything other than boxes, but I have a feeling I'm gonna have to do it with Memblocks and images.. :-(

ANYONE?

My Website:
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 5th Apr 2005 08:42
The only way I can think of apart from memblocks and images, is actually altering the backbuffer, using lock backbuffer and get backbuffer pointer (or something like that , i've never really tried it properly).

Isn't it? Wasn't it? Marvellous!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th Apr 2005 18:15
humm.. That just sounds complicated! Lol..

So nobody can think of ANY way of doing it?

What confuses me is that I found a function that produces an rgba colour value (rather than the built in rgb only one).

This coloud value, when used in conjunction with "ink" makes text have an alpha value (which in itself is VERY usefull ) But it doesn't work on 2D stuff for some reason, could this be a bug in DBPro?

Nick

My Website:
Tommy S
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location:
Posted: 5th Apr 2005 20:36
a stupid way of doing it would be to make your box form a black and whatever colour you want checker pattern. Then the black won't be shown. Have done it a couple of times but doesn't look that great.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th Apr 2005 20:58
You mean a kind of dithering effect.. That would work but:
a) Would probably look crappy..
b) Would probably be slow to render..

I'm really getting the feeling nobody here knows how to do it.. Maybe its a bug. I get get why text IS effected by the alpha value of a colour, but 2D Primitives are not.

My Website:
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 5th Apr 2005 22:34
Ok, here is an idiot proof function demonstrating what I mean . Making it taught me something about backbuffer access too...



Isn't it? Wasn't it? Marvellous!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th Apr 2005 23:10
hmm - looks promising... i'll give it a go, cheers hamish!

My Website:
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 5th Apr 2005 23:53
I managed to get my fps up from 19 to 25/26 by only referencing the pointer once per loop...



Isn't it? Wasn't it? Marvellous!
hannibal dark
User Banned
Posted: 6th Apr 2005 18:49
if you meant 2d transperancy see the code

wanna learn ? Then just ask it to me
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th Apr 2005 19:00
Cheers for the help guys - I came to the conclusion it was not really possible in an efficient manner. I was mainly hoping that someone might have got the ink with RGB idea working as it works with text, just not 2D primitives.

I ended up using Memblocks - take a look at my ants game in the ongoing competition thread.

Cheers again guys

Nick

My Website:
hannibal dark
User Banned
Posted: 6th Apr 2005 19:11 Edited at: 6th Apr 2005 19:28
sorry. when i enter a code it doesn't appaer here..
anyway.. here we go;

====================2d transparency main algo==================
========================By Hannibaldark========================

x_box = 300
y_box = 200
box_x = 200
box_y = 200
box_r = 20
box_g = 50
box_b = 200

for x = x_box to x_box + box_x
for y = y_box to y_box + box_y
a = point(x,y)
r = rgbr(a)
g = rgbg(a)
b = rgbb(a)

r = r + box_r
g = g + box_g
b = b + box_b

remstart
you can make lots of different formulas;
r = (r + box_r)/2
g = (g + box_g)/2
b = (b + box_b)/2
remend


if r >= 255 then r = 255
if g >= 255 then g = 255
if b >= 255 then b = 255

ink rgb(r,g,b),1

dot x,y

next y
next x

==================================================================
==================================================================

well let's make an example

=======================Transparent Fonts=======================
========================By Hannibaldark========================
================Written online in a few minutes================


set display mode 1024,768,32
sync on
sync rate 1000

load image "1024x768x32 bmp here",1,1

disable escapekey
cls

input "input a text here";text$
set text size 20
set text to bold
s = len(text$)


r=255
g=0
b=0



ink rgb(r,g,b),1
text 0,0,text$

dim mdat(s*20,20)
rem 20k shall be wrong here

for x = 0 to s*20
for y = 0 to 20
mdat(x,y) = point(x,y)
next y
next x

dx=7
dy=7

ax=0
ay=0


x_lim = 1024-s*20
y_lim = 748

routinne:
paste image 1,0,0

ax = ax + dx
ay = ay + dy

if ax >= x_lim
ax = x_lim - dx
dx = 0 - dx
endif

if ax <= 0
ax = 0 - dx
dx = 0 - dx
endif



if ay >= y_lim
ay = y_lim - dy
dy = 0 - dy
endif


if ay <= 0
ay = 0 - dy
dy = 0 - dy
endif

for x = ax to ax + s*20
for y = ay to ay + 20
a = point(x,y)
b = mdat((x-ax),(y-ay))

rr = rgbr(a)
gg = rgbg(a)
bb = rgbb(a)


if b <> 0
rr = rr + r
gg = gg + g
bb = bb + b

if rr >= 255 then rr = 255
if gg >= 255 then gg = 255
if bb >= 255 then bb = 255
ink rgb(rr,gg,bb),1
dot x,y
endif
next y
next x
if escapekey()=1 then end
rem what a silly work for esc
sync
goto routinne

wanna learn ? Then just ask it to me

Login to post a reply

Server time is: 2025-08-08 19:07:26
Your offset time is: 2025-08-08 19:07:26