2 -- Simple test application.
7 function CreateTestScene()
10 cubeframe
= sg
.Frame()
12 -- Create vertex buffer
13 vb
= sg
.VertexBuffer()
14 vb
:addAttribute( sg
.VertexBuffer
.at_Vector3f
, sg
.VertexBuffer
.a_Position
)
17 vec3
= awful
.math
.Vector3f
18 vb
:setVector3fAttribute( 0, 0, vec3( -1, -1, -1 ) )
19 vb
:setVector3fAttribute( 1, 0, vec3( -1, -1, 1 ) )
20 vb
:setVector3fAttribute( 2, 0, vec3( -1, 1, -1 ) )
21 vb
:setVector3fAttribute( 3, 0, vec3( -1, 1, 1 ) )
22 vb
:setVector3fAttribute( 4, 0, vec3( 1, -1, -1 ) )
23 vb
:setVector3fAttribute( 5, 0, vec3( 1, -1, 1 ) )
24 vb
:setVector3fAttribute( 6, 0, vec3( 1, 1, -1 ) )
25 vb
:setVector3fAttribute( 7, 0, vec3( 1, 1, 1 ) )
27 -- Create index buffer
28 ib
= sg
.IndexBuffer16( 24 )
60 geom1
= sg
.Geometry( vb
, ib
)
61 geom1
:addPrimitive( sg
.Primitive
.t_Quads
, 0, 8 )
62 geom2
= sg
.Geometry( vb
, ib
)
63 geom2
:addPrimitive( sg
.Primitive
.t_Quads
, 8, 8 )
64 geom3
= sg
.Geometry( vb
, ib
)
65 geom3
:addPrimitive( sg
.Primitive
.t_Quads
, 16, 8 )
69 mat1
.Emission
.value
= awful
.math
.Vector4f( 1, 0, 0, 1 )
70 mat1
.Specular
.value
= awful
.math
.Vector4f( 0, 0, 0, 1 )
72 mat2
.Emission
.value
= awful
.math
.Vector4f( 0, 1, 0, 1 )
73 mat2
.Specular
.value
= awful
.math
.Vector4f( 0, 0, 0, 1 )
75 mat3
.Emission
.value
= awful
.math
.Vector4f( 0, 0, 1, 1 )
76 mat3
.Specular
.value
= awful
.math
.Vector4f( 0, 0, 0, 1 )
79 drawable1
= sg
.Drawable( geom1
, mat1
, cubeframe
)
80 drawable2
= sg
.Drawable( geom2
, mat2
, cubeframe
)
81 drawable3
= sg
.Drawable( geom3
, mat3
, cubeframe
)
83 -- Create group holding all this stuff together
84 cubegroup
= sg
.Group()
85 cubegroup
:add( drawable1
)
86 cubegroup
:add( drawable2
)
87 cubegroup
:add( drawable3
)
88 cubegroup
.pFrame
= cubeframe
90 -- Save the cube into a file, for the lulz
91 --f = awful.io.FileOutputStream( "lulz.asg" )
92 --awful.abf.Writer.Save( f, cubegroup )
94 mat1
.Diffuse
.value
= awful
.math
.Vector4f( 1, 0, 0, 1 )
95 mat1
.Emission
.value
= awful
.math
.Vector4f( 0, 0, 0, 1 )
96 mat1
.Ambient
.value
= awful
.math
.Vector4f( 0.2, 0.2, 0.2, 1 )
98 mat1
.bBackfaceCulling
= true
100 shape
= awful
.shapes
.Cylinder( mat1
, cubeframe
)
102 f
= awful
.io
.FileOutputStream( "lulz.asg" )
103 awful
.abf
.Writer
.Save( f
, shape
)
106 return cubegroup
--cubegroup
110 -- Initialize SDL application object. It just use some arbitrary defaults for now.
111 app
= awful
.sdl
.App
.GetInstance()
113 scene
= CreateTestScene()
115 f
= awful
.io
.FileInputStream( "lulz.asg" )
116 scene
= awful
.abf
.Reader
.Load( f
)
119 camframe
= sg
.Frame()
120 camera
= sg
.Camera( camframe
)
121 camframe
.LocalToParent
.position
.y
= -7
124 proj
= sg
.PerspectiveProjection()
127 viewport
= sg
.ViewPort( proj
, camera
)
128 viewport
.Rect
= awful
.math
.Rectu32( 0, 0, 800, 600 )
131 -- Create a font object.
132 font
= sg
.Font( "FreeSans.ttf", 16 )
136 theme
= awful
.gui
.BoringTheme( font
)
138 -- Create a widget container.
139 guiroot
= awful
.gui
.SimpleContainer( theme
)
141 -- Create a window containing a layout group
142 window
= awful
.gui
.Window( guiroot
)
143 window
.Rect
= awful
.math
.Rectf( 50, 70, 0, 0 )
144 vg
= awful
.gui
.VGroup( window
)
145 awful
.gui
.Button( vg
, "Tubgirl" )
146 awful
.gui
.Button( vg
, "Goatse" )
148 hg
= awful
.gui
.HGroup( vg
)
149 awful
.gui
.Button( hg
, "eat" );
150 awful
.gui
.Button( hg
, "shit" );
151 awful
.gui
.Button( hg
, "Lemon party" );
153 awful
.gui
.Button( vg
, "lulz" )
155 guiroot
:buildSceneGraph()
159 -- Setup the gui viewport
160 guiproj
= sg
.PixelProjection()
161 guiviewport
= sg
.ViewPort( guiproj
)
162 guiviewport
.Rect
= awful
.math
.Rectu32( 0, 0, 800, 600 )
163 guiviewport
.bClearColorBuffer
= false
165 -- Setup the frame update function.
167 eventmanager
= awful
.gui
.EventManager
.GetInstance()
169 -- TODO: implement some way to directly connect a native function to a signal to avoid
170 -- going through the lua interpreter for nothing
171 app
.MouseMotionEvent
:connect(
172 function( position
, rel
)
173 eventmanager
:mouseMotionEvent( position
, rel
)
177 app
.MouseButtonEvent
:connect(
178 function( position
, butcode
, pressed
)
179 eventmanager
:mouseButtonEvent( position
, butcode
, pressed
)
183 eventmanager
.DefaultHandler
= guiroot
187 app
.FrameUpdate
:connect(
189 function( deltatime
)
191 sg
.RenderContext
.ClearAll()
193 guicontext
= sg
.RenderContext( guiviewport
)
194 guicontext
:addToRenderList()
196 guiroot
.pRenderable
:evaluate( guicontext
)
198 context
= sg
.RenderContext( viewport
)
199 context
:addToRenderList()
201 spin
= spin
+ 50 * deltatime
202 mtx
= awful
.math
.Matrix44f()
203 mtx
:rotation( spin
, awful
.math
.Vector3f( 1, 0, 0.5 ) )
204 scene
.pFrame
.LocalToParent
= mtx
205 --scene.pFrame.LocalToParent.position.x = 0
206 --scene.pFrame.LocalToParent.position.y = 0
207 --scene.pFrame.LocalToParent.position.z = 0
208 --scene.pFrame:dirty()
210 --mtx:rotation( spin, awful.math.Vector3f( 1, 0, 0 ) )
211 --camframe.LocalToParent = mtx
212 -- camframe.LocalToParent.position.x = 0
213 -- camframe.LocalToParent.position.y = -7
214 -- camframe.LocalToParent.position.z = 2
217 scene
:evaluate( context
)
219 sg
.RenderContext
.RenderAll()
227 -- Start the main loop.