def draw(self, projection, view, model, color_shader): GL.glUseProgram(color_shader.glid) matrix_location = GL.glGetUniformLocation(color_shader.glid, 'matrix') # matrix = frustum(-20, 20, -20, 20, -20, 20) # print(matrix) matrix = perspective(45, 480 / 640, -20, 100) # print(matrix) # matrix_S = scale(0.5) # matrix[0][0] = matrix_S[0][0] # matrix[1][1] = matrix_S[1][1] # matrix[2][1] = matrix_S[2][2] # matrix[3][3] = matrix_S[3][3] # matrix = matrix @ matrix_S matrix = matrix @ projection #rotate(vec(0, 0, 1), 45) GL.glUniformMatrix4fv(matrix_location, 1, True, matrix) # draw triangle as GL_TRIANGLE vertex array, draw array call GL.glBindVertexArray(self.glid) #GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3) #use index buffer GL.glDrawElements(GL.GL_TRIANGLES, self.index.size, GL.GL_UNSIGNED_INT, None) # 9 indexed verts = 3 triangles GL.glBindVertexArray(0)
def update_projection(self, fovy, width, height): """Update the projection matrix.""" if not self.program_manager: return if self.program_manager.program_id: GL.glUniformMatrix4fv( GL.glGetUniformLocation( self.program_manager.program_id, b"projection"), 1, GL.GL_TRUE, perspective( fovy, width / height, self.znear, self.zfar)) self.fovy = fovy
def draw(self, projection, view, model, color_shader, color): super().draw(projection, view, model, color_shader) # model, projection and view transform model = np.identity( 4 ) # translate(0.4, 0.7, 0) @ rotate(vec(1, 0, 0), 25) @ scale(0.7) view = lookat(np.array((0, 3, 3), 'f'), np.array((0, 0, 0), 'f'), np.array((0, 1, 0), 'f')) projection = perspective(45.0, 4 / 3, 0.1, 100.0) # transformation mvp = projection @ view @ model matrix_location = GL.glGetUniformLocation(color_shader.glid, 'matrix') GL.glUniformMatrix4fv(matrix_location, 1, True, mvp)
def draw(self, projection, view, model, color_shader, color, scaler, rotater): GL.glUseProgram(color_shader.glid) my_color_location = GL.glGetUniformLocation(color_shader.glid, 'color') # hard coded color : (0.6, 0.6, 0.9) GL.glUniform3fv(my_color_location, 1, color) matrix_location = GL.glGetUniformLocation(color_shader.glid, 'matrix') GL.glUniformMatrix4fv( matrix_location, 1, True, perspective(35, 640 / 480, 0.001, 100) @ translate(0, 0, -1) @ rotate(vec(0, 1, 0), rotater) @ scale(scaler)) # draw triangle as GL_TRIANGLE vertex array, draw array call GL.glBindVertexArray(self.glid) GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3) GL.glBindVertexArray(0)
def draw(self, projection, view, model, color_shader): GL.glUseProgram(color_shader.glid) matrix_location = GL.glGetUniformLocation(color_shader.glid, 'matrix') matrix = perspective(45, 480 / 640, -20, 100) matrix = matrix @ projection #rotate(vec(0, 0, 1), 45) GL.glUniformMatrix4fv(matrix_location, 1, True, matrix) # draw triangle as GL_TRIANGLE vertex array, draw array call GL.glBindVertexArray(self.glid) #use index buffer GL.glDrawElements(GL.GL_TRIANGLES, self.index.size, GL.GL_UNSIGNED_INT, None) # 9 indexed verts = 3 triangles GL.glBindVertexArray(0)
def __init__(self, position, fov, aspect, near, far): self.position = position self._ProjectionMatrix = perspective(fov, aspect, near, far) self._ViewMatrix = lookat(position, vec(0, 0, 0), vec(0, 1, 0)) self._ProjectionViewMatrix = self._ProjectionMatrix @ self._ViewMatrix