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.

Program Announcements / Advanced2D

Author
Message
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 18th Dec 2010 00:34 Edited at: 16th Jul 2011 13:14
~ UPDATED 13/07/11 ~

Hi all.
While working on my current project I had a need to draw some more complicated 2D shapes with alpha, fast, and unfortunately, although cloggy's dll has provided this excellently for a long time, it has become out of date and is incompatible with a number of new DBPro features which I'm using.

To solve the problem I quickly knocked up this little plugin which lets you draw a number of 2D shapes in both filled and unfilled varieties, and also a command to draw an image a bit like paste sprite, but without the overhead of creating a sprite, and slightly higher quality.

Update:
The latest version now supports:
- Batching (a2Start***Batch/a2EndBatch)
Dot batches are for use with a2Dot, line batches are used for all unfilled drawing commands, and triangle batches are used for all filled drawing commands. The batch size is an estimate of how many dots/lines/triangles you are going to draw. It doesn't matter if it's too big or too small, but the closer it is the more efficient the batch.
On my GeForce 7900 GS I can draw over 10 million visible dots per second using batching.

- Blend modes (a2SetBlendMode)
The use of this is fairly advanced. See this page for the possible blend modes and this page for the supported blend ops.

- Optional non-AA lines (a2SetLineAA)
Use a non-zero value to enable antialiasing on lines, and zero to disable it. Default is enabled.

- Clipping (a2SetClip)
Specify a clipping region. Nothing will be drawn outside this rectangle. You can reset the clipping region by using a2ResetClip.

- Fonts (a2CreateFont/a2DeleteFont)
Create a font using a2CreateFont. The ID is automatically allocated and returned to you. The sizeMode parameter controls how the size you specify is interpretted.
a2Size_Cell() - The size is interpretted as the cell size of the font in pixels.
a2Size_Char() - The size is interpretted as the character size of the font in pixels.
a2Size_Point() - The size is interpretted as a point size (such as 12pt).

- Text (a2Text/a2BoxText)
Draw text at a particular position on the screen. The box version will align the text in the box according the valign and halign parameters. 0 = top or left, 1 = center, 2 = bottom or right. The text is not clipped to the box.

- Font info (a2GetLineHeight/a2GetTextWidth)
The line height allows you to arrange multiple lines of text correctly. The text width includes whitespace in the text, so you can use it for drawing formatted text.

Command list:


All commands support alpha transparency. All shape drawing commands without "Fill" in draw the outline only. The DLL itself is only 31kb so don't worry about it increasing your executable size.

Just extract the attached zip file to your DBPro folder.

Rich Dersheimer has kindly made some help files which you can download here.

[b]

Attachments

Login to view attachments
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 24th Dec 2010 17:50
Nice Plugin! I'm using it in my WIP and it is incredibly fast compared to the built in commands, thanks a lot for sharing

TheComet

Rich Dersheimer
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 27th Dec 2010 20:16
Very nice! And generous of you to share!

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Jan 2011 20:48
I'm using this too. Also started a help file for myself. I'll share if I finish it.

Nice work Diggsey!

Ermes
16
Years of Service
User Offline
Joined: 27th May 2003
Location: ITALIA
Posted: 3rd Jan 2011 16:59
geat. i will use for sure.



[img][/img]
Sven B
14
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Jan 2011 15:39
Out of curiosity:
Does your plugin create a vertex buffer each time a drawing command is called?

Cheers!
Sven B

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Jan 2011 16:20
No, it uses DrawPrimitiveUP. Vertex buffers can actually be slower if you need to change every vertex every time you draw, which is the case for 2D shapes.

[b]
Sven B
14
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Jan 2011 16:52
I see, thanks!

I can't believe I missed those commands in the IDirect3DDevice9 interface... I'm ashamed of myself

Sven B

Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jan 2011 14:05
Just curious, do your drawing commands use anti-aliasing?

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 14th Jan 2011 16:02
It looks like they do, if you draw a line, take a snapshot and zoom in, you'll see the pixels "fade".

TheComet

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 14th Jan 2011 18:04
Lines do, filled shapes don't, but you can draw the outline version over the filled version with the same colour to get the same effect at very little cost.

[b]
Rich Dersheimer
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 9th Feb 2011 17:08
This is so cool! Love the alpha transparency and anti-alias. I'm using your plugin in my space trader game.

Thanks a bunch!

BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Feb 2011 18:27
Very useful again Diggsey, thanks.

Quote: "All commands support alpha transparency"


how do you get alpha transparency? The colour parameter is an integer (although RGB colours in DBP are DWORDS) and I don't see a way to apply alpha.

