当前位置: 首页>>代码示例>>Python>>正文


Python Shader.uniformf方法代码示例

本文整理汇总了Python中shader.Shader.uniformf方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.uniformf方法的具体用法?Python Shader.uniformf怎么用?Python Shader.uniformf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shader.Shader的用法示例。


在下文中一共展示了Shader.uniformf方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getShader

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]
def getShader( frag, seed ):
    with open ("shaders/basicvert.glsl", "r") as vertfile:
      vert = vertfile.read()

    with open ("shaders/noise.glsl", "r") as noisefile:
      noise = noisefile.read()

    with open ("shaders/utils.glsl", "r") as utilsfile:
      utils = utilsfile.read()

    with open ("shaders/header.glsl", "r") as headerfile:
      header = headerfile.read()

    fullfrag = header + noise + utils + frag

    with open( "Output/" + str( seed ) + "/" + str( seed ) + ".glsl", "w") as text_file:
        text_file.write( frag )

    with open( "Output/" + str( seed ) + "/" + str( seed ) + "full.glsl", "w") as text_file:
        text_file.write( fullfrag )

    shader = Shader( vert, fullfrag )
    shader.bind()
    shader.uniformf( "iResolution", x, y )
    return shader
开发者ID:innesmck,项目名称:shaderbot,代码行数:27,代码来源:quad.py

示例2: JuliaWindow

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]
class JuliaWindow(pyglet.window.Window):
	def __init__(self):
		super(JuliaWindow, self).__init__(caption = 'julia', width = 512, height = 512)

		self.C = (-0.70176, -0.3842)

		shader_path = 'julia'
		self.shader = Shader(''.join(open('%s.v.glsl' % shader_path)), ''.join(open('%s.f.glsl' % shader_path)))

	def on_mouse_motion(self, x, y, dx, dy):
		self.C = (6. * ((float(x) / window.width) - .5), 6 * ((float(y) / window.height) - .5))

	def on_draw(self):
		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()
		glOrtho(-1., 1., 1., -1., 0., 1.)

		glMatrixMode(GL_MODELVIEW)
		glLoadIdentity()

		self.shader.bind()
		self.shader.uniformf('C', *self.C)

		glBegin(GL_QUADS)
		glVertex2i(-1, -1)
		glTexCoord2i(-2, -2)
		glVertex2f(1, -1)
		glTexCoord2i(2, -2)
		glVertex2i(1,  1)
		glTexCoord2i(2, 2)
		glVertex2i(-1,  1)
		glTexCoord2i(-2, 2)
		glEnd()
		self.shader.unbind()
开发者ID:msarch,项目名称:py,代码行数:36,代码来源:julia-explorer.py

示例3: draw_gl_checkerboards

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]
def draw_gl_checkerboards(points,size=60,color=(1.,0.5,0.5,.5), grid=[7.0,7.0]):
    global simple_checkerboard_shader # we cache the shader because we only create it the first time we call this fn.
    if not simple_checkerboard_shader:
        grid = np.array(grid)
        # step = size/grid
        # in this example the step would be 10

        # we just draw single points, a VBO is much slower than this. But this is a little bit hacked.
        #someday we should replace all legacy fn with vbo's and shaders...
        # shader defines
        VERT_SHADER = """
        #version 120
        varying vec4 f_color;
        void main () {
               gl_Position = gl_ModelViewProjectionMatrix*vec4(gl_Vertex.xy,1.,1.);
               gl_PointSize = gl_Vertex.z; //this needs to be used on some hardware we cheat and use the z coord
               f_color = gl_Color;
               }
        """

        FRAG_SHADER = """
        #version 120
        varying vec4 f_color;
        uniform vec2 grid;
        void main()
        {
            // get the lowest integer value for the grid
            float total = floor(gl_PointCoord.x*grid.x) + floor(gl_PointCoord.y*grid.y);
            // make the checkerboard by alternating colors
            bool isEven = mod(total,2.0)==0.0;
            vec4 col1 = vec4(0.0,0.0,0.0,1.0);
            vec4 col2 = vec4(1.0,1.0,1.0,1.0);
            gl_FragColor = (isEven)? col1:col2;
        }
        """
        #shader link and compile
        simple_checkerboard_shader = Shader(VERT_SHADER,FRAG_SHADER)

    simple_checkerboard_shader.bind()
    simple_checkerboard_shader.uniformf('grid', *grid)
    glColor4f(*color)
    glBegin(GL_POINTS)
    for pt in points:
        glVertex3f(pt[0],pt[1],size)
    glEnd()
    simple_checkerboard_shader.unbind()
