c2328c6b955729c4880b066fc09b91dacab6e887
[nit.git] / lib / gamnit / depth / depth.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Framework for 3D games in Nit
16 module depth
17
18 intrude import more_materials
19 import more_models
20
21 redef class App
22
23 redef fun on_create
24 do
25 super
26
27 # Move the camera back a bit
28 world_camera.reset_height(10.0)
29 world_camera.near = 0.1
30
31 # Prepare programs
32 var program = versatile_program
33 program.compile_and_link
34 var gamnit_error = program.error
35 assert gamnit_error == null else print_error gamnit_error
36
37 program = normals_program
38 normals_program.compile_and_link
39 gamnit_error = program.error
40 assert gamnit_error == null else print_error gamnit_error
41 end
42
43 redef fun frame_core_draw(display) do frame_core_depth display
44
45 # Draw all elements of `actors` and then call `frame_core_flat`
46 protected fun frame_core_depth(display: GamnitDisplay)
47 do
48 # Update cameras on both our programs
49 versatile_program.use
50 versatile_program.mvp.uniform world_camera.mvp_matrix
51
52 normals_program.use
53 normals_program.mvp.uniform app.world_camera.mvp_matrix
54
55 for actor in actors do
56 for leaf in actor.model.leaves do
57 leaf.material.draw(actor, leaf)
58 end
59 end
60
61 frame_core_flat display
62 end
63 end