kaedroho
12
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 26th Feb 2011 18:32
You can either use IanMs rgba command from his Matrix1utils collection. Or you can add transparency to your image which you are pasting with the a2DrawImage command.

Your signature has been erased by a mod please reduce it to no larger than 600 x 120.
Rich Dersheimer
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 26th Feb 2011 19:14 Edited at: 26th Feb 2011 19:16
Any of the commands that call for a color integer will accept a DWORD with alpha, and using hex notation makes it easy, such as 0x880000FF, which gives a half-transparent blue, etc.



BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Feb 2011 22:14
Thanks, that helps

IanM's RGBA() returns the alpha channel value, maybe you meant SET ALPHA()? I tried it, and it worked. RGBA() had given me an error.

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2011 10:22 Edited at: 28th Feb 2011 14:17
cloggy's d3d plugin has the command you are after I think called "d3d_rgba(r,g,b,a)"...

I did have a working DBP function I'll dig out for those who don't like plugins.

Here it is (not my code):


Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Feb 2011 15:37 Edited at: 28th Feb 2011 15:38
Basically, an integer or dword is four bytes and the highest order byte is alpha, followed by red, green, blue. DBPro's rgb function always sets alpha to 255 but as people have pointed out, there are many ways to get around that. I find that the easiest way is to use hex notation.

[b]
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2011 15:44
I tend to set a bunch of colour global variables up in my setup code (constants would likely be better) unless I need to dynamically edit an alpha value but the little function I posted is really quick for those who don't understand (or don't want to understand) hex notation... like me...

As long as the rgba function runs fast enough I'm happy.

I do like this plugin Diggsey, will you be adding to it?

BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Feb 2011 17:03
I found SET ALPHA to be nice and easy, as posted in another thread it's working well on my Box2D Polygons...



Rich Dersheimer
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 28th Feb 2011 19:22
Hey Mr. Batvink! Neither your sig link nor your web button link are good anymore. Just sayin'...

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Feb 2011 23:36 Edited at: 28th Feb 2011 23:44
Funnily enough, I originally made this plugin for the exact same purpose as you batvink!

It's part of a level editor for a game I made, but haven't been able to release yet You can make any type of shape supported by box2d and it even shows you when it's invalid. The levels are completely scriptable with a specially made lua plugin and it's set up so all functions in the code and all box2d commands are accessible to the script. It even has a mission system and different objectives.

Editor:


Game:


The only problem is that the art is ripped from heli attack 3 (and had to be scaled up by a factor of 2), and I can't find an artist willing to redo the art as it's quite alot of work. I also need some images for props and level parts (that image above for example is supposed to be set in tunnels in the ground, not just against an earthy background with striped floors!)

@baxslash
I hadn't planned on adding any more features, but if there's anything you'd particularly like to see I might consider it?

[b]
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2011 10:12
Quote: "I hadn't planned on adding any more features, but if there's anything you'd particularly like to see I might consider it?"

Not really, just wondered if you had any more cool ideas. The triangle commands are great BTW! Very handy.

gwheycs62egydws
10
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 11th Apr 2011 06:55
Hi Diggsey

are there any more examples you could post ?

If a thought is Just a thought ~ so whats the main thought ?
gwheycs62egydws
10
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 11th Apr 2011 07:31
umm

the help file's would be nice to have too

only 2 of the commands are shown in the example

If a thought is Just a thought ~ so whats the main thought ?
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Apr 2011 11:02 Edited at: 11th Apr 2011 11:05
The shape drawing commands are fairly self explanatory.

The image commands are shown below (could make a nice screen-saver!)


If you don't want to colour the image, specify white (0xFFFFFFFF) as the colour to use when drawing the image.

[b]
gwheycs62egydws
10
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 11th Apr 2011 11:37
thanks Diggsey

perhaps to some one who is more comfortable with dbp and all additions

I can think of other places it could use

all i can say it takes a lot lot lot of time to build
a puzzle that has not been built yet

If a thought is Just a thought ~ so whats the main thought ?
gwheycs62egydws
10
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 11th Apr 2011 11:51
umm ya the shapes are but the other ones like

a2DrawImage
a2Option_FlipX
a2Option_FlipY

as to how they are implemented at this point

If a thought is Just a thought ~ so whats the main thought ?
gwheycs62egydws
10
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 11th Apr 2011 12:40 Edited at: 11th Apr 2011 12:41
I put together an example of all the commands in action

only 3 I do not know enough about to use at this point



If a thought is Just a thought ~ so whats the main thought ?
Jimmy
16
Years of Service
User Offline
Joined: 20th Aug 2003
Location: Back in the USA
Posted: 12th Apr 2011 17:57 Edited at: 12th Apr 2011 18:00
How did I miss this thread?

