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
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Post by Domso »

Ive found a very easy solution for this problem

Using a different vertexcolor for every vertexgroup und VertexCoords, its possible to adjust the deformation manually.

It works, but little experimental.
Anyway, thanks for the help =)
My Code

Code: Select all

EntityParent Findchild(test4,"Shin.Right"),(Findchild(test3,"Shin.Right"))        
EntityParent Findchild(test4,"Shin.Left"),(Findchild(test3,"Shin.Left"))        

EntityParent Findchild(test4,"Thigh.Right"),(Findchild(test3,"Thigh.Right"))        
EntityParent Findchild(test4,"Thigh.Left"),(Findchild(test3,"Thigh.Left"))     

EntityParent Findchild(test4,"Hip"),(Findchild(test3,"Back"))

Var tmpSurface=getsurface(test4,1)
For i As Integer = 0 To countvertices(tmpSurface)
	If vertexgreen(tmpsurface,i)=255 Then
		If vertexX(tmpsurface,i)<0 Then
			VertexCoords tmpSurface,i,vertexX(tmpsurface,i)+0.1,vertexY(tmpsurface,i),vertexZ(tmpsurface,i)
		ElseIf vertexX(tmpsurface,i)>0 Then 
			VertexCoords tmpSurface,i,vertexX(tmpsurface,i)-0.1,vertexY(tmpsurface,i),vertexZ(tmpsurface,i)
		EndIf
	EndIf
	
	If vertexRed(tmpsurface,i)=255 Then
		If vertexX(tmpsurface,i)<0 Then 
			VertexCoords tmpSurface,i,vertexX(tmpsurface,i),vertexY(tmpsurface,i)+0.4,vertexZ(tmpsurface,i)
		ElseIf vertexX(tmpsurface,i)>0 Then 
			VertexCoords tmpSurface,i,vertexX(tmpsurface,i),vertexY(tmpsurface,i)+0.4,vertexZ(tmpsurface,i)
		EndIf
		If vertexBlue(tmpsurface,i)=255 Then
			If vertexX(tmpsurface,i)<0 Then
				VertexCoords tmpSurface,i,vertexX(tmpsurface,i)+0.1,vertexY(tmpsurface,i)-0.4,vertexZ(tmpsurface,i)
			ElseIf vertexX(tmpsurface,i)>0 Then 
				VertexCoords tmpSurface,i,vertexX(tmpsurface,i)-0.1,vertexY(tmpsurface,i)-0.4,vertexZ(tmpsurface,i)
			EndIf
		EndIf
		
	EndIf
Next
salmonellus
Posts: 5
Joined: Feb 22, 2014 0:34

Re: MiniB3d for FreeBasic

Post by salmonellus »

I was hoping that someone on this forum could shed some light on a problem involving 'put image' under opend3b and 2d.bi.

Basically using 'put image' in the TRANS mode seems to be broken ( but putting an image in PSET mode is fine.)

I'm using:

Linux - Ubuntu 12.04

Freebasic 90.1

OpenB3D 7

The initialisation code is:

Code: Select all

#include "freetype2/freetype.bi"

#define Render_OpenGL
#include "openb3d.bi"
#include "fbgfx.bi"
#include once "GL/gl.bi"
#include once "GL/glu.bi"
#Include once "2d_ext.bi"

#include "fbsound.bi"

screenres 1280,1024, 24
Graphics3d 1280,1024, 24,2,1

cls
screensync
setmouse(500,500,1,0)	' don't keep it in the screen	



I then run a program developed in Freebasic without openb3d. It involves loading a screen image with load image ,pset which works fine. I then load
other images with magenta transparency which normally look fine on the background.

