示例#1
0
	def draw(self, gl, proj, view):
		# Retreive model and shader
		#
		vao, vao_size = Assets.get_geometry(tag="bullet")
		inst_vbo = Assets.get_inst_vbo(tag="bullet")
		prog = Assets.get_shader(tag="bullet")

		# Load geometry, shader and projection once
		#
		gl.glUseProgram(prog)
		gl.glBindVertexArray(vao)
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, proj.flatten()))

		# Create and buffer the instance data
		# 
		mv_array = []
		model = mat4.scale(0.5,0.5,0.5)

		for b in self.bullet_list:
			# Set up matricies
			#
			position = mat4.translate(b.position.x, b.position.y, b.position.z)
			mv = (view * position * model).transpose()
			mv_array.extend(mv.flatten())

		mv_c_array = pygloo.c_array(GLfloat, mv_array)
		gl.glBindBuffer( GL_ARRAY_BUFFER, inst_vbo )
		gl.glBufferData( GL_ARRAY_BUFFER, sizeof(mv_c_array), mv_c_array, GL_STREAM_DRAW )

		# Render
		# 	
		gl.glDrawArraysInstanced(GL_TRIANGLES, 0, vao_size, len(self.bullet_list))
示例#2
0
	def draw(self, gl, proj, view):
		# Set up matricies
		#
		model = mat4.rotateY(math.pi) * mat4.scale(0.2,0.2,0.2)
		rotation = self.get_orientation_matrix()
		position = mat4.translate(self.position.x, self.position.y, self.position.z)
		mv = view * position * rotation * model

		# Retreive model and shader
		#
		vao, vao_size = Assets.get_geometry(tag="ship")
		prog = Assets.get_shader(tag="ship")

		# Render
		# 
		gl.glUseProgram(prog)
		gl.glBindVertexArray(vao)
		
		gl.glUniform1f(gl.glGetUniformLocation(prog, "explode_time"), self.explode_time)
		if self.explode_time > 0.0:
			gl.glUniform3f(gl.glGetUniformLocation(prog, "color"), 1, 0.333, 1)
		else:
			gl.glUniform3f(gl.glGetUniformLocation(prog, "color"), 0.333, 1, 1)
		# }
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "modelViewMatrix"), 1, True, pygloo.c_array(GLfloat, mv.flatten()))
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, proj.flatten()))

		gl.glDrawArrays(GL_TRIANGLES, 0, vao_size)