Excellent plugin, Diggs! I've been needing something like this for my box2d level editor as well.

Also, I have fixed your image commands sample code for you:





NaGaFailMo.
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 12th Apr 2011 18:35
Yeah, I was mainly showing how to use the image commands so I forgot to use a2Dot as well

[b]
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Apr 2011 00:10
a2Dot is reportedly much slower than the standard DOT. I ran a little test myself and it was slower for me too (by a magnitude of 10 or more). While testing I also found that the a2* commands don't work with LOCK PIXELS.

Hope it's just a small glitch, and not too much work

gwheycs62egydws
10
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 13th Apr 2011 02:14 Edited at: 13th Apr 2011 02:15
Much thanks to
Diggsey & Jimmy

both examples help me understand how things work

I hope my example helps other understand how the commands are used

I did a little tweaking on the the
ini file for the dll

just so I could understand how a the command works

attached is all examples posted
and my tweaking to the ini file
so others can understand how to use the commands

my example was a quick put together

If a thought is Just a thought ~ so whats the main thought ?

Attachments

Login to view attachments
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th Apr 2011 03:33
Quote: "a2Dot is reportedly much slower than the standard DOT. I ran a little test myself and it was slower for me too (by a magnitude of 10 or more). While testing I also found that the a2* commands don't work with LOCK PIXELS."


That's not strictly true:



Using lock pixels will speed up dot significantly, making it faster. This is because a2Dot and dot work completely differently. The dot command moves the bitmap to system memory, edits a single pixel and then moves it back again. When you use lock pixels that means it only has to move it there and back once for however many dots you draw.

The downsides to using dot is that for less than about 1000 dots per frame, the moving of the bitmap takes more time than 1000 a2Dots, and you can't use transparency or any form of blending.

a2Dot works by sending a single point to the graphics card to be drawn. This means the drawing is hardware accelerated, the bitmap doesn't need to be moved, and transparency can be used. It is possible to speed up drawing lots of a2Dots at a time (100s of times faster than using dot with lock pixels) by using batching (sending all the points to the graphics card in one go), but this plugin doesn't support that (yet).

All the a2 commands use the graphics card to draw the shapes. The build in drawing commands except for box use the CPU to do it. That's why none of them support transparency.

[b]
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Apr 2011 16:10 Edited at: 13th Apr 2011 16:14
OK, that makes sense. I was helping somebody with an issue where he was editing 800x600 (480,000) pixels. So DOT may have become far more efficient in that scenario.

However...the basic test I did, using DOT and a2Dot with no pixel locking, populating the 800x600 screen 10 times, showed a2Dot as slower. I'll see if I can find the test code again.

EDIT: It's here...

http://forum.thegamecreators.com/?m=forum_view&t=183603&b=1&msg=2183934#m2183934

Jimmy
16
Years of Service
User Offline
Joined: 20th Aug 2003
Location: Back in the USA
Posted: 13th Apr 2011 17:00
I ran the test on my little EEEPC here, and a2Dot is nearly 100% faster...

the a2Dot set finished in 23 seconds, and the dot set finished in 44.

NaGaFailMo.
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 7th Jul 2011 23:41
Just majorly updated the plugin. (Got bored of their being no decent text support in dbpro since the d3d plugin stopped working...)

As for the a2Dot speed discussion, that can now be resolved The latest version can draw over 10 million visible dots per second when using the new batching feature.

[b]
Duffer
16
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 8th Jul 2011 01:10
@ Diggsey,

Many thanks for this - it's going to prove v useful for a project of mine.... missed this plugin first time around. Really useful for GUIs etc.

The ini file suggests there may be some help files? If you have any help files, gratefully received...

a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Jul 2011 10:28
Quote: "Just majorly updated the plugin."

Fantastic!! I'll take a look...

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Jul 2011 13:38
Quote: "The ini file suggests there may be some help files?"

I'm afraid not. The drawing commands are self-explanatory and the rest I've tried to explain in the first post. Intellisense should tell you the parameters needed.

[b]
Rich Dersheimer
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 8th Jul 2011 13:47 Edited at: 8th Jul 2011 13:59
Cool new stuff!

Do you have a list of the "constants" that are used by the program? I notice that a2CreateFont has three values for sizeMode, but what are the possile values for style and charSet? I'm adding the new commands to my personal help files for A2D and would like to include that info.

EDIT - nevermind, I just saw the values listed on the first page. Silly me.

By the way, I'd be happy to post my help files when I'm done.

BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Jul 2011 17:54
excellent, thanks Diggsey

