Draw3D (by hectic)

Blitz3D Forums/Blitz3D Programming/Draw3D (by hectic)

Abrexxes(Posted 2008) [#1]
Edit: Version 3.2 + Phys : http://www.hectic.de/data/Draw3D.V.3.2.rar



VERSION : 3.0

Draw3D is the fastest way to use 3D hardware (and features) power for 2D games. It gives you a collection of simple functions to speed up your game, and "stretch" it to "every" resolution in realtime!



Download v 3.0 : http://www.hectic.de/data/Draw3D.V.3.0.rar
Previous versions and the german board you will find here:
http://blitzbasic.pytalhost.de/viewforum.php?f=4&sid=8ebc11650e71a2002fa64894688fcf44
Note that Draw3D V3.0 is not compatible to older versions!



Have fun and thanks to hectic for this great stuff.




Abrexxes(Posted 2008) [#2]
Modification for 3.0 (only) 16:9 Fake

;Origin3D( X-Size, Y-Size, Mode )
Function Origin3D(FDrawX#,FDrawY#,Mode%=0) ; Mode 0 = stretch / Mode 1 = boxed
   If Mode = 0 Then DrawXScale=GraphicsWidth()/FDrawX : DrawYScale=GraphicsHeight()/FDrawY
   If Mode = 1 Then
      If FDrawX > GraphicsWidth() Then RuntimeError "Origin3D boxed X value smaller than screen"
      If FDrawY > GraphicsHeight() Then RuntimeError "Origin3D boxed Y value smaller than screen"
         DrawXScale=1 : DrawYScale=1
   EndIf
   ScaleEntity DrawPivot,DrawXScale/10.0,DrawYScale/10.0,1
   DrawXSize=FDrawX
   DrawYSize=FDrawY
End Function 


With this Origin version you have a third parameter to fake 16:9 screens (or whatever)
Graphics3D 800,600
Origin3D (800,400,1) 


cu


Abrexxes(Posted 2008) [#3]
***temp***


Danny(Posted 2008) [#4]
Thanks for setting up this thread Abrexxes;

What I especially like about Draw3D is that it can automatically adjust to different screen resolutions, that's fantasic! And thanks for the 16:9 trick by the way, that's extremely usefull as well..

I guess Draw3D's only 'weakness' (if you can call it that) is that you ALWAYS need a CAMERA entity for it to work. But that's a small price to pay... So i'm currently re-rigging my engine to accomodate for this..
Also the coordinate system takes getting used to - with 0,0 being in the center of the screen in stead of top left..

Sorry, but i've got tons of questions...

1) Do I understand correctly that with the Clear3D() command, it basically means it is faster to destroy and rebuild ALL graphics (surfaces) every frame - as opposed to leaving them on the screen? You'd think that would go against basic principals, but I undestand from some comments it DOES actually give a speed increase??

2) It would be handy if Draw3D comes with a tool or utility so you can make the bitmap fonts yourself (especially at runtime) - I'm still trying to figure that one out!

3) Do I undestand correctly that it won't be much trouble at all to create a DrawImage3D() variation that actually creates a 3D sprite-like quad (one that's not on the camera plane) - so that you can also use Draw3D for true 3D particles, instead of 2D particles?
That would add massive potential to Draw3D since it's one of the most compact and clever single surface systems I've seen!

4) Also, it would be very handy to have functions like these so you can better position text/buttons - taking into account the camera/font scale settings, etc.:
GetFontHeight3D%( fontHandle )
GetFontWidth3D%( fontHandle )
GetStringWidth3D%( fontHandle, txt$ )
GetStringHeight3D%( fontHandle, txt$ )

5) Last; any idea why 'alpha' seems to work on almost everything except image buttons?? They disappear (pop off) when alpha is set below 0.5, and appear (pop in) above 0.5 - but don't fade?!

Thanks and all the best,
Danny


Abrexxes(Posted 2008) [#5]
1) Draw3D has a "ClearList" with every image inside that you load/grab. If you call Clear3D() all the images are removed from the screen (like a 3D CLS). The next frame Draw3D draw them all again. But to clear all the images after each frame your grafikcard need some time. If you have now a picture in the background that is always on the same place you dont need to "clear" it each frame. So you can take this picture out of the "ClearList" with ClearOff3D and save some rendertime. This will speed up Nvidia cards enorm and ATI cards a little bit.

BUT! In this case dont redraw the image every frame. x). So be carefull with this.

2) What do you mean "at runtime"? You can take "FontText" to create a Font and "Photpshop" or "Gimp" to fix it. I dont think that hectic will make a workflow for this. But if anyone else will do that...? :)