示例#3
0
def _createVAO(gl, vert, norm, tex, mv_inst = False):

	# Converting to GL friendly format
	# 
	vert_array = pygloo.c_array(GLfloat, _flatten_list(vert))
	norm_array = pygloo.c_array(GLfloat, _flatten_list(norm))
	tex_array = pygloo.c_array(GLfloat, _flatten_list(tex))

	# Creating the VAO
	# 
	vao = GLuint(0)
	gl.glGenVertexArrays(1, vao)
	gl.glBindVertexArray(vao)

	# Vertex Position VBO  (pos 0)
	# 
	vbo_pos = GLuint(0)
	gl.glGenBuffers(1, vbo_pos)
	gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_pos)
	gl.glBufferData(GL_ARRAY_BUFFER, sizeof(vert_array), vert_array, GL_STATIC_DRAW)
	gl.glEnableVertexAttribArray(0)
	gl.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0)
	
	# Vertex Normal VBO  (pos 1)
	# 
	vbo_norm = GLuint(0)
	gl.glGenBuffers(1, vbo_norm)
	gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_norm)
	gl.glBufferData(GL_ARRAY_BUFFER, sizeof(norm_array), norm_array, GL_STATIC_DRAW)
	gl.glEnableVertexAttribArray(1)
	gl.glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0)

	# Vertex Texture Coordinate VBO  (pos 2)
	# 
	vbo_tex = GLuint(0)
	gl.glGenBuffers(1, vbo_tex)
	gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_tex)
	gl.glBufferData(GL_ARRAY_BUFFER, sizeof(tex_array), tex_array, GL_STATIC_DRAW)
	gl.glEnableVertexAttribArray(2)
	gl.glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0)

	# Optional model view matrix for instancing
	#
	vbo_mv = GLuint(0)
	if mv_inst:
		gl.glGenBuffers(1, vbo_mv)
		gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_mv)
		mv = mat4.identity()
		for r in xrange(4):
			row = pygloo.c_array(GLfloat, mv.row(r))
			gl.glVertexAttribPointer( 3 + r, 4, GL_FLOAT, False, sizeof(row)*4, sizeof(row) * r )
			gl.glEnableVertexAttribArray( 3 + r )
			gl.glVertexAttribDivisor( 3 + r, 1 )

	# Cleanup
	# 
	gl.glBindBuffer(GL_ARRAY_BUFFER, 0)
	gl.glBindVertexArray(0)

	return vao, vbo_mv
    def render(self, gl, mv, proj, wireframe=False):

        # Render Model
        #
        gl.glUseProgram(Geometry.solid_shader)
        gl.glBindVertexArray(self.vao)

        gl.glUniformMatrix4fv(
            gl.glGetUniformLocation(Geometry.solid_shader, "modelViewMatrix"),
            1, True, pygloo.c_array(GLfloat, _flatten_list(mv)))
        gl.glUniformMatrix4fv(
            gl.glGetUniformLocation(Geometry.solid_shader, "projectionMatrix"),
            1, True, pygloo.c_array(GLfloat, _flatten_list(proj)))

        gl.glDrawElements(GL_TRIANGLES, self.ibo_size, GL_UNSIGNED_INT, 0)
        gl.glBindVertexArray(0)

        if wireframe:
            # Render
            #
            gl.glEnable(GL_LINE_SMOOTH)
            gl.glUseProgram(Geometry.wire_shader)
            gl.glBindVertexArray(self.vao)

            gl.glUniformMatrix4fv(
                gl.glGetUniformLocation(Geometry.wire_shader,
                                        "modelViewMatrix"), 1, True,
                pygloo.c_array(GLfloat, _flatten_list(mv)))
            gl.glUniformMatrix4fv(
                gl.glGetUniformLocation(Geometry.wire_shader,
                                        "projectionMatrix"), 1, True,
                pygloo.c_array(GLfloat, _flatten_list(proj)))

            gl.glDrawElements(GL_TRIANGLES, self.ibo_size, GL_UNSIGNED_INT, 0)
            gl.glBindVertexArray(0)

        # Render selected and constrained points
        #
        gl.glPointSize(5.0)

        gl.glUseProgram(Geometry.flat_shader)
        gl.glBindVertexArray(self.vao_selected)
        gl.glUniform3fv(gl.glGetUniformLocation(Geometry.flat_shader, "color"),
                        1, pygloo.c_array(GLfloat, [1.0, 1.0, 0.0]))

        gl.glUniformMatrix4fv(
            gl.glGetUniformLocation(Geometry.flat_shader, "modelViewMatrix"),
            1, True, pygloo.c_array(GLfloat, _flatten_list(mv)))
        gl.glUniformMatrix4fv(
            gl.glGetUniformLocation(Geometry.flat_shader, "projectionMatrix"),
            1, True, pygloo.c_array(GLfloat, _flatten_list(proj)))

        gl.glDrawElements(GL_POINTS, len(self.selected), GL_UNSIGNED_INT, 0)

        gl.glBindVertexArray(self.vao_constrained)
        gl.glUniform3fv(gl.glGetUniformLocation(Geometry.flat_shader, "color"),
                        1, pygloo.c_array(GLfloat, [1.0, 0.0, 0.0]))

        gl.glDrawElements(GL_POINTS, len(self.constrained), GL_UNSIGNED_INT, 0)
        gl.glBindVertexArray(0)
	def render(self, gl, mv, proj, wireframe=False):

		# Render Model
		# 
		gl.glUseProgram(Geometry.solid_shader)
		gl.glBindVertexArray(self.vao)
		
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(Geometry.solid_shader, "modelViewMatrix"), 1, True, pygloo.c_array(GLfloat, _flatten_list(mv)))
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(Geometry.solid_shader, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, _flatten_list(proj)))

		gl.glDrawElements(GL_TRIANGLES, self.ibo_size, GL_UNSIGNED_INT, 0)
		gl.glBindVertexArray(0)


		if wireframe:
			# Render
			# 
			gl.glEnable(GL_LINE_SMOOTH)
			gl.glUseProgram(Geometry.wire_shader)
			gl.glBindVertexArray(self.vao)
			
			gl.glUniformMatrix4fv(gl.glGetUniformLocation(Geometry.wire_shader, "modelViewMatrix"), 1, True, pygloo.c_array(GLfloat, _flatten_list(mv)))
			gl.glUniformMatrix4fv(gl.glGetUniformLocation(Geometry.wire_shader, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, _flatten_list(proj)))

			gl.glDrawElements(GL_TRIANGLES, self.ibo_size, GL_UNSIGNED_INT, 0)
			gl.glBindVertexArray(0)



		# Render selected and constrained points
		#
		gl.glPointSize(5.0)

		gl.glUseProgram(Geometry.flat_shader)
		gl.glBindVertexArray(self.vao_selected)
		gl.glUniform3fv(gl.glGetUniformLocation(Geometry.flat_shader, "color"), 1, pygloo.c_array(GLfloat, [1.0, 1.0, 0.0]))

		
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(Geometry.flat_shader, "modelViewMatrix"), 1, True, pygloo.c_array(GLfloat, _flatten_list(mv)))
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(Geometry.flat_shader, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, _flatten_list(proj)))

		gl.glDrawElements(GL_POINTS, len(self.selected), GL_UNSIGNED_INT, 0)


		gl.glBindVertexArray(self.vao_constrained)
		gl.glUniform3fv(gl.glGetUniformLocation(Geometry.flat_shader, "color"), 1, pygloo.c_array(GLfloat, [1.0, 0.0, 0.0]))

		gl.glDrawElements(GL_POINTS, len(self.constrained), GL_UNSIGNED_INT, 0)
		gl.glBindVertexArray(0)
