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
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by Gunslinger »

Code: Select all

CameraClsColor(cam3, 0.8, 0.5, 0.7)
CameraFogColor(cam3, 0.1, 0.5, 0.9)
This color range is wrong, need to be in 0 to 255 range, color blue at 0.9 is to low for me to see :)
It will not fix the camera problem, seems a bug to me.
Same on LibOpenB3D version.
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Ok, found the bug: in "camera.cpp", the line

Code: Select all

			if(fog==-1) glFogf(GL_FOG_MODE,GL_LINEAR); // once only
should have been

Code: Select all

			glFogf(GL_FOG_MODE,GL_LINEAR);
I'll soon upload the patch
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Uploaded a new version, with bug fixed.
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Very simple example of decal mesh (version 1.3 is required)

Code: Select all

#include "openb3d.bi"
screen 18,  32, , &h10002 
Graphics3d 640,480,32,1,1

var camera=CreateCamera()
var light=createlight()
turnentity light,0,45,0

moveentity camera,0,0,-10

var sphere=createsphere()
var cube=createcube()
moveentity cube,.6,.3,0

var csg=meshcsg(sphere,cube,3)

entitycolor csg,255,0,0
entityorder csg,-1
entityparent csg,sphere
freeentity cube
'freeentity sphere

do
	turnentity sphere,0,.5,0
	renderworld
	flip
loop until multikey (1)
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by Gunslinger »

Nice work, thanks for the updates.
I have played around with mesh svg and lighting seems to be fix. in version 1.3
I don't think gaps in the mesh is suppose to happen?
Link to screen: https://ac1.servegame.com:88/Mesh-svg.png

Also made some screen of state of my game
the world/universe is almost infinitely large.
https://ac1.servegame.com:88/Screenshot20240208-1.png
https://ac1.servegame.com:88/Screenshot20240208-2.png
https://ac1.servegame.com:88/Screenshot20240208-3.png

Now i'm testing physic libraries.
For mesh loaded to trueasis and works great, just don't like the close source and limitations on publishing.
So now i have added a OpenB3D heightmap to reactphysics v0.7.1 got i to work after a lot of trial and error.
Probleems now is reacthysics v0.9 hase the ability to disable x movement of entities, and i have no idea how to get it to freebasic.

For now i'm also trying to understand the createterrain and quad tree where it loaded in.
Seem very annoying the terrain resolution is changing in very close to the camera.
I wish there was a way to set close by range to keep at high resolution quads octree.
https://ac1.servegame.com:88/Screenshot20240208-4.png
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

angros47 wrote: Feb 08, 2024 0:56 Uploaded a new version, with bug fixed.
Thanks, looks good here as well.
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Those little gaps, that look like cracks in the mesh are imperfections caused by the limits in floating point math. The decal mesh is supposed to be on the sphere, have you modified the provided source code? And are you using version 1.3?

In OpenB3D, terrains are rendered using the ROAM algorithm ( https://en.wikipedia.org/wiki/ROAM ), not a quadtree. The reason resolution changes is indeed the LOD (Level Of Detail) algorithm. The difference between a quadtree based LOD and a ROAM LOD is that in ROAM the resolution changes more gradually, and that avoids annoying gaps between adiacent triangles belonging to different LOD

Quadtrees are not supported by OpenB3D, while octrees are.

I have no experience with ReactPhysics3D, but it seems that the equivalents of terrain is HeightFieldShape there
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

The decal mesh example (with camera zoom 6) looks like this here:
https://surfdrive.surf.nl/files/index.p ... esh_01.png

Is there a way to check which version of openb3d is installed?
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

From your screenshot, it looks correct. There is no way to see which version is installed, but since I uploaded version 1.3 today, it's pretty simple to answer your question: if you use a version downloaded earlier, it's not 1.3

Also, I had to reupload it because I made a little mistake (starting with fog enabled, and wrong parameters). It's now fixed, but people who downloaded it earlier might need to redownload it
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by Gunslinger »

The decal mesh is supposed to be on the sphere
Sorry i did not know, and yes i got the last 1.3 version.
Still think there are very big caps in csg mesh.

My modifactaions

Code: Select all

#include "openb3d.bi"

screenres 1920,1080,  32, , &h10002 
Graphics3d 1920,1080,32,1,1

var camera=CreateCamera()
var light=createlight()
turnentity light,0,45,0

moveentity camera,0,0,-3

var sphere=createsphere()
var cube=createcube()
moveentity cube, 0.6, 0.3, 0
'positionentity cube, 0.6, 0.6, 0.6
var csg=meshcsg(sphere, cube,2)

entitycolor csg,255,0,0
entityorder csg,-1
entityparent csg,sphere
freeentity cube
moveentity csg, 1,0,0

'updatenormals csg
'wireframe 1
do
	turnentity sphere,0,.5,0
	renderworld
	flip
loop until multikey (1)
I also noted that csg mesh is flatshaded, need a updatenormals to look the same as the sphere.
And i will read about ROAM algorithm, thanks
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

In your version the decal mesh is off placed because you intentionally moved it to the right with "moveentity csg, 1,0,0".

I have learned about decals in 3d graphics only recently: basically, they are a way to apply a picture on the surface of a 3d mesh, usually on top of a regular texture, to represent some modifications to the surface: for example, on a wall, a texture can be used to show the brick pattern, while a decal can be used to show the moss, or the burn of a shot. On a car, a decal can be used to show the dirt on the surface. Different 3d engines have a different concept of decals: for example, in Roblox, the difference is only about the scaling and the fact that a texture is repeated, a decal isn't https://create.roblox.com/docs/it-it/pa ... res-decals . Since OpenB3D allows to set those parameters for a texture, those kind of decals can be implemented as regular texture with clamping.
Thanks to multi-texturing, and the possibility to have two texture coordinates set, it's easy to implement that kind of decals with the standard rendering. But what if custom shaders are used? Many custom shaders don't allow to render a texture on top of another, because they need multiple maps (like, a color map and a normal map). Also, it is not possible to "stack" more than one shader on the same surface. In these cases, there are two ways to implement a decal: one is to implement in during post processing, as it is done in deferred rendering. The other solution is to create a new, partially transparent surface on top of the old one, and use it to render the decal. On flat surfaces (like a wall) it's possible to do it by applying a sprite (in Blitz3D it was done, for example, in the demo castle.bb to show bullet holes in the wall); but if the surface is not flat, a regular sprite would cause part of the picture to "sink" in the mesh, or to float mid-air. So, instead of a regular quad, a customized mesh should be created: this kind of mesh is called a decal mesh ( https://docs.unrealengine.com/4.26/en-U ... eshDecals/ )
Deferred rendering is not implemented directly in OpenB3D: even if I will add it in the future, it will be in OpenB3D Plus. On the contrary, decal meshes were pretty simple to create, since the same algorithm used to make Combinatorial Solid Geometry (CSG) could create them easily. I actually achieved them by adding just two lines.
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by Gunslinger »

Ah yes got it now :)
First i did think csg function is for subtracting mesh shapes from 2 bodies.

I'm working as a engineer with 3D cad software a lot, where sometimes i use to subtract/add or intersect 3D bodies.
I was mistaken this is the same idea. it's not.

Maybe it's a good idea to pack some of your simpel examples of openB3D in freebasic with the download of libs.
I think openB3D is the best 3D lib that fits with the freebasic style and is easy to read.
Still need to know about openGL stuff.
Some examples help new people to get started easy.

Also think freebasic compiler need to be packed different to get new people in.
That's another endless discussion here on the forum better to keep out.
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Gunslinger wrote: Feb 10, 2024 9:59 Ah yes got it now :)
First i did think csg function is for subtracting mesh shapes from 2 bodies.
It is, if you use 0 as third parameter. If you use 1 it will sum the meshes. If you use 2, it will produce the intersection (that is what your program does). Version 1.3 also allow you to use 3, that produces the decal mesh.
Most 3d engines don't have CSG, but some have a specific routine for decal meshes. I realized that decal meshes could actually be produced by hijacking the CSG routine, so I added it
Gunslinger wrote: Feb 10, 2024 9:59 I'm working as a engineer with 3D cad software a lot, where sometimes i use to subtract/add or intersect 3D bodies.
I was mistaken this is the same idea. it's not.
From the manual:
MESH* MESHCSG(MESH* M1, MESH* M2, INT METHOD = 1)
m1 first mesh
m2 second mesh
method CSG operation:
0: subtraction
1: union
2: intersection
3: decal

Description
Creates a new mesh by performing a CSG (Constructive Solid Geometry) operation on two given meshes m1 and m2. Those meshes are not modified, and might need to be removed with FreeEntity at the end of the CSG operations.
The method parameter specifies which CSG operation must be performed: a subtraction removes the second mesh from the first, basically creating a hole inside m1, shaped like m2; an union combines the two meshes into one, removing all the superfluous geometry: in that, it differs from AddMesh, that includes also the intersecting parts of meshes, that should never be visible anyway (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/dungeon); an intersection creates a mesh that is made only by theintersecting parts of m1 and m2 (the intersection of two spheres can be used to produce a lens shaped mesh, for example); a decal produces a decal mesh, that is basically a very thin mesh that adheres to the surface of m1, and is delimited by m2: by setting a negative rendering order with EntityOrder it’s possible to render it after m1, so it will always be visible over it, and it can be useful to apply a different texture or material to a selected part of a mesh.

Gunslinger wrote: Feb 10, 2024 9:59 Maybe it's a good idea to pack some of your simpel examples of openB3D in freebasic with the download of libs.
I think openB3D is the best 3D lib that fits with the freebasic style and is easy to read.
Thank you! The reason I didn't include examples is that OpenB3D can be used in other languages, too (although FreeBasic is the one I have in mind as target)
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: MiniB3d for FreeBasic

Post by badidea »

Small remark, the 1.26 guide says on CreateCylinder:
"solid (optional) - true for a cylinder with a base, false for a tube. Defaults to true."
But it must be 1 for solid, not freebasic's boolean true.
angros47
Posts: 2308
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

True, because for C and C++ true is 1.
The reason is that in C/C++ a true/false is a boolean type, so a single bit, 0 or 1. In BASIC True is defined as NOT FALSE, and since FALSE is defined as 0, TRUE is defined as all bits enabled, so -1

The same applies to CreateCone
Post Reply