OpenB3D Wrapper?

BlitzMax Forums/MiniB3D Module/OpenB3D Wrapper?

Chapman7(Posted 2013) [#1]
Wondering if anyone made one for BlitzMax

Or maybe someone could tell me where to start


Chapman7(Posted 2013) [#2]
Alright so I thought I figured out how to do this but, I am stuck. I imported all of the C++ files and wrote out External Functions for every command and when I import and run with the test code, nothing happens.

OpenB3D.bmx:
Import "inc/3ds.cpp"
Import "inc/animation.cpp"
Import "inc/animation_keys.cpp"
Import "inc/bank.cpp"
Import "inc/bone.cpp"
Import "inc/brush.cpp"
Import "inc/camera.cpp"
Import "inc/collision.cpp"
Import "inc/collision2.cpp"
Import "inc/csg.cpp"
Import "inc/entity.cpp"
Import "inc/file.cpp"
Import "inc/functions.cpp"
Import "inc/geom.cpp"
Import "inc/global.cpp"
Import "inc/light.cpp"
Import "inc/material.cpp"
Import "inc/maths_helper.cpp"
Import "inc/matrix.cpp"
Import "inc/mesh.cpp"
Import "inc/model.cpp"
Import "inc/pick.cpp"
Import "inc/pivot.cpp"
Import "inc/project.cpp"
Import "inc/quaternion.cpp"
Import "inc/shadow.cpp"
Import "inc/sprite.cpp"
Import "inc/sprite_batch.cpp"
Import "inc/stencil.cpp"
Import "inc/string_helper.cpp"
Import "inc/surface.cpp"
Import "inc/terrain.cpp"
Import "inc/texture.cpp"
Import "inc/texture_filter.cpp"
Import "inc/tilt.cpp"
Import "inc/touch.cpp"
Import "inc/tree.cpp"
Import "inc/turn.cpp"
Import "inc/voxel.cpp"
Import "inc/x.cpp"

'C
Import "inc/collidetri.c"
Import "inc/stb_image.c"
Import "inc/GLee.c"

Extern
	Function BufferToTex(tex:Int Ptr,buffer:Int=0,frame:Int=0)
	Function BackBufferToTex(tex:Int Ptr,frame:Int=0)
	Function CameraToTex(tex:Int Ptr,cam:Int Ptr,frame:Int=0)
	Function TexToBuffer(tex:Int Ptr,buffer:Int=0,frame:Int=0)
	Function MeshCullRadius(ent:Int Ptr,radius:Float)
	Function AddAnimSeq:Int(ent:Int Ptr,length:Int)
	Function AddMesh(mesh1:Int Ptr,mesh2:Int Ptr)
	Function AddTriangle:Int(surf:Int Ptr,v0:Int,v1:Int,v2:Int)
	Function AddVertex:Int(surf:Int Ptr,x:Float,y:Float,z:Float,u:Float,v:Float,w:Float)
	Function AmbientLight(r:Float,g:Float,b:Float)
	Function AntiAlias(samples:Int)
	Function Animate(ent:Int Ptr,mode:Int,speed:Float,seq:Int,trans:Int)
	Function Animating:Int(ent:Int Ptr)
	Function AnimLength(ent:Int Ptr)
	Function AnimSeq:Int(ent:Int Ptr)
	Function AnimTime:Float(ent:Int Ptr)
	Function BrushAlpha(brush:Int Ptr,a:Float)
	Function BrushBlend(brush:Int Ptr,blend:Int)
	Function BrushColor(brush:Int Ptr,r:Float,g:Float,b:Float)
	Function BrushFX(brush:Int Ptr,fx:Int)
	Function BrushShininess(brush:Int Ptr,s:Float)
	Function BrushTexture(brush:Int Ptr,tex:Int Ptr,frame:Int,index:Int)
	Function CameraClsColor(cam:Int Ptr,r:Float,g:Float,b:Float)
	Function CameraClsMode(cam:Int Ptr,cls_depth:Int,cls_zbuffer:Int)
	Function CameraFogColor(cam:Int Ptr,r:Float,g:Float,b:Float)
	Function CameraFogMode(cam:Int Ptr,mode:Int)
	Function CameraFogRange(cam:Int Ptr,nnear:Float,nfar:Float)
	Function CameraPick:Int Ptr(cam:Int Ptr,x:Float,y:Float)
	Function CameraProject(cam:Int Ptr,x:Float,y:Float,z:Float)
	Function CameraProjMode(cam:Int Ptr,mode:Int)
	Function CameraRange(cam:Int Ptr,nnear:Float,nfar:Float)
	Function CameraViewport(cam:Int Ptr,x:Int,y:Int,width:Int,height:Int)
	Function CameraZoom(cam:Int Ptr,zoom:Float)
	Function ClearSurface(surf:Int Ptr,clear_verts:Int=True,clear_tris:Int=True)
	Function ClearTextureFilters()
	Function ClearWorld(entities:Int=True,brushes:Int=True,textures:Int=True)
	Function CollisionEntity:Int Ptr(ent:Int Ptr,index:Int)
	Function Collisions(src_no:Int,dest_no:Int,method_no:Int,response_no:Int)
	Function CollisionNX:Float(ent:Int Ptr,index:Int)
	Function CollisionNY:Float(ent:Int Ptr,index:Int)
	Function CollisionNZ:Float(ent:Int Ptr,index:Int)
	Function CollisionSurface:Int Ptr(ent:Int Ptr,index:Int)
	Function CollisionTime:Float(ent:Int Ptr,index:Int)
	Function CollisionTriangle:Int(ent:Int Ptr,index:Int)
	Function CollisionX:Float(ent:Int Ptr,index:Int)
	Function CollisionY:Float(ent:Int Ptr,index:Int)
	Function CollisionZ:Float(ent:Int Ptr,index:Int)
	Function CountChildren:Int(ent:Int Ptr)
	Function CountCollisions:Int(ent:Int Ptr)
	Function CopyEntity:Int Ptr(ent:Int Ptr,parent:Int Ptr)
	Function CopyMesh:Int Ptr(mesh:Int Ptr,parent:Int Ptr)
	Function CountSurfaces:Int(mesh:Int Ptr)
	Function CountTriangles:Int(surf:Int Ptr)
	Function CountVertices:Int(surf:Int Ptr)
	Function CreateBrush:Int Ptr(r:Float,g:Float,b:Float)
	Function CreateCamera:Int Ptr(parent:Int Ptr=Null)
	Function CreateCone:Int Ptr(segments:Int,solid:Int=True,parent:Int Ptr)
	Function CreateCylinder:Int Ptr(segments:Int=8,solid:Int=True,parent:Int Ptr=Null)
	Function CreateCube:Int Ptr(parent:Int Ptr=Null)
	Function CreateMesh:Int Ptr(parent:Int Ptr)
	Function CreateLight:Int Ptr(light_type:Int,parent:Int Ptr=Null)
	Function CreatePivot:Int Ptr(parent:Int Ptr)
	Function CreatePlane:Int Ptr(divisions:Int=1,parent:Int Ptr=Null)
	Function CreateShadow:Int Ptr(parent:Int Ptr,Static:String)
	Function CreateSphere:Int Ptr(segments:Int,parent:Int Ptr)
	Function CreateSprite:Int Ptr(parent:Int Ptr)
	Function CreateSurface:Int Ptr(mesh:Int Ptr,brush:Int Ptr)
	Function CreateStencil:Int Ptr()
	Function CreateTerrain:Int Ptr(size:Int,parent:Int Ptr)
	Function CreateTexture:Int Ptr(width:Int,height:Int,flags:Int,frames:Int)
	Function CreateVoxelSprite:Int Ptr(slices:Int,parent:Int Ptr)
	Function DeltaPitch:Float(ent1:Int Ptr,ent2:Int Ptr)
	Function DeltaYaw:Float(ent1:Int Ptr,ent2:Int Ptr)
	Function EntityAlpha(ent:Int Ptr,alpha:Float)
	Function EntityAutoFade(ent:Int Ptr,near:Float,far:Float)
	Function EntityBlend(ent:Int Ptr,blend:Int)
	Function EntityBox(ent:Int Ptr,x:Float,y:Float,z:Float,w:Float,h:Float,d:Float)
	Function EntityClass:String(ent:Int Ptr)
	Function EntityCollided:Int Ptr(ent:Int Ptr,type_no:Int)
	Function EntityColor(ent:Int Ptr,red:Float,green:Float,blue:Float)
	Function EntityDistance:Float(ent1:Int Ptr,ent2:Int Ptr)
	Function EntityFX(ent:Int Ptr,fx:Int)
	Function EntityInView:Int(ent:Int Ptr,cam:Int Ptr)
	Function EntityName:String(ent:Int Ptr)
	Function EntityOrder(ent:Int Ptr,order:Int)
	Function EntityParent(ent:Int Ptr,parent_ent:Int Ptr,glob:Int=True)
	Function EntityPick:Int Ptr(ent:Int Ptr,range:Float)
	Function EntityPickMode(ent:Int Ptr,pick_mode:Int,obscurer:Int=True)
	Function EntityPitch:Float(ent:Int Ptr,glob:Int=True)
	Function EntityRadius(ent:Int Ptr,radius_x:Float,radius_y:Float)
	Function EntityRoll:Float(ent:Int Ptr,glob:Int=True)
	Function EntityShininess(ent:Int Ptr,shine:Float)
	Function EntityTexture(ent:Int Ptr,tex:Int Ptr,frame:Int,index:Int)
	Function EntityType(ent:Int Ptr,type_no:Int,recursive:Int=True)
	Function EntityVisible:Int(src_ent:Int Ptr,dest_ent:Int Ptr)
	Function EntityX:Float(ent:Int Ptr,glob:Int=True)
	Function EntityY:Float(ent:Int Ptr,glob:Int=True)
	Function EntityYaw:Float(ent:Int Ptr,glob:Int=True)
	Function EntityZ:Float(ent:Int Ptr,glob:Int=True)
	Function ExtractAnimSeq:Int(ent:Int Ptr,first_frame:Int,last_frame:Int,seq:Int)
	Function FindChild:Int Ptr(ent:Int Ptr,child_name:String)
	Function FindSurface:Int Ptr(mesh:Int Ptr,brush:Int Ptr)
	Function FitMesh(mesh:Int Ptr,x:Float,y:Float,z:Float,width:Float,height:Float,depth:Float,uniform:Int)
	Function FlipMesh(mesh:Int Ptr)
	Function FreeBrush(brush:Int Ptr)
	Function FreeEntity(ent:Int Ptr)
	Function FreeShadow(shad:Int Ptr)
	Function FreeTexture(tex:Int Ptr)
	Function GetBrushTexture:Int Ptr(brush:Int Ptr,index:Int)
	Function GetChild:Int Ptr(ent:Int Ptr,child_no:Int)
	Function GetEntityBrush:Int Ptr(ent:Int Ptr)
	Function GetEntityType:Int(ent:Int Ptr)
	Function GetMatElement:Float(ent:Int Ptr,row:Int,col:Int)
	Function GetParentEntity:Int Ptr(ent:Int Ptr)
	Function GetSurface:Int Ptr(mesh:Int Ptr,surf_no:Int)
	Function GetSurfaceBrush:Int Ptr(surf:Int Ptr)	
	Function Graphics3D(width:Int,height:Int,depth:Int=0,mode:Int=0,rate:Int=60)
	Function HandleSprite(sprite:Int Ptr,h_x:Float,h_y:Float)
	Function HideEntity(ent:Int Ptr)
	Function LightColor(light:Int Ptr,red:Float,green:Float,blue:Float)
	Function LightConeAngles(light:Int Ptr,inner_ang:Float,outer_ang:Float)
	Function LightRange(light:Int Ptr,range:Float)
	Function LinePick:Int Ptr(x:Float,y:Float,z:Float,dx:Float,dy:Float,dz:Float,radius:Float)
	Function LoadAnimMesh:Int Ptr(file:String,parent:Int Ptr)
	Function LoadAnimTexture:Int Ptr(file:String,flags:Int,frame_width:Int,frame_height:Int,first_frame:Int,frame_count:Int)
	Function LoadBrush:Int Ptr(file:String,flags:Int,u_scale:Float,v_scale:Float)
	Function LoadMesh:Int Ptr(file:String,parent:Int Ptr)
	Function LoadTerrain:Int Ptr(file:String,parent:Int Ptr)
	Function LoadTexture:Int Ptr(file:String,flags:Int)
	Function LoadSprite:Int Ptr(tex_file:String,tex_flag:Int,parent:Int Ptr)
	Function MeshCSG:Int Ptr(m1:Int Ptr,m2:Int Ptr,Meth:Int=1)
	Function MeshDepth:Float(mesh:Int Ptr)
	Function MeshesIntersect:Int(mesh1:Int Ptr,mesh2:Int Ptr)
	Function MeshHeight:Float(mesh:Int Ptr)
	Function MeshWidth:Float(mesh:Int Ptr)
	Function ModifyTerrain(terr:Int Ptr,x:Int,z:Int,new_height:Float)
	Function MoveEntity(ent:Int Ptr,x:Float,y:Float,z:Float)
	Function NameEntity(ent:Int Ptr,name:String)
	Function PaintEntity(ent:Int Ptr,brush:Int Ptr)
	Function PaintMesh(mesh:Int Ptr,brush:Int Ptr)
	Function PaintSurface(surf:Int Ptr,brush:Int Ptr)
	Function PickedEntity:Int Ptr()
	Function PickedNX:Float()
	Function PickedNY:Float()
	Function PickedNZ:Float()
	Function PickedSurface:Int Ptr()
	Function PickedTime:Float()
	Function PickedTriangle:Int()
	Function PickedX:Float()
	Function PickedY:Float()
	Function PickedZ:Float()
	Function PointEntity(ent:Int Ptr,target_ent:Int Ptr,roll:Float=0)
	Function PositionEntity(ent:Int Ptr,x:Float,y:Float,z:Float,glob:Int=False)
	Function PositionMesh(mesh:Int Ptr,px:Float,py:Float,pz:Float)
	Function PositionTexture(tex:Int Ptr,u_pos:Float,v_pos:Float)
	Function ProjectedX:Float()
	Function ProjectedY:Float()
	Function ProjectedZ:Float()
	Function RenderWorld()
	Function RepeatMesh:Int Ptr(mesh:Int Ptr,parent:Int Ptr)
	Function ResetEntity(ent:Int Ptr)
	Function RotateEntity(ent:Int Ptr,x:Float,y:Float,z:Float,glob:Int=False)
	Function RotateMesh(mesh:Int Ptr,pitch:Float,yaw:Float,roll:Float)
	Function RotateSprite(sprite:Int Ptr,ang:Float)
	Function RotateTexture(tex:Int Ptr,ang:Float)
	Function ScaleEntity(ent:Int Ptr,x:Float,y:Float,z:Float,glob:Int=True)
	Function ScaleMesh(mesh:Int Ptr,sx:Float,sy:Float,sz:Float)
	Function ScaleSprite(sprite:Int Ptr,s_x:Float,s_y:Float)
	Function ScaleTexture(tex:Int Ptr,u_scale:Float,v_scale:Float)
	Function SetAnimTime(ent:Int Ptr,time:Float,seq:Int)
	Function SetCubeFace(tex:Int Ptr,face:Int)
	Function SetCubeMode(tex:Int Ptr,mode:Int)
	Function ShowEntity(ent:Int Ptr)
	Function SpriteViewMode(sprite:Int Ptr,mode:Int)
	Function StencilAlpha(stencil:Int Ptr,a:Float)
	Function StencilClsColor(stencil:Int Ptr,r:Float,g:Float,b:Float)
	Function StencilClsMode(stencil:Int Ptr,cls_depth:Int,cls_zbuffer:Int)
	Function StencilMesh(stencil:Int Ptr,mesh:Int Ptr,mode:Int=1)
	Function StencilMode(stencil:Int Ptr,m:Int,o:Int=1)
	Function TerrainHeight:Float(terr:Int Ptr,x:Int,z:Int)
	Function TerrainX:Float(terr:Int Ptr,x:Float,y:Float,z:Float)
	Function TerrainY:Float(terr:Int Ptr,x:Float,y:Float,z:Float)
	Function TerrainZ:Float(terr:Int Ptr,x:Float,y:Float,z:Float)
	Function TextureBlend(tex:Int Ptr,blend:Int)
	Function TextureCoords(tex:Int Ptr,coords:Int)
	Function TextureHeight:Int(tex:Int Ptr)
	Function TextureFilter(match_text:String,flags:Int)
	Function TextureName:String(tex:Int Ptr)
	Function TextureWidth:Int(tex:Int Ptr)
	Function TFormedX:Float()
	Function TFormedY:Float()
	Function TFormedZ:Float()
	Function TFormNormal(x:Float,y:Float,z:Float,src_ent:Int Ptr,dest_ent:Int Ptr)
	Function TFormPoint(x:Float,y:Float,z:Float,src_ent:Int Ptr,dest_ent:Int Ptr)
	Function TFormVector(x:Float,y:Float,z:Float,src_ent:Int Ptr,dest_ent:Int Ptr)
	Function TranslateEntity(ent:Int Ptr,x:Float,y:Float,z:Float,glob:Int=False)
	Function TriangleVertex:Int(surf:Int Ptr,tri_no:Int,corner:Int)
	Function TurnEntity(ent:Int Ptr,x:Float,y:Float,z:Float,glob:Int)
	Function UpdateNromals(mesh:Int Ptr)
	Function UpdateTexCoords(surf:Int Ptr)
	Function UpdateWorld(anim_speed:Float=1)
	Function UseStencil(stencil:Int Ptr)
	Function VectorPitch:Float(vx:Float,vy:Float,vz:Float)
	Function VectorYaw:Float(vx:Float,vy:Float,vz:Float)
	Function VertexAlpha:Float(surf:Int Ptr,vid:Int)
	Function VertexBlue:Float(surf:Int Ptr,vid:Int)
	Function VertexColor(surf:Int Ptr,vid:Int,r:Float,g:Float,b:Float,a:Float)
	Function VertexCoords(surf:Int Ptr,vid:Int,x:Float,y:Float,z:Float)
	Function VertexGreen:Float(surf:Int Ptr,vid:Int)
	Function VertexNormal(surf:Int Ptr,vid:Int,nx:Float,nz:Float)
	Function VertexNX:Float(surf:Int Ptr,vid:Int)
	Function VertexNY:Float(surf:Int Ptr,vid:Int)
	Function VertexNZ:Float(surf:Int Ptr,vid:Int)
	Function VertexRed:Float(surf:Int Ptr,vid:Int)
	Function VertexTexCoords(surf:Int Ptr,vid:Int,u:Float,v:Float,w:Float,coord_set:Int)
	Function VertexU:Float(surf:Int Ptr,vid:Int,coord_set:Int)
	Function VertexV:Float(surf:Int Ptr,vid:Int,coord_set:Int)
	Function VertexW:Float(surf:Int Ptr,vid:Int,coord_set:Int)
	Function VertexX:Float(surf:Int Ptr,vid:Int)
	Function VertexY:Float(surf:Int Ptr,vid:Int)
	Function VertexZ:Float(surf:Int Ptr,vid:Int)
	Function VoxelSpriteMaterial(voxelspr:Int Ptr,mat:Int Ptr)
	Function Wireframe(enable:Int)
	'Stopped At Extras
EndExtern


Test.bmx
Import "openb3d.bmx"

Graphics3D 1024,768

Local light:Int Ptr = CreateLight(2)
RotateEntity light, 45,0,0
PositionEntity light, 0,25,0

Local Camera:Int Ptr = CreateCamera()
PositionEntity camera,-20,10,0

Local plane:Int Ptr = CreatePlane(16)
TranslateEntity plane,0,-1,0
PointEntity camera,plane


For i = 1 To 100
	Local cube:Int Ptr = CreateCube()
	
	PositionEntity cube,Rnd(100),0,Rnd(100)
	Local shadow:Int Ptr = CreateShadow(cube,True)
	
	Local cylinder:Int Ptr = CreateCylinder()
	
	PositionEntity cylinder,Rnd(100),0,Rnd(100)
	Local shadow1:Int Ptr = CreateShadow(cylinder,True)
Next

wiretoggle=-1
While Not KeyHit(key_escape) And Not AppTerminate()
	
	If KeyHit(key_space) Then wiretoggle=-wiretoggle
	
	
	If KeyDown(KEY_UP) Then MoveEntity camera,0,0,1
	If KeyDown(KEY_DOWN) Then MoveEntity camera,0,0,-1
	If KeyDown(KEY_LEFT) Then MoveEntity camera,-1,0,0
	If KeyDown(KEY_RIGHT) Then MoveEntity camera,1,0,0
	
	
	If wiretoggle=1 Then Wireframe True Else Wireframe False
	
	
	UpdateWorld()
	RenderWorld()
	Flip()

Wend



Anyone able to point me in the right direction? It should at least populate a window with Graphics3D but it doesnt even do that.


Kryzon(Posted 2013) [#3]
Hello. First, all those pointers need to be of type (Byte Ptr) instead of (Int Ptr). I know it's counter-intuitive, but in BMax the Byte Ptr type serves as a 'generic pointer', with a size of four bytes.
You can replace the types easily by using the Edit -> Replace function in the IDE, replacing the occurrences of "Int Ptr" with "Byte Ptr".

In some pieces of code, this difference alone is enough for it to not even compile.
Read here: http://www.blitzbasic.com/Community/posts.php?topic=94811#1089288

After that's out of the way, I think the next problem is due to the fact that there is no graphics context available for OpenB3D to work in.
If you look in the source code, that Graphics3D function only sets OpenGL states, it does not create a context.

Instead of using Graphics3D, use something like this:
Import BRL.GLMax2D

Function InitOpenB3D( width:Int, height:Int, depth:Int=0, hertz:Int=60 )
	SetGraphicsDriver( GLMax2DDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER | GRAPHICS_ALPHABUFFER | GRAPHICS_STENCILBUFFER )
	Graphics( width, height, depth, hertz ) 'The flags are supplied above by the driver definition.
	Graphics3D( width, height, 0, 0, 0 ) 'OpenB3D call. The depth, mode and rate parameters are ignored.
End Function
It should do something.
I preferred to use the Max2D driver because you'll probably be able to render 2D images on top of the 3D graphics by setting the appropriate states like with the BeginMax2D and EndMax2D functions, available in MiniB3D.


Chapman7(Posted 2013) [#4]
Thanks Kryzon for the help! I changed every Int Ptr to Byte Ptr and I added the function InitOpenB3D. But it still didnt populate anything. So I did a test and just tried this code:

Import "openb3d.bmx"

width=800
height=600
depth=0
hertz=60

SetGraphicsDriver( GLMax2DDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER | GRAPHICS_ALPHABUFFER | GRAPHICS_STENCILBUFFER )
Graphics( width, height, depth, hertz ) 'The flags are supplied above by the driver definition.

WaitKey()


And for some reason, that doesn't even make a window or anything. It just says Executing and then Process complete. =/

I packaged the files if you or anyone wants to take a look: http://nvro.net/files/OpenB3D%20Test.zip

Btw to compile I had to get the latest MinGW, it may give someone an error in 3ds.cpp if it's not the latest.

Edit: I put REM and ENDREM around the functions in openb3d.bmx so it ONLY imported the cpp and c files and it still didnt populate a window using the test code above o.0


KronosUK(Posted 2013) [#5]
Your test example works with this.

Function InitOpenB3D:Int(width:Int=800, height:Int=600, depth:Int=0, mode:Int=0, rate:Int=60)
	GLGraphics(width,height,depth)
	glewinit()
	Return Graphics3D(width,height,depth,mode,rate)
End Function



I wrote a wrapper for OpenB3d a while back based on the dll but it looks like you have pretty much cracked it. One thing to note any texture files will need to be in the same folder as the .exe otherwise they won't load correctly. Also some settings will need to be reversed see the other OpenB3d thread for more details.

Rechecking thread I see this

convert camerapick(ent,x,y) to camerapick(ent,x,graphicsheight-y)

pitch is reversed (so, you need to use a minus sign in the pitch value for commands RotateEntity, TurnEntity, RotateMesh)


Chapman7(Posted 2013) [#6]
Strange... it still doesn't work for me. It still says "Executing blah blah" and then "Process Complete". Is there some OpenGL thing I am missing or maybe something with MinGW I need to change?

When I import the cpp and c files, even regular commands go out the window and it just goes from the regular "linking..." to "executing..." to "process complete" =/


KronosUK(Posted 2013) [#7]
Does this little program produce a window for you?

GLGraphics (800,600,0)


While Not KeyHit(key_escape)



Flip()
Wend



Chapman7(Posted 2013) [#8]
Indeed. But as soon as I throw 'Import "openb3d.bmx"' at the top, it doesn't show anything and does the whole "Executing test.blahblah" and a second later "Process Complete". I don't know why it does that, I even have the openb3d functions still REM'd. :(

Windows 8
Latest MinGW (GCC - 4.7.2-1)
Latest Driver Updates on a GT 640 (same thing on a Dell Laptop with Intel 4000)

The only thing I did with OpenB3D source was change the #include <GL/GLee.h> to #include "GLee.h" and in turn.cpp added
#include "maths_helper.h"
#include "entity.h"

But you said that those changes (the demo you downloaded) worked for you so I don't know what the heck is going on


angros47(Posted 2013) [#9]
The file turn.cpp is deprecated. It was an attempt to add quaternion based rotation using a piece of code made by EdzUp (If I recall correctly): in fact, while minib3d used euler based rotation (with the risk of gimbal lock), I wanted quaternions like in Blitz3d. But the solution used in turn.cpp was just a patch, with some limits (it was not 100% immune from gimbal lock)

When I ported the changes made by Warner in his version, I got quaternions working: so, the patch in turn.cpp become unnecessary anymore. You don't need it.


KronosUK(Posted 2013) [#10]
Does ordinary minib3d work for you Chapman7? Perhaps its a windows 8 driver problem.


Chapman7(Posted 2013) [#11]
Thanks angros47, when I get it working ill sift through turn.cpp and remove the patch. (unless you meant turn.cpp was the patch and I can remove it in which case) I tried just not including it, but I still cant get the program running.

KronosUK yeah man minib3d works like a charm on my PC. This is quite strange.

Its so bizarre that just including the cpp files causes the program to just end. Even with regular commands. Like:
Import "openb3d.bmx"
waitkey()

doesnt work properly.

angros47 did you have to download anything special to compile openb3d or just the GLee library?

EDIT: UGH I have been stabbing at this all day and I cant figure out anything. I have a Windows 7 laptop that, when compiles the test, actually crashes instead of just ending (its a crap laptop though so that doesnt suprise me). Ill maybe have to temporarily put Windows 7 on my pc to help debug the issue. Do you guys think if you packaged the exe, if I tried to run it, if it would kickback any errors that might lead us to the issue?


angros47(Posted 2013) [#12]
You can just get rid of turn.cpp, it's not used.

Under windows, if you have a complete mingw install, you don't need any download.

You shouldn't need gles: it's just a subset of opengl for embedded systems (like iphone: most of openB3D code comes from iminib3d for iphone, so it used gles: i replaced back gles include files with opengl)


Chapman7(Posted 2013) [#13]
So I tried it on my brothers laptop. It has windows 7 and its a pretty nice laptop (as far as specs go) and it still didnt work. :(

Are you guys using the latest MinGW? Other than that I have *no* idea what it could be


Kryzon(Posted 2013) [#14]
@Chapman7: so I downloaded that pack you shared in post #4.

Since they're all CPP files, it makes sense that BlitzMax output the following:

Building Test
Compiling:3ds.cpp
Compiling:animation.cpp
Compiling:animation_keys.cpp
Compiling:bank.cpp
Compiling:bone.cpp
...


It didn't like some lines in 3ds.CPP and x.CPP (lines 382 and 581 respectively), so I commented them just for the sake of testing.

You really need to make that OpenB3D.bmx into a module, as every time you want to run the app it needs to statically link (i.e compile) all these CPP files. If you make it into a module, you build it once and run straight away every time.
To get the keywords in that module highlighting, you need to run Program -> Rebuild Documentation in the IDE.

The Test program still glitches when it meets RenderWorld(), but it's a different result than what you're getting right now anyway. Debug mode doesn't tell anything except EXCEPTION_ACCESS_VIOLATION, so I can assume you'll have a lovely time debugging this one.
If I comment RenderWorld() out, it runs and there's a blank screen, which is a nice step.

Most likely you haven't got MinGW properly configured - don't forget you not only need to install it but need to set up the Environment Variables properly so BlitzMax knows where it is.

PS: Considering there's a DLL form of this library, have you tried importing it like KronosUK mentioned? this way you won't have to deal with CPPs, just importing the DLL and getting the procedures. Like it's done here.

PS2: If you're considering other options, I'd take a look at GMan's Irrlicht module.
http://www.gprogs.com/viewtopic.php?id=450


Chapman7(Posted 2013) [#15]
Kryzon I was getting those errors (lines 382 and 581) as well, from an older MinGW version (most likely the one that Brucey was passing around in the RAR). The latest doesnt show the errors, it just also doesnt run the program properly.

Yeah my goal was to make it into a module but once I started having the hiccups, I switched the openb3d to a bmx and imported it to rule out if it was an issue with it being a module. I have every intention on making it a module and providing nice documentation but this issue is being my scope of knowledge.

I tried the DLL and im pretty sure it did the same thing, ill see if I still have the test for it and recheck it.

I saw the irrlicht module and it was something I was considering. But the ease of OpenB3D (essentially being a minib3d with more features) really got my attention since obviously it would be easier for me (and others) to program with.

If this problem gets figured out, i will still happily provide support for a BMAX OpenB3D Module (adding/changing functions, documentation, etc) but as I said, this issue is beyond my abilities.


Chapman7(Posted 2013) [#16]
Hmm, so I pulled the DLL test back up and added the InitOpenB3D and I got a window up but its all white. KronosUK any chance I could test your wrapper out?


angros47(Posted 2013) [#17]
Why is depth set to 0 and not to 32?


Chapman7(Posted 2013) [#18]
I assumed OpenB3D was the same as minib3d and automatically got the depth if it was set to 0. Changing it to 32 still didn't fix it. :(

Were you able to come up with anything angros47?


angros47(Posted 2013) [#19]
If you have an old graphic card, maybe it doesn't support vbo... in file global.cpp, you can try to change vbo_enabled to false.

Also, openb3d has, in class Global, a method called Graphics (that is a reserved keyword in blitzmax): maybe changing its name ....

Anyway, if you are going to use openb3d.dll, try it in FreeBasic: if it works, we'll know that the issue is in creating an appropriate gl context in blitzmax.


Chapman7(Posted 2013) [#20]
FreeBasic indeed works. Ill play with it some more and see what I can come up with. I'll probably just TRY windows 7 to rule out any differences in os drivers. Then maybe get a c++ ide using the same MinGW installation BlitzMax will use, and see if I can get a window running.


Chapman7(Posted 2013) [#21]
I got it working! I'll update in a minute!

EDIT: Okay so using the older MinGW (the rar that Brucey handed out) I got some errors with 3ds.cpp and x.cpp (and therefore, errors with mesh.cpp) but I just didnt import the 3ds and x and I changed mesh.cpp and I was able to get it rendering.

Some weird things -
Left Side:
	SetGraphicsDriver( GLMax2DDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER | GRAPHICS_ALPHABUFFER | GRAPHICS_STENCILBUFFER )
	Graphics( width, height, depth )


Right Side:
	GLGraphics(width,height,depth)
	glewinit()


If I do GLGraphics instead of Graphics for the left side, the left side will look like the right side. This weird thing maybe because I recently updated BMX OpenGL graphics to 4.0.





They both run at about 190 FPS for some reason.


Chapman7(Posted 2013) [#22]
Is that kind of FPS normal? MiniB3D would give me at least a thousand with this example


Kryzon(Posted 2013) [#23]
I'm glad you got it running.
The problem with the right-side version is that you're not setting up the necessary flags. Look at the source for GLGraphics(), it's in mod\BRL.mod\glgraphics.mod\glgraphics.bmx - it doesn't set up any flags.
Is there a reason for you not using the left-side settings? It allows you to use Max2D for 2D rendering, with the BeginMax2D and EndMax2D calls.

Regarding the FPS, the engines are not doing the same things. You are using stencil shadowing in OpenB3D, and I assume you're not in MiniB3D - if you were, the FPS would most likely be less apart.
OpenB3D uses the source of iMiniB3D with several additions, so it should be really fast.

EDIT: I think those enlarged ghost shadows on the lower-left screen are a bug.


Chapman7(Posted 2013) [#24]
I'll take a look at GLGraphics Flags.

The left side settings is a possibility, I was just testing the two. OpenB3D however doesn't come with BeginMax2D and EndMax2D so I'd have to add that myself (currently if you drawtext after it renders the scene, it will just create a black window.

I removed the shadows because I suspected the same thing (that it was hogging a lot of the gpu) but the fps didnt change much (like only 10 IF that).

If I can't get the FPS up though substantially, I (like most) wont be able to use it.


angros47(Posted 2013) [#25]
A difference between openb3d and minib3d is that openb3d use quaternion-based rotations (more accurate, but a bit slower than euler-based rotations used in minib3d)

Anyway, unless you are moving all the objects in your scene, rotation functions should be never called (or called only once, if you move the camera)

How is the speed in freebasic? Maybe in blitzmax the image is converted in some way that eat time...


Juggernaut(Posted 2013) [#26]
Where can I get detail documentation and elaborate function reference of OpenB3D ? I am looking for something similar to Blitz3D and BlitzMAX
manual. Please help.


angros47(Posted 2013) [#27]
There is a wiki on the official site, but it's still incomplete


angros47(Posted 2013) [#28]
@Chapman7

Any news about FPS?


Chapman7(Posted 2013) [#29]
Nope, and debugging it is out of my skill level. What kind of FPS does FreeBasic get with it?


angros47(Posted 2013) [#30]
You should test yourself on your computer, since there is no point in comparing fps on different hardware.


Chapman7(Posted 2013) [#31]
Since I am unfamiliar with FreeBasic, are you able to convert this for me?:

Import "openb3d.bmx"

Graphics3D 1024,768

Local light:Int Ptr = CreateLight(2)
RotateEntity light, 45,0,0
PositionEntity light, 0,25,0

Local Camera:Int Ptr = CreateCamera()
PositionEntity camera,-20,10,0

Local plane:Int Ptr = CreatePlane(16)
TranslateEntity plane,0,-1,0
PointEntity camera,plane


For i = 1 To 100
	Local cube:Int Ptr = CreateCube()
	
	PositionEntity cube,Rnd(100),0,Rnd(100)
	Local shadow:Int Ptr = CreateShadow(cube,True)
	
	Local cylinder:Int Ptr = CreateCylinder()
	
	PositionEntity cylinder,Rnd(100),0,Rnd(100)
	Local shadow1:Int Ptr = CreateShadow(cylinder,True)
Next

wiretoggle=-1
While Not KeyHit(key_escape) And Not AppTerminate()
	
	If KeyHit(key_space) Then wiretoggle=-wiretoggle
	
	
	If KeyDown(KEY_UP) Then MoveEntity camera,0,0,1
	If KeyDown(KEY_DOWN) Then MoveEntity camera,0,0,-1
	If KeyDown(KEY_LEFT) Then MoveEntity camera,-1,0,0
	If KeyDown(KEY_RIGHT) Then MoveEntity camera,1,0,0
	
	
	If wiretoggle=1 Then Wireframe True Else Wireframe False
	
	
	UpdateWorld()
	RenderWorld()
	Flip()

Wend



BLaBZ(Posted 2013) [#32]
Why wouldn't you use miniB3D? This seems redundant, am I missing something?!


angros47(Posted 2013) [#33]
Here is the translated version:


#Include "openb3d.bi"

screenres 1024,768,32, , &h10002 
Graphics3D 1024,768


var light = CreateLight(2)
RotateEntity light, 45,0,0
PositionEntity light, 0,25,0

var Camera = CreateCamera()
PositionEntity camera,-20,10,0

var plane = CreatePlane(16)
TranslateEntity plane,0,-1,0
PointEntity camera,plane


For i as integer = 1 To 100
	var cube = CreateCube()
	
	PositionEntity cube,Rnd(1)*100,0,Rnd(1)*100
	var shadow = CreateShadow(cube,1)
	
	var cylinder = CreateCylinder()
	
	PositionEntity cylinder,Rnd(1)*100,0,Rnd(1)*100
	var shadow1 = CreateShadow(cylinder,1)
Next

var wiretoggle=-1
do
	
	If MultiKey(57) Then wiretoggle=-wiretoggle
	
	
	If MultiKey(&h48) Then MoveEntity camera,0,0,1
	If MultiKey(&h50) Then MoveEntity camera,0,0,-1
	If MultiKey(&h4b) Then MoveEntity camera,-1,0,0
	If MultiKey(&h4d) Then MoveEntity camera,1,0,0
	
	
	If wiretoggle=1 Then Wireframe 1 Else Wireframe 0
	
	
	UpdateWorld()
	RenderWorld()
	Flip()

loop until multikey(1)



If you remove the two lines with "CreateShadow", the program is much faster (and, since in minib3d shadows are not supported, maybe that's why with minib3d you got higher fps)


Chapman7(Posted 2013) [#34]
BLaBZ OpenB3D I assume will continued to be worked on. Ontop of that there are already several more features.

angros47 2 things.

1) How do I flip without it using VSync? I tried Flip(0) but that didn't work
2) That weird glitch thing where I zoom out and there are shadow objects that come into view (like the picture a couple of posts above) happens so it's not just BMAX in regards to that


angros47(Posted 2013) [#35]
About the shadow glitch: try reducing camera far range, or increasing cull radius of objects (the shadow volume will be shorter, it should fix the glitch)


About VSync: it's not supported by default in FreeBasic, you should try this:

http://www.freebasic.net/forum/viewtopic.php?f=7&t=13715&p=119261


feeble1(Posted 2014) [#36]
Continued on new thread.