示例#6
0
	def draw(self, gl, proj, view):
		prog = Assets.get_shader(tag="asteroid")
		gl.glUseProgram(prog)
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, proj.flatten()))


		model = mat4.scale(2,2,2)

		for i in xrange(1, 8):

			# Retreive model and shader, Load geometry once
			#
			vao, vao_size = Assets.get_geometry(tag="asteroid{num}".format(num=i))
			inst_vbo = Assets.get_inst_vbo(tag="asteroid{num}".format(num=i))
			gl.glBindVertexArray(vao)

			# Create buffer
			# 
			mv_array = []


			# Create the instance data
			# 
			count = 0
			for a in [a for ast_slice in self.asteroid_slice_list for a in ast_slice.get_asteroids() if a.ast_num == i]:

				# Set up matricies
				#
				rotation = mat4.rotateFromQuat(a.orientation)
				scale = mat4.scale(a.size,a.size,a.size)
				position = mat4.translate(a.position.x, a.position.y, a.position.z)
				mv = (view * position * rotation * scale * model).transpose()
				mv_array.extend(mv.flatten())
				count += 1


			# Upload the instace data
			# 
			mv_c_array = pygloo.c_array(GLfloat, mv_array)
			gl.glBindBuffer( GL_ARRAY_BUFFER, inst_vbo )
			gl.glBufferData( GL_ARRAY_BUFFER, sizeof(mv_c_array), mv_c_array, GL_STREAM_DRAW )

			# Render
			# 	
			gl.glDrawArraysInstanced(GL_TRIANGLES, 0, vao_size, count)
