MiniB3d for FreeBasic

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Postby Westbeam » Aug 04, 2010 13:24

Thank you. Now it works fine
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Postby Westbeam » Aug 04, 2010 15:32

Next question: How can i write text? "Draw String" doesn't work.
MusicianKool
Posts: 57
Joined: May 13, 2010 22:30

Postby MusicianKool » Aug 08, 2010 4:21

Are there any lib's needed to run this in Linux. air file errors with:
./air: error while loading shared libraries: libminib3d.so: cannot open shared object file: No such file or directory
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Postby Westbeam » Aug 08, 2010 8:03

U have to copy the libminib3d.so in the /lib-folder or your root-directory ;)
angros47
Posts: 1535
Joined: Jun 21, 2005 19:04

Postby angros47 » Aug 08, 2010 8:17

@MusicianKool

The library is included, but your system cannot see it.

Under Windows, a program will look for its library in current directory, and, after that, in system directory and in path directory.

Under linux, a program look for shared libraries in path directory, not in current directory.

So, to run "air", you should either copy libminib3d.so into a shared directory, or load the program with:

Code: Select all

LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH  ./air


"LD_LIBRARY_PATH=." tells the system to look for libraries in current directory,too.

@Westbeam
This is an issue of fbgfx: it cannot draw on opengl screen (and MiniB3d uses opengl screen). You can, anyway, draw to buffers, and use buffers as textures (but with a quirk: opengl uses RGBA format, FBGFX uses BGRA, so red and blue levels are swapped).

To use "DRAW STRING" on a texture, you could do something like:

Code: Select all

var tex=CreateTexture(512,512,1,1)
var img = imagecreate(512, 512,32)
draw string img, (10,10),"Hello World"
BufferToTex tex,img+32,1


And you can apply the texture to a sprite, or to a 3d object.

Otherwise, you can use another library to use text and 2d commands on OpenGL, like this:

http://www.freebasic.net/forum/viewtopic.php?t=10607
MusicianKool
Posts: 57
Joined: May 13, 2010 22:30

Postby MusicianKool » Aug 08, 2010 11:35

thank you.

one more question. I use 'make' on the source and it ends up being 40kb larger, is this a more resent version or because I should use 'make' with an [option]?

sorry I'm new to programing in Linux. I want to make more things available in the minib3d lib so that there is higher / greater control over vertexes, triangles and meshes. (want to make a Verlet system integrated to meshes, was trying to do this for blitz3d but not enough control over collision systems, but if i can code it into minib3d then i can use stuff that is already there making it 110% easier and collision capable)
angros47
Posts: 1535
Joined: Jun 21, 2005 19:04

Postby angros47 » Aug 08, 2010 16:25

For every version, I compiled the source code, and made a file with compiled library and source, so they are the same version.

I used a plain make command. Anyway, since the compiler links it with its own runtime, a different version of the compiler might produce a different binary file (that would explain the different file size)

Often, in linux, only the source code of a program is distributed, and it's compiled during the install process, to fit better (so, if your processor doesn't support some instructions, the program won't use them).

I haven't tested, but MiniB3D should work even on ARM processors (since it's derived from iMiniB3D, for iPhone, and doesn't use any x86 specific feature). Of course, if you compile on an ARM processor, the binary will be completely different from the one included.

So, don't worry: maybe you are not using the same linux distro I am using, so, a library for it has to be slightly different from a library for my system; but it will work exactly like my build.
angros47
Posts: 1535
Joined: Jun 21, 2005 19:04

Postby angros47 » Aug 13, 2010 16:39

Ok, here is a solution to use 2d commands (DRAW STRING, LINE, CIRCLE...) in MiniB3d, too:



Code: Select all

#include once "fbgfx.bi"
#include once "GL/gl.bi"

#ifdef Render_OpenGL


namespace ogl

dim shared as integer CORS(255)
dim shared as any ptr BUFFER
dim shared as integer TEXTURE,SCRX,SCRY,BPP
dim shared as double OFX,OFY,UPTIME
dim shared as integer FRAMESKIP=0


sub CallScreen( WID as integer,HEI as integer, BPP as integer,PAGS as integer,FLAGS as integer )
  Screenres WID,HEI,BPP,PAGS,FLAGS
  WindowTitle("OpenGL Render")