开发者ID:Tomaschewski,项目名称:pupil,代码行数:48,代码来源:utils.py

示例4: __init__

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]
class Unwrapper:
    """
    This unwrapper takes an image path and a parsed frame and fulfills
    the operations required to draw the unwrapped image.

    The draw operations MUST be called inside of the "on_draw" callback
    passed to "start_unwrap_window" in order to be fulfilled.  This class
    cannot function without an OpenGL window.
    """
    def __init__(self):

        # Create the shader.
        self.shader = Shader(vertex_shader, fragment_shader)

        # Set the texture unit.
        self.shader.bind()
        self.shader.uniformi('tex0', 0)
        self.shader.unbind()

        # Create a quad geometry to fit the whole window that will be the target of our drawing.
        self.batch = pyglet.graphics.Batch()
        self.batch.add(4, GL_QUADS, None, ('v2i', (0,0, 1,0, 1,1, 0,1)), ('t2f', (0,0, 1,0, 1,1, 0,1)))

    def update(self, img_path, frame):
        """
        Update the texture to the given image path, and update the shaders with the new
        frame information to unwrap the given image correctly.
        """

        # Recalculate the variables required to unwrap the new image.
        projector = PolygonProjector(frame.center_point, frame.center_vertices)
        angle_bounds = [v.angle for v in projector.vertices]
        radii = [p.center_dist for p in projector.projectors]
        angles = [p.center_angle for p in projector.projectors]

        # Load the new image, and update the size variables.
        self.texture = pyglet.image.load(img_path).get_texture()
        region_w, region_h = self.texture.width, self.texture.height
        actual_w, actual_h = self.texture.owner.width, self.texture.owner.height

        # Update the shader variables.
        self.shader.bind()
        self.shader.uniformf('region_size', region_w, region_h)
        self.shader.uniformf('actual_size', actual_w, actual_h)
        self.shader.uniformfv('angle_bounds', 1, angle_bounds)
        self.shader.uniformfv('radii', 1, radii)
        self.shader.uniformfv('angles', 1, angles)
        self.shader.uniformi('count', len(radii))
        self.shader.unbind()

    def draw(self):
        """Draw the unwrapped image to the window."""
        glBindTexture(self.texture.target, self.texture.id)
        self.shader.bind()
        self.batch.draw()
        self.shader.unbind()
        glBindTexture(self.texture.target, 0)

    def save_image(self, filename):
        """Save the current window image to the given filename."""
        pyglet.image.get_buffer_manager().get_color_buffer().save(filename)

    def get_fps(self):
        """Get the current framerate in frames per second."""
        return pyglet.clock.get_fps()
开发者ID:shaunlebron,项目名称:super-hexagon-unwrapper,代码行数:67,代码来源:unwrap.py

示例5: ShaderWindow

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]

