From fa19643fa0ee4fb3ab0dda70291a64bb6ac9c30e Mon Sep 17 00:00:00 2001 From: Steffen Temme Date: Tue, 29 Aug 2017 16:30:53 +0200 Subject: [PATCH] added renderfunction to a structure. Complex structure soon to come. --- Objects/Cube/cube_geometry.glsl | 1 - Objects/Structure.py | 26 +++++++++++++++++++++++++- main.py | 11 +++++++---- vertex.glsl | 1 - 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Objects/Cube/cube_geometry.glsl b/Objects/Cube/cube_geometry.glsl index b1f860e..2b407b3 100644 --- a/Objects/Cube/cube_geometry.glsl +++ b/Objects/Cube/cube_geometry.glsl @@ -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]; diff --git a/Objects/Structure.py b/Objects/Structure.py index 428a70b..8c52502 100644 --- a/Objects/Structure.py +++ b/Objects/Structure.py @@ -116,4 +116,28 @@ class Structure: glDisableVertexAttribArray(s) glDeleteBuffers(1,[s]) glDeleteVertexArrays(1, a) - check_error("Could not destroy vertex array") \ No newline at end of file + 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) \ No newline at end of file diff --git a/main.py b/main.py index d3a8154..eaebf5d 100644 --- a/main.py +++ b/main.py @@ -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))) diff --git a/vertex.glsl b/vertex.glsl index 366213d..97fc644 100644 --- a/vertex.glsl +++ b/vertex.glsl @@ -2,7 +2,6 @@ uniform mat4 projModelViewMatrix; -uniform mat3 normalMatrix; uniform mat3 rotMatrix; layout(location = 0) in vec3 in_position;