3) Why not, Draw3D use a simple Graphics3D mode. You can also make a simple 3D World and use only the text functions of Draw3D.

4) Or to write a little framework to make a setup during development (include "font_tool.bb" ;)

5) öhm...no..we will see.

bye


Danny(Posted 2008) [#6]
Ok thanks for that Abrexxes,

I guess 'ClearOff3D' is a 3.1 function because I don't see it in 3.0. But I see how Clear3D works so I can add it myself, no problem..

ciao for now,
Danny


Abrexxes(Posted 2008) [#7]
Ups..sorry. I have read ClearOff3D in your question . ^^ Yes, ClearOff3D and ClearOn3D will be in 3.1.


puki(Posted 2008) [#8]
This looks exciting.


Stevie G(Posted 2008) [#9]
Nice. Although when I tried it in fullscreen mode each individual letter quad overwrites the next by half?


_33(Posted 2008) [#10]
I tried 3.0 a while back, seemed like a pretty good contender to Fast Image.

Cheers


Abrexxes(Posted 2008) [#11]
Although when I tried it in fullscreen mode each individual letter quad overwrites the next by half?


Can you send us a zip file with your example and and/or make a screen please?

EDIT: Make sure that your fullscreen mode runs in 32 bit mode, else Alpha is not working. (Graphics3D 800,600,32,0)


Stevie G(Posted 2008) [#12]
I was running it in 16 bit. Strange that your alpha doesn't work unless 32bit depth is used?


Filax(Posted 2008) [#13]
Excellent library !!! Many thanks ;)


JoeGr(Posted 2008) [#14]
This is great! I've found the perfect use for the ImageLine3D() command. Check this out.



Download here


hectic(Posted 2008) [#15]
This is very nice work JoeGr ;)


Dreamora(Posted 2008) [#16]

I was running it in 16 bit. Strange that your alpha doesn't work unless 32bit depth is used?


Not really, 16 bit mode has no real alpha ... 16bit mode is "there or not there" alpha with dithering which results in very "funny" results.
Use masking if you are in 16bit


Abrexxes(Posted 2008) [#17]
@Stevie G
What dreamora says.
If you want to use 16bit mode you must use optimized 16bit (or 8bit) graphics and fonts (png saved with transparency bit). All the files included in the original download is 24bit alpha stuff.

But note that in 16 bit mode you can not use blend effects (for the buttons and so on), that is not a limitation of Draw3D but a limitation of the 16 bit mode. Here some links:
http://en.wikipedia.org/wiki/Color_depth + http://en.wikipedia.org/wiki/Portable_Network_Graphics

@ JoeGr Cool!


Roland(Posted 2008) [#18]
Hey all,
I've been using Draw3d 3.0 in my latest project, and it's a life-saver! It really is as fast as can be and makes setting up huds / particles way simpler than any other lib i've used.

I've made a couple of edits to my sourcecode -- if people would find them useful I'd be happy to share. The main thing that I added was to provide the option of basing your x,y coordinates at the top left of the screen instead of the center. I know that this is a pretty simple thing to change, but for screen interfaces and HUDs, it's pretty useful. So when designing your HUD in photoshop, you can set it up for your target resolution and specify exact pixel coordinates to where your images need to go on screen.

I also removed the default "glow" that happens when you hover over buttons, and created some simple helper functions to create buttons, groups of buttons, etc., that can be switched on and off, etc.

Abrexxes -- it would actually be really great if draw3d had the ability built in to create groups of buttons and stuff that could be controlled all together. I suspect that's often how they are going to be used.

The other feature that I'm needing in my game is to be able to create a draw3d image from a blitz image buffer. I need to render down a portion of the screen to a buffer and then handle that as a button (for a level selection screen). It would be awesome if the next version could include that.

The 16:9 mod is something I was going to request -- cheers!

Thanks again to Abrexxes and Hectic for this awesome lib. You guys rock!!!


Roland(Posted 2008) [#19]
Oh yeah -- the other thing I added which is really helpful (if used properly) is the ability to specify an entityorder when you load an image into draw3d. This way I was able to use some of my draw3d images for backgrounds (like starfields, etc.), and some for foregrounds, (like HUDs, etc.)...

Let me know if you want it!


hectic(Posted 2008) [#20]
EntityOrder is set automatically by load (LoadImage3D and LoadFont3D). Later loaded images (Surfaces), have a higher priority. Within a surface is like in normal 2D commands.

Attends: GrabImage3D create not a new Surface!!!


hectic(Posted 2008) [#21]
Roland,

The default 'Glow' is not available in the (new Version) V.3.1 more. This is because CreateTexture with some graphics cards do not work anymore. In V.3.1 must instead button-flag entered.

'Create groups for buttons' is not so easy, to be integrated. Draw3D is not for this been designed. It stays for all but free, to write extensions to the Draw3D. :)

Invisible Buttons possibly may be in the V.3.1 using native commands can be made. So wait.

-

Sorry if my English incomprehensible should be, I work with automatic translator.


Abrexxes(Posted 2008) [#22]
@Roland
my game is to be able to create a draw3d image from a blitz image buffer

That is not the problem. I have made a command for this but removed it because as hectic wrote Blitz has to much problems with the "CreateTextur" command on new cards and drivers. In the case where you dont need transparent values, you can create a textur like 512*512 (draw to the texturbuffer), and use a function to load it, but there is absoltely no garantie that this works with new drivers or cards.
After this you can grab your images.

Take the LoadImage3D and make your own LoadTexture3D function by modify params ans this line:
Local DrawTexture%=LoadTexture(FDrawFile,FDrawMode)

to load the textur handle
Local DrawTexture%=TexHandle

Where TexHandle is your handle that CreateTextur has returned.

bye


Pinete(Posted 2008) [#23]
Hi all,
just a question...
What about unicode for text? Is Draw3D capable of doing this kind of stuff?
FastText can do it and it is one of the reasons I'm using it...
:o)

All the best!


Abrexxes(Posted 2008) [#24]
If you make your own tables and fonts yes, else no.

Mean, it is possible to make other languages/carakters as bitmap font.

bye


hectic(Posted 2008) [#25]
Draw3D (fonts: standard.png, cosmic.png and courier.png) used 'ISO / IEC 8859-1' & 'Windows-1252'. This will be the most common languages. The Draw3D is designed primarily for games, not for typographical masterpieces. ;)

The Draw3D is therefore not as competition for FastText.


Danny(Posted 2008) [#26]
@Roland: Have you (or anyone else) managed to display fonts properly at 1:1 pixel scale? I've tried many things but keep getting that softy blurry look - which isn't really working for me...

Also, does anyone know of a tool or program to create these font bitmaps?? I used to have one when playing with FastText - but can't find it anymore :/

Thanks,
Danny


Abrexxes(Posted 2008) [#27]
hi Danny

Fontext is not bad, but you must "fix" the output with another programm and "put" the informations in pixel 0.0 (RGB) values.
See here: http://www.blitzbasic.com/Community/posts.php?topic=75269

about the rest hectic says:

the problem is that all the carakters are resized to fix them (same size)

A) You can make the fonts more sharpen, as you can see the originals are not 100%.

B) You can use 1024*1024 textures (and rewrite the function) but that needs more power.

C) you will have this problems all the time if Origin =! Graphics3D because all the fonts will be scaled.

So you can use fasttext to avoid this but only use simple fonts, or Draw3D and bitmaps with real game fonts.

cu

PS: If you have only thinks like "GAME OVER" or "LEVEL1" load them as image and use the 1pixel law. That means if you want a 120*30 image , use a 119*29 image and grab 120*30 as there is always a pixel lost when doing UV Mapping. se here last 5 posts:
http://www.blitzbasic.com/Community/posts.php?topic=75216


Danny(Posted 2008) [#28]
Thanks again for that A,

I'll check out the text and font routine and see if I can figure something out.
D3D works perfect with bitmaps, so it should be possible to get the correct scaling for letters I'd think...


Abrexxes(Posted 2008) [#29]
Caution Danny, hectic just try to support FONText with auto scalling when loading (size of each charakter is scanned), so wait out and spend not to much time in that at the moment, wait for 3.1. ^^

http://www.blitzbasic.com/toolbox/toolbox.php?tool=89

bye


Beaker(Posted 2008) [#30]
If I ever get time this century I may be willing to add a special Fontext output for Draw3D. Abbrexes, if you are interested then drop me some technical details to my e-mail address.


Abrexxes(Posted 2008) [#31]
Excellent !!!
If we have the new workaround for the "load" function we will see.

Thanks :)


hectic(Posted 2008) [#32]
@ Beaker,
First thank you for your offer. The following things would be important for me. But i can not the effort assess. So let me know how I can be cooperative


- *edit* Sorry, the first point already exist */edit*

- All characters should entirely to left. The width of individual characters, I would then read by ReadPixelFast (computing time savings in operation).

- There should be a warning, if some characters over the Grid. This happens for example with Autosize and certain effects.

- The grid should be 2 pixels wide. So every 1 pixel wide for top, down, left and right for each characters.


Text is automaticaly translatet


hectic(Posted 2008) [#33]
@Beaker, I have looked again FONText functions, and I am thrilled. I have also tried today that I have these problems themselves to filter and also managed. The only problem I have, if individual characters in the other characters Tilesection advised.

I will, in any case, a useful description of FONText in combination with Draw3D.


Roland(Posted 2008) [#34]
@Hectic -- Thanks for your responses!

I don't think that I was clear -- the reason that I created my own "entityorder" mod for draw3d was because I am using draw3d along with real 3d meshes in blitz. I needed some of my draw3d images to show up behind those other meshes and some to show up in front.

When I do this, I am aware that you can only affect the entityorder of different images that are loaded -- not grabbed... So I modified the "loadimage3d" command to accept an entity order and force the surface ahead or behind my 3d meshes...

Does this make sense?

thanks again, and I can't wait to see the next version. I haven't integrated any fonts in yet, but should be getting to that point soon, and it'll be great to have the fontext integration.

cheers,
roland


Abrexxes(Posted 2008) [#35]
@Roland Yes, in case that you use real meshes at the same time it make sense.

Good news for 3.1. Hectic has solwed a lot of "problems" with text for 3.1.
- They are now 100% sharpen if you use origin/graphics 1:1. Else you lose only the "rescale" factor like all the other graphics.
- If you load a bitmapfont draw3d is looking for the size of every charakter, that means that your text looks more professionnel as every charakter use "his" own x-value.
- You can now load every compatible bitmap font, the pixel 0.0 values has gone. (See above).

So, with the new native commands (use textures) and the new text routines we will have a "big" update. :)


Danny(Posted 2008) [#36]
Sounds exciting abrexxes! Well done hectic!


Naughty Alien(Posted 2008) [#37]
..hey..how to set up transparency for loaded graphics, buttons or whatever?


Abrexxes(Posted 2008) [#38]
Thanks danny, we have made a mega font (2048*2048*24bit alpha shadow) to see the maximum what is possible....that means for you that you can load whatever you want (from 64*64 to 2048*2048) to get the best precision X)

Pst...... [http://www.abrexxes.huntingsoftware.de/draw3d/2.png]

Oh yes baby..hectic has made a great job! I hope that we will see the final in the next days!

bye

PS: The first threads will change next time, so dont care if there are some gfx missing. The 16:9 origin fake will be include in 3.1.


Abrexxes(Posted 2008) [#39]
Naughty Alien

For "Pictures" use this command: ColorG3D(sr,sg,sb,sa) sa = Alpha

Use this command like the color command of B3D

For the buttons wait for 3.1, there are some changes.

We trie to releasy a full english doc with 3.1

Edit: Sorry, i forgot that alpha is a float value between 0 and 1, so to have a red-50% value the command will be ColorG3D(255,0,0,0.5)
Edit2: 3te posting has new informations about 3.1


cyberyoyo(Posted 2008) [#40]
First of all a big "UP" to Draw3d. Awesome library. I have integrated it in my engine and I'm not looking back!

And its fairly easy to modify the code to suit one's own needs, I have modified a few functions myself, for example to change the drawing order for each texture and each font (although it could be intersting to be able to do it by text or by sprite, but this seems more difficult, maybe it could be included in a future version?)


Now a few questions:
- changed "Nativ" commands (load every kind of textur as "blend")
- new "nativ" commands (load materials like "water" or "metal" to draw your natives


1)Abrexxes or hectic, could you elaborate on that? I don't understand what it is about, what are "water" or "metal" textures?

2)I am getting a MAV error at the end of each level of my game when I unload textures and reload new ones. The MAV is located somewhere in the D3D code (actually it's in clear3D()). I am thinking that it's probably a mistake in the order in which I'm calling the D3D commands, but I'm thinking maybe somebody else has already run into this problem, maybe there's a tip handy?
In any case I am going to try and fix it myself when the time has come.


hectic(Posted 2008) [#41]
hi cyberyoyo,

here is the beta of v.3.1 http://www.hectic.de/data/Draw3D.V.3.1.rar

1.) see the example '03, natives testing.bb'

2.) see the example '15, load on the fly corectly.bb'

please note, that is the beta of v.3.1 (for testing)


jhocking(Posted 2008) [#42]
This is great! I've found the perfect use for the ImageLine3D() command. Check this out.

omg so awesome


Filax(Posted 2008) [#43]
Hi Abrexxes :)

I'm trying to convert the library for blitzmax B3D SDK
but i get problem with text ? When i try to display some chars
the program display a strip of text for unknow reason...

If anybody can take a look? I don't understand why... The
code seem the same? Maybe a problem with the SDK?

The topic:
http://www.blitzbasic.com/Community/posts.php?topic=75656


hectic(Posted 2008) [#44]
@Filax,

please use the newer version 3.1.

the v.3.0 has a problems with Text3D.

I have completly rewrite the Text3D function in the new version.

http://www.blitzbasic.com/Community/posts.php?topic=75651

download: http://www.hectic.de/data/Draw3D.V.3.1.rar


Filax(Posted 2008) [#45]
Ok thanks :) i hope that the new version solve the problem :)

See ya Hectic and many thanks for this great lib :)


cyberyoyo(Posted 2008) [#46]
Wow the 3.1 version is impressive, especially the collision demo, nice toys!
Is there a doc available already?
I take it that we will have to use clearon()/clearoff() instead of using clear3d() at each frame, right?
are there any other major differences in the way the commands will be used?

And one request: is it possible to have maybe a way to set individually the draw order on each drawn sprite or text? maybe not for 3.1 but for a future version?


JoeGr(Posted 2008) [#47]
Thanks for the update!

And one request: is it possible to have maybe a way to set individually the draw order on each drawn sprite or text? maybe not for 3.1 but for a future version?

For now (unless a lot has changed since 3.0) you should be able to get the mesh associated with an image like this:

image3D=LoadImage3D("image.png",2,2,0)
imageMesh=PeekInt(GDrawBank,image3D+DRAWBANKMESH)

Then you can use Blitz's EntityOrder command on the mesh. Note that if you have several images grabbed from a single image using GrabImage3D this won't work because they share the same mesh. I think this is correct anyway.

EDIT: @jhocking - I just spotted your comment. Thanks! That was just a quick test to see if the technique would work. There's a much more impressive demo on its way... :)


cyberyoyo(Posted 2008) [#48]
Yes I know I have alerady implemented this possibility for images and fonts, but I was wondering if it was possible for individual sprites, but I'm thinking maybe it's not possible with a single surface system :(
Anyway i can still sort the drawing order if I really need it.

Hey I noticed the new quad3d! it seems to draw a deformed sprite. Nice.
I am going to try and apply the correct perspective to it according to two rotations, not sure if I'll manage it though it will be a bit complex :)
This should enable 3D particles :)


hectic(Posted 2008) [#49]
@JoeGr, good idea. Perhaps I included this in the V.3.11 :)


@cyberyoyo,

- realistic 3D-Sprites are not available in the Draw3D. You need the Z-Depth. sry...

- German doc ~50% (English doc =0% will be translated)

- ClearOff() ist for fast rendering and not animated objects (HUD-systems, borders, backgrounds etc., see Example: 13, ClearOff3D, free moving.bb)


Panno(Posted 2008) [#50]
it must be love ....

great Hectic !

ps. how to make the font bitmaps ??


hectic(Posted 2008) [#51]
@Panno,

Beaker has made a fantastic bitmap-fontcreator 'FONText'

http://www.blitzbasic.com/Community/posts.php?topic=65909

verdana1.png and verdana2.png has made with (screencapture of) MS-Excel (Cellsize 16x16 and 32x32).

cosmic1.png and cosmic2.png are handmade with MS-Paint and PhotoFiltre.

All other fonts I make with FONText.


Panno(Posted 2008) [#52]
if you use only fontext.bmp's you can use

IDrawAsc=Asc(Mid$(FDrawString,IDrawLoop,1))- fontext% in draw3d.bb row 1122

set fontext% = 1 for using a fontext.bmp


Roland(Posted 2008) [#53]
Hey Guys,

quick question... Are there some limits to how many images draw3d can load/grab at once? In my project I seemed to reach a state in which adding another image to my code would produce a MAV in draw3d's drawimage3d command. If i took out another image that one would work fine. I really don't have that many images in use -- maybe around 50-100...

I don't think the problem is video memory, as I have plenty of that. The MAV is happening on the "addvertex" command of the drawimage3d function.

thanks for your help! I LOVE Draw3d!
roland


Abrexxes(Posted 2008) [#54]
Hi, yes there is a limit, but not a limit of draw3D, but Blitz3D. I am sorry, i have not the time at the moment and i am not a freak of 3D, so i will transmit this to hectic.

@all hectic still working on 3.11 and i on super frog ;)

bye