Author Topic: GLBasic  (Read 4236 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
GLBasic
« on: January 24, 2013, 03:27:25 PM »


I noticed a post about GLBasic and thought I would give one of the demos a try. (Windows program under Wine) I have to say that even running under Wine it was impressive. If I was a gamer, I would take a second look.

Code: [Select]
// --------------------------------- //
// Project:Cubies
// Start: Thursday, September 02, 2004
// IDE Version: 2.40930

LIMITFPS 80

MAXCUBIE=8
DIM cubie_pos [MAXCUBIE+1][3]
DIM cubie_mov [MAXCUBIE+1][3]
DIM cubie_dirx[MAXCUBIE+1]
DIM cubie_ani [MAXCUBIE+1]
DIM cubie_life[MAXCUBIE+1]
DIM cols[4]
cols[0]=RGB(0x00, 0xff, 0x80)
cols[1]=RGB(0xff, 0xff, 0x40)
cols[2]=RGB(0xff, 0xff, 0xff)
cols[3]=RGB(0x00, 0x00, 0x80)

FOR all=0 TO MAXCUBIE
CreateCube(all, 1, cols[MOD(all, 4)])
dx=RND(12); dy=RND(25)+10
x=dx+INTEGER(dy/2)
y=dy
z=dy-dx-INTEGER(dy/2)
cubie_pos[all][0]=x
cubie_pos[all][1]=y
cubie_pos[all][2]=z
cubie_dirx[all]  =0
cubie_ani[all]   =RND(100)/100
cubie_life[all]  =RND(200)-40
NEXT

CreateStairs(MAXCUBIE+1, 1)
  camx = 6; camy = 19; camz = 0
WHILE TRUE
dpos = GETTIMER()/1200
ani=ani+dpos
camy=camy-dpos
camx=camx-dpos/2
camz=camz-dpos/2
IF ani>2
ani=ani-2
FOR num=0 TO MAXCUBIE
cubie_pos[num][0]=cubie_pos[num][0]+1
cubie_pos[num][1]=cubie_pos[num][1]+2
cubie_pos[num][2]=cubie_pos[num][2]+1
cubie_mov[num][0]=cubie_mov[num][0]+1
cubie_mov[num][1]=cubie_mov[num][1]+2
cubie_mov[num][2]=cubie_mov[num][2]+1
NEXT
camx=camx+1
camy=camy+2
camz=camz+1
ENDIF
FOR all=0 TO MAXCUBIE
cubie_ani[all]=cubie_ani[all]+dpos
cubie_life[all]=cubie_life[all]+dpos*10
IF cubie_ani[all]>1 AND cubie_life[all]>=0
cubie_ani[all]=cubie_ani[all]-1
cubie_pos[all][0]=cubie_pos[all][0]-1
cubie_pos[all][1]=cubie_pos[all][1]-1
cubie_pos[all][2]=cubie_pos[all][2]-1
IF cubie_dirx[all]
cubie_pos[all][0]=cubie_pos[all][0]+1
ELSE
cubie_pos[all][2]=cubie_pos[all][2]+1
ENDIF
cubie_dirx[all] = 1 - cubie_dirx[all]
ENDIF
IF cubie_life[all]>400 THEN cubie_life[all]=-50 // Poof
NEXT

phi=phi + GETTIMER()/27/5
psi=psi + GETTIMER()/13/5
RenderScene(-ABS(30*SIN(phi)), 7+7*(SIN(phi)+COS(psi)), -ABS(30*COS(psi)))
SHOWSCREEN
WEND


FUNCTION RenderScene: x, y, z
X_MAKE3D 1, 500, 35
X_CAMERA camx+x, camy+y, camz+z, camx, camy, camz
X_SPOT_LT 0, RGB(255,255,255), camx,camy,camz-5, 1,-1, 1, 45

FOR num=0 TO MAXCUBIE
DrawCubie(num, cubie_pos[num][0], cubie_pos[num][1], cubie_pos[num][2], cubie_ani[num], cubie_dirx[num])
NEXT

X_SCALING 1,1,1
X_MOVEMENT 0,-1,0
X_DRAWOBJ MAXCUBIE+1, 0

ENDFUNCTION

FUNCTION CreateStairs: num, sz
LOCAL x, y, z, dx, dy, col
sz=sz/2
X_AUTONORMALS 1
X_OBJSTART num
FOR dx=0 TO 12
FOR dy=4 TO 35
col=RGB(0, 0, 255)
IF MOD(dx*dy, 2)=0 THEN col=RainbowColour(dx/12)

// +->X
// |\
// V Y
// Z
//
//111111
//222222
//333333
//x = dx
//y = dy
//z = dy
//
//   12345
//  12345
// 12345
//12345
// x=dx
// y=dy
// z=dy-dx
//
//   1
//  123
// 12345
//123456
// 3456
//  56 -x+z
//
x=dx+INTEGER(dy/2)
y=dy
z=dy-dx-INTEGER(dy/2)

x=x*sz*2
y=y*sz*2
z=z*sz*2
// Back Face
X_OBJADDVERTEX -sz+x,  sz+y, -sz+z, 1, 1, col
X_OBJADDVERTEX -sz+x, -sz+y, -sz+z, 1, 0, col
X_OBJADDVERTEX  sz+x,  sz+y, -sz+z, 0, 1, col
X_OBJADDVERTEX  sz+x, -sz+y, -sz+z, 0, 0, col
X_OBJNEWGROUP
// Top Face
X_OBJADDVERTEX -sz+x,  sz+y,  sz+z, 0, 0, col
X_OBJADDVERTEX -sz+x,  sz+y, -sz+z, 0, 1, col
X_OBJADDVERTEX  sz+x,  sz+y,  sz+z, 1, 0, col
X_OBJADDVERTEX  sz+x,  sz+y, -sz+z, 1, 1, col
X_OBJNEWGROUP
// Left Face
X_OBJADDVERTEX -sz+x, -sz+y,  sz+z, 1, 0, col
X_OBJADDVERTEX -sz+x, -sz+y, -sz+z, 0, 0, col
X_OBJADDVERTEX -sz+x,  sz+y,  sz+z, 1, 1, col
X_OBJADDVERTEX -sz+x,  sz+y, -sz+z, 0, 1, col
X_OBJNEWGROUP
NEXT
NEXT
X_OBJEND
ENDFUNCTION


// ------------------------------------------------------------- //
// -=#  CREATECUBE  #=-
// ------------------------------------------------------------- //
FUNCTION CreateCube: num, sz, col
// Diese Variablen sind als LOCAL definiert:
// num, sz,
sz=sz/2
X_AUTONORMALS 1
X_OBJSTART num
// Front Face
X_OBJADDVERTEX  sz, -sz,  sz, 1, 0, col
X_OBJADDVERTEX -sz, -sz,  sz, 0, 0, col
X_OBJADDVERTEX  sz,  sz,  sz, 1, 1, col
X_OBJADDVERTEX -sz,  sz,  sz, 0, 1, col
X_OBJNEWGROUP
// Back Face
X_OBJADDVERTEX -sz,  sz, -sz, 1, 1, col
X_OBJADDVERTEX -sz, -sz, -sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz, -sz, 0, 1, col
X_OBJADDVERTEX  sz, -sz, -sz, 0, 0, col
X_OBJNEWGROUP
// Top Face
X_OBJADDVERTEX -sz,  sz,  sz, 0, 0, col
X_OBJADDVERTEX -sz,  sz, -sz, 0, 1, col
X_OBJADDVERTEX  sz,  sz,  sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz, -sz, 1, 1, col
X_OBJNEWGROUP
// Bottom Face
X_OBJADDVERTEX  sz, -sz, -sz, 0, 1, col
X_OBJADDVERTEX -sz, -sz, -sz, 1, 1, col
X_OBJADDVERTEX  sz, -sz,  sz, 0, 0, col
X_OBJADDVERTEX -sz, -sz,  sz, 1, 0, col
X_OBJNEWGROUP
// Right face
X_OBJADDVERTEX  sz,  sz, -sz, 1, 1, col
X_OBJADDVERTEX  sz, -sz, -sz, 1, 0, col
X_OBJADDVERTEX  sz,  sz,  sz, 0, 1, col
X_OBJADDVERTEX  sz, -sz,  sz, 0, 0, col
X_OBJNEWGROUP
// Left Face
X_OBJADDVERTEX -sz, -sz,  sz, 1, 0, col
X_OBJADDVERTEX -sz, -sz, -sz, 0, 0, col
X_OBJADDVERTEX -sz,  sz,  sz, 1, 1, col
X_OBJADDVERTEX -sz,  sz, -sz, 0, 1, col
X_OBJNEWGROUP
X_OBJEND
ENDFUNCTION // sz



// ------------------------------------------------------------- //
// -=#  DRAWCUBIE  #=-
// ------------------------------------------------------------- //
FUNCTION DrawCubie: num, x, y, z, pos, dirx
// Diese Variablen sind als LOCAL definiert:
// num, x, y, z, dirx
IF cubie_life[num]<0
cubie_ani[num]=.8
pos = 0.75
y = y-cubie_life[num]/3
ENDIF
IF pos<0.5
X_SCALING 1,1,1
IF dirx
cubie_mov[num][0] = x
cubie_mov[num][1] = y
cubie_mov[num][2] = z-2*pos
X_MOVEMENT cubie_mov[num][0], cubie_mov[num][1], cubie_mov[num][2]
X_ROTATION -90*pos*2, 1,0,0
ELSE
cubie_mov[num][0] = x-2*pos
cubie_mov[num][1] = y
cubie_mov[num][2] = z
X_MOVEMENT cubie_mov[num][0], cubie_mov[num][1], cubie_mov[num][2]
X_ROTATION 90*pos*2, 0,0,1
ENDIF
ELSE
IF dirx
cubie_mov[num][0] = x
cubie_mov[num][1] = y+COS((pos-.5)*180)*1-1
cubie_mov[num][2] = z-1
ELSE
cubie_mov[num][0] = x-1
cubie_mov[num][1] = y+COS((pos-.5)*180)*1-1
cubie_mov[num][2] = z
ENDIF
X_MOVEMENT cubie_mov[num][0], cubie_mov[num][1], cubie_mov[num][2]
X_SCALING 1, 1+SIN((pos-.5)*360)*.3, 1
ENDIF
X_DRAWOBJ num,0
ENDFUNCTION // DRAWCUBIE


FUNCTION RainbowColour: pos
npos=pos
WHILE npos>0.2
npos=npos-0.2
WEND
npos=npos*5.0
SELECT pos
CASE 0 TO 0.2
r=1; g=0; b=1-npos
CASE 0.2 TO 0.4
r=1; g=npos; b=0
CASE 0.4 TO 0.6
r=1-npos; g=1; b=0
CASE 0.6 TO 0.8
r=0; g=1-npos; b=npos
CASE 0.8 TO 1.0
r=npos; g=0; b=1
ENDSELECT
RETURN RGB(147+108*r, 147+108*g, 147+108*b)
ENDFUNCTION


X

Charles Pegge

  • Guest
Re: GLBasic
« Reply #1 on: January 24, 2013, 09:30:57 PM »

Very impressive demo. I like the float case ranges too, a feature we dont have yet. At 350K there is quite a hunky run-time embedded. I am curious to know what is in there :)