#.........这里部分代码省略.........
        self.p.append(permutation[i % len(permutation)])

  def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
    self.x -= dx * self.zoom;
    self.y -= dy * self.zoom;
    
  def on_mouse_release(self, x, y, button, modifiers):
    print "x: {}, y: {}, z: {}, zoom: {}, octs: {}, freq: {}".format(self.x, self.y, self.z, self.zoom, self.octives, self.freq)

  def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
    self.zoom -= scroll_y * 0.0025;
    print "x: {}, y: {}, z: {}, zoom: {}, octs: {}, freq: {}".format(self.x, self.y, self.z, self.zoom, self.octives, self.freq)

  def on_key_release(self, symbol, modifiers):
    if symbol == pyglet.window.key.F2:
      self.saveFromShader()
    elif symbol == pyglet.window.key.Q:
      self.x += 0.1;
    elif symbol == pyglet.window.key.A:
      self.x -= 0.1;
    elif symbol == pyglet.window.key.W:
      self.y += 0.1;
    elif symbol == pyglet.window.key.S:
      self.y -= 0.1;
    elif symbol == pyglet.window.key.E:
      self.z += 0.01;
    elif symbol == pyglet.window.key.D:
      self.z -= 0.01;
    elif symbol == pyglet.window.key.R:
      self.zoom += 0.0025;
    elif symbol == pyglet.window.key.F:
      self.zoom -= 0.0025;
    elif symbol == pyglet.window.key.T:
      self.octives += 1;
    elif symbol == pyglet.window.key.G:
      self.octives -= 1;
    elif symbol == pyglet.window.key.Y:
      self.freq += 0.01;
    elif symbol == pyglet.window.key.H:
      self.freq -= 0.01;
    print "x: {}, y: {}, z: {}, zoom: {}, octs: {}, freq: {}".format(self.x, self.y, self.z, self.zoom, self.octives, self.freq)
    
  def saveFromShader(self):
    a = (GLubyte * (4 * self.w * self.h))(0)
    glReadPixels(0, 0, self.w, self.h, GL_RGBA, GL_UNSIGNED_BYTE, a)
    image = pyglet.image.ImageData(self.w, self.h, 'RGBA', a)
    scriptPath = os.path.dirname(os.path.realpath(__file__))
    filePath = scriptPath + "/TESTSAVE_" + time.strftime("%Y%m%d_%H%M%S") + ".png"
    print "save to {}".format(filePath)
    image.save(filePath)

  def getPermutation(self):
    return [
      151,160,137, 91, 90, 15,131, 13,201, 95, 96, 53,194,233,  7,225,
      140, 36,103, 30, 69,142,  8, 99, 37,240, 21, 10, 23,190,  6,148,
      247,120,234, 75,  0, 26,197, 62, 94,252,219,203,117, 35, 11, 32,
       57,177, 33, 88,237,149, 56, 87,174, 20,125,136,171,168, 68,175,
       74,165, 71,134,139, 48, 27,166, 77,146,158,231, 83,111,229,122,
       60,211,133,230,220,105, 92, 41, 55, 46,245, 40,244,102,143, 54,
       65, 25, 63,161,  1,216, 80, 73,209, 76,132,187,208, 89, 18,169,
      200,196,135,130,116,188,159, 86,164,100,109,198,173,186,  3, 64,
       52,217,226,250,124,123,  5,202, 38,147,118,126,255, 82, 85,212,
      207,206, 59,227, 47, 16, 58, 17,182,189, 28, 42,223,183,170,213,
      119,248,152,  2, 44,154,163, 70,221,153,101,155,167, 43,172,  9,
      129, 22, 39,253, 19, 98,108,110, 79,113,224,232,178,185,112,104,
      218,246, 97,228,251, 34,242,193,238,210,144, 12,191,179,162,241,
       81, 51,145,235,249, 14,239,107, 49,192,214, 31,181,199,106,157,
      184, 84,204,176,115,121, 50, 45,127,  4,150,254,138,236,205, 93,
      222,114, 67, 29, 24, 72,243,141,128,195, 78, 66,215, 61,156,180,
    ]

  def on_draw(self):
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(-1., 1., 1., -1., 0., 1.)

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    self.shader.bind()
    self.shader.uniformi('p', *self.p)
    self.shader.uniformf('x', *[self.x])
    self.shader.uniformf('y', *[self.y])
    self.shader.uniformf('z', *[self.z])
    self.shader.uniformf('zoom', *[self.zoom])
    self.shader.uniformi('octives', *[self.octives])
    self.shader.uniformf('freq', *[self.freq])

    glBegin(GL_QUADS)
    glVertex2i(-1, -1)
    glTexCoord2i(-2, -2)
    glVertex2f(1, -1)
    glTexCoord2i(2, -2)
    glVertex2i(1, 1)
    glTexCoord2i(2, 2)
    glVertex2i(-1, 1)
    glTexCoord2i(-2, 2)
    glEnd()

    self.shader.unbind()
