Author |
Topic: OPEN GL (Read 1497 times) |
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: OPEN GL
« Reply #5 on: Jul 13th, 2015, 1:56pm » |
|
on Jul 13th, 2015, 1:16pm, bluatigro wrote: It's a good example of the speed benefit of LBB over LB.
When run on a 'widescreen' (16:9) display the aspect ratio isn't right (the minion is rather fat!) but my knowledge of OpenGL is not good enough to fix it.
Richard.
|
|
Logged
|
|
|
|
RobM
Junior Member
member is offline


Posts: 91
|
 |
Re: OPEN GL
« Reply #6 on: Jul 13th, 2015, 11:45pm » |
|
Under the "[tmr]" branch you can decrease the first value in the two "call glScale" lines. You should be able to use DisplayWidth & DisplayHeight to calculate the correct ratio, if you are so inclined.
Code:call glScale 0.<change me>,0.3,0.3
|
|
Logged
|
|
|
|
bluatigro
Full Member
member is offline


Gender: 
Posts: 111
|
 |
Re: OPEN GL
« Reply #7 on: Jul 14th, 2015, 07:40am » |
|
update : - right scale
error ? : - the animation is a litle shaky
change the Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
Code:
[tmr]
scan
call glClear GL.COLOR.BUFFER.BIT or GL.DEPTH.BUFFER.BIT
call glLoadIdentity
call glTranslate .6,.3,0
call glScale 0.3*winy/winx,0.3,0.3
call glRotate angle , 0,1,0
call walk.man angle * 3 , 30
call minion
call glLoadIdentity
call glTranslate -.6,0,0
call glScale 0.3*winy/winx,0.3,0.3
call glRotate angle , 0,1,0
call robot
calldll #gdi32,"SwapBuffers" _
, MainDC as ulong _
, ret as long
angle = angle + 5
wait
|
|
Logged
|
|
|
|
bluatigro
Full Member
member is offline


Gender: 
Posts: 111
|
 |
Re: OPEN GL
« Reply #8 on: Jul 17th, 2015, 09:27am » |
|
update : - scaled better
Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , winyx
winx = WindowWidth
winy = WindowHeight
winyx = winy / winx
Code:
[tmr]
scan
call glClear GL.COLOR.BUFFER.BIT or GL.DEPTH.BUFFER.BIT
call glLoadIdentity
call glScale winyx , 1 , 1
call glPushMatrix
call glTranslate .6,.3,0
call glScale 0.3,0.3,0.3
call glRotate angle , 0,1,0
call walk.man angle * 3 , 30
call minion
call glPopMatrix
call glPushMatrix
call glTranslate -.6,0,0
call glScale 0.3,0.3,0.3
call glRotate angle , 0,1,0
call robot
call glPopMatrix
calldll #gdi32,"SwapBuffers" _
, MainDC as ulong _
, ret as long
angle = angle + 5
wait
|
|
Logged
|
|
|
|
bluatigro
Full Member
member is offline


Gender: 
Posts: 111
|
 |