示例#7
0
def render(w, h):
    global gl
    global test_model
    global model_rotate_x
    global model_rotate_y
    global user_action

    # render model
    test_model.update(gl)
    test_model.render(gl,
                      get_viewmatrix(),
                      get_projmatrix(w, h),
                      wireframe=True)

    # Draw the seelection box
    if user_action in [Action.select, Action.add_select]:
        gl.glUseProgram(Geometry.flat_shader)
        i = pygloo.c_array(GLfloat, _flatten_list(mat4.identity()))
        gl.glUniformMatrix4fv(
            gl.glGetUniformLocation(Geometry.flat_shader, "modelViewMatrix"),
            1, True, i)
        gl.glUniformMatrix4fv(
            gl.glGetUniformLocation(Geometry.flat_shader, "projectionMatrix"),
            1, True, i)
        gl.glUniform3fv(gl.glGetUniformLocation(Geometry.flat_shader, "color"),
                        1, pygloo.c_array(GLfloat, [0.0, 0.0, 0.0]))

        global mouse_xpos
        global mouse_ypos
        global mouse_down_xpos
        global mouse_down_ypos

        x1 = (2 * mouse_xpos / w) - 1
        x2 = (2 * mouse_down_xpos / w) - 1
        y1 = -((2 * mouse_ypos / h) - 1)
        y2 = -((2 * mouse_down_ypos / h) - 1)

        gl.glColor3f(0.1, 0.1, 0.1)
        gl.glBegin(GL_LINE_LOOP)
        gl.glVertex3f(x1, y1, 0.0)
        gl.glVertex3f(x1, y2, 0.0)
        gl.glVertex3f(x2, y2, 0.0)
        gl.glVertex3f(x2, y1, 0.0)
        gl.glEnd()
示例#8
0
	def render(self, gl, w, h, ascii_r=None):

		self.alive_for += 1

		zfar = 1000
		znear = 0.1

		# Create view and projection matrix
		#
		proj = mat4.perspectiveProjection(math.pi / 3, float(w)/h, znear, zfar)

		cam_pos = vec3([0,-4,15])
		view = mat4.translate(cam_pos.x, cam_pos.y, cam_pos.z).inverse()
		model = mat4.rotateX(math.pi * 0.3) * mat4.rotateY(math.pi * (self.alive_for/100.0)) * mat4.scale(0.25, 0.25, 0.25)
		mv = view * model

		# Retreive model and shader
		#
		vao, vao_size = Assets.get_geometry(tag="enemyship")
		prog = Assets.get_shader(tag="ship")

		# Render Ship
		# 
		gl.glUseProgram(prog)
		gl.glBindVertexArray(vao)
		
		gl.glUniform3f(gl.glGetUniformLocation(prog, "color"), 0.333, 1, 1)
		gl.glUniform1f(gl.glGetUniformLocation(prog, "explode_time"), 0.0)
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "modelViewMatrix"), 1, True, pygloo.c_array(GLfloat, mv.flatten()))
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, proj.flatten()))

		gl.glDrawArrays(GL_TRIANGLES, 0, vao_size)


		if ascii_r:
			art = ascii.wordart("Level {l}".format(l=self.level), 'big', align='c')
			ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.5,0.333), textorigin = (0.5, 0.0), align = 'c')
			ascii_r.draw_text(self.textarea, screenorigin=(0.5,0.333), textorigin=(0.5, 1.0))



		return proj
    def update(self, gl):

        # Update vertex position information
        #
        gl.glBindVertexArray(self.vao)

        # Vertex Position VBO  (pos 0)
        pos_array = pygloo.c_array(GLfloat, _flatten_list(self.verts))
        gl.glBindBuffer(GL_ARRAY_BUFFER, self.vbo_pos)
        gl.glBufferData(GL_ARRAY_BUFFER, sizeof(pos_array), pos_array,
                        GL_STREAM_DRAW)
        gl.glEnableVertexAttribArray(0)
        gl.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0)

        # Update Selected/Constrained information
        #
        gl.glBindVertexArray(self.vao_selected)
        idx_array = pygloo.c_array(GLuint, self.selected)
        gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo_selected)
        gl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idx_array), idx_array,
                        GL_STREAM_DRAW)

        gl.glBindBuffer(GL_ARRAY_BUFFER, self.vbo_pos)
        gl.glEnableVertexAttribArray(0)
        gl.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0)

        gl.glBindVertexArray(self.vao_constrained)
        idx_array = pygloo.c_array(GLuint, self.constrained)
        gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo_constrained)
        gl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idx_array), idx_array,
                        GL_STREAM_DRAW)

        gl.glBindBuffer(GL_ARRAY_BUFFER, self.vbo_pos)
        gl.glEnableVertexAttribArray(0)
        gl.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0)

        # Cleanup
        gl.glBindVertexArray(0)
示例#10
0
	def update(self, gl):
		
		# Update vertex position information
		#
		gl.glBindVertexArray(self.vao)

		# Vertex Position VBO  (pos 0)
		pos_array = pygloo.c_array(GLfloat, _flatten_list(self.verts))
		gl.glBindBuffer(GL_ARRAY_BUFFER, self.vbo_pos)
		gl.glBufferData(GL_ARRAY_BUFFER, sizeof(pos_array), pos_array, GL_STREAM_DRAW)
		gl.glEnableVertexAttribArray(0)
		gl.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0)


		# Update Selected/Constrained information
		# 
		gl.glBindVertexArray(self.vao_selected)
		idx_array = pygloo.c_array(GLuint, self.selected)
		gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo_selected);
		gl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idx_array), idx_array, GL_STREAM_DRAW);

		gl.glBindBuffer(GL_ARRAY_BUFFER, self.vbo_pos)
		gl.glEnableVertexAttribArray(0)
		gl.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0)


		gl.glBindVertexArray(self.vao_constrained)
		idx_array = pygloo.c_array(GLuint, self.constrained)
		gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo_constrained);
		gl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idx_array), idx_array, GL_STREAM_DRAW);

		gl.glBindBuffer(GL_ARRAY_BUFFER, self.vbo_pos)
		gl.glEnableVertexAttribArray(0)
		gl.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0)

		# Cleanup
		gl.glBindVertexArray(0)
示例#11
0
def render(w,h):
	global gl
	global test_model
	global model_rotate_x
	global model_rotate_y
	global user_action

	# render model
	test_model.update(gl)
	test_model.render(gl, get_viewmatrix(), get_projmatrix(w,h), wireframe=True)

	# Draw the seelection box
	if user_action in [Action.select, Action.add_select]:
		gl.glUseProgram(Geometry.flat_shader)
		i = pygloo.c_array(GLfloat, _flatten_list(mat4.identity()))
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(Geometry.flat_shader, "modelViewMatrix"), 1, True, i)
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(Geometry.flat_shader, "projectionMatrix"), 1, True, i)
		gl.glUniform3fv(gl.glGetUniformLocation(Geometry.flat_shader, "color"), 1, pygloo.c_array(GLfloat, [0.0, 0.0, 0.0]))

		global mouse_xpos
		global mouse_ypos
		global mouse_down_xpos
		global mouse_down_ypos

		x1 = (2*mouse_xpos/w)-1
		x2 = (2*mouse_down_xpos/w)-1
		y1 = -((2*mouse_ypos/h)-1)
		y2 = -((2*mouse_down_ypos/h)-1)

		gl.glColor3f(0.1, 0.1, 0.1);
		gl.glBegin(GL_LINE_LOOP)
		gl.glVertex3f( x1, y1, 0.0)
		gl.glVertex3f( x1, y2, 0.0)
		gl.glVertex3f( x2, y2, 0.0)
		gl.glVertex3f( x2, y1, 0.0)
		gl.glEnd()
