MiniB3d for FreeBasic
Re: MiniB3d for FreeBasic
Directional lights (the ones created with CreateLight(1) ) are not affected by their position, only by their direction. Commands like "PositionEntity" or "MoveEntity" have no effect on how the light looks like, only "RotateEntity" and "TurnEntity" will produce a visible change. That's because the light is supposed to be at infinite distance.
-
- Posts: 103
- Joined: Mar 08, 2016 19:10
- Location: The Netherlands
Re: MiniB3d for FreeBasic
Oke i got something working light now with a quick rotating sun.
http://ac1.servegame.com:88/download/AirTest01.zip
After problems with loadmesh from DJpeters in openB3D-xx.dll
i got back to older version.
My problems with light came from flat planes or empty terrain.
Some how it not working for spotlights, only for directional light.
I think it a bug?
Test it for your self..
I gave the fighter plane a spot light in front.
When i shine on my AddTriangle plane it works as i expect.
On the flat terrain with water looks it has no effect.
I hope you can enplane this?
http://ac1.servegame.com:88/download/AirTest01.zip
After problems with loadmesh from DJpeters in openB3D-xx.dll
i got back to older version.
My problems with light came from flat planes or empty terrain.
Some how it not working for spotlights, only for directional light.
I think it a bug?
Test it for your self..
I gave the fighter plane a spot light in front.
When i shine on my AddTriangle plane it works as i expect.
On the flat terrain with water looks it has no effect.
I hope you can enplane this?
Re: MiniB3d for FreeBasic
Your program should be modified in this way:
and you must add, in the main cycle, after
the line:
In this way, the sun will cast an accurate shadow.
The lines:
are not needed, all you need to do if you want the spotlight to be bound to the airplane is to set craft as its parent. Right after the line:
add:
Last but not least: in your example, the only entity casting a shadow is the airplane. And so, light1 (that is supposed to be its headlight) cannot cast a correct shadow, since it's in the same place! think about a car... if you are driving at night, and the only light is coming from the car's headlights, you will never see the shadow of that car. To see the shadow you need an external light source.
You might want to disable shadow casting for that specific light, by changing its type from 3 to -3 (a negative light type behave in the same way on objects, but shadows are not rendered for it)
Code: Select all
var sun=createpivot()
var sun1=CreateLight( 1,sun)
RotateEntity sun1,90,0,0
PositionEntity sun1,0,-100,0
LightColor sun1, 255,255,255
AmbientLight 64,64,64
Code: Select all
TurnEntity sun,-.5,0,0
Code: Select all
PositionEntity sun, EntityX(craft), EntityY(craft), EntityZ(craft)
The lines:
Code: Select all
PositionEntity light1, EntityX(craft), EntityY(craft)+2, EntityZ(craft)
RotateEntity light1, entityPitch(craft),entityyaw(craft),entityroll(craft)
Code: Select all
var craft= loadmesh("./fighter.3ds")
Code: Select all
entityparent light1,craft
You might want to disable shadow casting for that specific light, by changing its type from 3 to -3 (a negative light type behave in the same way on objects, but shadows are not rendered for it)
-
- Posts: 103
- Joined: Mar 08, 2016 19:10
- Location: The Netherlands
Re: MiniB3d for FreeBasic
I got it, the shadow is not done right.
Great tip using -1 to -3 for no shadow cast lights.
I have not seen that on any forums.
Let me show a picture what i mean with light problem i have.
http://ac1.servegame.com:88/image/Scree ... adow03.PNG
The spotlight shows up my Triangle plane.
While the flat terrain has no light reflection at all !
And the green mounting terrain has a reflection as long as it is not flat scaled.
I have tried every EntityFX setting of adding texture, no luck.
Not a real problem for me because i'm planning not to use the terrain function.
But i do like to understand more before i start programming.
Great tip using -1 to -3 for no shadow cast lights.
I have not seen that on any forums.
Let me show a picture what i mean with light problem i have.
http://ac1.servegame.com:88/image/Scree ... adow03.PNG
The spotlight shows up my Triangle plane.
While the flat terrain has no light reflection at all !
And the green mounting terrain has a reflection as long as it is not flat scaled.
I have tried every EntityFX setting of adding texture, no luck.
Not a real problem for me because i'm planning not to use the terrain function.
But i do like to understand more before i start programming.
Last edited by Gunslinger on Aug 21, 2019 18:21, edited 1 time in total.
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: MiniB3d for FreeBasic
If no once report any problem's how we should fix them ?Gunslinger wrote:After problems with loadmesh from DJpeters in openB3D-xx.dll
I fixed only small bugs and never touched the load function what is the problem ?
Joshy
-
- Posts: 103
- Joined: Mar 08, 2016 19:10
- Location: The Netherlands
Re: MiniB3d for FreeBasic
i'm not sure. i only know the fighter.3ds from my last zip file does not load when i use your version. (Console: Error: Can't Find Document File '0')D.J.Peters wrote:If no once report any problem's how we should fix them ?Gunslinger wrote:After problems with loadmesh from DJpeters in openB3D-xx.dll
I fixed only small bugs and never touched the load function what is the problem ?
Joshy
I have seen different kind of pointers in openb3d.bi for the loadmesh funcion. (changing that did not fix the probleem)
And i'm on windows10 64bit machine compiling 32bit most of the time with freebasic 1.05.0-win
Maybe a good idea to add this to your openB3D.bi file.
Code: Select all
type tLightType as long
const as tLightType DIRECTIONAL_LIGHT = 1 ' default
const as tLightType POINT_LIGHT = 2
const as tLightType SPOT_LIGHT = 3
const as tLightType DIRECTIONAL_LIGHT_NOSHADOW = -1 ' \
const as tLightType POINT_LIGHT_NOSHADOW = -2 ' --- without shadows
const as tLightType SPOT_LIGHT_NOSHADOW = -3 ' /
Very mush looks like what is used a lot in Unity game engine.
Re: MiniB3d for FreeBasic
Oh, I understand now. Yes, UpdateNormals works only with meshes, and not with terrains. It's a bug I forgot to fix.
To fix it, in functions.cpp, replace the function UpdateNormals with:
and recompile the library
To fix it, in functions.cpp, replace the function UpdateNormals with:
Code: Select all
void UpdateNormals(Entity* ent){
Mesh* mesh=dynamic_cast<Mesh*>(ent);
Terrain* terr=dynamic_cast<Terrain*>(ent);
Geosphere* geo=dynamic_cast<Geosphere*>(ent);
if (geo)
geo->UpdateNormals();
else if (terr)
terr->UpdateNormals();
else if (mesh)
mesh->UpdateNormals();
}
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: MiniB3d for FreeBasic
I'm sure this isn't an error !
(again I changed nothing on LoadXYZ())
if your content are in the same folder make sure that the app folder is the current use:
chdir(exepath())
var aAnimMesh = LoadAnimMesh("ninja.b3d")
if the content you will load are not in the current folder you use something like this:
var aAnimMesh = LoadAnimMesh("./media/ninja.b3d")
NOTE: On your Windows 10 if you use FBIDE [F5] for quick run sometimes the created fbidetemp.exe
isn't at the same folder where your *.bas file is
with other words the current path for LoadXYZ() are not the same !
How ever a like OpenB3d but not the any pointer interface ;-)
Joshy
(again I changed nothing on LoadXYZ())
if your content are in the same folder make sure that the app folder is the current use:
chdir(exepath())
var aAnimMesh = LoadAnimMesh("ninja.b3d")
if the content you will load are not in the current folder you use something like this:
var aAnimMesh = LoadAnimMesh("./media/ninja.b3d")
NOTE: On your Windows 10 if you use FBIDE [F5] for quick run sometimes the created fbidetemp.exe
isn't at the same folder where your *.bas file is
with other words the current path for LoadXYZ() are not the same !
How ever a like OpenB3d but not the any pointer interface ;-)
Joshy
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: MiniB3d for FreeBasic
@angros47 in PostFX::AddRenderTarget() you use GL_FLOAT for all iFormats:Isn't it ?
iFormat = GL_RGBA16F = GL_FLOAT
iFormat = GL_RGBA32F = GL_FLOAT
iFormat = GL_RGBA8 = GL_UNSIGNED_BYTE <-- !!!
or GL_UNSIGNED_BYTE are only used if you read the texture back from GPU ?
Joshy
Code: Select all
glTexImage2D(GL_TEXTURE_2D, 0, iFormat, pass[pass_no].width, pass[pass_no].height, 0, GL_RGBA, GL_FLOAT, 0);
iFormat = GL_RGBA16F = GL_FLOAT
iFormat = GL_RGBA32F = GL_FLOAT
iFormat = GL_RGBA8 = GL_UNSIGNED_BYTE <-- !!!
or GL_UNSIGNED_BYTE are only used if you read the texture back from GPU ?
Joshy
Re: MiniB3d for FreeBasic
I hope this could help: https://stackoverflow.com/questions/344 ... rnalformat
"iFormat" is the internal format (how data are stored in the video memory). GL_RGBA and GL_FLOAT are related to the pixel data used to created the texture (a pointer to these data is passed with the last parameter)
Since, in PostFx, no data are passed to the texture. In fact, the last parameter is 0: glTexImage2D is only used to create an empty texture, since pixel data will come from the framebuffer (glFramebufferTexture2D will take care of that), the parameters related to pixel data format are irrelevant.
"iFormat" is the internal format (how data are stored in the video memory). GL_RGBA and GL_FLOAT are related to the pixel data used to created the texture (a pointer to these data is passed with the last parameter)
Since, in PostFx, no data are passed to the texture. In fact, the last parameter is 0: glTexImage2D is only used to create an empty texture, since pixel data will come from the framebuffer (glFramebufferTexture2D will take care of that), the parameters related to pixel data format are irrelevant.
-
- Posts: 103
- Joined: Mar 08, 2016 19:10
- Location: The Netherlands
Re: MiniB3d for FreeBasic
I will look in the loadmesh dieper. When i get back from vacation.
Thanks angros for the updatelight fix.
Thanks angros for the updatelight fix.
-
- Posts: 103
- Joined: Mar 08, 2016 19:10
- Location: The Netherlands
Re: MiniB3d for FreeBasic
I'm unable to say whats going on.
Look like there are differences in the loadmesh functions.
I made a example hier: http://ac1.servegame.com:88/download/Loadfighter.zip
.b3d files load fine like the ninja.b3d
the fighter.3ds file from air demo in not working on peters version, well on angros47 openb3d lib.
I did fount a other 3ds file with only a cube in it that loads just fine.
Also the ninja demo still gives me errors while working great.
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskinbl.jpg'
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskinbr.jpg'
Error: Can't Find Document File './media/nskinbr.jpg'
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskingr.jpg'
Error: Can't Find Document File './media/nskingr.jpg'
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskinwh.jpg'
Error: Can't Find Document File './media/nskinwh.jpg'
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskinrd.jpg'
Nowhere in the code i have the path "C:/work/.."
i'm confused.
Got the files from peters from this post viewtopic.php?f=14&t=27233&p=255789&hil ... 3d#p255789
Look like there are differences in the loadmesh functions.
I made a example hier: http://ac1.servegame.com:88/download/Loadfighter.zip
.b3d files load fine like the ninja.b3d
the fighter.3ds file from air demo in not working on peters version, well on angros47 openb3d lib.
I did fount a other 3ds file with only a cube in it that loads just fine.
Also the ninja demo still gives me errors while working great.
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskinbl.jpg'
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskinbr.jpg'
Error: Can't Find Document File './media/nskinbr.jpg'
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskingr.jpg'
Error: Can't Find Document File './media/nskingr.jpg'
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskinwh.jpg'
Error: Can't Find Document File './media/nskinwh.jpg'
Error: Can't Find Document File 'C:/work/ninja/enemyninja/nskinrd.jpg'
Nowhere in the code i have the path "C:/work/.."
i'm confused.
Got the files from peters from this post viewtopic.php?f=14&t=27233&p=255789&hil ... 3d#p255789
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: MiniB3d for FreeBasic
@Gunslinger the "absolute wrong texture paths" are stored in the "ninja.b3d" file.
Here are a fix to change the absolute path's to relative path's.
Compile and run it in the /media folder !
NOTE: The original file are overwritten with the fixed version !
Joshy
edit: The fixed "ninja.b3d" file are in the ".zip" file now.
file: "ninja_fix.bas"
Here are a fix to change the absolute path's to relative path's.
Compile and run it in the /media folder !
NOTE: The original file are overwritten with the fixed version !
Joshy
edit: The fixed "ninja.b3d" file are in the ".zip" file now.
file: "ninja_fix.bas"
Code: Select all
function readTag(byref stream as any ptr, byref restlength as longint) as string
dim as string tag
if restlength<4 then
print "error: in readTag end of stream !"
beep : sleep: end 1
end if
for i as integer= 0 to 3
tag &= chr(cptr(ubyte ptr,stream)[i])
next
stream+=4 : restlength-=4
return tag
end function
function readFloat(byref stream as any ptr, byref restlength as longint) as single
dim as single ret
if restlength<4 then
print "error: in readU32 end of stream !"
beep : sleep: end 1
end if
ret = cptr(single ptr,stream)[0]: stream+=4 : restlength-=4
return ret
end function
function readI32(byref stream as any ptr, byref restlength as longint) as long
dim as long ret
if restlength<4 then
print "error: in readI32 end of stream !"
beep : sleep: end 1
end if
ret = cptr(long ptr,stream)[0]: stream+=4 : restlength-=4
return ret
end function
function readString(byref stream as any ptr, byref restLength as longint) as string
dim as string ret
dim as ubyte char = cptr(ubyte ptr,stream)[0]:stream+=1:restLength-=1
while char<>0
ret &= chr(char)
char = cptr(ubyte ptr,stream)[0]:stream+=1:restLength-=1
wend
if restlength<0 then
print "error: in readString end of stream !"
beep : sleep: end 1
end if
return ret
end function
'
' main
'
chdir exepath()
var hFile = FreeFile()
if open("ninja.b3d",for binary,access read, as #hFile) then
print "error: can't read 'ninja.b3d' !"
beep : sleep : end 1
end if
var nBytes = LOF(hFile)
if nBytes<>106407 then
close #hFile
print "error: this is not the original 'ninja.b3d' file !"
beep : sleep : end 1
end if
dim as ubyte ptr FileBuffer = allocate(nBytes)
get #hFile,,*FileBuffer,nBytes
close #hFile
print "file size: " & nBytes ' 106407
var stream = FileBuffer
var BB3D_Tag = readI32(stream,nBytes)
var BB3D_Size = readI32(stream,nBytes)
var BB3D_Version = readI32(stream,nBytes)
var TEXS_Tag = readI32(stream,nBytes)
var TEXS_Size = readI32(stream,nBytes)
type BB3D_TEXTURE
as string file
as long flag
as long blend
as single u_pos
as single v_pos
as single u_scale
as single v_scale
as single angle
end type
dim as BB3D_TEXTURE tex(4)
' subtract "old" TEXS tag size from BB3D tag size
BB3D_Size -= TEXS_Size
' reset TEXS tag size
TEXS_Size=0
for i as integer = 0 to 4
with tex(i)
.file = readString(stream,nBytes)
print "change: '" & .file & "' to './media/nskinbl.jpg'"
.file = "./media/nskinbl.jpg"
TEXS_Size+=len(.file)+1 ' + 1 zero string terminator
.flag = readI32(stream,nBytes)
.blend = readI32(stream,nBytes)
.u_pos = readFloat(stream,nBytes)
.v_pos = readFloat(stream,nBytes)
.u_scale = readFloat(stream,nBytes)
.v_scale = readFloat(stream,nBytes)
.angle = readFloat(stream,nBytes)
TEXS_Size += 28
end with
next
hFile = FreeFile()
if open("ninja.b3d",for binary,access write, as #hFile) then
print "error: can't write 'ninja.b3d' fix !"
beep : sleep : end 1
end if
print "write fixed 'ninja.b3d' file"
' add "new" fixed TEXS tag size to the BB3D tag size
BB3D_Size += TEXS_Size
' write BB3D header
put #hFile,,BB3D_Tag
put #hFile,,BB3D_Size
put #hFile,,BB3D_Version
' write fixed texture tag
put #hFile,,TEXS_Tag
put #hFile,,TEXS_Size
' write the fixed textures
for i as integer = 0 to 4
with tex(i)
dim as ubyte char
for j as integer = 0 to len(.file)-1
char = .file[j]
put #hFile,,char
next
char = 0
put #hFile,,char ' zero string terminator
put #hFile,,.flag
put #hFile,,.blend
put #hFile,,.u_pos
put #hFile,,.v_pos
put #hFile,,.u_scale
put #hFile,,.v_scale
put #hFile,,.angle
end with
next
' write rest of the file
put #hFile,,*stream,nBytes
close #hFile
deallocate FileBuffer
print "done ..."
sleep
-
- Posts: 103
- Joined: Mar 08, 2016 19:10
- Location: The Netherlands
Re: MiniB3d for FreeBasic
Oke thats is clear now.
Then what about the fighter.3ds file?
Is the problem also in the file it self.
That does not explain why your version 1.25 openB3D build is not load it.
While the other from angros47 works fine.
Then what about the fighter.3ds file?
Is the problem also in the file it self.
That does not explain why your version 1.25 openB3D build is not load it.
While the other from angros47 works fine.