end sub

' ***** Make a integer multiple of a power of 2 ****
#macro ogl_MulBits( MultipleBits, MyIntVar )
asm
  mov eax,[MyIntVar]
  dec eax
  shr eax,(MultipleBits)
  inc eax
  shl eax,(MultipleBits)
  mov [MyIntVar],eax
end asm
#endmacro
' ***** Raise a integer to a power of 2 *****
#macro ogl_Power2( MyIntNumber )
asm
  mov eax,[MyIntNumber] 
  dec eax
  bsr ecx,eax
  inc ecx
  mov eax,0xFFFF0000 
  rol eax,cl
  and eax,0xFFFF
  inc eax
  mov [MyIntNumber],eax
end asm
#endmacro

end namespace

#undef cls
sub cls
   dim i as integer=ogl.SCRX*ogl.SCRY*ogl.BPP/8
   dim p as byte ptr=screenptr
   do
      i-=1
      *p=0
      p+=1
   loop until i=0
   
end sub



#undef screenres
sub screenres( WID as integer=-1, HEI as integer=-1, BPP as integer=32, PAGS as integer=1, FLAGS as integer=0 )
 
  dim as integer TEXX,TEYY
  dim as any ptr TMP
  dim as integer SCX,SCY
  ScreenControl(fb.GET_DESKTOP_SIZE,SCX,SCY) 
  if WID=-1 then WID=SCX
  if HEI=-1 then HEI=SCY 
  if WID>=SCX or HEI>=SCY then FLAGS or= fb.gfx_fullscreen
 
  ogl_Power2(BPP)
  if BPP <> 8 and BPP <> 32 and BPP <> 32 then BPP = 32 
  if BPP = 8 then exit sub
  ogl_Mulbits( 3, WID)
  ogl_Mulbits( 3, HEI)
  ogl.SCRX = WID:ogl.SCRY = HEI
  TEXX = WID:TEYY = HEI 
  ogl_Power2(TEXX) 
  ogl_Power2(TEYY)
  ogl.OFX=WID/TEXX
  ogl.OFY=HEI/TEYY 
  ogl.BPP=BPP
  ogl.callscreen WID,HEI,BPP,PAGS,fb.GFX_OPENGL or FLAGS 
  glViewport(0,0,WID,HEI)
  glMatrixMode(GL_PROJECTION)  'Select The Projection Matrix
  glLoadIdentity()             'Reset The Projection Matrix
  glMatrixMode(GL_MODELVIEW)   'Select The Modelview Matrix
  glLoadIdentity()             'Reset The Projection Matrix
  glEnable(GL_TEXTURE_2D)      'Texture Mapping
  glGenTextures 1, @ogl.TEXTURE
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)
  glClearColor(0f, 0f, 0f, 1.0f)
  glClear(GL_COLOR_BUFFER_BIT) 
  glLoadIdentity()
  glBindTexture GL_TEXTURE_2D, ogl.TEXTURE
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR) 
  if BPP = 8 then BPP=32
  TMP = ImageCreate(TEXX,TEYY,0,BPP)   
  if BPP = 32 then
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TEXX,TEYY,0,GL_BGRA,GL_UNSIGNED_BYTE,TMP+sizeof(fb.image))
  else
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,TEXX,TEYY,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,TMP+sizeof(fb.image))   
  end if
 
  if ogl.bpp = 8 then
    ogl.BUFFER = TMP
  else
    ImageDestroy(TMP)
  end if
  cls 
end sub

#undef screensync

