added renderfunction to a structure.

Complex structure soon to come.
This commit is contained in:
steffen 2017-08-29 16:30:53 +02:00
parent f4c68a8297
commit fa19643fa0
4 changed files with 32 additions and 7 deletions

View file

@ -4,7 +4,6 @@ layout(points) in;
layout(triangle_strip,max_vertices=24) out;
uniform mat4 projModelViewMatrix;
uniform mat3 normalMatrix;
uniform mat3 rotMatrix;
uniform mat4 lightProjModelViewMatrix[7];

View file

@ -117,3 +117,27 @@ class Structure:
glDeleteBuffers(1,[s])
glDeleteVertexArrays(1, a)
check_error("Could not destroy vertex array")
def render(self,projMatrix,geometryRotMatrix,alternateprograms = None):
for key,tupel in self.vais.items():
if alternateprograms == None:
program_id = key
else:
assert key in alternateprograms.keys
program_id = alternateprograms[key]
glUseProgram(program_id)
check_error("Renderingprogram is not initialized!")
projection = glGetUniformLocation(program_id, 'projModelViewMatrix')
rot = glGetUniformLocation(program_id, 'rotMatrix')
glUniformMatrix4fv(projection, 1, GL_FALSE, np.array(projMatrix))
glUniformMatrix3fv(rot, 1, GL_FALSE, np.array(geometryRotMatrix))
glBindVertexArray(tupel[0])
glDrawArrays(GL_POINTS, 0, len(self.Objects[key]))
check_error("Rendering problem")
glBindVertexArray(0)
glUseProgram(0)

11
main.py
View file

@ -21,6 +21,7 @@ import time
name = b'ball_glut'
struct = None
program_id = 0
program2_id = 0
program3_id = 0
@ -124,7 +125,7 @@ def main():
#glAttachShader(program_id, l.FragmentShaderId)
glLinkProgram(program_id)
global struct
struct = Structure()
struct.addShape(program_id,c)
struct.buildvertexArrays()
@ -206,6 +207,7 @@ def main():
0, 1, 0,
1, 0, 0,
1, 1, 0], dtype=np.float32), program2_id)
struct.render(projMatrix,rotate(rx, 0, 0))
glutMainLoop()
return
@ -284,17 +286,18 @@ rx = 0
ry = 0
def render(program_id,projMatrix,vai,x,y,z):
ident = np.transpose(np.matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]], np.float32))
#global struct
#struct.render(translate(x, y, z) * rotate(0,ry,0,True) * projMatrix,rotate(rx, 0, 0))
glUseProgram(program_id)
check_error("Renderingprogram is not initialized!")
projection = glGetUniformLocation(program_id, 'projModelViewMatrix')
normal = glGetUniformLocation(program_id, 'normalMatrix')
rot = glGetUniformLocation(program_id, 'rotMatrix')
glUniformMatrix4fv(projection, 1, GL_FALSE, np.array(translate(x, y, z) * rotate(0,ry,0,True) * projMatrix))
glUniformMatrix3fv(normal, 1, GL_FALSE, np.array(ident))
glUniformMatrix3fv(rot, 1, GL_FALSE, np.array(rotate(rx, 0, 0)))

View file

@ -2,7 +2,6 @@
uniform mat4 projModelViewMatrix;
uniform mat3 normalMatrix;
uniform mat3 rotMatrix;
layout(location = 0) in vec3 in_position;