MiniB3d for FreeBasic
Don't forget Maplet: now it's freeware, and it produces B3D files:
http://www.blitzbasic.com/Products/maplet.php
It works under windows and wine, and it has been written by the author of Blitz3D. Anyway, the author has lost the source code, so it won't be updated.
It's really easy to use, since it works by CSG: you can draw a room, then you add and remove walls, stairs and so on.
Many other tools can be used for lightmapping; Blender can be used:
http://vi-wer.de.tl/Lightmap-Tutorial.htm
http://www.blitzbasic.com/Products/maplet.php
It works under windows and wine, and it has been written by the author of Blitz3D. Anyway, the author has lost the source code, so it won't be updated.
It's really easy to use, since it works by CSG: you can draw a room, then you add and remove walls, stairs and so on.
Many other tools can be used for lightmapping; Blender can be used:
http://vi-wer.de.tl/Lightmap-Tutorial.htm
... a real pity... :(angros47 wrote:the author has lost the source code, so it won't be updated
I am hoping to compile for GLES at some point, I am unsure if the new shadow code will be able to be ported as if has some GL code in it(eg. glBegin(GL_QUADS)) but I may still give it a go, when I get my head around it.
-
- Posts: 2
- Joined: Oct 21, 2011 13:42
This is the main page:
http://sourceforge.net/projects/minib3d/files/
The official wiki (very incomplete) is at http://sourceforge.net/apps/mediawiki/m ... =Main_Page
When I made the site, I haven't change the library name to OpenB3d yet.
http://sourceforge.net/projects/minib3d/files/
The official wiki (very incomplete) is at http://sourceforge.net/apps/mediawiki/m ... =Main_Page
When I made the site, I haven't change the library name to OpenB3d yet.
-
- Posts: 2
- Joined: Oct 21, 2011 13:42
Veggie already did it: http://www.glbasic.com/forum/index.php? ... 6#msg56816
Anyway, you could simply read the blitz manual: http://blitzbasic.com/b3ddocs/docs.php
Most commands are similar. There are few differences: rotation commands, for example, have pitch that works in the opposite way (i.e., when porting a program from Blitz3d, you need to invert pitch values).
Also, texture buffers work in a different way, because FreeBasic has its own graphic buffers (that you can manipulate with GET and PUT), and they can be used in OpenB3d.
Anyway, you could simply read the blitz manual: http://blitzbasic.com/b3ddocs/docs.php
Most commands are similar. There are few differences: rotation commands, for example, have pitch that works in the opposite way (i.e., when porting a program from Blitz3d, you need to invert pitch values).
Also, texture buffers work in a different way, because FreeBasic has its own graphic buffers (that you can manipulate with GET and PUT), and they can be used in OpenB3d.
Is it possible to map a texture to a cube with an individual picture for every side?
Texture flag: 128 = Cubic environment map should do the job, but it does not work for me, maybe I'm doing wrong.
This is, what I try:
Version (1) puts the same bitmap on every side and work of course.
Version (2) does not work. I played with the flags without success.
Version (3) does also not work. For a test, I placed a 6x1 ratio bitmap in the same folder.
Any ideas?
Texture flag: 128 = Cubic environment map should do the job, but it does not work for me, maybe I'm doing wrong.
This is, what I try:
Code: Select all
#include "openb3d.bi"
'see MultiKey example
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif
screen 18, 32, , &h02
Graphics3d 640,480,32,1,1
var cam=createcamera()
CameraClsColor cam,128,192,255 'color of sky
var cube=createcube()
' (1) same texture on every side
var img = imagecreate(64,64,32)
Line img,(0,0)-(63,63),RGB(0,200,100),BF
draw string img, (32-4*4,24),"CUBE"
var tex=CreateTexture(64,64,1,1)
BufferToTex tex,img+32,1
' (2) individual texture on every side of the cube
' texture flag: 128 = Cubic environment map
'var img = imagecreate(64*6,64,32)
'For i As Integer=0 To 5
' Line img,(0+i*64,0)-(63+i*64,63),RGB(0,i*50,100),BF
' draw string img, (32-4*6+i*64,24),"CUBE "+str(i)
'Next i
'var tex=CreateTexture(64*6,64,128,1)
'BufferToTex tex,img+32,1
' (3) individual texture on every side of the cube
' using LoadTexture, 32*6 x 32 pixel bitmap
'var tex=LoadTexture("cube6.bmp",128)
EntityTexture cube,tex
moveentity cube,0,0,5
AmbientLight(200, 200, 200)
Do
'animation
turnentity cube,1,1,0
renderworld
flip
Sleep 30
Loop Until MultiKey(SC_Escape)
Version (2) does not work. I played with the flags without success.
Version (3) does also not work. For a test, I placed a 6x1 ratio bitmap in the same folder.
Any ideas?
Another question for texture.
Can I make a cylinder look like a wheel?
This is my try and looks strange:
That's a pretty cool Lib. Doing 3D stuff is so easy now, thank you.
Can I make a cylinder look like a wheel?
This is my try and looks strange:
Code: Select all
' Can I map different bitmaps to surfaces of an object?
' example:
' let cylinder look like a wheel, tread looks strange
'
#include "openb3d.bi"
screen 18, 32, , &h02
Graphics3d 640,480,32,1,1
var cam=createcamera()
CameraClsColor cam,150,150,150
var wheel=createcylinder(32)
ScaleEntity wheel,.5,.15,.5
PositionEntity wheel,0,0,2
TurnEntity wheel,90,0,0
'create texture from image
var img = imagecreate(128,128,32)
Line img,(0,0)-(127,127),RGB(30,30,30),BF
Circle img, (64,64),44,RGB(200,200,200),,,,F
Circle img, (64,64),40,RGB(100,100,100),,,,F
var tex=CreateTexture(128,128,1,1)
BufferToTex tex,img+32,1
EntityTexture wheel,tex
Do
'animation
turnentity wheel,0,0,1
renderworld
flip
Sleep 10
Loop Until inkey=chr(27)
That's a pretty cool Lib. Doing 3D stuff is so easy now, thank you.
Cube mapping (and sphere mapping) are used to map reflections: so, they will always show the same part of the texture when you turn the mesh, but they will change when you move the camera.
To be able to map a different texture to every face of a cube, a solution could be the use of VertexU and VertexW: they will set the vertex coord for each vertex (you can say that the first vertex correspond to point 0,0 of a texture, for example). So, you'll be able to apply only part of a texture to each face of a cube, and every face can have a different part of the texture.
About the wheel: you could use a simple trick, by using two cylinders: in fact, you can create a cylinder with no "top" and "bottom" (there will be only the "ring", not the two circles that cap the cylinder) by acting to the second parameter of CreateCylinder.
So, you can have a solid cylinder with the wheel texture, and a slightly larger cylinder (not solid) with the tread texture.
To be able to map a different texture to every face of a cube, a solution could be the use of VertexU and VertexW: they will set the vertex coord for each vertex (you can say that the first vertex correspond to point 0,0 of a texture, for example). So, you'll be able to apply only part of a texture to each face of a cube, and every face can have a different part of the texture.
About the wheel: you could use a simple trick, by using two cylinders: in fact, you can create a cylinder with no "top" and "bottom" (there will be only the "ring", not the two circles that cap the cylinder) by acting to the second parameter of CreateCylinder.
So, you can have a solid cylinder with the wheel texture, and a slightly larger cylinder (not solid) with the tread texture.
Thank you for the quick response.
I'm new to 3D programming. I will check the Vertex functions, thanks for the explanation. I completety misunderstood the Cube mapping - now I know, why the streets, build of textured cubes, did look so strange.
I tried to build a wheel with an extra cylinder ring, as you suggested.
If createcylinder(n,0) is the right command, it seems not to work for me. The ring appears as a solid cylinder.
Here's my code.
The tread cylinder width is animated, sometimes smaller and sometimes wider than the wheel cylinder.
When it's wider, the wheel cylinder is completety covered, so the ring option does not work for me.
A workaround is, to make the tread cylinder smaller than the wheel, but the two covered surfaces might drop performance.
I'm new to 3D programming. I will check the Vertex functions, thanks for the explanation. I completety misunderstood the Cube mapping - now I know, why the streets, build of textured cubes, did look so strange.
I tried to build a wheel with an extra cylinder ring, as you suggested.
If createcylinder(n,0) is the right command, it seems not to work for me. The ring appears as a solid cylinder.
Here's my code.
Code: Select all
' example:
' try to let a cylinder look like a wheel
#include "openb3d.bi"
screen 18, 32, , &h02
Graphics3d 640,480,32,1,1
var cam=createcamera()
CameraClsColor cam,150,150,150
var wheel=createcylinder(32,1) 'solid cylinder
ScaleEntity wheel,.5,.15,.5
TurnEntity wheel,90,0,0
var tread=createcylinder(32,0) 'ring of cylinder
ScaleEntity tread,.51,.15,.51
TurnEntity tread,90,0,0
'position (1) - wheel and tread at same position
PositionEntity wheel,0,0,2
PositionEntity tread,0,0,2
'position (2) - wheel and tread next to each other
' PositionEntity wheel,-.7,0,2
' PositionEntity tread,.7,0,2
'tread image
var img = imagecreate(128,128,32)
Line img,(0,0)-(127,127),RGB(140,80,80),BF
'create tread texture from image
var ttex=CreateTexture(128,128,1,1)
BufferToTex ttex,img+32,1
EntityTexture tread,ttex
'wheel image
Line img,(0,0)-(127,127),RGB(30,30,30),BF
Circle img, (64,64),44,RGB(200,200,200),,,,F
Circle img, (64,64),40,RGB(100,100,100),,,,F
'create wheel texture from image
var wtex=CreateTexture(128,128,1,1)
BufferToTex wtex,img+32,1
EntityTexture wheel,wtex
Dim As Double i
Do
'animation
turnentity wheel,0,0,1
turnentity tread,0,0,1
ScaleEntity tread,.51,.15+Sin(i)/100,.51
i+=.1
renderworld
flip
Sleep 10
Loop Until inkey=chr(27)
When it's wider, the wheel cylinder is completety covered, so the ring option does not work for me.
A workaround is, to make the tread cylinder smaller than the wheel, but the two covered surfaces might drop performance.
Maybe a typo in mesh.cpp?
->
Code: Select all
Mesh* Mesh::CreateCylinder(int verticalsegments,int solid,Entity* parent_ent){
...
if(solid=true){
thissidesurf=thiscylinder->CreateSurface();
}
Code: Select all
if(solid==true){
Function TerrainY
I use TerrainY to move a camera over the ground, climbing hills etc.
When I walk over the terrain borders, I get strange effects.
Leaving the terrain in Z direction, bring a wrap around effect. I climb phantom hills, that I already left behind me. Leaving the terrain in X direction, sometimes causes a crash of the program.
I suggest, to perform a coordinates check, before accessing the height-array.
file terrain.cpp
I use TerrainY to move a camera over the ground, climbing hills etc.
When I walk over the terrain borders, I get strange effects.
Leaving the terrain in Z direction, bring a wrap around effect. I climb phantom hills, that I already left behind me. Leaving the terrain in X direction, sometimes causes a crash of the program.
I suggest, to perform a coordinates check, before accessing the height-array.
file terrain.cpp
Code: Select all
float Terrain::TerrainY (float x, float y, float z){
TFormPoint(x, y, z, 0, this);
float p0[3],p1[3],p2[3];
<range check of tformed_x, tformed_z (0..tsize)>
<return 0.0, if coordinates are out of range>
<return height, if coordinates are in range>
Terrain test program.
Program needs "Water-2_mip.BMP" from demo zip
Move camera out of the terrain to see, what I mean.
The tarrain border is animated to move up and down in the example program. I expected the values 0 and 255 to address the border, however I found out, that coordinates have to be 254 and 256.
Not a problem, but strange.
Program needs "Water-2_mip.BMP" from demo zip
Move camera out of the terrain to see, what I mean.
Code: Select all
'TerrainY Demo
'Walk outside the terrain.
'need "Water-2_mip.BMP" from demo
'
#include "openb3d.bi"
'see MultiKey example
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif
screen 18, 32, , &h02
Graphics3d 640,480,32,1,1
Dim As Double camy,f 'camera height
var cam=createcamera()
moveentity cam,0,2,0
CameraClsColor cam,128,192,255 'color of sky
var tx=LoadTexture( "water-2_mip.bmp",3 )
ScaleTexture tx,.0010,.0010
var water=CreatePlane()
EntityTexture water,tx
EntityBlend water,1
EntityAlpha water,.75
PositionEntity water,0,0,0
Const terrscale=1
var terrain = CreateTerrain(256) 'power of two, 32, 64, 128, 256, 512
ScaleEntity terrain,terrscale,1,terrscale
PositionEntity terrain,-128*terrscale-16,-5,128*terrscale
EntityFX terrain,1
var light=createlight()
RotateEntity light,-60,0,0
'create image of terrain
'(RGB swap red and blue when converting to texture)
var img32=imagecreate(32,32,32)
Line img32,(0,0)-(31,31),RGB(255,100,0),BF
Line img32,(0,0)-(15,15),RGB(100,255,0),BF
Line img32,(16,16)-(31,31),RGB(100,255,0),BF
'create texture from image
var tertex=CreateTexture(32,32,1,1)
BufferToTex tertex,img32+32,1
EntityTexture terrain,tertex
EntityColor terrain,20,100,40
var ohd=CreateSprite(cam)
moveentity ohd,3.8,2.5,5
Dim Shared As Any Ptr ohdtex, ohdimg
ohdtex=CreateTexture(128,128,1,1)
ohdimg=imagecreate(128,128,32)
EntityTexture ohd,ohdtex
EntityAlpha ohd, 0.7
Dim Shared As String ohdtext(7)
'show text from string array ohdtext() to ohd
Sub ohdflush
Line ohdimg,(0,0)-(127,127),RGB(150,10,0),BF
For i As Integer=0 To 7
draw String ohdimg, (0,i*16),ohdtext(i)
Next i
BufferToTex ohdtex,ohdimg+32,1
End Sub
ohdtext(0) ="* TerrainY Test *"
ohdtext(5) ="-----------------"
ohdtext(6) ="Keys: Cursor,y,x"
ohdtext(7) ="-----------------"
ohdflush
for x As Integer = 0 To 256
For z As Integer = 0 To 256
' ModifyTerrain(terrain,x,z,0.185+Sin(x/10)*Sin(z/10)/5.0)
ModifyTerrain(terrain,x,z,0.25+Sin(x/10)*Sin(z/10)*0.3)
next z
next x
Const coast=0 'coast line ends under the sea
For x As Integer = 0 To 256
ModifyTerrain(terrain, 0,x,coast) 'west coast
ModifyTerrain(terrain,256,x,coast) 'east coast
ModifyTerrain(terrain,x, 0,coast) 'north coast
ModifyTerrain(terrain,x,254,coast) 'south coast
next x
AmbientLight(200, 200, 200)
Do
'animation
PositionEntity water,0+3*Cos(Timer),0,0
'move terrain edge up and down
For x As Integer = 0 To 256
ModifyTerrain(terrain, 0,x,0.2+Cos(Timer)/5) 'west coast
ModifyTerrain(terrain,256,x,0.2+Cos(Timer)/5) 'east coast
ModifyTerrain(terrain,x, 0,0.2+Cos(Timer)/5) 'north coast
ModifyTerrain(terrain,x,254,0.2+Cos(Timer)/5) 'south coast
next x
If Multikey(SC_RIGHT) Then turnentity cam,0,-1,0,0
If Multikey(SC_LEFT) Then turnentity cam,0,1,0,0
If Multikey(SC_DOWN) Then TranslateEntity cam,0,0,-1,0
If Multikey(SC_UP) Then TranslateEntity cam,0,0, 1,0
If Multikey(SC_y) AndAlso camy>0 Then camy-=0.1
If Multikey(SC_x) Then camy+=0.1
If Multikey(SC_c) Then TranslateEntity cam,-.1,0,0
If Multikey(SC_v) Then TranslateEntity cam,.1,0,0
ohdtext( 1)="X="+str(EntityX(cam))
ohdtext( 2)="Y="+str(EntityY(cam))
ohdtext( 3)="Z="+str(EntityZ(cam))
ohdtext( 4)="DIR="+str(Int(EntityYAW(cam)))
ohdflush
'move camera over terrain
f=TerrainY(terrain,EntityX(cam),EntityY(cam),EntityZ(cam))
If f<5.0 Then f=5.0
PositionEntity cam,EntityX(cam),_
-2.0+camy+f,_
EntityZ(cam)
renderworld
flip
Sleep 10
Loop Until MultiKey(SC_Escape)
Code: Select all
'move terrain edge up and down
For x As Integer = 0 To 256
ModifyTerrain(terrain, 0,x,0.2+Cos(Timer)/5) 'west coast
ModifyTerrain(terrain,256,x,0.2+Cos(Timer)/5) 'east coast
ModifyTerrain(terrain,x, 0,0.2+Cos(Timer)/5) 'north coast
ModifyTerrain(terrain,x,254,0.2+Cos(Timer)/5) 'south coast
next x
Last edited by oog on Oct 29, 2011 12:42, edited 1 time in total.
You are right; thank you.oog wrote:Maybe a typo in mesh.cpp?
->Code: Select all
Mesh* Mesh::CreateCylinder(int verticalsegments,int solid,Entity* parent_ent){ ... if(solid=true){ thissidesurf=thiscylinder->CreateSurface(); }
Code: Select all
if(solid==true){
The same bug affected original version of iMinib3d, and has been fixed in the next version.