sub screenSync() 
  dim BT as double,TMP as any ptr, BUFSZ as integer   
  static as integer FS
  BT=timer
  glBindTexture GL_TEXTURE_2D, ogl.TEXTURE 
  FS += 1
  if FS > OGL.FRAMESKIP then FS=0 
  if FS=0 then
  if ogl.BPP = 32 then   
    glTexSubImage2D(GL_TEXTURE_2D,0,0,0,ogl.SCRX,ogl.SCRY,GL_BGRA,GL_UNSIGNED_BYTE,screenptr) 

  elseif ogl.BPP = 16 then
    glTexSubImage2D(GL_TEXTURE_2D,0,0,0,ogl.SCRX,ogl.SCRY,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,screenptr)
  else
    for BUFSZ = 0 to 255
      'ogl.CORS(BUFSZ) = rgba(64,0,BUFSZ,0)
      Palette Get BUFSZ,ogl.CORS(BUFSZ)
    next BUFSZ
    TMP = screenptr
    BUFSZ = ogl.SCRX*ogl.SCRY
    asm
      mov esi,[TMP]   
      mov edi,[ogl.BUFFER]
      add edi,sizeof(fb.image)
      mov edx,offset ogl.CORS     
      mov ecx,[BUFSZ]
      xor eax,eax
      _8TO32_NEXTPIXEL_:
      lodsb
      mov ebx,[EDX+EAX*4]
      mov [edi],ebx
      add edi,4
      dec ecx
      jnz _8TO32_NEXTPIXEL_
    end asm
    glTexSubImage2D(GL_TEXTURE_2D,0,0,0,ogl.SCRX,ogl.SCRY,GL_BGRA,GL_UNSIGNED_BYTE,ogl.BUFFER+sizeof(fb.image))
  end if
  end if

  glDisable(GL_LIGHTING)
  glDisable(GL_CULL_FACE)
  glDisable(GL_NORMALIZE)
  glMatrixMode (GL_PROJECTION)
  glPushMatrix ()
  glLoadIdentity ()
  glOrtho (-1, 1, -1, 1, -1, 1)
  glEnable(GL_TEXTURE_2D)
  glEnable(GL_BLEND)
  glEnable(GL_ALPHA_TEST)
  glDisable(GL_DEPTH_TEST)
  glMatrixMode (GL_MODELVIEW)
  glLoadIdentity ()

  glBegin(GL_QUADS)     
  glTexCoord2f(ogl.OFX, ogl.OFY):glVertex3f(1,-1,0) 
  glTexCoord2f(0, ogl.OFY):glVertex3f(-1,-1,0) 
  glTexCoord2f(0,0):glVertex3f(-1,1,0) 
  glTexCoord2f(ogl.OFX, 0):glVertex3f(1,1,0) 
  glEnd()
  ogl.UPTIME=timer-BT
  flip

  glEnable(GL_LIGHTING)
  glEnable(GL_CULL_FACE)
  glEnable(GL_NORMALIZE)
  glDisable(GL_TEXTURE_2D)
  glDisable(GL_BLEND)
  glEnable(GL_DEPTH_TEST)


end sub

#else
namespace ogl
dim shared as double UPTIME
dim shared as integer FRAMESKIP=0
end namespace
#endif


you can save it as "opengl.bas", and include it in your program with:

Code: Select all

#define Render_OpenGL
#include "OpenGL.bas"


It's based on a work by MySoft: http://www.freebasic.net/forum/viewtopic.php?t=11214

It redefines SCREENRES and CLS.

To use it with MiniB3D, you can simply set screen mode as usally:

Code: Select all

screenres 640,480,32

graphics3d 640,480


(you can't use SCREEN, and you don't need to specify the opengl option)

Also, instead of using FLIP to display the rendered image (in MiniB3D, you usually need to use FLIP after any RenderWorld), you have to use ScreenSync

So, code like:

Code: Select all

RenderWorld
Flip


Should become

Code: Select all

RenderWorld
ScreenSync


You will see both 2d and 3d image at the same time.

Note: you can use Flip, too (it should be a bit faster than ScreenSync), but you won't see 2d image: when you use ScreenSync, 2d image will come back; it could be useful to provide an overlay on your 3d image (i.e., in a 3d game, you can show instruments in 2d mode, so you can hide them with ease)

Operations on 2d screen (like scrolling) won't affect 3d worlds, and vice-versa. Commands like GET and PUT cannot work on 3d image (you cannot get a 3d image and save it as a BMP, for example)

Maybe, I'll add this include file to the next release of MiniB3D. Anyway, it won't be included in MiniB3D DLL, since it's specific for FreeBasic.
angros47
Posts: 1535
Joined: Jun 21, 2005 19:04

Postby angros47 » Oct 16, 2010 18:08