Charles

Peter

  • Guest
Re: GLBasic
« Reply #2 on: January 25, 2013, 01:49:38 AM »
If you have a deeper look in the showcase, you will find a lot of games by me.
I am member there. But I have abandoned this forum, very unfriendly there.

GlBasic isn't free, another point to avoid it.
Glbasic has strange syntax, not  really Basic, C is possible, but circumstantially.

OxygenBasic has more speed  and is easier to use.

By the way: my name is PeterPan there.

Charles Pegge

  • Guest
Re: GLBasic
« Reply #3 on: January 25, 2013, 03:21:16 AM »
Thanks for the insider information Peter. Always something to be gained by looking at different implementations of Basic.

I have now added support for float cases, (previously all the terms were evaluated as integers). I hope this does not cause any subtle errors.

float f=.21

select case f
case .1 to .2
  print "ok1"
case .2 to .3
  print "ok2"
end select


Also, this version fix a problem which showed up under stress. (Creating new Oxygen compilers, then running large programs with them)

All versions will now carry a date stamp:

print version 'result A40 11:16 25/01/2013


Charles

PS Oxygen update down the thread:
« Last Edit: January 25, 2013, 02:38:38 PM by Charles Pegge »

Peter

  • Guest
Re: GLBasic
« Reply #4 on: January 25, 2013, 04:31:54 AM »
Hi Charles,