Re: OPEN GL
« Reply #9 on: Jul 21st, 2015, 08:55am » |
|
update : - minion whit glasses
Code:
sub minion
call setbox 0 , 1 , 0 , 1 , 1 , 1
call sphere 24 , 24 , yellow
call setbox 0 , .5 , 0 , 1 , .5 , 1
call cylinder 24 , 1 , 1 , yellow
call setbox 0 , -1 , 0 , 1 , 1 , 1
call sphere 24 , 24 , blue
call setbox 0 , -.5 , 0 , 1 , .5 , 1
call cylinder 24 , 1 , 1 , blue
call glPushMatrix
call glTranslate .4 , .7 , -.8
call glRotate 90 , 1 , 0 , 0
call setbox 0,0,0 , .4,.4,.4
call cylinder 12 , 1 , 1 , gray
call glPopMatrix
call glPushMatrix
call glTranslate -.4 , .7 , -.8
call glRotate 90 , 1 , 0 , 0
call setbox 0,0,0 , .4,.4,.4
call cylinder 12 , 1 , 1 , gray
call glPopMatrix
call glPushMatrix
call child .4 , .7 , -.8 , eye , xyz
call setbox 0,0,0 , .3,.3,.3
call sphere 12 , 12 , white
call setbox 0,0,-.3 , .1,.1,.1
call sphere 12 , 12 , black
call glPopMatrix
call glPushMatrix
call child -.4 , .7 , -.8 , eye+lr , xyz
call setbox 0,0,0 , .3,.3,.3
call sphere 12 , 12 , white
call setbox 0,0,-.3 , .1,.1,.1
call sphere 12 , 12 , black
call glPopMatrix
call glPushMatrix
call child 1 , -.3 , 0 , arm , xzy
call setbox 0,0,0 , .2,.2,.2
call sphere 12 , 12 , yellow
call setbox .2,-.5,0 , .1,.5,.1
call cylinder 12 , 1 , 1 , yellow
call glPushMatrix
call child .2 , -1 , 0 , elbow , xyz
call setbox 0,-.5,0 , .1,.5,.1
call cylinder 12 , 1 , 1 , yellow
call glPushMatrix
call child 0 , -1 , 0 , wrist , yzx
call setbox 0,-.3,0 , .15,.3,.15
call sphere 12 , 12 , yellow
call glPopMatrix
call glPopMatrix
call glPopMatrix
call glPushMatrix
call child -1 , -.3 , 0 , arm+lr , xzy
call setbox 0,0,0 , .2,.2,.2
call sphere 12 , 12 , yellow
call setbox -.2,-.5,0 , .1,.5,.1
call cylinder 12 , 1 , 1 , yellow
call glPushMatrix
call child -.2 , -1 , 0 , elbow+lr , xyz
call setbox 0,-.5,0 , .1,.5,.1
call cylinder 12 , 1 , 1 , yellow
call glPushMatrix
call child 0 , -1 , 0 , wrist+lr , yzx
call setbox 0,-.3,0 , .15,.3,.15
call sphere 12 , 12 , yellow
call glPopMatrix
call glPopMatrix
call glPopMatrix
call glPushMatrix
call child .5 , -1 , 0 , leg , yxz
call setbox 0,-.5,0 , .2,.5,.2
call cylinder 12 , 1 , 1 , blue
call glPushMatrix
call child 0 , -1 , 0 , knee , xyz
call cylinder 12 , 1 , 1 , blue
call glPushMatrix
call child 0 , -1 , 0 , enkle , zxy
call setbox 0,0,-.3 , .2,.2,.4
call cube gray,gray,gray,gray,gray,gray
call glPopMatrix
call glPopMatrix
call glPopMatrix
call glPushMatrix
call child -.5 , -1 , 0 , leg+lr , yxz
call setbox 0,-.5,0 , .2,.5,.2
call cylinder 12 , 1 , 1 , blue
call glPushMatrix
call child 0 , -1 , 0 , knee+lr , xyz
call cylinder 12 , 1 , 1 , blue
call glPushMatrix
call child 0 , -1 , 0 , enkle+lr , zxy
call setbox 0,0,-.3 , .2,.2,.4
call cube gray,gray,gray,gray,gray,gray
call glPopMatrix
call glPopMatrix
call glPopMatrix
end sub
|
| « Last Edit: Jul 21st, 2015, 08:55am by bluatigro » |
Logged
|
|
|
|
RNBW
Full Member
member is offline


Gender: 
Posts: 106
|
 |
Re: OPEN GL
« Reply #12 on: Jul 23rd, 2015, 09:29am » |
|
This shows the difference in speed between LBB and LB!
The figures crawl and stutter in LB, whereas in LBB they move quickly and smoothly.
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline


Gender: 
Posts: 106
|
 |
Re: OPEN GL
« Reply #14 on: Jul 25th, 2015, 2:08pm » |
|
I've not looked at the updated code, but it has improved the speed on LB and no longer stutters, although it is not showing as much on the screen (it's now just a sort of doughnut).
However, loading the code into LBB shows that it is still much quicker and smoother than LB. All credit to Richard Russell and BB4W.
|
|
Logged
|
|
|
|
bluatigro
Full Member
member is offline


Gender: 
Posts: 111
|
 |