Since file-pasta has problems, I moved the program to sourceforge.

Also, version 0.25 is out: many bug fixed, please replace your old files with this. You should notice also an improved terrain rendering.
joseywales72
Posts: 206
Joined: Aug 27, 2005 2:02
Location: Istanbul, Turkey

Postby joseywales72 » Oct 19, 2010 14:14

Hi angros47,

First of all, thanks for your hard work. minib3d is really great, but I have some questions.

Previous versions had some examples and media files(Flight sim, birds etc.) Your last version (0.25) does not have them. It would be great to have some very basic working examples. Also, I tried to compile old examples but when I run them a segmentation fault occurs. (I use ArchLinux, 2.6.35,32bit at work) Could it be that 0.25 breaks compatibility with the previous ones?

By the way, is there any place you can point me to find some tutorials on minib3d? The original site seems a little bit awkward (It gives a Php error), I searched the Blitzbasic forums for some tutorials but many of them are dead links.

Thank you again and sorry for my possible mistakes. I'm not a native speaker.

Anil
angros47
Posts: 1535
Joined: Jun 21, 2005 19:04

Postby angros47 » Oct 19, 2010 16:56

joseywales72 wrote:Hi angros47,

First of all, thanks for your hard work. minib3d is really great, but I have some questions.

Previous versions had some examples and media files(Flight sim, birds etc.) Your last version (0.25) does not have them. It would be great to have some very basic working examples. Also, I tried to compile old examples but when I run them a segmentation fault occurs. (I use ArchLinux, 2.6.35,32bit at work) Could it be that 0.25 breaks compatibility with the previous ones?


I've tested old samples, they still works. I've just tested again the flight simulator, it works.
On your system, did they work with previous version?

Sometime, errors occur when you compile a demo for windows, since windows is not case-sensitive for file names.

Can you at least draw a cube?

Code: Select all

#include "minib3d.bi"

screen 18, 32, , &h02   

Graphics3d 640,480,32,1,1


var cube=createcube()
moveentity cube,0,0,5
var cam=createcamera()
renderworld
flip
sleep





By the way, is there any place you can point me to find some tutorials on minib3d? The original site seems a little bit awkward (It gives a Php error), I searched the Blitzbasic forums for some tutorials but many of them are dead links.

Thank you again and sorry for my possible mistakes. I'm not a native speaker.

Anil


My version of minib3d is different from the one available on Blitzbasic site, since it is based on iminib3d (written in c++), but it includes also some improvements that warner made for minib3d.

So, there are no tutorial yet... I guess I'd have to write one.
Anyway, many Blitz3D tutorials applies to MiniB3d, too. The main difference is: in entity rotations, the pitch works in opposite way (but that is a trivial difference, I believe: I haven't fixed it because I didn't want to add more + and - in the source)
joseywales72
Posts: 206
Joined: Aug 27, 2005 2:02
Location: Istanbul, Turkey

Postby joseywales72 » Oct 20, 2010 11:41

Thank you angros47, but my problem persists. The cube example compiles and runs, but no window opens and when I press a key, it returns to command line. (I run the program with ./cube)

I'm not sure what is the problem, I'll try minib3d at home with Windows and Ubuntu 10.04 and see what happens.

Thank you again and I'll let you know.
Anil
angros47
Posts: 1535
Joined: Jun 21, 2005 19:04

Postby angros47 » Nov 05, 2010 9:54

joseywales72
Posts: 206
Joined: Aug 27, 2005 2:02
Location: Istanbul, Turkey

Postby joseywales72 » Nov 06, 2010 0:00

Hi angros47,

Thank you for the demos, and the problem (seg fault etc.) does not appear on Windows, I guess it is something to do with my Linux X driver.

Anil
angros47
Posts: 1535
Joined: Jun 21, 2005 19:04

Postby angros47 » Nov 06, 2010 0:13

It might be also a problem of libraries:

1) Check if you can run a graphic program written in freebasic (i.e., a simple program using LINE, PSET and so on); if it doesn't work, maybe you haven't installed all the building libraries

2) Check if OpenGL demos work: since you said that no window opens, maybe you don't have the opengl libraries (minib3d uses them).

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest