MiniB3d for FreeBasic

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Postby Domso » May 29, 2012 12:25

Ive found a problem
I want to make a animated mesh clickable. So Im using a code like this

Code: Select all

mesh=LoadAnimMesh("mesh.b3d")
EntityPickMode mesh, 2,1
PositionEntity mesh, x,y,z
animate mesh,1,1


But the program crashes while executing... without EntityPickMode it works fine....
angros47
Posts: 1551
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » May 29, 2012 12:38

I can't reproduce the bug without the mesh.
angros47
Posts: 1551
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Jun 03, 2012 17:18

Well, I haven't released updates for a while. Anyway, I'm still working on it; here is a pre-release (source only) of what there will be in the next version: it's still incomplete, and I haven't yet tested it on windows (only on linux), but the main work is done:

http://sourceforge.net/projects/minib3d/files/version%200.5%20preview.zip/download

In this version, I'm introducing shader support (I used some of klepto's work): shaders can be loaded and applied to any surface (just like brushes): also, with UseFloat it's possible to bind a float variable to a shader variable (every time you change the value of the variable, and render the world, the new parameter is automatically passed to the shader); also, vertex data and transformation matrices (that openb3d uses internally) can be passed to a shader with UseSurface and UseMatrix.

Oh, and stencil shadows now should work.
313studio
Posts: 10
Joined: May 21, 2007 16:15

Re: MiniB3d for FreeBasic

Postby 313studio » Jun 10, 2012 20:53

This is a great news. I really appreciate your hard work. Can't wait to test.
angros47
Posts: 1551
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Jul 05, 2012 22:30

Ok, version 0.5 is online:

https://sourceforge.net/projects/minib3d/files/

It has a first, simple support for shaders (it still doesn't support passing of 80-bit float, or matrices to a shader)

Note for the linux version: the file name changed from libopenb3d.so to libOpenB3D.so (linux is case sensitive): the declare file has been updated, but you need to recompile your programs, otherwise they will still try to use the old version of the library.

I still need to work on it, but I've already delayed the release too much.
angros47
Posts: 1551
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Jul 08, 2012 8:55

Here is a very simple demo of shaders:

Code: Select all

#include "openb3d.bi"

screen 18, 32, , &h02   

   
Graphics3d 640,480,32,1,1


var camera=createcamera(0)
var cube=Createcube()
moveentity cube,0,0,15
scaleentity cube,5,5,5,0

dim a as single
dim key as string

var shader=loadshader("shader", "", "plasma.frag")


shademesh cube,shader

usefloat shader, "sTime",a

do
   a=a+.01

   key=inkey
        if key=" " then moveentity camera,0,0,-0.1
        if key=chr(255)+"H" then turnentity cube,1,0,0,0
        if key=chr(255)+"P" then turnentity cube,-1,0,0,0
        if key=chr(255)+"M" then turnentity cube,0,-1,0,0
        if key=chr(255)+"K" then turnentity cube,0,1,0,0
   updateworld 1
   renderworld
   sleep 1
   flip
loop until key=chr(27)



And this is the file "plasma.frag"

Code: Select all

//Simple Plasma effect fragment shader by Dave Stanley(Dr_D)

uniform float sTime;
void main(void)
{
vec4 Color1 = vec4(0.0);
vec2 tpos = gl_FragCoord.xy;
float t = sTime;
float x = tpos.x;
float y = tpos.y;

Color1.r = (0.5 + 0.49 * cos(t+x / (128.0 + 32.0 * cos(y / 64.0+t))) * cos(y / (320.0 + 16.0 * sin(x / 64.0 ))));
Color1.g = (0.5 - 0.49 * cos(x*2 / (96.0 + 16.0 * cos(y*2.0 / (256.0+t)))) * cos(y / (64.0 + 16.0  * sin(x / 64.0 + t))));
Color1.b = (0.5 - 0.49 * sin(y / (128.0 + 8.0 * cos(x / (96.0 + t)))) * cos(x / (64.0 + 32.0  * sin(y / 512.0 )) ));

gl_FragColor = Color1;
}


Try it!
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Postby Westbeam » Jul 19, 2012 14:30

Hey, i am searching for a method to control the camera with the mouse like in an ego-shooter. I tried it this way:

Code: Select all

Screencontrol 4, MouseX, MouseY
MouseX /= 2: MouseY /= 2
OldMouseX = MouseX: OldMouseY = MouseY
SetMouse(MouseX, MouseY, 0, 1)
'...
If GetMouse(MouseX2, MouseY2) = 0 Then
      If MouseX2 <> MouseX Or MouseY2 <> MouseY Then
         OldMouseX += MouseX2-MouseX: OldMouseY += MouseY2-MouseY
         If EntityPitch(Cam)>=-67 And EntityPitch(Cam)<=67 Then
            TurnEntity Cam,-(MouseY2-MouseY),-(MouseX2-MouseX),0,0
         Elseif EntityPitch(Cam)<-67 Then
            RotateEntity Cam,-67,0,0
         Elseif EntityPitch(Cam)>67 Then
            RotateEntity Cam,67,0,0
         End If
         SetMouse(MouseX, MouseY)
      End If
   End If
If Multikey(&h11) Then MoveEntity cam,0,0,0.7

But it is a little bit ugly. Is there a better method?
angros47
Posts: 1551
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Jul 19, 2012 16:02

Of course there is:

Code: Select all

    If GetMouse(MouseX2, MouseY2) = 0 Then
          If MouseX2 <> MouseX Or MouseY2 <> MouseY Then
             OldMouseX += MouseX2-MouseX: OldMouseY += MouseY2-MouseY

             camerapitch-=(MouseY2-MouseY)
             camerayaw-=(MouseX2-MouseX)
             rotateentity cam,camerapitch,camerayaw,0
             sleep 1
          End If
       End If
    If Multikey(&h11) Then MoveEntity camera,0,0,0.7
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Re: MiniB3d for FreeBasic

Postby Westbeam » Jul 19, 2012 16:23

Awesome, thank you. :)
But i think it is better, when you put a "SetMouse(MouseX, MouseY)" after the RotateEntity, because the camera will not stop moving, when you dont do it.
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Postby Domso » Aug 01, 2012 11:31