开发者ID:MichaelReel,项目名称:pyxamples,代码行数:104,代码来源:run_procedural_shader.py

示例6: Terrain

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]

#.........这里部分代码省略.........
            glFogf(GL_FOG_DENSITY, 0.7)
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP)
        glClipPlane(GL_CLIP_PLANE0, (ctypes.c_double * 4)(0, -1, 0, self.water_line))
        glStencilFunc(GL_EQUAL, 0, -1)
        self.drawHeightGrid()
        glFogf(GL_FOG_DENSITY, 0)
        glDisable(GL_CLIP_PLANE0)
        glPopAttrib()
        self.drawSeaLevel()
        #glPopAttrib()

    def setSeaMaterial(self) :
        glClearColor(0, 0, .0, 1)

        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE)
        #glDepthFunc(GL_LEQUAL);
        glShadeModel(GL_SMOOTH);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec(.7, .7, .8, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, vec(.7, .7, .8, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
        #glMaterialfv(GL_FRONT, GL_COLOR_INDEXES, vec(1.0, 1, 1))
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 105)

        glDisable(GL_CULL_FACE)
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glActiveTexture( GL_TEXTURE0 )
        glBindTexture( GL_TEXTURE_2D, self.sea_tex.id)
        glColor4f(.1,.3,0.6, 0.7)
        if SHADER :
            self.waveTime += 0.025
            self.waterShader.uniformi("tex0", 0 )
            self.waterShader.uniformf("waveTime", self.waveTime )
            self.waterShader.uniformf("waveWidth", self.waveWidth )
            self.waterShader.uniformf("waveHeight", self.waveHeight )

    def drawSeaLevel( self ) :
        if SHADER : self.waterShader.Use()
        self.setSeaMaterial()
        if not 'water' in self.dlists:
            self.dlists['water'] = glGenLists(1)
            glNewList(self.dlists['water'], GL_COMPILE)
            glBegin(GL_TRIANGLES)    
            s = 1./33
            a = self.a
            y = self.water_line+self.waveHeight
            s = 1

            for z in xrange( -a, a, s ) : 
                for x in xrange( -a, a, s ) :

                    glNormal3f(0,1,0)
                    glTexCoord2i(1, 1)
                    glVertex3f(x +1, y, z +1) 
                    glNormal3f(0,1,0)
                    glTexCoord2i(0, 0)
                    glVertex3f(x + 0, y, z + 0)
                    glNormal3f(0,1,0)
                    glTexCoord2i(0, 1)
                    glVertex3f(x + 0, y, z +1) 

                    glNormal3f(0,1,0)
                    glTexCoord2i(0, 0)
                    glVertex3f(x + 0, y, z + 0)  
                    glNormal3f(0,1,0)
开发者ID:Dejmas,项目名称:Terrain,代码行数:70,代码来源:terrain.py

示例7: MainWindow

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]
class MainWindow(pyglet.window.Window):
    def __init__(self, **kwargs):
        config = pyglet.gl.Config(sample_buffers=1, samples=4)

        pyglet.window.Window.__init__(self, width=1000, height=700,
            resizable=True, config=self.config, **kwargs)

        self.fps = pyglet.clock.ClockDisplay()
        self.shader = Shader(vertex_shader, fragment_shader)
        self.center = np.array([0.0,0.0])
        self.show_fps = False

        self.screen_size = np.array([self.width, self.height])
        self.view_size = np.array([3.0, 2.0])
        self.col_scale = 4000.0

        self.draw()

    def on_key_press(self, symbol, modifiers):
        if symbol == key.ESCAPE:
            self.has_exit = True
        elif symbol == key.F:
            self.set_fullscreen(not self.fullscreen)
            self.screen_size = np.array([self.width, self.height])
        elif symbol == key.F1:
            self.show_fps = not self.show_fps
        elif symbol == key.F2:
            pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png')
        elif symbol == key.C:
            self.renderC()
            return
        elif symbol == key.DOWN:
            self.col_scale *= 0.9
            print self.col_scale
            self.renderC() 
            return
        elif symbol == key.UP:
            self.col_scale *= 1.1
            print self.col_scale
            self.renderC() 
            return

        self.draw()

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        delta = np.array((dx,dy))
        self.center += delta * self.view_size / self.screen_size
        self.draw()

    def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
        scale = 1.1 ** scroll_y
        screen_center = np.array([self.width/2.0, self.height/2.0])
        self.center += (scale - 1.0) * (np.array([x,y]) - screen_center) * (self.view_size / self.screen_size)
        self.view_size *= scale
        self.draw()

    def on_resize(self, width, height):
        pyglet.window.Window.on_resize(self, width, height)
        self.draw()

    def draw(self):
            if self.view_size[0] < 1e-4 or self.view_size[1] < 1e-4 :
                self.renderC()
                return

            gl.glClear(gl.GL_COLOR_BUFFER_BIT)
            gl.glLoadIdentity()
            self.shader.bind()
            self.shader.uniformf("z", self.center)
            self.shader.uniformf("res", self.screen_size)
            self.shader.uniformf("view", self.view_size)

            #draw square across screen
            gl.glBegin(gl.GL_QUADS)
            gl.glVertex3f(0.0, 0.0, 0.0)
            gl.glVertex3f(0.0, self.height, 0.0)
            gl.glVertex3f(self.width, self.height, 0.0)
            gl.glVertex3f(self.width, 0.0, 0.0)
            gl.glEnd()

            self.shader.unbind()
            if self.show_fps:
                self.fps.draw()
            self.flip()

    def run(self):
        while not self.has_exit:
            pyglet.clock.tick()
            self.dispatch_events()

    def renderC(self):
        w, h, = self.width,self.height
        t = time.time()
        imagetype = c.c_byte * (w * h * 3)
        imagedata = imagetype()
        clib.mandelbrot(c.c_int(w), c.c_int(h),c.c_double(self.col_scale), vec2(self.center), vec2(self.view_size), imagedata)
        image = pyglet.image.ImageData(w, h, "RGB", imagedata, pitch = 3 * c.sizeof(c.c_char) * w)
        image.blit(0,0)
        self.flip()
        return image