OPEN GL : rainbow torus
« Reply #15 on: Jul 26th, 2015, 1:32pm » |
|
update : - torus can have rainbow colors
code at : http://libertybasic.nl/viewtopic.php?f=4&t=637&p=2518#p2518
warning : if you make the sides of the totus to great or to smal the code stops whitout showing something
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: OPEN GL
« Reply #17 on: Jul 27th, 2015, 2:00pm » |
|
I'm puzzled that your programs run so slowly. Here's a similar thing done using Direct3D rather than OpenGL (their performance is usually similar) which runs at full frame rate! The cursor keys move the camera.
Richard.
Code:' Direct3D Demonstration
' (C) R.T.Russell 2015, http://lbbooster.com/
nomainwin
WindowWidth=DisplayWidth
WindowHeight=DisplayHeight
open "D3D8.DLL" for DLL as #d3d8
open "OLEAUT32.DLL" for DLL as #oleaut32
if instr(Platform$, "LBB") then
open "Direct3D Demonstration" for window as #w
else
open "Direct3D Demonstration" for graphics_nsb as #w
end if
#w "when characterInput [key]"
#w "trapclose [quit]"
hw=hwnd(#w)
calldll #d3d8, "Direct3DCreate8", 120 as long, IDirect3D8 as long
struct D3DDISPLAYMODE,_
Width as long, Height as long,_
RefreshRate as long, Format as long
struct parm, Adapter1 as long, pMode as struct
parm.pMode.struct=D3DDISPLAYMODE.struct
r=CallMethod(IDirect3D8, 8, parm.struct) ' ::GetAdapterDisplayMode
D3DDISPLAYMODE.struct=parm.pMode.struct
struct D3DPARMS,_
BackBufferWidth as long, BackBufferHeight as long,_
BackBufferFormat as long, BackBufferCount as long,_
MultiSampleType as long, SwapEffect as long,_
DeviceWindow as long, Windowed as long,_
EnableAutoDepthStencil as long,_
AutoDepthStencilFormat as long,_
Flags as long, FullScreenRefreshRateInHz as long,_
FullScreenPresentationInterval as long
D3DPARMS.BackBufferFormat.struct=D3DDISPLAYMODE.Format.struct
D3DPARMS.SwapEffect.struct=1
D3DPARMS.Windowed.struct=1
D3DPARMS.EnableAutoDepthStencil.struct=1
D3DPARMS.AutoDepthStencilFormat.struct=80
struct parm,_
Adapter as long, DeviceType as long, FocusWindow as ulong,_
BehaviorFlags as long, PresentationParameters as struct,_
ReturnedDeviceInterface as struct
struct temp, v as long
parm.DeviceType.struct=1
parm.FocusWindow.struct=hw
parm.BehaviorFlags.struct=32
parm.PresentationParameters.struct=D3DPARMS.struct
parm.ReturnedDeviceInterface.struct=temp.struct
r=CallMethod(IDirect3D8, 15, parm.struct) ' ::CreateDevice
temp.struct=parm.ReturnedDeviceInterface.struct
IDirect3DDevice8=temp.v.struct
' IDirect3DDevice8::SetRenderState
struct parm, State as long, Value as long
parm.State.struct=22 ' D3DRS_CULLMODE
parm.Value.struct=2
r=CallMethod(IDirect3DDevice8, 50, parm.struct)
parm.State.struct=137 ' D3DRS_LIGHTING
parm.Value.struct=0
r=CallMethod(IDirect3DDevice8, 50, parm.struct)
parm.State.struct=7 ' D3DRS_ZENABLE
parm.Value.struct=1
r=CallMethod(IDirect3DDevice8, 50, parm.struct)
triangles=12
vertices=3*triangles
vertexshader=hexdec("52")
vertexsize=28
struct temp, v as long
struct parm,_
Length as long, Usage as long, FVF as long,_
Pool as long, VertexBuffer as struct
parm.Length.struct=vertices*vertexsize
parm.FVF.struct=vertexshader
parm.VertexBuffer.struct=temp.struct
r=CallMethod(IDirect3DDevice8, 23, parm.struct) ' ::CreateVertexBuffer
temp.struct=parm.VertexBuffer.struct
IDirect3DVertexBuffer8=temp.v.struct
struct temp, v as long
struct parm,_
OffsetToLock as long, SizeToLock as long,_
ppbData as struct, Flags as long
parm.SizeToLock.struct=vertices*vertexsize
parm.ppbData.struct=temp.struct
r=CallMethod(IDirect3DVertexBuffer8, 11, parm.struct) ' ::Lock
temp.struct=parm.ppbData.struct
VertexData=temp.v.struct
for tri = 0 to 11
read c$ : c = hexdec(c$)
for ver = tri*3 to tri*3 + 2
for p=VertexData+ver*vertexsize to VertexData+ver*vertexsize+20 step 4
read r
calldll #oleaut32, "VarR4FromR8", r as double, p as long, r as void
next p
calldll #oleaut32, "VarUI4FromUI8", c as ulong, 0 as long, p as long, r as void
next ver
next tri
r=CallMethod(IDirect3DVertexBuffer8, 12, "") ' ::Unlock
struct parm, StreamNumber as long, StreamData as long, Stride as long
parm.StreamData.struct=IDirect3DVertexBuffer8
parm.Stride.struct=vertexsize
r=CallMethod(IDirect3DDevice8, 83, parm.struct) ' ::SetStreamSource
struct parm, Handle as long
parm.Handle.struct=vertexshader
r=CallMethod(IDirect3DDevice8, 76, parm.struct) ' ::SetVertexShader
timer 20, [render]
wait
[key]
select case Inkey$
case chr$(0)+chr$(37): Xcam = Xcam - 0.5
case chr$(0)+chr$(39): Xcam = Xcam + 0.5
case chr$(0)+chr$(38): Ycam = Ycam + 0.5
case chr$(0)+chr$(40): Ycam = Ycam - 0.5
end select
wait
[render]
yaw=time$("ms") / 2000
roll=time$("ms") / 800
struct parm,_
Count as long, pRects as long, Flags as long,_
BackColor as long, Z as long, Stencil as long
parm.Flags.struct=3
parm.BackColor.struct=hexdec("808080")
parm.Z.struct=float(1)
r=CallMethod(IDirect3DDevice8, 36, parm.struct) ' ::Clear
r=CallMethod(IDirect3DDevice8, 34, "") ' ::BeginScene
struct matrix,_
f11 as long, f12 as long, f13 as long, f14 as long,_
f21 as long, f22 as long, f23 as long, f24 as long,_
f31 as long, f32 as long, f33 as long, f34 as long,_
f41 as long, f42 as long, f43 as long, f44 as long
matrix.f11.struct=float(1)
matrix.f22.struct=float(1)
matrix.f33.struct=float(1)
matrix.f43.struct=float(24) ' Viewing distance
matrix.f44.struct=float(1)
struct parm, State as long, Matrix as struct
parm.State.struct=2 ' view transform
parm.Matrix.struct=matrix.struct
r=CallMethod(IDirect3DDevice8, 37, parm.struct) ' ::SetTransform
fv=0.5 ' Vertical field of view
ar=DisplayWidth / DisplayHeight ' Aspect ratio
zn=1 ' Near clipping plane
zf=1000 ' Far clipping plane
h=1/tan(fv/2)
matrix.f11.struct=float(h/ar)
matrix.f22.struct=float(h)
matrix.f33.struct=float(zf/(zf-zn))
matrix.f44.struct=float(0)
matrix.f34.struct=float(1)
matrix.f43.struct=float(0-zn*zf/(zf-zn))
parm.State.struct=3 ' projection transform
parm.Matrix.struct=matrix.struct
r=CallMethod(IDirect3DDevice8, 37, parm.struct) ' ::SetTransform
for cube = 0 to 4
Xpos = Xcam + 4*cube - 8
Ypos = Ycam
sy=sin(yaw) : cy=cos(yaw)
sp=sin(pitch) : cp=cos(pitch)
sr=sin(roll) : cr=cos(roll)
matrix.f11.struct=float(sy*sp*sr+cy*cr)
matrix.f12.struct=float(cp*sr)
matrix.f13.struct=float(cy*sp*sr-sy*cr)
matrix.f14.struct=0
matrix.f21.struct=float(sy*sp*cr-cy*sr)
matrix.f22.struct=float(cp*cr)
matrix.f23.struct=float(cy*sp*cr+sy*sr)
matrix.f24.struct=0
matrix.f31.struct=float(cp*sy)
matrix.f32.struct=float(0-sp)
matrix.f33.struct=float(cp*cy)
matrix.f34.struct=0
matrix.f41.struct=float(Xpos)
matrix.f42.struct=float(Ypos)
matrix.f43.struct=float(Zpos)
matrix.f44.struct=float(1)
struct parm, State as long, Matrix as struct
parm.State.struct=256 ' world transform
parm.Matrix.struct=matrix.struct
r=CallMethod(IDirect3DDevice8, 37, parm.struct) ' ::SetTransform
struct parm,_
PrimitiveType as long,_
StartVertex as long, PrimitiveCount as long
parm.PrimitiveType.struct=4 ' D3DPT_TRIANGLELIST
parm.PrimitiveCount.struct=triangles
r=CallMethod(IDirect3DDevice8, 70, parm.struct) ' ::DrawPrimitive
next cube
r=CallMethod(IDirect3DDevice8, 35, "") ' ::EndScene
struct parm,_
SourceRect as struct, DestRect as struct,_
DestWindowOverride as long, DirtyRegion as struct
r=CallMethod(IDirect3DDevice8, 15, parm.struct) ' ::Present
' Fix float underflow exception (LB only)
bugfix$=chr$(219)+chr$(227)+chr$(194)+chr$(16)
calldll #user32, "CallWindowProcA", bugfix$ as ptr,_
0 as long, 0 as long, 0 as long, 0 as long, r as long
wait
[quit]
r=CallMethod(IDirect3DVertexBuffer8, 2, "") ' ::Release
r=CallMethod(IDirect3DDevice8, 2, "") ' ::Release
r=CallMethod(IDirect3D8, 2, "") ' ::Release
close #w
close #oleaut32
close #d3d8
end
' Cube (12 triangles):
data "FF0000FF", 1,-1,-1, 0,-1, 0, -1,-1,-1, 0,-1, 0, -1,-1, 1, 0,-1, 0
data "FF0000FF", -1,-1, 1, 0,-1, 0, 1,-1, 1, 0,-1, 0, 1,-1,-1, 0,-1, 0
data "FF00FF00", -1, 1, 1, 0, 1, 0, -1, 1,-1, 0, 1, 0, 1, 1,-1, 0, 1, 0
data "FF00FF00", 1, 1,-1, 0, 1, 0, 1, 1, 1, 0, 1, 0, -1, 1, 1, 0, 1, 0
data "FF00FFFF", 1, 1,-1, 1, 0, 0, 1,-1,-1, 1, 0, 0, 1,-1, 1, 1, 0, 0
data "FF00FFFF", 1,-1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1,-1, 1, 0, 0
data "FFFF0000", -1,-1, 1, -1, 0, 0, -1,-1,-1, -1, 0, 0, -1, 1,-1, -1, 0, 0
data "FFFF0000", -1, 1,-1, -1, 0, 0, -1, 1, 1, -1, 0, 0, -1,-1, 1, -1, 0, 0
data "FFFF00FF", 1,-1, 1, 0, 0, 1, -1,-1, 1, 0, 0, 1, -1, 1, 1, 0, 0, 1
data "FFFF00FF", -1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1,-1, 1, 0, 0, 1
data "FFFFFF00", -1, 1,-1, 0, 0,-1, -1,-1,-1, 0, 0,-1, 1,-1,-1, 0, 0,-1
data "FFFFFF00", 1,-1,-1, 0, 0,-1, 1, 1,-1, 0, 0,-1, -1, 1,-1, 0, 0,-1
function float(n)
struct temp, v as long
calldll #oleaut32, "VarR4FromR8", n as double, temp as struct, r as void
float=temp.v.struct
end function
function CallMethod(object, method, parm$)
code$=chr$(139)+"D$"+chr$(4)+chr$(139)+"T$"+chr$(8)+chr$(139)+"L$" _
+ chr$(16)+"VW"+chr$(139)+"t$"+chr$(20)+chr$(43)+chr$(225)+chr$(139) _
+ chr$(252)+chr$(243)+chr$(164)+chr$(80)+chr$(139)+chr$(0)+chr$(255) _
+ chr$(20)+chr$(144)+chr$(95)+chr$(94)+chr$(194)+chr$(16)+chr$(0)
p$=parm$
n=len(p$)
calldll #user32, "CallWindowProcA", code$ as ptr, object as long,_
method as long, p$ as ptr, n as long, CallMethod as long
end function
|
|
Logged
|
|
|
|
|