示例#12
0
	def draw(self, gl, proj, view, _cache = {}):
		# Retreive model and shader
		#
		vao, vao_size = Assets.get_geometry(tag="mine")
		inst_vbo = Assets.get_inst_vbo(tag="mine")
		prog = Assets.get_shader(tag="mine")

		# Load geometry, shader and projection once
		#
		gl.glUseProgram(prog)
		gl.glBindVertexArray(vao)
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, proj.flatten()))

		# explode time instanced vbo
		vbo_explode_time = _cache.get('vbo_explode_time', None)
		if not vbo_explode_time:
			vbo_explode_time = GLuint(0)
			gl.glGenBuffers(1, vbo_explode_time)
			_cache['vbo_explode_time'] = vbo_explode_time
		# }
		
		gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_explode_time)
		gl.glEnableVertexAttribArray(7)
		gl.glVertexAttribPointer(7, 1, GL_FLOAT, GL_FALSE, 0, 0)
		gl.glVertexAttribDivisor(7, 1)
		
		# Create and buffer the instance data
		# 
		mv_array = []
		et_array = []
		sphere_mv_array = []
		model = mat4.scale(0.5,0.5,0.5)

		for m in self.mine_list:
			# Set up matricies
			#
			position = mat4.translate(m.position.x, m.position.y, m.position.z)
			mv = (view * position * model).transpose()
			mv_array.extend(mv.flatten())
			
			et_array.append(m.explode_time)
			
			scale = mat4.scale(m.explosion_radius, m.explosion_radius, m.explosion_radius)
			mv = (view * position * scale).transpose()
			sphere_mv_array.extend(mv.flatten())

		mv_c_array = pygloo.c_array(GLfloat, mv_array)
		gl.glBindBuffer( GL_ARRAY_BUFFER, inst_vbo )
		gl.glBufferData( GL_ARRAY_BUFFER, sizeof(mv_c_array), mv_c_array, GL_STREAM_DRAW )
		
		gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_explode_time)
		gl.glBufferData(GL_ARRAY_BUFFER, len(et_array) * 4, pygloo.c_array(GLfloat, et_array), GL_STREAM_DRAW)
		
		# Render Mines
		# 	
		gl.glDrawArraysInstanced(GL_TRIANGLES, 0, vao_size, len(self.mine_list))


		# Retreive model and shader
		#
		vao, vao_size = Assets.get_geometry(tag="minesphere")
		inst_vbo = Assets.get_inst_vbo(tag="minesphere")

		# Load geometry, shader and projection once
		#
		gl.glBindVertexArray(vao)

		mv_c_array = pygloo.c_array(GLfloat, sphere_mv_array)
		gl.glBindBuffer( GL_ARRAY_BUFFER, inst_vbo )
		gl.glBufferData( GL_ARRAY_BUFFER, sizeof(mv_c_array), mv_c_array, GL_STREAM_DRAW )

		# Render Mine spheres
		# 	
		gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
		#gl.glDrawArraysInstanced(GL_TRIANGLES, 0, vao_size, len(self.mine_list))
		gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