开发者ID:TomHodson,项目名称:Fractal-Explorer,代码行数:102,代码来源:viewer.py

示例8: open

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]
    #D[4:12:,4:12] = 0
    image = pyglet.image.ImageData(D.shape[1],D.shape[0],'RGBA',D.ctypes.data)
    sprite = pyglet.sprite.Sprite(image)


    # Reaction-diffusion shader
    # -------------------------
    vertex_shader   = open('./reaction-diffusion.vert').read()
    fragment_shader = open('./reaction-diffusion.frag').read()
    reaction_shader = Shader(vertex_shader, fragment_shader)

    reaction_shader.bind()
    reaction_shader.uniformi('texture', 0)
    reaction_shader.uniformi('params',  1)
    reaction_shader.uniformi('display', 2)
    reaction_shader.uniformf('dt', dt)
    reaction_shader.uniformf('dx', 1.0/width)
    reaction_shader.uniformf('dy', 1.0/height)
    reaction_shader.uniformf('dd', dd)
    reaction_shader.unbind()

    # Color shader
    # ------------
    vertex_shader   = open('./color.vert').read()
    fragment_shader = open('./color.frag').read()
    color_shader    = Shader(vertex_shader, fragment_shader)

    color_shader.bind()
    color_shader.uniformi('texture', 0)
    color_shader.unbind()
开发者ID:rougier,项目名称:grayscott,代码行数:32,代码来源:grayscott.py

示例9: __init__

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]

#.........这里部分代码省略.........
                    //    newColor = vec4(1.0, 0.0, 0.0, 1.0);
                    //}

                    float alpha = 1.0 - smoothstep(-width * feather, width * feather, length(offset) - width);

                    newColor = vec4(color.r * alpha, color.g * alpha, color.b * alpha, alpha);

                    gl_FragColor = newColor;
                }
             '''])
        
    def drawLineInNormalizedCoordinates(self, start, end, width):
        lineBatch = pyglet.graphics.Batch()
    
        direction = pointsSubtract(end, start)
        cross = pointNormalized(pointCross(direction))
        cross = (cross[0], cross[1] * (window.width / window.height))
        crossAlt = pointNormalized(pointCrossAlt(direction))
        crossAlt = (crossAlt[0], crossAlt[1] * (window.width / window.height))
        
        aspect = window.width / window.height
        widthVector = pointsMultiply(pointNormalized((width, width * aspect)), width)
        vertex_list = lineBatch.add(
            6,
                                    pyglet.gl.GL_TRIANGLES,
                                    None,
                                    ('v2f',
                                     (start[0], start[1], end[0], end[1], start[0], start[1],
                                      start[0], start[1], end[0], end[1], end[0], end[1])
                                    ),
                                    ('c4f',
                                     (1.0, 0.0, 0.0, 1.0,  1.0, 0.0, 0.0, 0.5,  1.0, 0.0, 0.0, 0.5,
                                      
                                      0.0, 1.0, 0.0, 1.0,  0.0, 0.0, 1.0, 1.0,  0.0, 0.0, 1.0, 1.0)
                                    ),
                                    ('n3f',
                                     (cross[0], cross[1], 1.0,  crossAlt[0], crossAlt[1], 1.0,  crossAlt[0], crossAlt[1], 1.0,
                                      cross[0], cross[1], 1.0, cross[0], cross[1], 1.0,  crossAlt[0], crossAlt[1], 1.0)
                                     )
                                    ,
                                    ('1g2f',
                                     (widthVector[0], widthVector[1],  widthVector[0], widthVector[1],  widthVector[0], widthVector[1],
                                      
                                      widthVector[0], widthVector[1],  widthVector[0], widthVector[1],  widthVector[0], widthVector[1])
                                    )
                                    )
    
        self.__drawBatch(lineBatch, widthVector[0])
        
    def drawLine(self, start, end, width):
        lineBatch = pyglet.graphics.Batch()
        
        start = pointsDivide(start, (window.width, window.height))
        end = pointsDivide(end, (window.width, window.height))
        
        direction = pointsSubtract(end, start)
        cross = pointNormalized(pointCross(direction))
        cross = (cross[0], cross[1] * (window.width / window.height))
        cross = pointNormalized(cross)
        crossAlt = pointNormalized(pointCrossAlt(direction))
        crossAlt = (crossAlt[0], crossAlt[1] * (window.width / window.height))
        crossAlt = pointNormalized(crossAlt)

        #since in veretx shader coordinates ar maped into device normalized space we do not need to divide width by half
        width = width / window.width
        
        aspect = window.width / window.height
        widthVector = (width, width) #pointMultipliedByScalar(pointNormalized((width, width * aspect)), width)
        vertex_list = lineBatch.add(
            6,
                                    pyglet.gl.GL_TRIANGLES,
                                    None,
                                    ('v2f',
                                     (start[0], start[1], end[0], end[1], start[0], start[1],
                                      start[0], start[1], end[0], end[1], end[0], end[1])
                                    ),
                                    ('c4f',
                                     (1.0, 1.0, 1.0, 1.0,  1.0, 1.0, 1.0, 1.0,  1.0, 1.0, 1.0, 1.0,
                                      
                                      1.0, 1.0, 1.0, 1.0,  1.0, 1.0, 1.0, 1.0,  1.0, 1.0, 1.0, 1.0)
                                    ),
                                    ('n3f',
                                     (cross[0], cross[1], 1.0,  crossAlt[0], crossAlt[1], 1.0,  crossAlt[0], crossAlt[1], 1.0,
                                      cross[0], cross[1], 1.0, cross[0], cross[1], 1.0,  crossAlt[0], crossAlt[1], 1.0)
                                     )
                                    ,
                                    ('1g2f',
                                     (widthVector[0], widthVector[1],  widthVector[0], widthVector[1],  widthVector[0], widthVector[1],

                                      widthVector[0], widthVector[1],  widthVector[0], widthVector[1],  widthVector[0], widthVector[1])
                                    )
                                   )
        self.__drawBatch(lineBatch, widthVector[0])

    def __drawBatch(self, batch, width):
        self.shader.bind()
        self.shader.uniformf("feather", self.feather)
        self.shader.uniformf("width", width)
        batch.draw()
        self.shader.unbind()
开发者ID:rolan-reznik,项目名称:GLLInes,代码行数:104,代码来源:GLLines.py

示例10: GLRender

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformf [as 别名]
class GLRender(object):
	
	scale = 1
	angles = [0,0,0]
	mol = None
	envTex = None
	
	def __init__(self):
		# Setup the GLSL program
		with open('molgl.vert','r') as f:
			vert = f.readlines()
		with open('molgl.frag','r') as f:
			frag = f.readlines()
		self.shader = Shader(vert=vert, frag=frag)
		
		# Some parameters
		glEnable(GL_DEPTH_TEST)
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
	
	def applySceneTransforms(self):
		gluLookAt(0, 0, 2*self.mol.radius, 0, 0, 0, 0, 1, 0); # Push molecule away from the origin along -Z direction.
		glScalef(self.scale,self.scale,self.scale);
		def mouse_rotate(xAngle, yAngle, zAngle):
			glRotatef(xAngle, 1.0, 0.0, 0.0);
			glRotatef(yAngle, 0.0, 1.0, 0.0);
			glRotatef(zAngle, 0.0, 0.0, 1.0);
		mouse_rotate(self.angles[0],self.angles[1],self.angles[2]);
		glTranslatef(-self.mol.x, -self.mol.y, -self.mol.z); # Bring molecue center to origin
		
	def set_molecule(self, mol):
		self.mol = mol
		
	def set_envmap(self, envmap):
		if self.envTex: glDeleteTextures(self.envTex)
		self.envTex = glGenTextures(1);
		glBindTexture(GL_TEXTURE_2D, self.envTex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, envmap.shape[0], envmap.shape[1], 0, 
			GL_RGB, GL_FLOAT, envmap);
		glBindTexture(GL_TEXTURE_2D, 0);

	def render(self):
		glEnable(GL_TEXTURE_2D)
		glBindTexture(GL_TEXTURE_2D, self.envTex)
		self.applySceneTransforms()
		self.shader.bind()
		#self.shader.uniformf('scale',self.scale)
		self.shader.uniformf('scale', 1)
		self.shader.uniformi('tex', 0)
		self.shader.uniformi('envMapping', 1)

		# Draw all the sphere
		for sphere in self.mol.spheres:
			glColor3f(sphere.r, sphere.g, sphere.b);
			glPushMatrix()
			glTranslatef(sphere.x, sphere.y, sphere.z);
			q = gluNewQuadric()
			gluSphere(q, sphere.radius,20,20)
			#glutSolidSphere(sphere.radius,20,20);
			glPopMatrix()
		self.shader.unbind()
		glBindTexture(GL_TEXTURE_2D, 0)
		glDisable(GL_TEXTURE_2D)
开发者ID:amiller,项目名称:graphicsii,代码行数:68,代码来源:glrender.py


注:本文中的shader.Shader.uniformf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。