-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderer.py
More file actions
101 lines (71 loc) · 2.78 KB
/
Renderer.py
File metadata and controls
101 lines (71 loc) · 2.78 KB
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
95
96
97
98
99
100
'''
* Renderer.py
*
* Created on: 15.12.2018
* Author: Andrew Jason Bishop
*
* General description:
* xxx
'''
import OpenGL.GL as GL
import ctypes as ct
class Renderer:
def __init__(self, _shaderProg):
self.shaderProgram = _shaderProg
def prepare(self):
GL.glClearColor( 0.231, 0.231, 0.243, 1.0 )
GL.glEnable( GL.GL_DEPTH_TEST )
def render(self, _model):
GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT )
self.start()
GL.glBindVertexArray( _model.getVaoID() )
GL.glEnableVertexAttribArray( 0 )
GL.glDrawElements( GL.GL_TRIANGLES,
_model.getVertexCount(),
GL.GL_UNSIGNED_INT,
ct.c_void_p(0) ) #ct.c_void_p(0)
#GL.glDrawArrays( GL.GL_TRIANGLES, 0, _model.getVertexCount() )
GL.glDisableVertexAttribArray( 0 )
GL.glBindVertexArray( 0 )
self.stop()
def render_textured_model(self, _texModel):
rawModel = _texModel.rawModel
texture = _texModel.modelTexture
texID = texture.texID
GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT )
GL.glBindVertexArray( rawModel.getVaoID() )
GL.glEnableVertexAttribArray( 0 )
GL.glEnableVertexAttribArray( 1 )
#GL.glBindTexture(GL.GL_TEXTURE_2D, texID)
GL.glDrawElements( GL.GL_TRIANGLES,
rawModel.getVertexCount(),
GL.GL_UNSIGNED_INT,
ct.c_void_p(0) ) #ct.c_void_p(0)
GL.glDisableVertexAttribArray( 0 )
GL.glDisableVertexAttribArray( 1 )
GL.glBindVertexArray( 0 )
def render_entity(self, _entity, _shader):
texModel = _entity.texturedModel
modelTex = texModel.modelTexture
texID = modelTex.texID
rawModel = texModel.getRawModel()
tMat = _entity.getTransformationMatrix()
GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT )
GL.glBindVertexArray( rawModel.getVaoID() )
GL.glEnableVertexAttribArray( 0 )
GL.glEnableVertexAttribArray( 1 )
self.shaderProgram.loadTransformationMatrix( tMat )
#self.shaderProgram.loadFloat( "uniScale", 0.8 )
#GL.glBindTexture(GL.GL_TEXTURE_2D, texID)
GL.glDrawElements( GL.GL_TRIANGLES,
rawModel.getVertexCount(),
GL.GL_UNSIGNED_INT,
ct.c_void_p(0) )
GL.glDisableVertexAttribArray( 0 )
GL.glDisableVertexAttribArray( 1 )
GL.glBindVertexArray( 0 )
def start(self):
GL.glUseProgram( self.shaderProgram )
def stop(self):
GL.glUseProgram( 0 )
''' END '''