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 Discussion / Sprite Alpha Blending?

Author
Message
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 16th Aug 2007 19:19
Hi all, i am working on a game(Microbial Madness), and i have a sprite that i need the sides of to blend into the background, but the colors of my background vary. I was wondering if i could alpha blend the sprite. He is a little microscopic guy swimming in a pool of primordial soup.

The problem with the gaming community is people think that the resolution of a game defines how good it is. I am not afraid to make a game where the main character is 50x50.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 16th Aug 2007 19:47
alpha blending a sprite?? i'll have to get back to you on that....
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 16th Aug 2007 19:50
ty

The problem with the gaming community is people think that the resolution of a game defines how good it is. I am not afraid to make a game where the main character is 50x50.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 16th Aug 2007 20:05
nope. i dont think you can. but try asking someone with some coding expereance.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Aug 2007 20:34 Edited at: 16th Aug 2007 20:43
@Pixelator

Hello,
There are a couple of ways to do this.

Whatever area on the sprite you want transparent (background showing through) color black. And use SET SPRITE <num>,1,1. If you want the complcated way where an image appears translucent or any color seems transparent or blended read on.

Bascially, you take two images (or an image and a background) and you look at the color value of a pixel at a certain coordinate for each image. You take the separate components of the pixels (r g and b values) and give them a weight (alpha percentage). The more weight a component has for a particular pixel in one of the images, the stronger it's intensity, and the opposite applies to the other images pixel. For example - the maximum value any r g or b component can have is 255. If two images are on top of each other and you want them to blend, the total of the blend for a component is 255 which means if one image pixel component is at 255, the other has to be at zero. Or if one is at 128, the other would have to be at 127. This shift is what allows one image to be stronger than the other which controls how images are blended.

There are examples all over the internet of coding alpha blend routines. If you have DBC enhanced, using memblocks is a good way because you can convert image data to memblocks fairly easily.

If you don't have enhanced, you could write a routine to read the file format of a bitmap (fast) or you could use the POINT command and look at each pixel in an image on the screen (slow but easy). The easiest bitdepth (screen depth) to deal with is 24 or 32 bit. 16 bit is the most difficult.

Another way is to use a ready made dll (again if you have DBC enhanced). There is an excellent image manipulation package (open source) called FreeImage. It has just about everything you need to do whatever you want to an image in many formats. Here's a link:

http://freeimage.sourceforge.net/

Here's some example code blending two images in DBC. It requires freeimage.dll. After each image is drawn, press ENTER. After the two images have been drawn, they are saved to disk. They are then loaded and blended by freeimage. I put the code together quickly so it's a bit clunky, but shows you how your desired result can be achieved without you having to code your own alpha blending routine.



Enjoy your day.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 16th Aug 2007 20:38
WoW......cool.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 16th Aug 2007 21:14
@ latch
THANKYOU!!!!!!!!

The problem with the gaming community is people think that the resolution of a game defines how good it is. I am not afraid to make a game where the main character is 50x50.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th Aug 2007 22:10 Edited at: 16th Aug 2007 22:23
@Pixelator
Been looking at Spore?
Got any ideas on how to make the cell membrane all jelly-like?

@Latch
That sounds pretty cool, I can see this being very slow in DBC though
Quote: "If you don't have enhanced, you could write a routine to read the file format of a bitmap (fast)"

I don't understand what you mean, or what that would do?

Your signature has been erased by a mod because it was rubbish.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 16th Aug 2007 23:03
@ obese
yes, actually i decided to use a 3d plain and have the image as a texture so that i can scroll it making him look like he is swimming. But im having problems with the fact that as he goes down, he looks like he is bending. Attached is a picture of him.

The problem with the gaming community is people think that the resolution of a game defines how good it is. I am not afraid to make a game where the main character is 50x50.

Attachments

Login to view attachments
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Aug 2007 01:06
his texture looks good but he doesn't look very cellular to me, but then again I'm not a microbiologist
here's a nice pic i found of some micro organism dudes

Protozoa
Vorticella

Paramecium bursaris (this one has micro-alga growing inside it!)


Cyanobacteria


Ecdysozoa
Hypsibius Dujardini

A colony of Rotifer Conochilus Hippocrepis

