LB Booster
Programming >> BASIC code examples >> Using OpenGL in LBB
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1429012205

Using OpenGL in LBB
Post by Richard Russell on Apr 14th, 2015, 11:50am

Over at the LB Community Forum there's been some renewed interest in Rob's OpenGL demos here:

OpenGL 3D Graphics in Liberty BASIC

Please note that there's a bug in the 'OpenGL in LB.bas' framework which can cause it to crash in LBB. Specifically, in the SUB CreateBMPTexture the following line needs to be changed (in the gluBuild2DMipmaps call):

Was: Code:
      arr AS long ,_ 

Needs to be: Code:
      array AS long ,_ 

This also makes the STRUCT arr unnecessary. Why the original code seemed to work in LB4.04 I have no idea.

Richard.
Re: Using OpenGL in LBB
Post by RobM on Apr 14th, 2015, 2:56pm

Actually, the whole sub can be changed as below. There are a few calls in the original code that aren't necessary. I think you pointed this out when we were porting my program over to LBB :)

Code:
SUB CreateBMPTexture filename$ , texture
    call glBindTexture GL.TEXTURE.2D , texture
    OPEN "DevIL.dll" FOR dll AS #dev
    CALLDLL #dev , "ilInit" , ret AS long
    'CALLDLL #dev , "ilGenImages" , 1 AS long , ret AS long
    CALLDLL #dev , "ilBindImage" , 1 AS long , ret AS long
    CALLDLL #dev , "ilLoadImage" , filename$ AS ptr , ret AS long
    CALLDLL #dev , "ilConvertImage" , 6408 AS long , 5121 AS long , ret AS long
    CALLDLL #dev , "ilGetData" , array AS long
    'STRUCT arr , bitmaparray AS long
    'arr.bitmaparray.struct = array
    CALLDLL #dev , "ilGetInteger" , 3560 AS long , IL.IMAGE.BPP AS long
    CALLDLL #dev , "ilGetInteger" , 3556 AS long , IL.IMAGE.WIDTH AS long
    CALLDLL #dev , "ilGetInteger" , 3557 AS long , IL.IMAGE.HEIGHT AS long
    CALLDLL #dev , "ilGetInteger" , 3562 AS long , IL.IMAGE.FORMAT AS long
    'CALLDLL #gl , "glTexImage2D" , 3553 AS long , 0 AS long , IL.IMAGE.BPP AS long , IL.IMAGE.WIDTH AS long , IL.IMAGE.HEIGHT AS long , IL.IMAGE.FORMAT AS long , 5121 AS long , array AS long , ret AS long
    CALLDLL #glu , "gluBuild2DMipmaps" , 3553 AS long , 4 AS long , IL.IMAGE.WIDTH AS long , IL.IMAGE.HEIGHT AS long , 6408 AS long , 5121 AS long , array AS long , ret AS long
    CALLDLL #dev , "ilDeleteImages" , 1 AS long , ret AS long
    CLOSE #dev
END SUB
 

Re: Using OpenGL in LBB
Post by Richard Russell on Apr 14th, 2015, 3:40pm

on Apr 14th, 2015, 2:56pm, RobM wrote:
There are a few calls in the original code that aren't necessary.

Indeed, but I wanted to list the minimum change necessary for it to run without crashing. Leaving the 'superfluous' calls doesn't seem to do any obvious harm.

More importantly, are you able to correct the version available for download from the link at LBPE?

Richard.
Re: Using OpenGL in LBB
Post by RobM on Apr 14th, 2015, 3:49pm

on Apr 14th, 2015, 3:40pm, Richard Russell wrote:
More importantly, are you able to correct the version available for download from the link at LBPE?

Richard.


Not sure. I see that the current file was uploaded by Rod. I will have to see if I can figure it out.
Re: Using OpenGL in LBB
Post by RobM on Apr 14th, 2015, 4:06pm

Done! Took a few tries but I got it.