-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
94 lines (77 loc) · 2.92 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from OpenGL.GL import *
from config_screen import *
from drawings import *
from vertexes import *
from vertexes import *
import keyboard as kb
# Getting all the vertexes used in our project.
# Creating the house.
house = get_vertexes_house()
index_vertexes = {}
start = 0
index_vertexes['house'] = [start,len(house)]
start = len(house)
# Creating the person
person, coords_person = get_vertexes_person()
index_vertexes['person'] = [start]
for value in coords_person:
index_vertexes['person'].append(index_vertexes['person'][-1] + value)
start = len(person) + start
# Creating the ground
ground, coords_ground, colors = get_vertexes_ground(10000)
index_vertexes['ground'] = [start]
for value in coords_ground:
index_vertexes['ground'].append(index_vertexes['ground'][-1] + value)
start = len(ground) + start
# Creating the tree.
tree, coords_tree = get_vertexes_tree()
index_vertexes['tree'] = [start]
for value in coords_tree:
index_vertexes['tree'].append(index_vertexes['tree'][-1] + value)
start = len(tree) + start
# Creating the sun.
sun, coords_sun = get_vertexes_sun()
index_vertexes['sun'] = [start]
for value in coords_sun:
index_vertexes['sun'].append(index_vertexes['sun'][-1] + value)
# Joining everyone
vertexes = np.concatenate((house, person))
vertexes = np.concatenate((vertexes, ground))
vertexes = np.concatenate((vertexes, tree))
vertexes = np.concatenate((vertexes, sun))
#-----------------------------------------------------------------------------------
# Configuring the screen used to show the objects.
window = init_window()
program = create_program()
send_data_to_gpu(program, vertexes)
render_window(window)
# Activating the keyboard handler function and initializing an auxiliar variable.
glfw.set_key_callback(window,kb.key_event)
#-----------------------------------------------------------------------------------
# Getting GPU variables.
loc_color = get_loc_color(program)
loc_transformation = get_loc_transformation(program)
#-----------------------------------------------------------------------------------
# Code main loop.
while not glfw.window_should_close(window):
# Reading user interactions.
glfw.poll_events()
kb.sun_rot += kb.sun_speed
kb.person_step += kb.person_speed
# Activating the polygon view mode.
if kb.polyMode:
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)
else:
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
# Clearing screen and loading a new solid background.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glClearColor(1.0, 1.0, 1.0, 1.0)
# Drawing the objects.
draw_ground(loc_transformation, loc_color, index_vertexes, colors)
draw_house(loc_transformation, loc_color)
draw_person(loc_transformation, loc_color, index_vertexes)
draw_tree(loc_transformation, loc_color, index_vertexes)
draw_sun(loc_transformation, loc_color, index_vertexes)
# Displaying the next frame.
glfw.swap_buffers(window)
glfw.terminate()