I got an error with building a dll.

Line number  494 has:  End Function
Older Oxygen DLL  goes  unproblematic.

This is the SAVEBYTE function and this work in each library what I have done.

X

Charles Pegge

  • Guest
Re: GLBasic
« Reply #5 on: January 25, 2013, 05:02:41 AM »
Can you show me that function, Peter?

Peter

  • Guest
Re: GLBasic
« Reply #6 on: January 25, 2013, 05:27:03 AM »
Yes,
Code: [Select]
Function SaveByte(string File,byref dest as any,sys count) as sys Export   
    sys handle,wc
    handle=CreateFile File,GENERIC_WRITE,FILE_SHARE_WRITE,BYVAL 0,OPEN_ALWAYS,0,0
    WriteFile handle,dest,count,&wc, Byval 0
    CloseHandle handle
    Return wc
End Function

Charles Pegge

  • Guest
Re: GLBasic
« Reply #7 on: January 25, 2013, 05:57:57 AM »
Thanks. My A (10 Jan) does not have createfile. Can you send me your most recent?


PS: Tested with MinWin (with a few extra equates). It works ok here

X
« Last Edit: January 25, 2013, 06:20:20 AM by Charles Pegge »

Peter

  • Guest
Re: GLBasic
« Reply #8 on: January 25, 2013, 07:17:46 AM »
Hi Charles,

