MiniB3d for FreeBasic

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
BagamutX
Posts: 10
Joined: Oct 19, 2012 13:27

Re: MiniB3d for FreeBasic

Post by BagamutX »

angros47 wrote:Just as you usually do in FreeBasic.

You can use 2d.bi to have both the 3d scene and the usual 2d screen (where you can use all standard freebasic commands)
Thanks i'll try. Does any body use SDL + OpenB3D, i'm interesting to using SDL_ttf and over SDL libs with OpenB3D?
angros47
Posts: 2387
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

As far as I know, super_castle did it with an old version of openb3d:

http://www.freebasic.net/forum/viewtopi ... 47#p133847

(at time, I haven't yet changed the name to OpenB3D, so the included file was minib3d.bi instead: you have to replace it, of course)

I've never tried that solution, anyway.
BagamutX
Posts: 10
Joined: Oct 19, 2012 13:27

Re: MiniB3d for FreeBasic

Post by BagamutX »

angros47 wrote:As far as I know, super_castle did it with an old version of openb3d:

http://www.freebasic.net/forum/viewtopi ... 47#p133847

(at time, I haven't yet changed the name to OpenB3D, so the included file was minib3d.bi instead: you have to replace it, of course)

I've never tried that solution, anyway.
Ok i'll try.
angros47
Posts: 2387
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Ok, version 0.6 is out!

Download it here:
http://sourceforge.net/projects/minib3d/files/

I added some support for uvw mapping (aXu, you needed it, didn't you?), Constructive Solid Geometry (try to build a random dungeon with it!), stencils (do you want a Portal clone in FreeBasic? now you can at least try), CameraToTex (to help cubemapping), and voxel sprites (I implemented them in OpenB2D, so I added them in OpenB3D, too)


Here is a demo of CSG:

Code: Select all

#include "openb3d.bi"

screen 18, 32, , &h02	

	
Graphics3d 640,480,32,1,1


var camera=createcamera(0)

var tube=Createcylinder(16)
scaleentity tube,10,50,10

var tube2=Createcylinder(16)
scaleentity tube2,10,50,10
rotateentity tube2,0,0,90



var cs=meshcsg(tube, tube2)

scaleentity tube,8,50,8
scaleentity tube2,8,50,8

var cs2=meshcsg(tube, tube2)
cs=meshcsg(cs, cs2,0)



'moveentity cs,0,0,15

fitmesh cs,-1,-1,-1,2,2,2,1
scaleentity cs,5,5,5,0
moveentity cs,0,0,15


dim a as single
dim key as string


var light=createlight()
positionentity light,5,5,5
pointentity light, tube

freeentity tube
freeentity tube2



do
'EntityTexture cube,tex',a
a=a+.01':if a>30 then a=0
'setfloat shader, "sTime",a


	key=inkey
        if key=" " then moveentity camera,0,0,0.1
        if key=chr(255)+"H" then turnentity cs,1,0,0
        if key=chr(255)+"P" then turnentity cs,-1,0,0,0
        if key=chr(255)+"M" then turnentity cs,0,-1,0,0
        if key=chr(255)+"K" then turnentity cs,0,1,0,0
        updateworld 1
        renderworld
        sleep 1
        flip
loop until key=chr(27)
chung
Posts: 648
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Re: MiniB3d for FreeBasic

Post by chung »

tryed the new version 0.6 with Tilecity_chung : crashes on init.
return back to version 0.5
angros47
Posts: 2387
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Maybe your video card doesn't support VBO.

In version 0.5 VBO were available, but disabled. In version 0.6 they are enabled.

You could fix it by changing global.cpp.

Otherwise, I just added a file already compiled with the fix (OpenB3D 0.6 for FB win32 NO VBO.zip). Please try it and let me know if it works.
chung
Posts: 648
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Re: MiniB3d for FreeBasic

Post by chung »

I tryed it.Ok now it works better
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Post by Domso »

is there any posiblity to parent a vertex to an other mesh ?
without i have to do it manually... and this is a lot of work
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: MiniB3d for FreeBasic

Post by D.J.Peters »

You can reduce the size of the windows dll
from 2.197.634 to 1.431.040 bytes. (upx will compress it than to only 524.288 bytes)
in makefile add -s and use $(CC) for stb_image.c also.

Code: Select all

CCMPILER = g++
CC=g++ -Wall -O3 -s
...
stb_image.o	: stb_image.c
	$(CC) -c stb_image.c -o stb_image.o
collidetri.o	: collidetri.c
	gcc -s -c collidetri.c -o collidetri.o
...
you should fix the problem of
gcc versus $(CC) -c collidetri.c -o collidetri.o

I think many more FB users would use your fine lib
if you put some examples to the archive.

Joshy
chung
Posts: 648
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Re: MiniB3d for FreeBasic

Post by chung »

i tryed the full optimization -O3 too and gained 20% fps on tilecity_chung.

About shadows : to avoid flashing shadows due to shadow surfaces too close to objects surface, i have tryed the following mod to shadow.cpp (i apply to the shadows vertex a small translation in direction of the camera)

Code: Select all

...
float camx,camy,camz;

void ShadowObject::Update(Camera* Cam){
    camx=Cam->EntityX(true);
    camy=Cam->EntityY(true);
    camz=Cam->EntityZ(true);

...

void ShadowObject::UpdateCaster(){
...
	for(it=Tri.begin();it!=Tri.end();it++){
		ShadowTriangle* etet = *it;

		float kdist=1.2/(10.0+abs(camx-etet->v1x)+abs(camy-etet->v1y)+abs(camz-etet->v1z));

		etet->tf_v1x= etet->v1x+kdist*(camx-etet->v1x);
		etet->tf_v1y= etet->v1y+kdist*(camy-etet->v1y);
		etet->tf_v1z= etet->v1z+kdist*(camz-etet->v1z);
		mat1->TransformVec(etet->tf_v1x, etet->tf_v1y, etet->tf_v1z, 1);

		kdist=1.2/(10.0+abs(camx-etet->v2x)+abs(camy-etet->v2y)+abs(camz-etet->v2z));

		etet->tf_v2x= etet->v2x+kdist*(camx-etet->v2x);
		etet->tf_v2y= etet->v2y+kdist*(camy-etet->v2y);
		etet->tf_v2z= etet->v2z+kdist*(camz-etet->v2z);
		mat1->TransformVec(etet->tf_v2x, etet->tf_v2y, etet->tf_v2z, 1);

                kdist=1.2/(10.0+abs(camx-etet->v3x)+abs(camy-etet->v3y)+abs(camz-etet->v3z));

		etet->tf_v3x= etet->v3x+kdist*(camx-etet->v3x);
		etet->tf_v3y= etet->v3y+kdist*(camy-etet->v3y);
		etet->tf_v3z= etet->v3z+kdist*(camz-etet->v3z);
		mat1->TransformVec(etet->tf_v3x, etet->tf_v3y, etet->tf_v3z, 1);

		e0x= etet->tf_v3x - etet->tf_v2x;
		e0y= etet->tf_v3y - etet->tf_v2y;
		e0z= etet->tf_v3z - etet->tf_v2z;
		e1x= etet->tf_v2x - etet->tf_v1x;
		e1y= etet->tf_v2y - etet->tf_v1y;
		e1z= etet->tf_v2z - etet->tf_v1z;
...
	}


and shadows become stables.
Last edited by chung on Dec 04, 2012 14:01, edited 1 time in total.
angros47
Posts: 2387
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

@Domso: what do you mean? Why would you assign vertex to another mesh?

@D.J.Peters: you are right, I should provide more examples.
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Post by Domso »

i do some experiments on mesh deformation
normally there are bones for it, but you cant set a bone parent to an other mesh, backwards it works
thats why im trying to create a "bone-mesh" using the vertexcolors
therefore I need to set a vertex parent to a mesh
also I know no posibility to move bones manually... only with the keyframe-animation
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: MiniB3d for FreeBasic

Post by D.J.Peters »

where are the method param of MeshCSG() defined ?

By the wy
can you add this missing enums in the next release please.

Joshy

Code: Select all

' BRUSH
enum BRUSH_FLAGS
  BrushFlagColor      =  1 ' (default)
  BrushFlagAlpha      =  2
  BrushFlagMasked     =  4
  BrushFlagMipmapped  =  8 
  BrushFlagClampU     = 16 
  BrushFlagClampV     = 32
  BrushFlagSpherical  = 64
end enum
enum BRUSH_BLEND_MODE
  BrushBlendAlpha = 1 ' (default)
  BrushBlendMultiply
  BrushBlendAdd
end enum
enum BRUSH_FX_MODE
  BrushFXNothing           =  0 '(default)
  BrushFXFullbright        =  1
  BrushFXVertexColor       =  2
  BrushFXFlatshaded        =  4
  BrushFXNoFog             =  8
  BrushFXNoBackfaceCulling = 16
  BrushFXAlphaBlending     = 32 ' only for Entity
end enum

' LIGHT
enum LIGHT_TYPE
  directionallight = 1 '(default)
  pointlight
  spotlight
end enum

' SPRITE
enum VIEW_MODE
  fixed = 1 ' (sprite always faces camera - default)
  free      ' (sprite is independent of camera)
  upright1  ' (sprite always faces camera, but rolls with camera as well, unlike mode no.1)
  upright2  ' (sprite always remains upright. Gives a 'billboard' effect. Good for trees, spectators etc.)
end enum

' TEXTURE
enum TEXTURE_BLEND_MODE
  NoBlend        = 0
  NoBlendNoAlpha = 1 ' (alpha when texture loaded with alpha flag)
  Multiply       = 2 ' (default)
  Add            = 3 
  Dot3           = 4 
  Multiply2      = 5
end enum 
enum TEXTURE_COORD_SET
  SetFirst  = 0 ' (default)
  SetSecond
end enum
enum TEXTURE_CUBE_FACE
  FaceLeft     = 0 ' (negative X) face
  FaceForward      ' (positive Z) face - (default)
  FaceRight        ' (positive X) face
  FaceBackward     ' (negative Z) face
  FaceUp           ' (positive Y) face
  FaceDown         ' (negative Y) face
end enum
enum TEXTURE_CUBE_MODE
  ModeSpecular = 1 '(default)
  ModeDiffuse
  ModeRefraction
end enum  
enum TEXTURE_FLAG
  FlagColor     =   1 '(default)
  FlagAlpha     =   2 
  FlagMasked    =   4
  FlagMipmapped =   8
  FlagClampU    =  16
  FlagClampV    =  32
  FlagSpherical =  64
  FlagCubic     = 128 
  FlagStore     = 256
  FlagForce     = 512
end enum
angros47
Posts: 2387
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Method=0 means that the second mesh is subtracted from the first mesh (the command MeshCSG does NOT modify existing meshes, it creates a new mesh that is the result of the CSG operation: so, you need to delete or hide original meshes if you want to see the result)

Method=1 (default) means that the first mesh and the second mesh are added (intersecting part of the meshes are removed: if you use this operation to add many boxes and cylinders, then you flip the result with FlipMesh, you will get a set of corridors/dungeons)

Method=2 means that the first mesh is intersected with the second mesh, and only the intersecting part is used. For example, by intersecting two spheres, you can get a lens.
angros47
Posts: 2387
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

@Domso

You should be able to access bones using GetChild statement.
Post Reply