[EXAMPLES]

* BUG: Update to new gb.sdl behaviour.


git-svn-id: svn://localhost/gambas/trunk@3727 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Laurent Carlier 2011-04-02 16:39:17 +00:00
parent bbd61e496d
commit 63c56db5d4
2 changed files with 56 additions and 56 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

@ -1,36 +1,36 @@
' Gambas module file
PRIVATE hWebCam AS VideoDevice
PRIVATE CONST ScrWidth AS Integer = 640
PRIVATE CONST ScrHeight AS Integer = 480
Private hWebCam As VideoDevice
Private Const ScrWidth As Integer = 640
Private Const ScrHeight As Integer = 480
' Needed for frame count
PRIVATE Frames AS Integer
PRIVATE CTime AS Float
Private Frames As Integer
Private CTime As Float
' Rotations
PRIVATE xrot AS Float
PRIVATE yrot AS Float
PRIVATE zrot AS Float
Private xrot As Float
Private yrot As Float
Private zrot As Float
' texture
PRIVATE textures AS NEW Integer[]
PRIVATE Screen AS NEW Window(TRUE) AS "Screen"
Private textures As New Integer[]
Private Screen As New Window(True) As "Screen"
PRIVATE logo AS image
PRIVATE tmpLogo AS Image
PRIVATE hTimer AS NEW Timer AS "Timer1"
PRIVATE count AS Integer
PRIVATE UpdateLogo AS Boolean
Private logo As Image
Private tmpLogo As Image
Private hTimer As New Timer As "Timer1"
Private count As Integer
Private UpdateLogo As Boolean
PUBLIC SUB Main()
Public Sub Main()
TRY hWebCam = NEW VideoDevice("/dev/video0")
IF ERROR THEN
PRINT ("Unable to open video device")
RETURN
Try hWebCam = New VideoDevice("/dev/video0")
If Error Then
Print ("Unable to open video device")
Return
END IF
End If
hWebCam.Hue = 10
hWebCam.Color = 10
hWebcam.Resize(320, 240)
@ -41,27 +41,27 @@ PUBLIC SUB Main()
screen.Width = ScrWidth
screen.Height = ScrHeight
Screen.show()
Screen.Border = Screen.Resizable
Screen.Resizable = True
InitGL()
textures = Gl.GenTextures(1)
LoadTextures()
Screen_resize()
CTime = Timer()
hTimer.Delay = 200
hTimer.Enabled = TRUE
hTimer.Enabled = True
END
End
PUBLIC SUB LoadTextures()
Public Sub LoadTextures()
Gl.BindTexture(gl.GL_TEXTURE_2D, textures[0])
Gl.TexImage2D(logo)
Gl.TexParameteri(gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
Gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
END
End
PUBLIC SUB InitGL()
Public Sub InitGL()
' Enable smooth shading
Gl.ShadeModel(gl.GL_SMOOTH)
@ -78,24 +78,24 @@ PUBLIC SUB InitGL()
' Really Nice Perspective Calculations
Gl.Hint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)
END
End
PUBLIC SUB Screen_close()
Public Sub Screen_close()
' Delete textures if needed
IF (textures.count > 0) THEN Gl.DeleteTextures(textures)
If (textures.count > 0) Then Gl.DeleteTextures(textures)
END
End
PUBLIC SUB Screen_resize()
Public Sub Screen_resize()
' Width/Height Ratio
DIM ratio AS Float
DIM Height AS Integer
Dim ratio As Float
Dim Height As Integer
Height = Screen.Height
' Protect against a divide by zero
IF Height = 0 THEN Height = 1
If Height = 0 Then Height = 1
ratio = Screen.Width / Height
@ -112,21 +112,21 @@ PUBLIC SUB Screen_resize()
Gl.MatrixMode(gl.GL_MODELVIEW)
GL.LoadIdentity()
END
End
PUBLIC SUB Screen_Draw()
Public Sub Screen_Draw()
DIM calc AS Float
INC count
IF UpdateLogo THEN
Dim calc As Float
Inc count
If UpdateLogo Then
'count = 0
'logo = tmpLogo
logo.Resize(256, 256)
LoadTextures()
UpdateLogo = FALSE
ENDIF
UpdateLogo = False
Endif
Gl.Clear(gl.GL_COLOR_BUFFER_BIT OR gl.GL_DEPTH_BUFFER_BIT)
Gl.Clear(gl.GL_COLOR_BUFFER_BIT Or gl.GL_DEPTH_BUFFER_BIT)
Gl.LoadIdentity()
Gl.Translatef(0.0, 0.0, -5.0)
@ -225,32 +225,32 @@ PUBLIC SUB Screen_Draw()
Gl.End()
INC (Frames)
IF (Timer() > CTime + 5) THEN
Inc (Frames)
If (Timer() > CTime + 5) Then
calc = Timer() - CTime
PRINT CStr(Frames) & " frames in " & Format$(calc, "#.0") & " seconds = " & Format$((Frames / calc), "######.000") & " FPS"
Print CStr(Frames) & " frames in " & Format$(calc, "#.0") & " seconds = " & Format$((Frames / calc), "######.000") & " FPS"
Frames = 0
CTime = Timer()
ENDIF
Endif
xrot += 0.3 ' X Axis Rotation
yrot += 0.2 ' Y Axis Rotation
zrot += 0.4 ' Z Axis Rotation
WAIT 0.05
Wait 0.05
END
End
PUBLIC SUB Screen_keyPress()
Public Sub Screen_keyPress()
IF key.Code = key.F1 THEN Screen.Fullscreen = NOT Screen.Fullscreen
IF key.Code = key.Esc THEN Screen.Close()
If key.Code = key.F1 Then Screen.Fullscreen = Not Screen.Fullscreen
If key.Code = key.Esc Then Screen.Close()
END
End
PUBLIC SUB Timer1_Timer()
Public Sub Timer1_Timer()
logo = hWebCam.Image
UpdateLogo = TRUE
UpdateLogo = True
END
End