Here's the approppriate code:

	dim x as integer = 420
	dim y as integer = 220

	cls
	'RenderWorld	
	'ScreenSync	
	var mypicture  = imagecreate(1280,1024,24)
	bload( "Graphics/SplashScreen.bmp", mypicture )
	put (0,0), mypicture, pset				' **** This works fine

	imagedestroy mypicture	' No longer needed once displayed
	' the mask color is Magenta, which is RGB(255, 0, 255).

	var optpic = imagecreate(400,100,24)
	bload( "Graphics/ng1.bmp", optpic )
	put (x,y), optpic, trans				' ******* This doesn't work
	'ScreenSync
	y = y + 110


	bload( "Graphics/sg2.bmp", optpic )
	put (x,y), optpic, trans
	'ScreenSync
	y = y + 110


	bload( "Graphics/lg2.bmp", optpic )
	put (x,y), optpic, trans
	y = y + 110

	bload( "Graphics/rg2.bmp", optpic )
	put (x,y), optpic, trans
	y = y + 110

	bload( "Graphics/og1.bmp", optpic )
	put (x,y), optpic, trans
	y = y + 110

	bload( "Graphics/qg1.bmp", optpic )
	put (x,y), optpic, trans

	imagedestroy optpic
	ScreenSync
What happens is that the transparent (magenta) pixels don't display at all, but the pixels which ought to display from the source image don't dispaly normally -
the underlying image is removed but what is displayed looks like a 'hole' in the background through which one can see the previous screen contents.
This happens even though the previous contents were removed by CLS !

Other libraries like freetype and fbsound continue to work normally.


**On reflection, it occurs to me that the core of the problem is that when an image displayed with PSET, the displayed
pixels come from the source image as you would expect. But when an image is displayed with TRANS, the displayed pixels do NOT come from the source image but instead
come from the previous screen buffer - as it was before CLS removed it**

What I have tried that hasn't helped:

- using opend3b v7 as posted on this board
- Eternal Pain's version of 2d.bi
- using 24 or 32 bit graphics makes no difference

Anybody got any ideas on this ?
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

Hey :)

Do you know how to get the Z-Buffer in OpenB3D?
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

What do you mean?
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

I want to get the Z-Buffer as a texture. Is this possible with OpenB3D?
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

You want to get the z buffer (that contains all the "depth" informations of every pixel on the screen) and use as a texture... how? Z buffer data are not "visible"... do you want to convert them to greyscale images? Or you are going to use them in a shader?

Or something else?
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

You wrote:you want to convert them to greyscale images?
Yes
angros wrote:You want to get the z buffer and use as a texture... how?
Well that's what I want to know. ;-)
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

There is no OpenB3D command to do such a thing (I never found anybody who need it). Anyway, it should be possible to add it: in file "texture.cpp", in the function BackBufferToTex, locate the line:

Code: Select all

glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,Global::height-height,width,height,0);
and try replacing it with:

Code: Select all

glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,0,Global::height-height,width,height,0);
It might work.
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Post by Domso »

is it possible, that AddVertex() has an internal max-x size?
My Code doesnt work well with MAX_SIZE > 100

with more then 100 it creates "double triangles"

it isnt a big thing, because scaleEntity would solved it...

Code: Select all

#include "openb3d.bi"
#Define MAX_SIZE 100

screenres 800,600,32,,&h10002
graphics3d 800,600

var tmpMesh=createMesh()
var tmpSur=createSurface(tmpMesh)

wireframe 1
for x as integer = 1 to MAX_SIZE
	for y as integer = 1 to MAX_SIZE
		
		AddTriangle(tmpSur,AddVertex(tmpSur,x,0,y),AddVertex(tmpSur,x+1,0,y),AddVertex(tmpSur,x,0,y+1))
		
		AddTriangle(tmpSur,AddVertex(tmpSur,x+1,0,y+1),AddVertex(tmpSur,x,0,y+1),AddVertex(tmpSur,x+1,0,y))
	next
next
MeshCullRadius tmpMesh,10000
'updatenormals tmpter
EntityFX tmpMesh,16

var cam=createcamera()
var light=createLight()
moveEntity cam,0,1,0
do
	if MultiKey(&h48) then turnEntity cam,1,0,0
	if MultiKey(&h50) then turnEntity cam,-1,0,0
	If MultiKey(&h4d) then turnentity cam,0,-1,0
	If MultiKey(&h4b) then turnentity cam,0,1,0
	if MultiKey(&h39) then moveEntity cam,0,0,1

	updateworld
	renderworld
	flip

loop until multikey(1)
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

AddVertex has no internal limits; you can verify by changing:

Code: Select all

for x as integer = 1 to MAX_SIZE
    for y as integer = 1 to MAX_SIZE
with something like:

Code: Select all