hi

i want to do some water-effects and have now some problems...
the easiest way to do would be createmirror(), but this command is missing


the other way is to create a cubemap...
there a many instructions written in blitz3d and they use the command
CopyRect() to copy a part of the backbuffer into a texture...
I think in openb3d theres BackBufferToTex(), but this copys the whole backbuffer...

I need some help ;P
angros47
Posts: 1551
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Aug 01, 2012 18:09

CreateMirror is not available; in fact, it is a cool command, but pretty useless: it works only horizontally, and it mirrors everything everywhere (it means, objects that are underwater will be mirrored over the water). Anyway, there is a way to emulate it: in OpenB3d, the command ScaleEntity can be applied to camera, too: if you use "ScaleEntity camera, 1, -1, 1" it will rendered a mirrored world.

So, you could do a multipass rendering: you first render your world, then you render mirrored world, and then you use the "flip" command: to prevent second rendering from clearing the first one, you can use CameraClsMode:

Code: Select all

RenderWorld
CameraClsMode camera, 0,0
ScaleEntity camera,1,-1,1
RenderWorld
CameraClsMode camera, 1,1
ScaleEntity camera,1,1,1
Flip


Note: if you mirror a camera, all entities will be flipped (an "inside out" effect): to prevent this, you have to disable backface culling, using EntityFX object,16 on every entity.


