Ejemplo n.º 1
0
	def runningSession(self):
		try:
			GL_shaders.glUseProgram(self.shader)
			self.myTexture2D.bind(0) # Passed an id which is also passed to shader via uniforms
			self.whatevs.bind(1)
			self.myModel.bind()
			
			GL.glUniformMatrix4fv(
				self.UNIFORMS['my_ModelMatrix'],1, GL.GL_TRUE,
				self.ModelMatrix.get())
            
			GL.glUniformMatrix4fv(
				self.UNIFORMS['my_ViewMatrix'],1, GL.GL_TRUE,
				self.ViewMatrix.get())
            
			GL.glUniformMatrix4fv(
				self.UNIFORMS['my_ProjectionMatrix'],1, GL.GL_TRUE,
				self.ProjectionMatrix.get())
			
			GL.glUniform1i(self.UNIFORMS['tex0'], 0) # same id as passed to texture2D.bind()
			GL.glUniform1i(self.UNIFORMS['tex1'], 1)
		finally:
			self.myModel.unbind()
			self.whatevs.unbind()
			self.myTexture2D.unbind()
			GL_shaders.glUseProgram(0)
Ejemplo n.º 2
0
 def drawScene(self):
     #This is where we change graphics. Things in here won't actually be applied right away
     #to the canvas. So when this function is done, drawing will be applied right after.
     
     vbo = GLvbo.VBO(self.myTriangle)
     #The vertex-buffer-object has to stay in here since
     #it cannot be "selfed" or we get errors
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     
     GLshaders.glUseProgram(self.GLEngineShader)
     try: 
         vbo.bind()
         try:
             GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
             GL.glEnableClientState(GL.GL_COLOR_ARRAY)
             #GL.glVertexPointerf(vbo)
             GL.glVertexPointer(3, GL.GL_FLOAT, 24, vbo)
             GL.glColorPointer(3, GL.GL_FLOAT, 24, vbo+12)
             GL.glDrawArrays(GL.GL_TRIANGLES, 0, 9)
         finally:
             vbo.unbind()
             GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
             GL.glDisableClientState(GL.GL_COLOR_ARRAY)
     finally:
         GLshaders.glUseProgram(0)
Ejemplo n.º 3
0
    def DrawBlock(self):
        global _lightVector

        shaders.glUseProgram(self.shader)
        invT = np.linalg.inv(glGetDouble(GL_MODELVIEW_MATRIX)).transpose()
        glUniformMatrix4fv(self.uniformInvT, 1, False, invT)
        try:
            self.vbo.bind()
            try:
                glEnableVertexAttribArray(self.position)
                glEnableVertexAttribArray(self.color)
                glEnableVertexAttribArray(self.vertex_normal)
                stride = 44
                glVertexAttribPointer(self.position, 3, GL_FLOAT, False,
                                      stride, self.vbo)
                glVertexAttribPointer(self.color, 3, GL_FLOAT, False, stride,
                                      self.vbo + 12)
                glVertexAttribPointer(self.vertex_normal, 3, GL_FLOAT, True,
                                      stride, self.vbo + 24)
                glDrawArrays(GL_QUADS, 0, 24)

            finally:
                self.vbo.unbind()
                glDisableVertexAttribArray(self.position)
                glDisableVertexAttribArray(self.color)
                glDisableVertexAttribArray(self.vertex_normal)
        finally:
            shaders.glUseProgram(0)
Ejemplo n.º 4
0
    def __init__(self, screen):
        self.rot_x = 0
        self.rot_y = 0
        self.lines = False
        self.pause = False
        # glEnable(GL_LIGHTING)
        # glEnable(GL_LIGHT0)
        vs_source = open('shaders/' + vert_name, "r")
        vs_source = vs_source.read()
        VERTEX_SHADER = shaders.compileShader(vs_source, GL_VERTEX_SHADER)

        fs_source = open('shaders/' + frag_name, "r")
        fs_source = fs_source.read()
        FRAGMENT_SHADER = shaders.compileShader(fs_source, GL_FRAGMENT_SHADER)

        self.shader = shaders.compileProgram(VERTEX_SHADER, FRAGMENT_SHADER)

        # glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE)
        shaders.glUseProgram(self.shader)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)
        light_position = [0.0, -1.0, 1.0, 1.0]
        glLightfv(GL_LIGHT0, GL_POSITION, light_position)
        glShadeModel(GL_SMOOTH)
        self.screen = screen
        self.aspect = screen.get_width() / screen.get_height()
        gluPerspective(45.0, self.aspect, 0.1, 200.0)

        glClearColor(0.0, 0.0, 0.0, 1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        return
	def paintGL_UnProjector(self):
		if not self.shader_UnProjector: self.__init__UnProjector()

		glUseProgram(self.shader_UnProjector)

		v=	glGetFloatv(GL_VIEWPORT)
		glUniform2f(self.res, v[2],v[3])

		c1,c2=self.centroids
		glUniform3f(self.c1, *c1)
		glUniform3f(self.c2, *c2)

		v=	glGetIntegerv( GL_VIEWPORT )
		m=	glGetDoublev( GL_MODELVIEW_MATRIX )
		p=	glGetDoublev( GL_PROJECTION_MATRIX )

		w,h=v[2:] ; kwa={'modelMatrix':m, 'projMatrix':p, 'viewport':v}

		#nearz,farz=0,-1
		nearz,farz=-1,0 # because 0,1 dont work. So far will be origin plane
		glUniform3f(self.near11,	*UnProject(0,0,nearz,	**kwa))
		glUniform3f(self.near12,	*UnProject(0,h,nearz,	**kwa))
		glUniform3f(self.near21,	*UnProject(w,0,nearz,	**kwa))
		glUniform3f(self.near22,	*UnProject(w,h,nearz,	**kwa))

		glUniform3f(self.far11,		*UnProject(0,0,farz,	**kwa))
		glUniform3f(self.far12,		*UnProject(0,h,farz,	**kwa))
		glUniform3f(self.far21,		*UnProject(w,0,farz,	**kwa))
		glUniform3f(self.far22,		*UnProject(w,h,farz,	**kwa))

		#glRectf(-.75,-.75,.75,.75)
		glRectf(-1,-1,1,1)
Ejemplo n.º 6
0
    def _render_in_mode(self, mvp, points_vbo, colors_vbo, count, mode):
        shaders.glUseProgram(self._program)
        GL.glUniformMatrix4fv(GL.glGetUniformLocation(self._program, 'mvp'), 1,
                              True, mvp)

        points_vbo.bind()
        arg_position = GL.glGetAttribLocation(self._program, 'position')
        GL.glEnableVertexAttribArray(arg_position)
        GL.glVertexAttribPointer(arg_position, 3, GL.GL_FLOAT, False, 0,
                                 points_vbo)

        colors_vbo.bind()
        arg_in_color = GL.glGetAttribLocation(self._program, 'in_color')
        GL.glEnableVertexAttribArray(arg_in_color)
        GL.glVertexAttribPointer(arg_in_color, 3, GL.GL_FLOAT, False, 0,
                                 colors_vbo)

        GL.glDrawArrays(mode, 0, count)

        points_vbo.unbind()
        colors_vbo.unbind()

        GL.glDisableVertexAttribArray(arg_position)
        GL.glDisableVertexAttribArray(arg_in_color)
        shaders.glUseProgram(0)
Ejemplo n.º 7
0
 def Render(self, mode):
     """Render the geometry for the scene."""
     shaders.glUseProgram(self.shader)
     try:
         self.vbo.bind()
         try:
             glEnableClientState(GL_VERTEX_ARRAY)
             glVertexPointerf(self.vbo)
             glDrawArrays(GL_TRIANGLES, 0, 9)
         finally:
             self.vbo.unbind()
             glDisableClientState(GL_VERTEX_ARRAY)
             # self.vbo = vbo.VBO(
             # 	array( [
             # 		[  2,-1, 0 ],
             # 		[  4,-1, 0 ],
             # 		[  4, 1, 0 ],
             # 		[  2,-1, 0 ],
             # 		[  4, 1, 0 ],
             # 		[  2, 1, 0 ],
             # 		# [  2,-2, 0 ],
             # 		# [  4,-2, 0 ],
             # 		# [  4, 0, 0 ],
             # 		# [  2,-2, 0 ],
             # 		# [  4, 0, 0 ],
             # 		# [  2, 0, 0 ],
             # 	],'f')
             # )
     finally:
         shaders.glUseProgram(0)
Ejemplo n.º 8
0
def unprep(state):
	(glEnable if state["blend"] else glDisable)(GL_BLEND)
	shaders.glUseProgram(state["program"])
	glBlendFunc(state["srcfunc"], state["dstfunc"])
	(glEnableVertexAttribArray if state["penable"] else glDisableVertexAttribArray)(_locations["p"])
	# glVertexAttribPointer(_locations["p"], state["psize"], state["ptype"], state["pnorm"], state["pstride"], state["ppointer"])
	pass
Ejemplo n.º 9
0
def cubeModel(shader):
    glTranslate(3.0,0.,0.)
    shaders.glUseProgram(shader)
    myUniformLocation = glGetUniformLocation(shader, "myUniform");
    glUniform4f(myUniformLocation, 0.9,0.3,0.3,1.0);    
    glutSolidCube(1.)  
    glDeleteProgram(shader)  
def on_display():
    for i in range(0, updates_per_frame):
        lattice.evolve()

    lattice.update_moments()
    moments_texture.collect()

    for i in range(0, updates_per_frame):
        particles.update(aging=False)

    lattice.sync()

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    shaders.glUseProgram(shader_program)
    glUniformMatrix4fv(projection_id, 1, False,
                       numpy.asfortranarray(projection))
    moments_texture.bind()

    glBegin(GL_POLYGON)
    glVertex(0, 0, 0)
    glVertex(lattice.geometry.size_x, 0, 0)
    glVertex(lattice.geometry.size_x, lattice.geometry.size_y, 0)
    glVertex(0, lattice.geometry.size_y, 0)
    glEnd()

    shaders.glUseProgram(particle_program)
    glUniformMatrix4fv(particle_projection_id, 1, False,
                       numpy.asfortranarray(projection))
    particles.bind()
    glPointSize(point_size)
    glDrawArrays(GL_POINTS, 0, particles.count)

    glutSwapBuffers()
Ejemplo n.º 11
0
def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
    glutInitWindowSize(800, 800)
    glutCreateWindow('fluid')

    FRAGMENT_SHADER = shaders.compileShader(
        """#version 120
        void main() {
            gl_FragColor = vec4( 0, 1, 0, 1 );
        }""", GL_FRAGMENT_SHADER
    )

    shader = shaders.compileProgram(FRAGMENT_SHADER)
    shaders.glUseProgram(shader)

    glutDisplayFunc(display)
    glutIdleFunc(display)

    glMatrixMode(GL_PROJECTION)
    gluPerspective(40.0, 1.0, 1.0, 200.0)
    glMatrixMode(GL_MODELVIEW)

    gluLookAt(0, 0, 180,
              0, 0, 0,
              0, 1, 0)

    glPushMatrix()
    glutMainLoop()

    return
Ejemplo n.º 12
0
    def draw(self):

        for polIdx, pol in zip(range(len(self.verts)), self.verts):
            
            GL.glActiveTexture(GL.GL_TEXTURE0+polIdx)
            GL.glBindTexture(GL.GL_TEXTURE_2D, self.texIdx[polIdx])
            
            shaders.glUseProgram(self.shader)
            loc = GL.glGetUniformLocation(self.shader, "u_translate")
            GL.glUniformMatrix4fv(loc, 1, GL.GL_FALSE, self.translationMatrix.matrix)
            loc = GL.glGetUniformLocation(self.shader, "u_rotate")
            GL.glUniformMatrix4fv(loc, 1, GL.GL_FALSE, self.rotationMatrix.matrix)
            loc = GL.glGetUniformLocation(self.shader, "u_scale")
            GL.glUniformMatrix4fv(loc, 1, GL.GL_FALSE, self.scalingMatrix.matrix)
            loc = GL.glGetUniformLocation(self.shader, "u_texture")
            GL.glUniform1i(loc, polIdx)
            loc = GL.glGetUniformLocation(self.shader, "u_rotationCenter")
            GL.glUniform4fv(loc, 1, self.rotationCenter)
            
            GL.glBegin(GL.GL_POLYGON)
            
            GL.glTexCoord2f(1.0-self.uvs[polIdx][0][0], 1.0-self.uvs[polIdx][0][1])
            GL.glVertex3f(pol[0][0], pol[0][1], pol[0][2])
            GL.glTexCoord2f(1.0-self.uvs[polIdx][0][0], 1.0-self.uvs[polIdx][1][1])
            GL.glVertex3f(pol[1][0], pol[1][1], pol[1][2])
            GL.glTexCoord2f(1.0-self.uvs[polIdx][1][0], 1.0-self.uvs[polIdx][1][1])
            GL.glVertex3f(pol[2][0], pol[2][1], pol[2][2])
            GL.glTexCoord2f(1.0-self.uvs[polIdx][1][0], 1.0-self.uvs[polIdx][0][1])
            GL.glVertex3f(pol[3][0], pol[3][1], pol[3][2])
            
            GL.glEnd()
            
            shaders.glUseProgram(0)
Ejemplo n.º 13
0
    def paint(self, mvp_matrix):
        if not self._is_initialized:
            self.initialize()
            self._is_initialized = True

        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glEnableClientState(gl.GL_INDEX_ARRAY)

        shaders.glUseProgram(self._shader)

        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vertex_vbo)
        gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, self._index_vbo)

        gl.glPolygonMode(gl.GL_FRONT, gl.GL_LINE)
        gl.glPolygonMode(gl.GL_BACK, gl.GL_LINE)

        gl.glUniformMatrix4fv(self._mvp_handle, 1, gl.GL_FALSE, mvp_matrix);
        gl.glEnableVertexAttribArray(self._position_handle)
        for mesh in self._model._meshes:
            if self._model._vertex_type == b'\x02':
                gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, False, mesh._vertex_size, ctypes.c_void_p(mesh._vertex_buffer_offset))
            elif self._model._vertex_type == b'\x0E':
                gl.glVertexAttribPointer(0, 3, half_float_vertex.GL_HALF_FLOAT, False, mesh._vertex_size, ctypes.c_void_p(mesh._vertex_buffer_offset))
            else:
                raise Exception('Unknown vertex_type: %s' % self._model._vertex_type)
            gl.glDrawElements(gl.GL_TRIANGLES, mesh._index_count, gl.GL_UNSIGNED_SHORT, ctypes.c_void_p(mesh._index_buffer_offset * 2))
        gl.glDisableVertexAttribArray(self._position_handle)

        shaders.glUseProgram(0)

        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
        gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, 0)

        gl.glDisableClientState(gl.GL_INDEX_ARRAY)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
Ejemplo n.º 14
0
	def Render(self, mode=0):
		"""Render the geometry for the scene."""
		super(TestContext, self).Render(mode)
		glUseProgram(self.shader)
		glUniform1f(self.tween_location, self.tween_fraction)
		try:
			self.vbo.bind()
			try:
				glEnableVertexAttribArray(self.position_location)
				glEnableVertexAttribArray(self.tweened_location)
				glEnableVertexAttribArray(self.color_location)
				stride = 4 * 9
				glVertexAttribPointer(
					self.position_location, 
					3, GL_FLOAT, False, stride, self.vbo)
				glVertexAttribPointer(
					self.tweened_location, 
					3, GL_FLOAT, False, stride, self.vbo + 12)
				glVertexAttribPointer(
					self.color_location, 
					3, GL_FLOAT, False, stride, self.vbo + 24)
				glDrawArrays(GL_TRIANGLES, 0, 9)
			finally:
				self.vbo.unbind()
				glDisableVertexAttribArray(self.position_location)
				glDisableVertexAttribArray(self.tweened_location)
				glDisableVertexAttribArray(self.color_location)
		finally:
			shaders.glUseProgram(0)
Ejemplo n.º 15
0
 def render(self):
     try:
         GL_shaders.glUseProgram(self.shader)
         try:
             GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vbo)
             
             GL.glVertexAttribPointer( # Vertex data
                 0,                  # Attribute 0 in this attribute array
                 3,                  # This attribute uses 3 elements
                 GL.GL_FLOAT,        # These values are of type "GL_FLOAT"
                 False,              # Normalize values? No!
                 self.vertex_data.shape[1]*c.sizeof(c.c_float), # bits per row, 4 bits for floats, 6 elements in one row (doubles are 8)
                 c.c_void_p(0))               # Where in each row does attribute start?
             GL.glEnableVertexAttribArray(0)
             
             GL.glVertexAttribPointer( # Extra vertex data
                 1,
                 3,
                 GL.GL_FLOAT,
                 False,
                 self.vertex_data.shape[1]*c.sizeof(c.c_float),
                 c.c_void_p(3*4))
             GL.glEnableVertexAttribArray(1)
             
             GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, self.ibo)
             GL.glDrawElements(
                 GL.GL_TRIANGLES,
                 self.index_data.size,
                 GL.GL_UNSIGNED_INT, c.c_void_p(0))
         finally:
             GL.glDisableVertexAttribArray(0)
             GL.glDisableVertexAttribArray(1)
             GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
     finally:
         GL_shaders.glUseProgram(0)
Ejemplo n.º 16
0
    def _render(self, mvp, v_buffer, shader, c_buffer=None, points=True):
        ctn = len(v_buffer) // 3

        shaders.glUseProgram(shader)
        v_buffer.bind()
        GL.glUniformMatrix4fv(GL.glGetUniformLocation(shader, 'mvp'), 1, True,
                              mvp)

        position_loc = GL.glGetAttribLocation(shader, 'position_in')
        GL.glEnableVertexAttribArray(position_loc)
        GL.glVertexAttribPointer(position_loc, 3, GL.GL_FLOAT, False, 0,
                                 v_buffer)
        if c_buffer is None:
            color_loc = GL.glGetAttribLocation(shader, 'color_in')
            GL.glVertexAttrib3fv(color_loc,
                                 np.array([1, 1, 0], dtype=np.float32))

        v_buffer.unbind()

        if c_buffer is not None:
            c_buffer.bind()
            color_loc = GL.glGetAttribLocation(shader, 'color_in')
            GL.glEnableVertexAttribArray(color_loc)
            GL.glVertexAttribPointer(color_loc, 3, GL.GL_FLOAT, False, 0,
                                     c_buffer)

            c_buffer.unbind()

        GL.glDrawArrays(GL.GL_POINTS if points else GL.GL_LINES, 0, ctn)

        GL.glDisableVertexAttribArray(position_loc)
        if c_buffer is not None:
            GL.glDisableVertexAttribArray(color_loc)
        shaders.glUseProgram(0)
Ejemplo n.º 17
0
	def renderTranslucent(self):
		try:
			GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, self.translucentFBO)
			GL.glClearBufferfv(GL.GL_DEPTH, 0, 1)
			GL_shaders.glUseProgram(self.shaderTranslucent)
			self.tex1.bind(0)
			self.model2.bind()
			
			GL.glUniformMatrix4fv(
					self.UNIFORMSTranslucent['my_ModelMatrix'],1, GL.GL_TRUE,
					self.ModelMatrix.get())
				
			GL.glUniformMatrix4fv(
				self.UNIFORMSTranslucent['my_ViewMatrix'],1, GL.GL_TRUE,
				self.ViewMatrix.get())
			
			GL.glUniformMatrix4fv(
				self.UNIFORMSTranslucent['my_ProjectionMatrix'],1, GL.GL_TRUE,
				self.ProjectionMatrix.get())
			
			GL.glUniform1i(self.UNIFORMSTranslucent['tex0'], 0)
		finally:
			self.model2.unbind()
			self.tex1.unbind()
			GL_shaders.glUseProgram(0)
			GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0)
    def _render_object(mvp, position, color, program, n_points, uniform_color=False, drawing_object=GL.GL_POINTS):
        shaders.glUseProgram(program)
        GL.glUniformMatrix4fv(
            GL.glGetUniformLocation(program, 'mvp'),
            1, True, mvp)

        # If color is fragment-level then use uniform, pass an array otherwise
        if uniform_color:
            GL.glUniform3fv(
                GL.glGetUniformLocation(program, 'color'),
                1, color)
        else:
            color.bind()
            color_loc = GL.glGetAttribLocation(program, 'color')
            GL.glEnableVertexAttribArray(color_loc)
            GL.glVertexAttribPointer(color_loc, 3, GL.GL_FLOAT,
                                     False, 0,
                                     color)

        position.bind()
        position_loc = GL.glGetAttribLocation(program, 'position')
        GL.glEnableVertexAttribArray(position_loc)
        GL.glVertexAttribPointer(position_loc, 3, GL.GL_FLOAT,
                                 False, 0,
                                 position)
        GL.glDrawArrays(drawing_object, 0, n_points)

        GL.glDisableVertexAttribArray(position_loc)
        position.unbind()
        if not uniform_color:
            GL.glDisableVertexAttribArray(color_loc)
            color.unbind()
        shaders.glUseProgram(0)
Ejemplo n.º 19
0
 def render( self, mode, shader=None ):
     """Render this shader in the current mode"""
     renderer = mode.cache.getData(self)
     if renderer is None:
         renderer = self.compile( mode, shader )
         if renderer is False:
             log.warn("""%s""",
                 self.compileLog,
             )
     if renderer not in (None,False):
         try:
             GL_shaders.glUseProgram( renderer )
         except error.GLError, err:
             log.error( '''Failure compiling: %s''', '\n'.join([
                 '%s: %s'%(shader.url or shader.source,shader.compileLog)
                 for shader in self.shaders
             ]))
             raise
         else:
             for uniform in mode.uniforms:
                 uniform.render( self, mode )
             for uniform in self.uniforms:
                 uniform.render( self, mode )
             # TODO: retrieve maximum texture count and restrict to that...
             i = 0
             for texture in self.textures:
                 if texture.render( self, mode, i ):
                     i += 1
Ejemplo n.º 20
0
def scenemodel(shader):
    # glRotate(90,0.,0.,1.)
    shaders.glUseProgram(shader)
    myUniformLocation = glGetUniformLocation(shader, "myUniform");
    glUniform4f(myUniformLocation, 0.2,0.5,1.0,1.0);
    glutSolidTeapot(1.)
    glDeleteProgram(shader)
Ejemplo n.º 21
0
    def Render( self, mode):
        """Render the geometry for the scene."""

        BaseContext.Render( self, mode )
        if not mode.visible:
            return

        self.ViewPort( self.width, self.height )

        shaders.glUseProgram(self.shader)

        glUniform2f( self.UNIFORM_LOCATIONS['viewport'], self.width, self.height )
        glUniform1f( self.UNIFORM_LOCATIONS['pointSizeThreshold'], 0.0 )
        glUniform1f( self.UNIFORM_LOCATIONS['MaxPixelSize'], 50.0 )
        glUniform1f( self.UNIFORM_LOCATIONS['ConstantRadius'], 1.0 )

        glRotate( 45, 0,1,0 )
        glScale( 3,3,3 )

        # Clear The Screen And The Depth Buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        try:
            self.vbo.bind()
            try:
                glEnableClientState( GL_VERTEX_ARRAY );
                glEnable( GL_PROGRAM_POINT_SIZE );
                glVertexPointerf( self.vbo )
                # glDrawArrays( GL_TRIANGLES, 0, 9 )
                glDrawArrays( GL_POINTS, 0, 9 )
            finally:
                self.vbo.unbind()
                glDisableClientState( GL_VERTEX_ARRAY );
        finally:
            shaders.glUseProgram( 0 )
Ejemplo n.º 22
0
    def draw(self):
        glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)

        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, self.pfmtexobj)
        glActiveTexture(GL_TEXTURE1)
        glBindTexture(GL_TEXTURE_2D, self.media.texobj)
        glActiveTexture(GL_TEXTURE2)
        glBindTexture(GL_TEXTURE_2D, self.blend.texobj)

        shaders.glUseProgram(self.shader)
        glUniform1i(self.texture0Loc, 0)
        glUniform1i(self.texture1Loc, 1)
        glUniform1i(self.texture2Loc, 2)
        glUniform1f(self.blendGammaLoc, self.blendGamma)
        glUniform1f(self.targetGammaLoc, self.targetGamma)
        glUniform1f(self.mediaGammaLoc, self.mediaGamma)
        glUniformMatrix4fv(self.warpMatLoc, 1, GL_FALSE, self.warpMat)

        glEnableClientState(GL_VERTEX_ARRAY)
        glEnableClientState(GL_TEXTURE_COORD_ARRAY)

        glBindBuffer(GL_ARRAY_BUFFER, self.vertdata)
        glVertexPointer(2, GL_FLOAT, 0, None)
        glTexCoordPointer(2, GL_FLOAT, 0, None)

        glDrawArrays(GL_TRIANGLES, 0, 6)

        glUseProgram(0)

        glPopClientAttrib()

        self.saveOutputImage()
Ejemplo n.º 23
0
	def Render(self, mode=0):
		"""Render the geometry for the scene."""
		super(TestContext, self).Render(mode)
		glUseProgram(self.shader)
		try:
			self.vbo.bind()
			try:
				glUniform4f(self.light_ambient_location, 0.2, 0.2, 0.2, 1.0)
				glUniform4f(self.light_diffuse_location, 1, 0.8, 0.8, 1)
				glUniform3f(self.light_location_location, 2, 2, 10)
				glUniform4f(self.material_ambient_location, 0.2, 0.2, 0.8, 1.0)
				glUniform4f(self.material_diffuse_location, 1, 1, 1, 1)
				glEnableVertexAttribArray(self.vertex_position_location)
				glEnableVertexAttribArray(self.vertex_normal_location)
				stride = 6 * 4
				glVertexAttribPointer(
					self.vertex_position_location, 
					3, GL_FLOAT, False, stride, self.vbo)
				glVertexAttribPointer(
					self.vertex_normal_location,
					3, GL_FLOAT, False, stride, self.vbo + 12)
				glDrawArrays(GL_TRIANGLES, 0, 18)
			finally:
				self.vbo.unbind()
				glDisableVertexAttribArray(self.vertex_position_location)
				glDisableVertexAttribArray(self.vertex_normal_location)
		finally:
			shaders.glUseProgram(0)
Ejemplo n.º 24
0
    def _render_tracked_cam_track(self, view_proj):
        shaders.glUseProgram(self._shaders.line)
        try:
            self._buffer_objects.track.bind()
            position_loc = None
            try:
                GL.glUniformMatrix4fv(
                    GL.glGetUniformLocation(self._shaders.line, 'mvp'), 1,
                    True, view_proj)
                GL.glUniform3fv(
                    GL.glGetUniformLocation(self._shaders.line, 'color'), 1,
                    np.array([1, 1, 1], dtype=np.float32))

                position_loc = GL.glGetAttribLocation(self._shaders.line,
                                                      'position')
                GL.glEnableVertexAttribArray(position_loc)
                GL.glVertexAttribPointer(position_loc, 3, GL.GL_FLOAT, False,
                                         0, self._buffer_objects.track)
                GL.glDrawArrays(GL.GL_LINE_STRIP, 0,
                                self._buffer_objects.track.data.shape[0])
            finally:
                if position_loc is not None:
                    GL.glDisableVertexAttribArray(position_loc)
                self._buffer_objects.track.unbind()
        finally:
            shaders.glUseProgram(0)
Ejemplo n.º 25
0
 def Render(self, mode):
     '''render the geometry of the scene'''
     # tell opengl to use our shader
     shaders.glUseProgram(self.shader)
     try:
         # bind data into gpu
         self.vbo.bind()
         try:
             # tells opengl to access vertex once
             # we call a draw function
             glEnableClientState(GL_VERTEX_ARRAY)
             # point at our vbo data
             glVertexPointerf(self.vbo)
             # actually tell opengl to draw
             # the stuff in the VBO as a series
             # of triangles
             glDrawArrays(GL_TRIANGLES, 0, 9)
         finally:
             # cleanup, unbind the our data from gpu ram
             # and tell opengl that it should not
             # expect vertex arrays anymore
             self.vbo.unbind()
             glDisableClientState(GL_VERTEX_ARRAY)
     finally:
         # stop using our shader
         shaders.glUseProgram(0)
Ejemplo n.º 26
0
    def draw_scroll(self, offset, scale):
        glPushMatrix()

        shaders.glUseProgram(self.shader)

        glUniform1f(glGetUniformLocation(self.shader, "offset"), offset)
        glUniform1f(glGetUniformLocation(self.shader, "scale"), scale)

        self.vbo.bind()
        glColor4f(1.0, 0.0, 0.0, 1.0)
        glEnableClientState(GL_VERTEX_ARRAY)
        glVertexPointerf(None)

        vbo_edge = self.nrows % self.history
        strip_nvertices = (self.points - 1) * 4

        glPushMatrix()
        glTranslatef(0.0, -float(vbo_edge) / self.history, 0.0)
        glDrawArrays(GL_QUADS, strip_nvertices * (self.history - vbo_edge), strip_nvertices * vbo_edge)
        glPopMatrix()

        glPushMatrix()
        glTranslatef(0.0, -1.0 - float(vbo_edge) / self.history, 0.0)
        glDrawArrays(GL_QUADS, 0, strip_nvertices * (self.history - vbo_edge))
        glPopMatrix()

        glDisableClientState(GL_VERTEX_ARRAY)
        self.vbo.unbind()
        shaders.glUseProgram(0)

        glPopMatrix()
Ejemplo n.º 27
0
	def cleanup(self):
		'''
		Cleans up after the shader has been used
		'''
		glDisableVertexAttribArray(self.attrib_position)
		
		# Unbind the shader
		shaders.glUseProgram(0)
Ejemplo n.º 28
0
	def paintGL_Spheres(self):
		if not self.shader_Spheres: self.__init__Spheres()

		shaders.glUseProgram(self.shader_Spheres)

		c1,c2=self.centroids
		self.drawSphere( c1 , (1,0,0,1) )
		self.drawSphere( c2 , (0,0,1,1) )
Ejemplo n.º 29
0
    def paintGL(self):
        if GL.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER) == 33305:
            return
        
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)
        
        if not self.texture:
            return
            
        if not self.shader:
            self.compileShaders()

        if not self.vbo:
            self.vbo = GL.glGenBuffers(1)

        shaders.glUseProgram(self.shader)
               
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vbo)
        vertices = numpy.array(
            [-self.scale + self.cx, -self.scale + self.cy ,
             self.scale + self.cx, -self.scale + self.cy,
             self.scale + self.cx, self.scale + self.cy,
             -self.scale + self.cx, self.scale + self.cy,
            0,0,1,0,1,1,0,1], dtype = numpy.float32)
      
        GL.glBufferData(GL.GL_ARRAY_BUFFER, 64, vertices, GL.GL_STATIC_DRAW)
        
        loc = GL.glGetAttribLocation(self.shader, "positionIn")
        GL.glEnableVertexAttribArray(loc)
        GL.glVertexAttribPointer(loc, 2, GL.GL_FLOAT, 0, 8, c_void_p(0))
        
        loc = GL.glGetAttribLocation(self.shader, "texIn")
        GL.glEnableVertexAttribArray(loc)
        GL.glVertexAttribPointer(loc, 2, GL.GL_FLOAT, 0, 8, c_void_p(32))
              
        def _uniformLoc(name):
            return GL.glGetUniformLocation(self.shader,name)
        GL.glUniform1f(_uniformLoc("g"), self.gamma);
        GL.glUniform1f(_uniformLoc("m"), math.pow(2, self.exposure + 2.47393))
        GL.glUniform1f(_uniformLoc("s"), math.pow(2, -3.5 * self.gamma))
        GL.glUniform1i(_uniformLoc("hdr_mode"), self.hdr_mode);
        GL.glUniform1i(_uniformLoc("texture"), 0);
        GL.glActiveTexture(GL.GL_TEXTURE0);
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture)

        GL.glDrawArrays(GL.GL_QUADS, 0, 4);

        GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
        loc = GL.glGetAttribLocation(self.shader, "positionIn")
        GL.glDisableVertexAttribArray(loc)
        loc = GL.glGetAttribLocation(self.shader, "texIn")
        GL.glDisableVertexAttribArray(loc)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
        shaders.glUseProgram(0)
        
        if self.rightBtnDown:
            self.renderPixelInfo()
Ejemplo n.º 30
0
    def draw_content(self):
        glPushMatrix()
        glTranslated(-1.0, 0.0, 0.0)
        glScalef(2.0, 1.0, 1.0)

        self.shader.setup(self.mag_range)
        self.multitexture.draw_scroll(self.texture_edge)
        shaders.glUseProgram(0)
        glPopMatrix()
Ejemplo n.º 31
0
	def runningSession(self):
		try:
			GL_shaders.glUseProgram(self.shader) ##TODO: revise handling of shaders - objects?
			
			GL.glUniformMatrix4fv(
				self.UNIFORMS['my_ModelMatrix'],1, GL.GL_TRUE,
				self.ModelMatrix.get())
            
			GL.glUniformMatrix4fv(
				self.UNIFORMS['my_ViewMatrix'],1, GL.GL_TRUE,
				self.ViewMatrix.get())
            
			GL.glUniformMatrix4fv(
				self.UNIFORMS['my_ProjectionMatrix'],1, GL.GL_TRUE,
				self.ProjectionMatrix.get())
			try:
				GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vbo)
				
				GL.glVertexAttribPointer( # Vertex data
					0,                  # Attribute 0 in this attribute array
					3,                  # This attribute uses 3 elements
					GL.GL_FLOAT,        # These values are of type "GL_FLOAT"
					False,              # Normalize values? No!
					self.vertex_data.shape[1]*c.sizeof(c.c_float), # bits per row, 4 bits for floats, 6 elements in one row (doubles are 8)
					c.c_void_p(0))               # Where in each row does attribute start?
				GL.glEnableVertexAttribArray(0)
				
				GL.glVertexAttribPointer( # Vertex data
					1,                  # Attribute 0 in this attribute array
					3,                  # This attribute uses 3 elements
					GL.GL_FLOAT,        # These values are of type "GL_FLOAT"
					False,              # Normalize values? No!
					self.vertex_data.shape[1]*c.sizeof(c.c_float), # bits per row, 4 bits for floats, 6 elements in one row (doubles are 8)
					c.c_void_p(3*4))               # Where in each row does attribute start?
				GL.glEnableVertexAttribArray(0)
				
				GL.glVertexAttribPointer( # Vertex data
					2,                  # Attribute 0 in this attribute array
					2,                  # This attribute uses 3 elements
					GL.GL_FLOAT,        # These values are of type "GL_FLOAT"
					False,              # Normalize values? No!
					self.vertex_data.shape[1]*c.sizeof(c.c_float), # bits per row, 4 bits for floats, 6 elements in one row (doubles are 8)
					c.c_void_p(6*4))               # Where in each row does attribute start?
				GL.glEnableVertexAttribArray(0)

				GL.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, self.ibo)
				GL.glDrawElements(
					GL.GL_TRIANGLES,
					self.vertex_index.size,
					GL.GL_UNSIGNED_INT, c.c_void_p(0))
			finally:
				GL.glDisableVertexAttribArray(0)
				GL.glDisableVertexAttribArray(1)
				GL.glBindBuffer(GL.GL_ARRAY_BUFFER, 0)
		finally:
			GL_shaders.glUseProgram(0)
Ejemplo n.º 32
0
    def setup(self, mag_range):
        scale = (self.TEX_RANGE[1] - self.TEX_RANGE[0]) / (mag_range[1] - mag_range[0]) * (self.M2C_RANGE[1] - self.M2C_RANGE[0])
        shift = (self.TEX_RANGE[0] - mag_range[0]) / (self.TEX_RANGE[1] - self.TEX_RANGE[0]) + self.M2C_RANGE[0] / scale

        shaders.glUseProgram(self.program)

        glUniform1i(glGetUniformLocation(self.program, "sampler"), 0)
        glUniform1f(glGetUniformLocation(self.program, "scale"), scale)
        glUniform1f(glGetUniformLocation(self.program, "shift"), shift)
        glActiveTexture(GL_TEXTURE0)
Ejemplo n.º 33
0
 def __exit__(self, exc_type, exc_value, traceback):
     try:
         while self._attr_enabled:
             loc = self._attr_enabled.pop()
             G.glDisableVertexAttribArray(loc)
     finally:
         try:
             if self._indices_vbo is not None:
                 self._indices_vbo.unbind()
             self._vbo.unbind()
         finally:
             shaders.glUseProgram(0)
Ejemplo n.º 34
0
 def compileProgram(self):
     '''
     Compiles the vertex shader and the fragment shader and
     runs glUseProgram on the resulting program object
     '''
     # Compile each shader
     vertex_shader = shaders.compileShader(vs_src, GL_VERTEX_SHADER)
     fragment_shader = shaders.compileShader(fs_src, GL_FRAGMENT_SHADER)
     # Compile and link the program
     self.shader = shaders.compileProgram(vertex_shader, fragment_shader)
     # Tells the GL Context that this is the pipeline to use.
     shaders.glUseProgram(self.shader)
Ejemplo n.º 35
0
 def render(self):
     GL_shaders.glUseProgram(self.shader)
     GL.glUniform1f(self.UNIFORMS['a'], 0.5)
     GL.glUniform4f(self.UNIFORMS['b'], 1.0, 1.0, 0.0, 1.0)
     GL.glUniform1i(self.UNIFORMS['s'], 0)
     GL.glUniform1i(self.UNIFORMS['t'], 1)
     
     try:
         self.vbo.bind() # Select "self.vbo"
         self.ibo.bind() # Select "self.ibo"
         #  It won't deselect "self.vbo" since they target different buffers
         try:
             GL.glEnableVertexAttribArray(0)
             GL.glEnableVertexAttribArray(1)
             GL.glEnableVertexAttribArray(2)
             
             GL.glVertexAttribPointer( # Vertex data, maybe...
                 0,              # Attribute 0 in this attribute array
                 3,              # This attribute uses 3 elements
                 GL.GL_FLOAT,    # These values are of type "GL_FLOAT"
                 False,          # Normalize values? No!
                 8*4,            # bits per row, 4 bits for floats, 6 elements in one row (doubles are 8)
                 self.vbo)       # Where in each row does attribute start? A little unintuitive...
             
             GL.glVertexAttribPointer( # Normal data, maybe...
                 1,
                 3,
                 GL.GL_FLOAT,
                 False,
                 8*4,
                 self.vbo + 3*4)
                 
             GL.glVertexAttribPointer( # UV-mapping data, maybe...
                 2,
                 2,
                 GL.GL_FLOAT,
                 False,
                 8*4,
                 self.vbo + 6*4)
             
             GL.glDrawElements(
                 GL.GL_TRIANGLES,
                 6, ##TODO: create method that gets number of indices in IBO!
                 GL.GL_UNSIGNED_INT, self.ibo)
         finally:
             self.vbo.unbind()
             self.ibo.unbind()
             GL.glDisableVertexAttribArray(0)
             GL.glDisableVertexAttribArray(1)
             GL.glDisableVertexAttribArray(2)
     finally:
         GL_shaders.glUseProgram(0)
Ejemplo n.º 36
0
 def Render(self, mode):
     GLshaders.glUseProgram(self.myShader)
     try:
         self.vbo.bind()
         try:
             GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
             GL.glVertexPointerf(self.vbo)
             GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3)
         finally:
             self.vbo.unbind()
             GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
     finally:
         GLshaders.glUseProgram(0)
Ejemplo n.º 37
0
def render():
  # blue bg
  blue = (0.0, 0.0, 1.0, 0.0)
  glClearColor(*blue)
  glClear(GL_COLOR_BUFFER_BIT)

  # this should go in an init function really
  # http://pyopengl.sourceforge.net/context/tutorials/shader_1.html
  VERTEX_SHADER = shaders.compileShader("""
    #version 120
    void main() {
      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    }
  """, GL_VERTEX_SHADER)

  FRAGMENT_SHADER = shaders.compileShader("""
    #version 120
    void main() {
      gl_FragColor = vec4( 0, 1, 0, 1 );
    }
  """, GL_FRAGMENT_SHADER)

  shader = shaders.compileProgram(VERTEX_SHADER,FRAGMENT_SHADER)

  myvbo = vbo.VBO(
    array( [
      [  0, 1, 0 ],
      [ -1,-1, 0 ],
      [  1,-1, 0 ],
      [  2,-1, 0 ],
      [  4,-1, 0 ],
      [  4, 1, 0 ],
      [  2,-1, 0 ],
      [  4, 1, 0 ],
      [  2, 1, 0 ],
    ],'f')
  )

  shaders.glUseProgram(shader)
  try:
    myvbo.bind()
    try:
      glEnableClientState(GL_VERTEX_ARRAY);
      glVertexPointerf(myvbo)
      glDrawArrays(GL_TRIANGLES, 0, 9)
    finally:
      myvbo.unbind()
      glDisableClientState(GL_VERTEX_ARRAY);
  finally:
    shaders.glUseProgram(0)
Ejemplo n.º 38
0
	def Render(self, mode):
		"""Render the geometry for the scene."""
		shaders.glUseProgram(self.shader)
		try:
			self.vbo.bind()
			try:
				glEnableClientState(GL_VERTEX_ARRAY)
				glVertexPointerf(self.vbo)
				glDrawArrays(GL_TRIANGLES, 0, 9)
			finally:
				self.vbo.unbind()
				glDisableClientState(GL_VERTEX_ARRAY)
		finally:
			shaders.glUseProgram(0)
Ejemplo n.º 39
0
 def render(self):
     GL_shaders.glUseProgram(self.shader)
     try:
         self.vbo.bind()
         try:
             GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
             GL.glVertexPointerf(self.vbo)
         
             # Draw triangles, start at 0 in vbo and continue for 3 entries (one triangle!)
             GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3)
         finally:
             self.vbo.unbind()
             GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
     finally:
         GL_shaders.glUseProgram(0)
Ejemplo n.º 40
0
	def renderComposition(self):
		try:
			GL_shaders.glUseProgram(self.shaderComposition)
			GL.glActiveTexture(GL.GL_TEXTURE0 + 0)
			GL.glBindTexture(GL.GL_TEXTURE_2D, self.opaqueDEPTHtex)
			GL.glActiveTexture(GL.GL_TEXTURE0 + 1)
			GL.glBindTexture(GL.GL_TEXTURE_2D, self.translucentDEPTHtex)
			self.canvas.bind()
			
			GL.glUniform1i(self.UNIFORMSComposition['tex0'], 0)
			GL.glUniform1i(self.UNIFORMSComposition['tex1'], 1)
		finally:
			self.canvas.unbind()
			GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
			GL_shaders.glUseProgram(0)
Ejemplo n.º 41
0
def paint():
            #print("DRAW")
    if not initialized:
        init()
    shaders.glUseProgram(shader_program)

    old_warnings = warnings[:]
    warnings.clear()

    #re-bind the textures every draw, to be safe
    for texnr, tex in enumerate(texture_locations):
        gl.glActiveTexture(gl.GL_TEXTURE0+texnr)
        loc = texture_locations[tex]
        gl.glUniform1i(loc, texnr)
        store = texdict[tex]
        store.bind()

    for uniform in list(uniform_dirty):
        if uniform not in uniform_locations:
            continue
        if uniform not in uniform_types:
            continue
        utype = uniform_types[uniform]
        value = uniform_values.get(uniform, None)
        if value is None:
            warnings.append("WARNING: unset uniform '%s'" % uniform)
            continue
        loc = uniform_locations[uniform]
        set_uniform(value, utype, loc)
        uniform_dirty.remove(uniform)

    glstate_module.set_state(**glstate)
    if glclear not in (None, False):
        if glclear == True:
            glstate_module.clear()
        else:
            glstate_module.clear(*glclear)
    renderer.draw()

    # Heisenbug!!! see below. Seems to be solved now
    try:
        warnings
    except NameError:
        return

    if warnings != old_warnings:
        for warning in warnings:
            print(warning)
Ejemplo n.º 42
0
    def draw(self):
        if self.is_empty: return
        if self.vbo is None: self.vbo = vbo.VBO(self.vbo_data)
        shaders.glUseProgram(Chunk.shader)
        self.vbo.bind()
        glEnableClientState(GL_VERTEX_ARRAY)
        glEnableClientState(GL_COLOR_ARRAY)

        glVertexPointer(3, GL_FLOAT, 24, self.vbo)
        glColorPointer(3, GL_FLOAT, 24, self.vbo + 12)
        glDrawArrays(GL_QUADS, 0, self.vbo_data.size / 6)

        self.vbo.unbind()
        glDisableClientState(GL_VERTEX_ARRAY)
        glDisableClientState(GL_COLOR_ARRAY)
        shaders.glUseProgram(0)