for x as integer = 100 to MAX_SIZE
    for y as integer = 100 to MAX_SIZE
I don't know what causes your issue (looks like it occurs when MAX_SIZE is 105 or more, at least on my computer).

Maybe you are using too many vertices, and OpenGL can't manage them (as far as I can check, internally vertex coords are stored correctly); if you create some unused vertices, the bug occurs even if they are not used in triangles.

Anyway, you are using more vertices than you actually need: in fact, you create three new vertices for each triangle, but you shouldn't: you should just create three vertices from the first triangle, and then only one vertex for every other triangle (in fact, the second triangle has two vertices in common with the first one, the third triangle has two vertices in common with the second one, and so on).

If you want to create a really big mesh, made by many small "tiles", you could always use an octree (they are a new feature, available in the last version)
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Re: MiniB3d for FreeBasic

Post by D.J.Peters »

hello angros47
before I write my own GL lib
any change you get the wrong shadow behavior fixed ?
(in the case you don't remember your shadows pops up and goes away in non realistic manner)

Joshy
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

I remember...

Do you remember my answer?

http://freebasic.net/forum/viewtopic.ph ... 72#p179372


This is a problem of stencil shadows (http://en.wikipedia.org/w/index.php?tit ... nstruction), and it affects other 3d engines, too:

http://www.ogre3d.org/docs/manual/manua ... uette-Edge

So, even if you write your own engine, you will face the same problem. The only fix would be to use another shadow solution, like shadow texture mapping (but it won't be as easy as just "CreateShadow", and shadows would be ugly on complex surfaces). Or you can try to build a shader... this is the most "modern" solution, but it won't work on all hardware.
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Post by Domso »

angros47 wrote: I don't know what causes your issue (looks like it occurs when MAX_SIZE is 105 or more, at least on my computer).
Maybe you are using too many vertices, and OpenGL can't manage them (as far as I can check, internally vertex coords are stored correctly); if you create some unused vertices, the bug occurs even if they are not used in triangles.
ok, then i will use multiple tiles with a size of 100x100
angros47 wrote: Anyway, you are using more vertices than you actually need: in fact, you create three new vertices for each triangle, but you shouldn't: you should just create three vertices from the first triangle, and then only one vertex for every other triangle (in fact, the second triangle has two vertices in common with the first one, the third triangle has two vertices in common with the second one, and so on).
I dont know how it affects openB3d, but on the german reference for Addtriangle there is this warning:
Multiple triangles can also use the same vertex points. Unfortunately, it deteriorates the shading of the objects. Blitz Basic created by default with each triangle three vertex points.
Ive never tested it; does it affect openb3d?
angros47 wrote: If you want to create a really big mesh, made by many small "tiles", you could always use an octree (they are a new feature, available in the last version)
Do you mean to use OctreeMesh for every single tile or create a block-tile with Octreeblock ? I think all new instances from Octreeblock has the same texture, but every tile must have a different texture.
angros47
Posts: 2386
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Post by angros47 »

Using the same vertex in two triangles does not really deteriorate the shading; the only problem is, the vertex normal is only one; if you are shading a smooth surface (like a sphere), it won't be an issue, but if the vertex is on an edge (like in a cube), it would need to have different normals for different triangles: in a cube, every vertex is used by three faces, but each face must have a flat shading, so all its vertices should have the same normals (different from normals of other faces); so, three vertices are used, at the same place.

But if you are going to make a flat surface (like a floor made by many tiles), each vertex should have the same normals of all other ones, so it's not an issue.

About octrees: if you have a different texture for every tile you should use octreemesh, but if there is only two or three textures you should use octreeblock.

Anyway, in your previous example, you used only one mesh with just one surface... you could use only one texture on it.
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Post by Westbeam »

Are "DeltaYaw" and "DeltaPitch" working correctly?
This code should rotate the "ArrowPtr" so it points at the entity "object1", but it doesn't work. It always points in the middle of nowhere, but why?

Code: Select all

dy = DeltaYaw(camera,object)
dp = DeltaPitch(camera,object2)
tAngle = ((ATan2(-dy,dp)+360) Mod 360)
MultiPut(0,xmax/2,ymax/2,ArrowPtr,1,1,tAngle,1)
Post Reply