About cubemapping: to use single faces, you need to create a texture using CreateTexture (width, height, 128), and use SetCubeFace before any BackBufferToTex (untested, it should work; please report me if it doesn't)
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Postby Domso » Aug 02, 2012 12:28

ok. thank you
now all works fine
cubemapping works, too ;P
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Postby Domso » Aug 03, 2012 11:26

ive tried to make a simple cubemap program, but it doenst work right...

If I use a "normal"-texture without "+128" then it works, but of course only like a static shadow...
Using a texture with 128 doenst work... But I think, theres a problem with my code and not with openb3d ;P

The cone should be reflected... but this doenst work...
I think theres something wrong with the reflection-sub...

Would be nice, if you can have a look at it


Code: Select all

#Include "openb3d.bi"         
ScreenRes 1200 ,800 , 32, , &h10002
Graphics3d 1200 ,800 ,32,2,1

'Basic Objects
Dim As Any Ptr camera,terrain,texture,light,obj,obj2,obj2_srf,obj2_tex

'Camera
camera=createCamera
moveEntity camera,0,10,0
CameraClsColor camera,222,252,255
PositionEntity camera, 0, 1, -100
turnentity camera, 0, -90, 0, 0
MoveEntity camera, 0, 0, 50

'Light
light=createlight

'Terrain
terrain=createplane
Entitycolor terrain,128,64,0

'object
obj=createcone
scaleentity obj,10,10,10
MoveEntity obj, 300, 100, -100
Entitycolor obj,123,213,1
Entityfx obj,1+16

'object, which should reflect obj
obj2=createcube
obj2_tex=createtexture(256, 256,128)
'obj2_tex=createtexture(1200, 800)
scaleentity obj2,100,1,100
MoveEntity obj2, 400, 1, -100
Entityfx obj2,1+16
Entitytexture obj2,obj2_tex
Entitycolor obj2,30,30,222



'Update Cubemap
sub reflexion(ref_camera As Any Ptr,ref_obj As Any Ptr,ref_tex As Any ptr)
   Dim As double c_x,c_y,c_z,c_w1,c_w2,c_w3
   
   'Save old Camera position
   c_x=EntityX(ref_camera)
   c_y=Entityy(ref_camera)
   c_z=Entityz(ref_camera)
   
   c_w1=Entitypitch(ref_camera)
   c_w2=Entityyaw(ref_camera)
   c_w3=Entityroll(ref_camera)

   
   hideEntity ref_obj
   
   'Put the camera in the object
   positionEntity ref_camera,EntityX(ref_obj),Entityy(ref_obj),Entityz(ref_obj)
   rotateEntity ref_camera,0,0,0
   
   'Set the cubefaces (0-5)
   SetCubeFace ref_tex,0
   RotateEntity ref_camera,0,90,0
   renderworld
   backbuffertotex(ref_tex,0)
   
   SetCubeFace ref_tex,1
   RotateEntity ref_camera,0,0,0
   renderworld
   backbuffertotex(ref_tex,0)
   
   SetCubeFace ref_tex,2
   RotateEntity ref_camera,0,-90,0
   renderworld
   backbuffertotex(ref_tex,0)
   
   SetCubeFace ref_tex,3
   RotateEntity ref_camera,0,180,0
   renderworld
   backbuffertotex(ref_tex,0)
   
   SetCubeFace ref_tex,4
   RotateEntity ref_camera,-90,0,0
   renderworld
   backbuffertotex(ref_tex,0)
   
   SetCubeFace ref_tex,5
   RotateEntity ref_camera,90,0,0
   renderworld
   backbuffertotex(ref_tex,0)
   
'Put the cam at the old position
positionEntity ref_camera,c_x,c_y,c_z
rotateEntity ref_camera,c_w1,c_w2,c_w3

showentity ref_obj

End Sub


Do
   'update the cubemap
   reflexion(camera,obj2,obj2_tex)
   
      ' Arrow-Key and SPACE to move camera
        If MultiKey(&h39) Then moveEntity camera , 0, 0, 1
       If MultiKey(&h48) Then turnentity camera,1,0,0
       If MultiKey(&h50) Then turnentity camera,-1,0,0
       If MultiKey(&h4d) Then turnentity camera,0,-1,0,0
         If MultiKey(&h4b) then turnentity camera,0,1,0,0
        
         'Q;E;W;A;S;D to move the object
       If MultiKey(&h10) Then moveEntity obj,0,1,0 'Q
       if MultiKey(&h12) Then moveEntity obj,0,-1,0 'E
       If MultiKey(&h11) Then moveEntity obj,0,0,1 'W
       if MultiKey(&h1F) Then moveEntity obj,0,0,-1 'S
       If MultiKey(&h1E) Then moveEntity obj,1,0,0 'A
       If MultiKey(&h20) then moveEntity obj,-1,0,0 'D
   
   updateworld
   renderworld
   flip
Loop Until MultiKey(1)
clearworld
End
angros47
Posts: 1551
Joined: Jun 21, 2005 19:04

Re: MiniB3d for FreeBasic

Postby angros47 » Aug 03, 2012 19:38

First: you should position the camera in another way:

Code: Select all

       positionEntity ref_camera,c_x, -c_y, c_z 'EntityX(ref_obj),Entityy(ref_obj),Entityz(ref_obj)



Second: you should "tune" camera position for each frame (you might need to adjust zoom factor, too); a hint: before each "RenderWorld", use CameraClsColor with a different value: you'll be able to check which face are you working on, and when it's visible.
Domso
Posts: 45
Joined: Jan 16, 2011 11:26

Re: MiniB3d for FreeBasic

Postby Domso » Aug 04, 2012 11:49

ok thank you ;P

finally I got it to work...
I changed the screen-resolution to the texture-resolution and use a surface instead of a scaled cube as reflector...

but theres an other issue... If you have more than one cubemap-textures, all cubemap-textures show the same...
for example if u use 2 reflector-objects you need 2 textures... But both objects schow the same...

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest