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 / I need a replacement for flip bitmap

Author
Message
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th Nov 2004 12:01
The subject pretty much says it all!

I'm creating semi transparent reflective water and i need a flip bitmap command which works many times quicker than the DBP one!

Any Ideas on how to do this?

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 12th Nov 2004 18:12
can't you make an image with the "get image" command, and create sprite that's flipped with that image?

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 12th Nov 2004 18:17
OR, if its an object, can you not rotate it 180? OR inverse UV map it?

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th Nov 2004 21:32
No, neither of those work. the Object flipping doesn't work, and i'm already using get image, flip bitmap. It's no where near fast enough!

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Nov 2004 23:06
You could try getting the physical screen memory and copying it in scanline chunks. Not sure if that would be fast enough either, but it'd be faster than flipping the bitmap I expect.

It won't do much good for me to explain it all here, much better if I get back to you later with some code - I can't even remember the commands to get at the screen data just now.


Van-B


It's c**p being the only coder in the village.
DeepBlue
22
Years of Service
User Offline
Joined: 17th May 2003
Location: A little box in the UK
Posted: 13th Nov 2004 00:01 Edited at: 13th Nov 2004 00:17
OK thought I'd test it & try some different solutions and oh boy your right the in-built flip bitmap is relatively slow compared to what you can do in code.

Just using standard DBP best I found was to create a 2nd bitmap and copy a line at a time from the top of the source bitmap down and the bottom of the target bitmap up. Then simply copy the target bitmap back over the source bitmap.

On a a 200 * 134 bitmap got the following times:
flip bitmap - 19.64ms
function (dynamically generates/deletes temp bitmap) - 6.00ms
pre-created & re-used temp bitmap - 1.95ms

The source/ test code is here, you just need a bitmap called image1.bmp



[Edit]
Wow just tested above with a 640x480 image very big difference:
flip bitmap - 204.00ms
function (dynamically generates/deletes temp bitmap) - 9.48ms
pre-created & re-used temp bitmap - 5.00ms
[Edit]

DeepBlue

The coder formerly known as Twynklet.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 13th Nov 2004 01:11
Why cant you UV map the image in reverse?
So instead of the mesh holding 0 -> 1, it hold 0 -> -1? Would that not work?

Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 13th Nov 2004 03:34
Memblocks definately.

Make a meblock the same size as the screen then use copy memory to copy lines straight from the back buffer (use get back buffer ptr() to find out where this is) but inverse the order.

I've got to do some homework now but I'll post examples later.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Nov 2004 19:47 Edited at: 13th Nov 2004 20:22
Piece of cake with memblocks. I'll do it write now. In the meantime, fancy yourself with this little spotlight demo. A texture bounces around the screen but shown as completely black until you put your mouse(flashlight) over it. The image is redrawn with the spotlight overlaying it.
crap, never uploaded it.

"eureka" - Archimedes

Attachments

Login to view attachments
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Nov 2004 20:14
Ok, here's a flip image command using memblocks. If you look at the code, you can see how to easily adjust it to flip horizontally instead.
Image size I used was 200x200.


"eureka" - Archimedes
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 13th Nov 2004 23:13
@Phaelax:
Nice spotlight code! Couple of points:
(1) I know its a demo - but some framerate based movement would be better.. No flashligh = 600+FPS, with flashlight = 137FPS.. Good idea though!

(2) If you move the flahslight quickly on mine, it leaves artifacts/distortions behind..

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Nov 2004 03:56
so don't move it fast.
code was never exactly optimized, besides that's not what he wanted anyway. The major slowdown is because I'm only rewriting the data when there's a visual change. Never quite dropped that much for me, but different pc's i guess. I see what you mean about the artifacts.

"eureka" - Archimedes
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 14th Nov 2004 04:24
I know it was only a demo (hence me saying so in point 1).. Hehe. I only said that as I could see it could be a VERY usefull tool once working in a bullet proof way. Is that how they do it in Halflife?

The Wendigo
22
Years of Service
User Offline
Joined: 13th Sep 2002
Location: A hole near the base of a tree in the US
Posted: 14th Nov 2004 04:33
You wouldn't by any chance be trying to reflect the skybox would you? If this is the case, then you cannot flip that. the problem you may be having is that you cube mapped the skybox and the water. The only known work around I have is to cube map the water only, and load in your skybox with everything textured the way you need. I ran into this with one of my engines.


Home of DOOP, Strata Works, and Height
DeepBlue
22
Years of Service
User Offline
Joined: 17th May 2003
Location: A little box in the UK
Posted: 14th Nov 2004 14:53
@Phaelax

Tried the memblock code I thought it would be faster (I was going to get around to trying it as well but never had time), but it's not.

Modified the code slightly to be able to compare times


On a 640x480 image/bitmap on my system the memblock based function takes approx 85ms to flip the image as compared to the function I posted above which uses copy bitmap takes approx 9.5ms. The key seems to be to keep it as simple as possible as even lock pixels on the function I wrote actually slowed the flip time.

DeepBlue