示例#13
0
	def render(self, gl, w, h, ascii_r=None):
		zfar = 1000
		znear = 0.1

		# Create view and projection matrix
		#
		proj = mat4.perspectiveProjection(math.pi / 3, float(w)/h, znear, zfar)
		view = self.scene["ship"].get_view_matrix()
		# view = self.scene["enemy_ship"].get_view_matrix()

		# Render all objects in the scene
		# 
		for (_, obj) in self.scene.items():
			obj.draw(gl, proj, view)

		if ascii_r:
			for (_, obj) in self.scene.items():
				obj.draw_ascii(ascii_r, proj, view)

			ship = self.scene['ship']
			
			if ship.win:
				if self.show_score :
					art = ascii.wordart('Bonuses!\n', 'big', align='c')
					ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.5,0.75), textorigin = (0.5, 0.0))

					# Draw the bonus from mission_info
					art = ascii.wordart('Bounty\nDamage Bill\nAmmo Bill\nProfit', 'big', align='r')
					ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.45,0.75), textorigin = (1.0, 1.0))

					#Scores associated with bonuses
					art = ascii.wordart('${0}\n$-{1}\n$-{2}\n${3}'.format(self.bounty, self.damage_bill, self.ammo_bill, self.score), 'big', align='r')
					ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.55,0.75), textorigin = (0.0, 1.0))

				else :
					art = ascii.wordart('SHOT BRO!', 'big', align='c')
					ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.5,0.5), textorigin = (0.5, 0.5))

					art = ascii.wordart('[SHOOT] to continue', 'small', align='c')
					ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.5,0.3), textorigin = (0.5, 0.5))
				
			elif self.scene["ship"].dead:
				art = ascii.wordart('YOU HAVE DIED !\nYOU LOSE !', 'big', align='c')
				ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.5,0.5), textorigin = (0.5, 0.5))

				art = ascii.wordart('[SHOOT] to continue', 'small', align='c')
				ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.5,0.3), textorigin = (0.5, 0.5))
			
			elif self.scene["enemy_ship"].win:
				art = ascii.wordart('YOUR BOUNTY ESCAPED !\nNo one will hire you anymore.\nYOU LOSE !', 'big', align='c')
				ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.5,0.5), textorigin = (0.5, 0.5))

				art = ascii.wordart('[SHOOT] to continue', 'small', align='c')
				ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.5,0.3), textorigin = (0.5, 0.5))
		# temp ?
		
		


		# Debug colliding spheres
		#
		if self.show_spheres:
			all_spheres = [s for (_, obj) in self.scene.items() for s in obj.get_sphere_list()]
			# all_spheres.extend( self.scene["ship"].get_sphere_list() )
			# all_spheres.extend( self.scene["bullet_collection"].get_sphere_list() )
			# all_spheres.extend( self.scene["asteroid_field"].get_sphere_list() )

			if len(all_spheres) > 0 :

				# Retreive model and shader
				#
				vao, vao_size = Assets.get_geometry(tag="sphere")
				inst_vbo = Assets.get_inst_vbo(tag="sphere")
				prog = Assets.get_shader(tag="sphere")

				# Load geometry, shader and projection once
				#
				gl.glUseProgram(prog)
				gl.glBindVertexArray(vao)
				gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, proj.flatten()))

				gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

				# Create and buffer the instance data
				# 
				mv_array = []
				for s in all_spheres:
					scale = mat4.scale(s.radius, s.radius, s.radius)
					position = mat4.translate(s.center.x, s.center.y, s.center.z)
					mv = (view * position * scale).transpose()
					mv_array.extend(mv.flatten())

				mv_c_array = pygloo.c_array(GLfloat, mv_array)
				gl.glBindBuffer( GL_ARRAY_BUFFER, inst_vbo )
				gl.glBufferData( GL_ARRAY_BUFFER, sizeof(mv_c_array), mv_c_array, GL_STREAM_DRAW )

				# Render
				# 	
				gl.glDrawArraysInstanced(GL_TRIANGLES, 0, vao_size, len(all_spheres))

				gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)


				
		# ascii needs proj matrix
		return proj