What do you mean with (A 10 jan) ?
Do you mean A.dll 10 january ?

The last dll has a bug, if I create a dll.
I use the dll  25.12.2o12 and there is no problem!

The SaveByte function works okay, there is nothing wrong on it.
Code: [Select]
include "minwin.inc"

Function SaveByte(string File,byref dest as any,sys count) as sys Export   
    sys handle,wc
    handle=CreateFile File,GENERIC_WRITE,FILE_SHARE_WRITE,BYVAL 0,OPEN_ALWAYS,0,0
    WriteFile handle,dest,count,&wc, Byval 0
    CloseHandle handle
    Return wc
End Function


string n="s.txt"
string a="one-two-three"
savebyte n,a,len a

print "okay"

savebyte "alien.txt","banana",len("banana")

print "banana"

X

Charles Pegge

  • Guest
Re: GLBasic
« Reply #9 on: January 25, 2013, 10:25:58 AM »
I have no DLL problems here.

From the error message, WriteFile appeared to be the problem. It was not recognised as a procedure. How did you bind it?

PS

I can reproduce the error by using this binding technique of yours:

Sub CallDll(sys DllAdr, string libName)
    GetProcAddress DllAdr, libName
    Return eax
End Sub

sys WriteFile=CallDll(ud,"WriteFile")


In this case you have to explicitly call Writefile...

« Last Edit: January 25, 2013, 11:17:39 AM by Charles Pegge »

Peter

  • Guest
Re: GLBasic
« Reply #10 on: January 25, 2013, 01:39:39 PM »
Hi Charles,

There is no low-level binding, I do declare this Api.

Code: [Select]
! WriteFile Lib "kernel32.dll" (sys hFile, ByRef lpBuffer As Any,sys nNumberOfBytesToWrite,lpNumberOfBytesWritten,ByRef lpOverlapped As OVERLAPPED) as sys
This theme is now over, I will work with that older December DLL.

Charles Pegge

  • Guest
Re: GLBasic
« Reply #11 on: January 25, 2013, 02:03:36 PM »
Hi Peter,

I have found a vulnerability to redefinitions of a declaration. I think it is very likely to be the cause of the problem you saw. so I will get this fixed ASAP. I am glad this problem showed up early. Thank you Peter :)

Charles Pegge

  • Guest
Re: GLBasic
« Reply #12 on: January 25, 2013, 02:36:42 PM »
Fixed!

X

Peter

  • Guest
Re: GLBasic
« Reply #13 on: January 25, 2013, 02:59:26 PM »
Well done, Charles.

No error here!   A.dll completed.

X