The coder formerly known as Twynklet.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 14th Nov 2004 19:08
@Phaelax - are you mapping the image to an objects or sprite? If so - ahy not negative UV map it?

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 15th Nov 2004 21:36
@Phaelax - I ran your code, thanks but it says that image at line whatever doesn't exist. That line is the make memblock from image. The image i'm using was created with set camera to image.

I know the image DOES exist, but will your code fail if the image is a camera? It looks that way to me.

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Nov 2004 09:41
Any extra help out there?

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 16th Nov 2004 09:44
Lol.. Why is everyone ignoring my suggestion of negative UV Mapping?! Lol..

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Nov 2004 10:43
I don't know how to do that.

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 16th Nov 2004 10:55
Are you making your own mesh?

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Nov 2004 10:56
it's a plain object.

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 16th Nov 2004 11:01
Hmm..

As you know, I've done some work with mesh's and memblocks. In that you can set the UV coords per vertice. By setting the range from 0-1 to either 0-(-1) or 1-0 it should reverse the image. Basically, you would invert the gradient..

i'm going to bed now, but I'll make an example tomorrow if I have time.. (busy day)..

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Nov 2004 11:02
Sweeet!

(i needs )

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 16th Nov 2004 11:22
Ok.. Again, knew I wouldn't be able to sleep with this prob on my mind



Just edit the load image to point at any old image.. preferably one you can tell has flipped.

Press U - will flip in the "U axis"
Press V - will flip in the "V axis"

Esc quits..

Err... Post any questions and i'll answer tomorrow.. Nite m8!

DeepBlue
22
Years of Service
User Offline
Joined: 17th May 2003
Location: A little box in the UK
Posted: 16th Nov 2004 12:34
Nic thats very nice indeed its so damn fast I cant time it (apparently around 0.02ms), just wasn't commenting because I like to see code, now we all kneal down and worship the mighty god of memblock UV mapping

DeepBlue

The coder formerly known as Twynklet.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 16th Nov 2004 19:59


It is pretty quick - my machine was fluctuating between 3100 and 3300 FPS and thats with lots of stuff loaded in the background!

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Nov 2004 02:41
there's no way that could be faster. creating an object with a memblock is waaaaay too slow for real-time use.

3300? what kinda terrahertz machine you running?

"eureka" - Archimedes
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Nov 2004 02:42
Hmmm, I just thought of something. If your image is on a plane, you you want to flip it, can't you just rotate your plane 180 degrees? That would see the absolute fastest.

"eureka" - Archimedes
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 18th Nov 2004 03:46
Its not creating the object from the memblock EVERY frame, just everytime you press the button to flip the UV data.

Memblock->mesh->object is actually quite quick..

As for machine specs, they're not far off yours Plaelax..

AMD Barton 2500+ Overclocked to 3200+
1Gb DDR400
ATI 9800XT 256Mb
Abit NF7S V2

If you want an example of the speed of memblock->object.. Check out my wave generator. IT creates a new object every frame. It does a few hundred frames a second on my PC.

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Nov 2004 10:26
I used this code to flip the image every frame, and it works sweetly.
You cant just rotate the plain 180 Degrees as then the image would still be wrong.

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 18th Nov 2004 10:40
Yeah, Mirroring and rotating are different creatures

I'm glad it works..

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Nov 2004 10:41
and it works well!

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Nov 2004 10:42 Edited at: 18th Nov 2004 10:42
XBox live is cool, halo2 sucks!
Outrun2 is only good in live mode! (Off topic i know, but let me rant!)

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 19th Nov 2004 02:04
This works!

scale object texture obj,1,-1

Boo!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 19th Nov 2004 02:08 Edited at: 19th Nov 2004 02:20
That works fine if you want the object mirrored, but as I understand it, Mobiius only wanted the TEXTURE mirrored..

[EDIT] Although it is usefull to know you can mirror entire objects like that.. Does it invert the normals too? Or does it make the object inside out like making a sphere with negative size does?

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 19th Nov 2004 02:17
thats right.

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 19th Nov 2004 07:06
Confused.

That command only flips the texture. It does not touch the object at all. I thought that's what you wanted.

Boo!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 19th Nov 2004 07:28
Oh crap - I misread what you said.. Lol.. You put scale object TEXTURE.. LOL.. I thought it was just scale object.

In THAT case, yes.. that works MUCH more efficiently than my method

Soz about that Spooky!

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 19th Nov 2004 08:31
a more efficient version?
Let me try that too.

1800+ XP - GeforceFX 5600 - 256MbDDR - 60Gb Hdd - XP Pro
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Nov 2004 08:39
umm, i only get about 550fps with a blank screen on a p2.8e chip. And also, the whole reason why ppl do use the memblock matrix for use with water/wave effects is because the creation is too slow. You'd be the only person I've ever heard get those kind of frame rates while creating an object from a memblock.

"eureka" - Archimedes
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 19th Nov 2004 09:02
Hehe.. I'm pround

I have a AMD 3200, 1Gb RAM and a 9800XT 256Mb.. So that might have something to do with it.

Login to post a reply

Server time is: 2025-06-10 05:44:09
Your offset time is: 2025-06-10 05:44:09