示例#14
0
	def __init__(self, gl, v=[], vtf=[], f=[]):
		if not Geometry.solid_shader:
			Geometry.solid_shader = makeProgram(gl, "330 core", [GL_VERTEX_SHADER, GL_GEOMETRY_SHADER, GL_FRAGMENT_SHADER],
				open("shaders/solid_shader.glsl").read())

		if not Geometry.wire_shader:
			Geometry.wire_shader = makeProgram(gl, "330 core", [GL_VERTEX_SHADER, GL_GEOMETRY_SHADER, GL_FRAGMENT_SHADER],
				open("shaders/wireframe_shader.glsl").read())

		if not Geometry.flat_shader:
			Geometry.flat_shader = makeProgram(gl, "330 core", [GL_VERTEX_SHADER, GL_FRAGMENT_SHADER],
				open("shaders/flat_color_shader.glsl").read())



		self.verts = v
		self.vertToFaces = vtf
		self.faces = f
		self.selected = []
		self.constrained = []


		# Creating the VAO and VBO(s) for mesh
		# 
		self.vao = GLuint(0)
		gl.glGenVertexArrays(1, self.vao)
		gl.glBindVertexArray(self.vao)

		# Index IBO
		idx_array = pygloo.c_array(GLuint, _flatten_list(self.faces))
		self.ibo = GLuint(0)
		self.ibo_size = len(idx_array)
		gl.glGenBuffers(1, self.ibo)
		gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo);
		gl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idx_array), idx_array, GL_STATIC_DRAW);

		# Vertex Position VBO
		self.vbo_pos = GLuint(0)
		gl.glGenBuffers(1, self.vbo_pos)
		gl.glBindVertexArray(0)



		# Creating the VAO(s) for selected/constrained points
		#

		# Selected
		self.vao_selected = GLuint(0)
		gl.glGenVertexArrays(1, self.vao_selected)
		gl.glBindVertexArray(self.vao_selected)

		self.ibo_selected = GLuint(0)
		gl.glGenBuffers(1, self.ibo_selected)

		# Constrained
		self.vao_constrained = GLuint(0)
		gl.glGenVertexArrays(1, self.vao_constrained)
		gl.glBindVertexArray(self.vao_constrained)

		self.ibo_constrained = GLuint(0)
		gl.glGenBuffers(1, self.ibo_constrained)



		# Make the update
		self.update(gl)
示例#15
0
    def __init__(self, gl, v=[], vtf=[], f=[]):
        if not Geometry.solid_shader:
            Geometry.solid_shader = makeProgram(
                gl, "330 core",
                [GL_VERTEX_SHADER, GL_GEOMETRY_SHADER, GL_FRAGMENT_SHADER],
                open("shaders/solid_shader.glsl").read())

        if not Geometry.wire_shader:
            Geometry.wire_shader = makeProgram(
                gl, "330 core",
                [GL_VERTEX_SHADER, GL_GEOMETRY_SHADER, GL_FRAGMENT_SHADER],
                open("shaders/wireframe_shader.glsl").read())

        if not Geometry.flat_shader:
            Geometry.flat_shader = makeProgram(
                gl, "330 core", [GL_VERTEX_SHADER, GL_FRAGMENT_SHADER],
                open("shaders/flat_color_shader.glsl").read())

        self.verts = v
        self.vertToFaces = vtf
        self.faces = f
        self.selected = []
        self.constrained = []

        # Creating the VAO and VBO(s) for mesh
        #
        self.vao = GLuint(0)
        gl.glGenVertexArrays(1, self.vao)
        gl.glBindVertexArray(self.vao)

        # Index IBO
        idx_array = pygloo.c_array(GLuint, _flatten_list(self.faces))
        self.ibo = GLuint(0)
        self.ibo_size = len(idx_array)
        gl.glGenBuffers(1, self.ibo)
        gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ibo)
        gl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(idx_array), idx_array,
                        GL_STATIC_DRAW)

        # Vertex Position VBO
        self.vbo_pos = GLuint(0)
        gl.glGenBuffers(1, self.vbo_pos)
        gl.glBindVertexArray(0)

        # Creating the VAO(s) for selected/constrained points
        #

        # Selected
        self.vao_selected = GLuint(0)
        gl.glGenVertexArrays(1, self.vao_selected)
        gl.glBindVertexArray(self.vao_selected)

        self.ibo_selected = GLuint(0)
        gl.glGenBuffers(1, self.ibo_selected)

        # Constrained
        self.vao_constrained = GLuint(0)
        gl.glGenVertexArrays(1, self.vao_constrained)
        gl.glBindVertexArray(self.vao_constrained)

        self.ibo_constrained = GLuint(0)
        gl.glGenBuffers(1, self.ibo_constrained)

        # Make the update
        self.update(gl)