Quote: "As for the a2Dot speed discussion, that can now be resolved"


Yay!

RedFlames
12
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 9th Jul 2011 21:58 Edited at: 9th Jul 2011 22:14
Hey Diggsey, this sounded like an awesome replacement for d3dFunc's, as it has a critical bug with Rendertargets... So i tried the same with your functions, but it produces the same results!

I'll attach a screenshot and project to demonstrate my problem...

One is using D3d, the other A2d, but it's exactly the same error... The rendertarget should look the same as the "standard" drawn ones.


My System:
Windows 7 (x64)
Intel Core2Duo E6550 2x2.33Ghz
Ati Radeon HD3850 512MB
4GB DDR-800 RAM

Oh and here is the fix I'm currently using.

Somehow i think this is related to DirectX / Direct3d instead of your plugin... So can anyone reproduce my results?

Edit: The zip-file contains 2 precompiled EXE-files for d3d and a2d, and the source has a Constant at the top to switch between d3d/a2d.

Attachments

Login to view attachments
gwheycs62egydws
10
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 9th Jul 2011 23:13
it seems with DBP

the lighting levels have been reduced

the command to bring the light up is

SET AMBIENT LIGHT 47

this should fix that quirk

If a thought is Just a thought ~ so whats the main thought ?
Rich Dersheimer
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 10th Jul 2011 00:42 Edited at: 11th Jul 2011 09:32
Diggsey, I'm finding that a2DrawImage is not giving me a clean image. The drawn image is a little bit blurry, maybe like it's anti-aliased or something. here's an example... a stack of four graphics, the first is the original drawn to the screen, the second is drawn with a2DrawImage, the third is pasted, and the fourth is a pasted sprite.

EDIT: image removed because the problem was fixed.

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Jul 2011 14:01 Edited at: 10th Jul 2011 14:02
@RedFlames
That's the expected output for what you've done. First of all you are drawing to a render target with an alpha channel, and then you're drawing to a render target (the backbuffer) which doesn't have an alpha channel. If you want them to look the same, create the render target without an alpha channel like so:


If you need an alpha channel:
First, don't expect the output to look the same as if you draw straight to a backbuffer. It's impossible because colour blending is not associative (ie. if + is the blending operation: color1 + (color2 + color3) is not usually the same as (color1 + color2) + color3.)

Secondly, you might want to change the blending mode. I'll try to explain how blending works:
Blending combines a source colour with a destination colour in a certain way to produce a single resultant pixel colour. Each colour channel is treated as though the values range from 0 to 1.

- The source and destination colours are each multiplied by a colour or value. By default, the source is multiplied by its own alpha value, and the destination is multiplied by one minus the source's alpha value.

- These new colours are then combined using a simple operation (by default adding) but it could be any from this list.

If you think about it, these default blending settings mean that if the source has zero alpha, the resulting colour is the same as the destination (ie. no change) and if the source has full alpha, the resulting colour is equal to the source.

The problem is when drawing to a render-target that has alpha. Even if it has full alpha to begin with (which yours didn't since you cleared it to transparent, making the problem much worse), after drawing something semitransparent to it, it will no longer have full alpha (because the alpha channel is blended with the source's alpha channel just like any other colour channel)

It is possible to have a different blend mode for the alpha channel from the others but this plugin doesn't support that yet.

[b]
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 10th Jul 2011 14:21 Edited at: 10th Jul 2011 14:38
@Rich Dersheimer
Looks like I forgot the half-pixel offset which D3D requires. I've fixed it and will update the first post soon.

edit:
Updated the first post. Separate alpha blending is now possible, and a2DrawImage should be nice and sharp.

[b]
Rich Dersheimer
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 10th Jul 2011 16:36
Quote: "Updated the first post. Separate alpha blending is now possible, and a2DrawImage should be nice and sharp."



Sweet!

And I just noticed that the convenient a2ResetClip was added to the command list as well.

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th Jul 2011 22:50
Just uploaded an update which fixes a rather obscure bug caused by a "feature" of the VC++ optimising compiler.

[b]
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jul 2011 10:54
Diggsey, I have a question regarding this plugin. I'm using it for a netbook game and it works fine but when I run "a2line" on my netbook I get a 4/5 pixel thick line instead of 1 pixel (I get the same using cloggy's dll)... any ideas why? I assume it's cause the graphics are not great on a netbook (using an N455 Intel Atom chipset).

I should really try the DBP "line" command and see if that works but I have a feeling it will work in the same way.

It kind of spoils my laser scope when it turns into a flashlight

Login to post a reply

Server time is: 2019-12-09 07:14:23
Your offset time is: 2019-12-09 07:14:23