Gastrotrich Chaetonotus




wow there are so many of these!
http://www.micromacro.co.uk/micro_organisms/micro_organisms.htm

And here's a nice pic of some micro-alga (called Dunaliella Salina) which I think is a food source for microbes.


Your signature has been erased by a mod because it was rubbish.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Aug 2007 01:58
Quote: "That sounds pretty cool, I can see this being very slow in DBC though "

Quote: "you could write a routine to read the file format of a bitmap (fast) or you could use the POINT command and look at each pixel in an image on the screen (slow but easy). "


Let me clarify: disk access of the bitmap to get at it's pixels is much faster than using the point command. But using the point command with an image on the screen is easier than writing a bitmap reading routine. Both methods would be best suited for a static blended image. Trying to have dynamic alpha blending would be terribly slow using either of these methods - unless you had a very small image. If you want dynamic alpha blending beyond black as transparency for dark basic, you'll need a dll for the best speed. If you want to use FreeImage for alpha blending dynamically, you'd have to use the functions in conjunction with memblocks and convert the memblocks to images. My example with freeimage is just to show that the tools are there for alpha blending -

And Obese - rotation is in there also. So you could rotate sprites and images anywhere from 0 to 360. I believe the core image handling of DarkBASIC is done using FreeImage.

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Aug 2007 02:59
Oh cool
I'm really unimpressed with the small amount of sprite commands so that would be a real help thanks

Your signature has been erased by a mod because it was rubbish.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 17th Aug 2007 20:05
i actually made him not as single celled, but 57 celled. I think i might change it back to 2d though, but then i cant scroll the texture,or can i?

(Y=M*X+B)=(X=(Y-B)/M)=(B=Y-M*X)=(M=Y-B/X)
and if you can figure out what it means i will give you a cookie.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Aug 2007 22:38 Edited at: 17th Aug 2007 22:40
Those Vorticella look a lot like Will Wright's cell in the spore video.

Quote: "i actually made him not as single celled, but 57 celled. I think i might change it back to 2d though, but then i cant scroll the texture,or can i?"

I don't think there's a built-in command for it but it shouldn't be too hard to do, the only question is is it going to harm the speed?
I will look into FreeImage as this seems to solve a lot of problems

@Latch
do you have any ideas for how to make a smooth and flexible membrane?

Your signature has been erased by a mod because it was rubbish.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 17th Aug 2007 23:04 Edited at: 19th Aug 2007 22:01
@ obese87

you're right, that is cool.

http://video.google.com/videoplay?docid=8372603330420559198
is a very good demo of spore that shows all the phases in detail.

(Y=M*X+B)=(X=(Y-B)/M)=(B=Y-M*X)=(M=Y-B/X)
and if you can figure out what it means i will give you a cookie.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 19th Aug 2007 20:12
Quote: "@Latch
do you have any ideas for how to make a smooth and flexible membrane?"


What do you mean?

Enjoy your day.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 19th Aug 2007 21:59
Quote: "What do you mean?"


Watch the video and at the beginning look at the skin of the little critter that Will controls.

(Y=M*X+B)=(X=(Y-B)/M)=(B=Y-M*X)=(M=Y-B/X)
and if you can figure out what it means i will give you a cookie.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 20th Aug 2007 03:02
@Latch
I was referring to how membranes are flexible in a sort of liquid way, is there a way to recreate this in DB?
It probably involves a lot of maths.
Can anyone tell me what tangent is used for, i've used sine and cosine but tangent seems to act in a strange way and I haven't found a use for it. Is there a tutorial on maths used in programming?

Your signature has been erased by a mod because it was rubbish.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Aug 2007 05:03
Quote: "@Latch
I was referring to how membranes are flexible in a sort of liquid way, is there a way to recreate this"


In answer to your question, if you want a wave like effect rippling through the microbe, you can calculate a wave motion for the pixels (a contraction and expansion). Best to create multiple images and then flip through them instead of calculating it real-time.

Quote: "Can anyone tell me what tangent is used for"

Uhhh, that's a huge question.

Tangent is basically the slope of a line. It is equal to y/x . So it is very useful in all sorts of ways. In programming, there is a lot of right triangle math - to find distances, to figure out rotation and polar coordinates, to figure out angles, etc. So if you can memorize this:

SOH CAH TOA - it tells you the relationships between sin cos and tan in a right triangle and the 3 sides.

Sin = Opposite/Hypotenuse
Cos = Adjacent/Hypotenuse
Tan = Opposite/Adjacent

If you have a vector that starts at x1,y1 and ends at x2,y2 you can figure out it's angle by using arctangent:
slope = y2-y1/x2-x1
angle = atan(slope)

Tangent represents the perpendicular to the radius of a circle. This is useful in calculating something like the collision of two pool balls.

You might want to study up on trig and especially right triangle math.

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 20th Aug 2007 20:46 Edited at: 20th Aug 2007 20:48
Thanks Latch
My maths is rubbish, I've done all this stuff in school but that was just lines of questions, no explanation of what's going on!
I looked on the forum for Tangents but all I found was a really bad explanation. I kind of understand now.

Here is a picture of two pool balls, are the purple lines acting like Tangents?

hmm... something is telling me that doesn't look right.

Your signature has been erased by a mod because it was rubbish.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 20th Aug 2007 21:32
My brain hurts

(Y=M*X+B)=(X=(Y-B)/M)=(B=Y-M*X)=(M=Y-B/X)
and if you can figure out what it means i will give you a cookie.
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 21st Aug 2007 01:31
Quote: "Here is a picture of two pool balls, are the purple lines acting like Tangents?"


The white line in the middle is a tangent. In terms of circles the tangent is a line that touches ONLY ONE point on the circle. This is because the slope is always inwards and so the tangent will never touch any other part of the circle. A real tangent is just what Latch said, a line with the same slope as a particular point in a graph of a function(for example) that intersects the graph at that point.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 21st Aug 2007 02:30 Edited at: 21st Aug 2007 02:30
ow... trigonometry is hard on people in grade school.


ps

I AM NOT A LITTLE KID!!!!!
i'm barely even in gradeschool as i am very close to juniorhigh.

(Y=M*X+B)=(X=(Y-B)/M)=(B=Y-M*X)=(M=Y-B/X)
and if you can figure out what it means i will give you a cookie.
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 21st Aug 2007 02:50
I took trigonometry in 8th grade and did OK. It just takes alot of time to learn the concepts and everything as its such a broad topic and everything is inter-connected, so it's hard for people who aren't actually taking it as a class in school to understand it completely.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Aug 2007 12:48
ok thanks

Your signature has been erased by a mod because it was rubbish.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 21st Aug 2007 18:11
Quote: "it's hard for people who aren't actually taking it as a class in school to understand it completely."


Ain't that the truth

(Y=M*X+B)=(X=(Y-B)/M)=(B=Y-M*X)=(M=Y-B/X)
and if you can figure out what it means i will give you a cookie.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Aug 2007 20:47
@Pixelator
I was thinking way too much in 2d. If you use plains as 3d sprites, you can do all the rotation and transparency you want using the 3d commands - including Ghost Object On.



Enjoy your day.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 23rd Aug 2007 00:23
i have switched it to 2d acctually but i hav postponed that game to work on my operating system that i am working on. thank you

A^2+b^2=c^2, but D^2-A^2/g^2*t-r-o-u-b-l-e = w+i+t+h / a*(c*a/p^i+t+o+l)/T+rhyming+with/P+f/o*r^(p-o-o/l)

That equation has a quote from a movie in it. Find it for a cookie
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 31st Aug 2007 18:53
@ OBese87

Quote: "Here is a picture of two pool balls, are the purple lines acting like Tangents"


I don't think so (I may be wrong)

but I think...



it's not drawn very accurately, but

the green line is the radius

the purple line is the tangent - it touches the edge of the circle only once

there's a right angle between the radius and the tangent

there are an infinite number of radiuses and tangents

can't think of anything else off the top of my head... haven't done maths in about 6 weeks and i only got a B in my AS levels so maybe I'm not as good as I thought

http://jamesmason01.googlepages.com/index.htm
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 31st Aug 2007 19:18
thanks DB that radius line just made it make a lot more sense to me

Your signature has been erased by a mod because it was rubbish.

Login to post a reply

Server time is: 2025-06-03 21:38:31
Your offset time is: 2025-06-03 21:38:31