Beispiel #1
0
def rect(a, b, color=(1.0,1.0,1.0), alpha=1.0):
    """
    Draws a rectangle in the plane spanned by a,b with GL_QUADS

    :param a: Point a
    :type a: 2-float tuple

    :param b: Point b
    :type b: 2-float tuple

    :param color: the color in [0..1] range
    :type color: 3-float tuple

    :param aa: Anti aliasing Flag

    :param alpha: the alpha value in [0..1] range

    """

    glDisable(GL_TEXTURE_2D)

    glBegin(GL_QUADS)
    glVertex3f(a[0], a[1], 0)
    glVertex3f(b[0], a[1], 0)
    glVertex3f(b[0], b[1], 0)
    glVertex3f(a[0], b[1], 0)

    glEnd()
    glEnable(GL_TEXTURE_2D)
    glColor4f(color+(alpha,))
Beispiel #2
0
    def set_3d(self):
        """ Configure OpenGL to draw in 3d.

        """
        width, height = self.get_size()

        gl.glEnable(gl.GL_DEPTH_TEST)

        gl.glViewport(0, 0, width, height)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluPerspective(65.0, width / float(height), 0.1, DIST)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        x, y = self.rotation
        gl.glRotatef(x, 0, 1, 0)
        gl.glRotatef(-y, math.cos(math.radians(x)), 0, math.sin(math.radians(x)))
        x, y, z = self.position
        gl.glTranslatef(-x, -y, -z)

        gl.glEnable(gl.GL_LIGHTING)
        gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, GLfloat4(0.05,0.05,0.05,1.0))
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glColorMaterial(gl.GL_FRONT, gl.GL_AMBIENT_AND_DIFFUSE)
        #gl.glLightfv(gl.GL_LIGHT1,gl.GL_SPOT_DIRECTION, GLfloat3(0,0,-1))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_AMBIENT, GLfloat4(0.5,0.5,0.5,1.0))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, GLfloat4(1.0,1.0,1.0,1.0))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, GLfloat4(0.35,1.0,0.65,0.0))
        #gl.glLightfv(gl.GL_LIGHT0,gl.GL_SPECULAR, GLfloat4(1,1,1,1))
        gl.glDisable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_LIGHT1)
Beispiel #3
0
    def on_draw(self):
        """
        Render the screen.
        """
        start = time.time()

        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glDisable(GL.GL_BLEND)

        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.vertex_vbo_id)
        GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
        GL.glVertexPointer(2, GL.GL_FLOAT, 0, 0)

        GL.glBindBuffer(GL.GL_ARRAY_BUFFER, self.color_vbo_id)
        GL.glEnableClientState(GL.GL_COLOR_ARRAY)
        GL.glColorPointer(3, GL.GL_FLOAT, 0, 0)

        offset = 0
        for shape in self.shape_list:
            render_rect_filled(shape, offset)
            offset += 4

        elapsed = time.time() - start
        print(elapsed)
Beispiel #4
0
def circle(pos, radius, color=(1.0,1.0,1.0), alpha=1.0,segments=6):
    """
    Draws a circle with gluDisk 
    
    :param pos: center of the circle
    :type pos: 2-float tuple

    :param radius: radius of the circle
    :type radius: float

    :param color: the color in [0..1] range
    :type color: 3-float tuple

    :param alpha: the alpha value in [0..1] range

    :param segments: number of segments
    :type segments: int

    """

    glDisable(GL_TEXTURE_2D)

    c = gluNewQuadric()
    glColor4f(color[0], color[1], color[2], alpha)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], 0)
    gluDisk(c, 0, radius, segments, 1)
    glPopMatrix()
    glColor4f(1.0,1.0,1.0,1.0)
    glEnable(GL_TEXTURE_2D)
Beispiel #5
0
 def draw(self):
     if self._render_object:
         pgl.glPushAttrib(pgl.GL_ENABLE_BIT | pgl.GL_POLYGON_BIT | pgl.GL_DEPTH_BUFFER_BIT)
         if self._overlay:
             pgl.glDisable(pgl.GL_DEPTH_TEST)
         self._render_object.draw()
         pgl.glPopAttrib()
Beispiel #6
0
    def poll(dt):
        out = next(itr, False)
        if out is False:
            if args.pause:
                label.text = "Done. ('q' to quit)"
            else:
                pyglet.app.exit()
        elif out is not None:
            name, buf = out
            real_dt = time.time() - last_time[0]
            last_time[0] = time.time()
            if buf.dtype == np.uint8:
                fmt = gl.GL_UNSIGNED_BYTE
            elif buf.dtype == np.uint16:
                fmt = gl.GL_UNSIGNED_SHORT
            else:
                label.text = 'Unsupported format: ' + buf.dtype
                return

            h, w, ch = buf.shape
            gl.glEnable(tex.target)
            gl.glBindTexture(tex.target, tex.id)
            gl.glTexImage2D(tex.target, 0, gl.GL_RGB8, w, h, 0, gl.GL_RGBA,
                            fmt, buf.tostring())
            gl.glDisable(tex.target)
            label.text = '%s (%g fps)' % (name, 1./real_dt)
        else:
            label.text += '.'
Beispiel #7
0
 def create_window(self, _iScr=0, _title="", _dx=0, _dy=0, _left=0, _top=0,
                   _scale=1.0, _isScrOvl=False, _iScrGUI=0, _offset=(0,0)):
   """ If the renderer was initialized, create a window instance and store
       it in the internal window list. For parameters, see Window class.
   """
   if self.isReady:
     self.winList.append(Window(self, _iScr, _title, _dx, _dy, _left, _top,
                                _scale, _isScrOvl, _iScrGUI, _offset))    
     '''
     if len(self.winList) == 1:
     # Is the first window, set some general OpenGL properties
     #
     '''
     GL.glClearColor(0., 0., 0., 0.)
     GL.glColor3f(1., 1., 1.)
     GL.glDisable(GL.GL_DEPTH_TEST)
     GL.glEnable(GL.GL_BLEND)
     GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
     '''
     GL.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
     GL.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
 
     GL.glShadeModel(GL_FLAT) # GL_FLAT or GL_SMOOTH
     GL.glEnable(GL_POINT_SMOOTH)
     '''
     return self.winList[-1]
   else:  
     return None
Beispiel #8
0
    def draw(self):
        from miru.context import context
        gl.glEnable(gl.GL_LINE_STIPPLE)
        gl.glLineStipple(1, 0x51315)
        gl.glColor4f(*self.color)
        for c in self.metaCamera.cameras:

            vp = c.projection

            x = vp.x == 0 and 1 or vp.x
            width = vp.x == 0 and vp.width - 1 or vp.width
            width = (vp.x + vp.width) >= context.window.width and width - 1 or width

            y = vp.y == 0 and 1 or vp.y
            height = vp.y == 0 and vp.height - 1 or vp.height
            height = (vp.y + vp.height) >= context.window.height and height - 1 or height

            gl.glBegin(gl.GL_LINE_LOOP)
            gl.glVertex2f(x, y)
            gl.glVertex2f(x, y + height)
            gl.glVertex2f(x + width, y + height)
            gl.glVertex2f(x + width, y)
            gl.glEnd()
        gl.glDisable(gl.GL_LINE_LOOP)
        gl.glColor4f(1,1,1,1)
 def on_draw(self):
     self.window.clear()
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glPushMatrix()
     gl.glLoadIdentity()
     self.camera()
     gl.glEnable(self.grass.target)
     gl.glEnable(gl.GL_BLEND)
     gl.glBindTexture(self.grass.target, self.grass.id)
     W = 10000.
     graphics.draw(4, gl.GL_QUADS,
         ('v2f', (-W, -W, W, -W, W, W, -W, W)),
         ('t2f', (0., 0., W*5., 0., W*5., W*5., 0., W*5.))
     )
     gl.glDisable(self.grass.target)
     for lane in self.lanes:
         self.draw_lane_surface(lane)
     for lane in self.lanes:
         self.draw_lane_lines(lane)
     for obj in self.objects:
         self.draw_object(obj)
     for car in self.cars:
         if car!=self.main_car and car not in self.visible_cars:
             self.draw_car(self.anim_x[car], car.color)
     if self.heat is not None:
         self.draw_heatmap()
     for car in self.cars:
         if car==self.main_car or car in self.visible_cars:
             self.draw_car(self.anim_x[car], car.color)
     gl.glPopMatrix()
     if isinstance(self.main_car, Car):
         self.label.text = 'Speed: %.2f'%self.anim_x[self.main_car][3]
         self.label.draw()
     if self.output is not None:
         pyglet.image.get_buffer_manager().get_color_buffer().save(self.output.format(self.frame))
Beispiel #10
0
    def draw(self):
        if self._dirty:
            self._context = Context()
            self._parts = []
            self.free()
            self.render()
            self.build_vbo()
            self._dirty = False

        # set
        gl.glEnable(self._texture.target)
        gl.glBindTexture(self._texture.target, self._texture.id)
        gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glPushMatrix()
        self.transform()
        # cuadric.begin()
        self._vertex_list.draw(gl.GL_TRIANGLES)
        # cuadric.end()

        # unset
        gl.glPopMatrix()
        gl.glPopAttrib()
        gl.glDisable(self._texture.target)
Beispiel #11
0
 def setup(self):
   # One-time GL setup
   gl.glClearColor(1, 1, 1, 0)
   gl.glColor3f(1, 0, 0)
   gl.glEnable(gl.GL_DEPTH_TEST)
   gl.glEnable(gl.GL_CULL_FACE)
   gl.glDisable(gl.GL_LIGHTING)
Beispiel #12
0
 def unset_state(self):
     """
     Disables the scissor test
     """
     if not self.was_scissor_enabled:
         gl.glDisable(gl.GL_SCISSOR_TEST)
     gl.glPopAttrib()
Beispiel #13
0
def enable_states(gl_states):
    """Context Manager that calls glEnable and glDisable on a list of gl states."""
    for state in gl_states:
        gl.glEnable(state)
    yield
    for state in gl_states:
        gl.glDisable(state)
Beispiel #14
0
 def _set_backface_culling(self, value):
     self._backface_culling = value
     if self._backface_culling:
         gl.glCullFace(gl.GL_BACK)
         gl.glEnable(gl.GL_CULL_FACE)
     else:
         gl.glDisable(gl.GL_CULL_FACE)
Beispiel #15
0
    def blit_buffer(self, framebuffer, parent_width, parent_height, **kwargs):
        """Draw the texture into the parent scene

        .. warning:

            This method's arguments are not part of the API yet and may change
            at any time.
        """
        gl.glViewport(0, 0, parent_width, parent_height)

        gl.glTexParameteri(gl.GL_TEXTURE_2D,
            gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
        gl.glBindTexture(gl.GL_TEXTURE_2D, framebuffer.texture_id)
        gl.glEnable(gl.GL_TEXTURE_2D)

        gl.glColor4fv((gl.GLfloat * 4)(*self.color + (self.opacity, )))
        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)  # premultipl.
        gl.glBegin(gl.GL_TRIANGLE_STRIP)
        gl.glTexCoord2f(0, 0)
        gl.glVertex2i(0, 0)
        gl.glTexCoord2f(0, parent_height)
        gl.glVertex2i(0, parent_height)
        gl.glTexCoord2f(parent_width, 0)
        gl.glVertex2i(parent_width, 0)
        gl.glTexCoord2f(parent_width, parent_height)
        gl.glVertex2i(parent_width, parent_height)
        gl.glEnd()
        gl.glTexParameteri(gl.GL_TEXTURE_2D,
            gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
        gl.glDisable(gl.GL_TEXTURE_2D)
        gl.glTexParameteri(gl.GL_TEXTURE_2D,
            gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glViewport(0, 0, parent_width, parent_height)
def update_display(verts,tex_coords,texture=bird_texture):
    gl.glClearColor(0.2, 0.4, 0.5, 1.0)

    gl.glEnable(texture.target)
    gl.glBindTexture(texture.target, texture.id)

    gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
   
    gl.glEnable(gl.GL_ALPHA_TEST)                                                            
    gl.glAlphaFunc (gl.GL_GREATER, .1)                             
    #gl.glEnable(gl.GL_BLEND)                                                            
    #gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)                             
    gl.glEnable(gl.GL_DEPTH_TEST) 

    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)

    n=len(verts[:])
    #TODO verts._buffer.ctypes.data is awkward
    gl.glVertexPointer(3, vert_dtype.gl, 0, verts[:].ctypes.data)
    gl.glTexCoordPointer(3, tex_dtype.gl, 0, tex_coords[:].ctypes.data)
    gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, n)
    #unset state
    gl.glPopAttrib()
    gl.glDisable(texture.target)
Beispiel #17
0
    def display(self, mode_2d=False):
        with self.lock:
            glPushMatrix()
            glTranslatef(self.offset_x, self.offset_y, 0)
            glEnableClientState(GL_VERTEX_ARRAY)

            has_vbo = isinstance(self.vertex_buffer, VertexBufferObject)
            if self.display_travels:
                self._display_travels(has_vbo)

            glEnable(GL_LIGHTING)
            glEnableClientState(GL_NORMAL_ARRAY)
            glEnableClientState(GL_COLOR_ARRAY)
            glMaterialfv(GL_FRONT, GL_SPECULAR, vec(1, 1, 1, 1))
            glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0, 0, 0))
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)

            glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
            self._display_movements(has_vbo)

            glDisable(GL_LIGHTING)

            glDisableClientState(GL_COLOR_ARRAY)
            glDisableClientState(GL_VERTEX_ARRAY)
            glDisableClientState(GL_NORMAL_ARRAY)

            glPopMatrix()
Beispiel #18
0
    def after_draw(self, camera):
        """Called by CocosNode when the texture is already grabbed.
        The FrameBuffer will be unbound and the texture will be drawn

        :Parameters:
            `camera` : `Camera`
                The target's camera object.
        """

        # capture after drawing
        self.grabber.after_render(self.texture)

        # after unbinding
        # set a 3d projection
        self._set_3d_projection()

        # and center the camera
        camera.locate(force=True)

        # blit
        gl.glEnable(self.texture.target)
        gl.glBindTexture(self.texture.target, self.texture.id)

        gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)

        self._blit()

        gl.glPopAttrib()
        gl.glDisable(self.texture.target)
Beispiel #19
0
 def display(self, mode_2d=False):
     glEnable(GL_LINE_SMOOTH)
     orig_linewidth = (GLfloat)()
     glGetFloatv(GL_LINE_WIDTH, orig_linewidth)
     glLineWidth(3.0)
     glCallList(self.display_list)
     glLineWidth(orig_linewidth)
     glDisable(GL_LINE_SMOOTH)
Beispiel #20
0
    def postDraw(self):
        """Called right after this layer draws; should revert any changes from
        preDraw()."""
        self._layerProjectLocalToScreenUndo()

        if self._scissorBox is not None:
            gl.glDisable(gl.GL_SCISSOR_TEST)

        frameCachedProperty.clear(self)
Beispiel #21
0
    def draw(self, win=None):
        
        #set the window to draw to
        if win==None: win=self.win
        if win.winType=='pyglet': win.winHandle.switch_to()
        
        #work out next default depth
        if self.depth==0:
            thisDepth = self.win._defDepth
            self.win._defDepth += _depthIncrements[self.win.winType]
        else:
            thisDepth=self.depth

        GL.glPushMatrix()

        #scale and rotate
        prevScale = self.win.setScale(self._winScale)
        GL.glTranslatef(self._posRendered[0],self._posRendered[1],thisDepth)#NB depth is set already
        GL.glRotatef(self.ori,0.0,0.0,1.0)
        self.win.setScale('pix',None, prevScale)
        
        if self._useShaders: #then rgb needs to be set as glColor
            #setup color
            desiredRGB = (self.rgb*self.contrast+1)/2.0#RGB in range 0:1 and scaled for contrast
            if numpy.any(desiredRGB**2.0>1.0):
                desiredRGB=[0.6,0.6,0.4]
            GL.glColor4f(desiredRGB[0],desiredRGB[1],desiredRGB[2], self.opacity)
        else: #color is set in texture, so set glColor to white
            GL.glColor4f(1,1,1,1)

        GL.glDisable(GL.GL_DEPTH_TEST) #should text have a depth or just on top?
        #update list if necss and then call it
        if self.win.winType=='pyglet':
            
            #and align based on x anchor
            if self.alignHoriz=='right':
                GL.glTranslatef(-self.width,0,0)#NB depth is set already
            if self.alignHoriz in ['center', 'centre']:
                GL.glTranslatef(-self.width/2,0,0)#NB depth is set already
                
            #unbind the mask texture regardless
            GL.glActiveTexture(GL.GL_TEXTURE1)
            GL.glEnable(GL.GL_TEXTURE_2D)
            GL.glBindTexture(GL.GL_TEXTURE_2D, 0)
            #unbind the main texture
            GL.glActiveTexture(GL.GL_TEXTURE0)
            GL.glEnable(GL.GL_TEXTURE_2D)
            #then allow pyglet to bind and use texture during drawing
            
            self.glyphStr.draw()            
            GL.glDisable(GL.GL_TEXTURE_2D) 
        else: 
            #for pygame we should (and can) use a drawing list   
            if self.needUpdate: self._updateList()
            GL.glCallList(self._listID)
        GL.glEnable(GL.GL_DEPTH_TEST)                   # Enables Depth Testing
        GL.glPopMatrix()
Beispiel #22
0
 def set_depth_test(self, on=True):
     """Enables z test. On by default"""
     if on:
         gl.glClearDepth(1.0)
         gl.glEnable(gl.GL_DEPTH_TEST)
         gl.glDepthFunc(gl.GL_LEQUAL)
         gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)
     else:
         gl.glDisable(gl.GL_DEPTH_TEST)
Beispiel #23
0
    def update_flags(self):
        if self.view['wireframe']: 
            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
        else:
            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)

        if self.view['cull']:
            gl.glEnable(gl.GL_CULL_FACE)
        else:
            gl.glDisable(gl.GL_CULL_FACE)
Beispiel #24
0
 def init_gl(self):
     gl.glEnable(gl.GL_BLEND)
     gl.glEnable(gl.GL_POINT_SMOOTH)
     gl.glEnable(gl.GL_LINE_SMOOTH)
     gl.glShadeModel(gl.GL_SMOOTH)
     gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
     gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT,gl.GL_NICEST);
     #gl.glHint(gl.GL_POINT_SMOOTH_HINT,gl.GL_NICEST);
     #gl.glHint(gl.GL_LINE_SMOOTH_HINT,gl.GL_NICEST);
     gl.glDisable(gl.GL_DEPTH_TEST)
Beispiel #25
0
	def renderCatalog(cat, far):
		gl.glDisable(gl.GL_LIGHTING)
		for s in cat:
			c = s.getRgb()
			gl.glPointSize(s.getSize())
			gl.glBegin(gl.GL_POINTS)
			gl.glColor3f(c[0], c[1], c[2])
			gl.glVertex3f(far * cos(s.ra_rad) * cos(s.dec_rad), far * sin(s.ra_rad) * cos(s.dec_rad), far * sin(s.dec_rad))
			gl.glEnd()
		gl.glEnable(gl.GL_LIGHTING)
Beispiel #26
0
    def unset_state(self):
        '''
        Disables the scissor test
        '''
        if self._scale != 1.0:
            gl.glPopMatrix(gl.GL_MODELVIEW_MATRIX)

        if not self.was_scissor_enabled:
            gl.glDisable(gl.GL_SCISSOR_TEST)
        gl.glPopAttrib()
Beispiel #27
0
 def set_2d(self, size):
     """Configure OpenGL to draw in 2d."""
     width, height = size
     GL.glDisable(GL.GL_DEPTH_TEST)
     GL.glViewport(0, 0, width, height)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     GL.glOrtho(0, width, 0, height, -1, 1)
     GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glLoadIdentity()
Beispiel #28
0
    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.F and (modifiers & pyglet.window.key.MOD_ACCEL):
            director.window.set_fullscreen(not director.window.fullscreen)
            return True

        elif symbol == pyglet.window.key.P and (modifiers & pyglet.window.key.MOD_ACCEL):
            import cocos.scenes.pause as pause
            pause_sc = pause.get_pause_scene()
            if pause:
                director.push(pause_sc)
            return True

        elif symbol == pyglet.window.key.W and (modifiers & pyglet.window.key.MOD_ACCEL):
            # import wired
            if not self.wired:
                gl.glDisable(gl.GL_TEXTURE_2D)
                gl.glPolygonMode(gl.GL_FRONT, gl.GL_LINE)
                gl.glPolygonMode(gl.GL_BACK, gl.GL_LINE)
                # wired.wired.install()
                # wired.wired.uset4F('color', 1.0, 1.0, 1.0, 1.0 )
                self.wired = True
            else:
                gl.glEnable(gl.GL_TEXTURE_2D)
                gl.glPolygonMode(gl.GL_FRONT, gl.GL_FILL)
                gl.glPolygonMode(gl.GL_BACK, gl.GL_FILL)
                self.wired = False
                # wired.wired.uninstall()
            return True

        elif symbol == pyglet.window.key.X and (modifiers & pyglet.window.key.MOD_ACCEL):
            director.show_FPS = not director.show_FPS
            return True

        elif symbol == pyglet.window.key.I and (modifiers & pyglet.window.key.MOD_ACCEL):
            from .layer import PythonInterpreterLayer

            if not director.show_interpreter:
                if director.python_interpreter is None:
                    director.python_interpreter = cocos.scene.Scene(PythonInterpreterLayer())
                    director.python_interpreter.enable_handlers(True)
                director.python_interpreter.on_enter()
                director.show_interpreter = True
            else:
                director.python_interpreter.on_exit()
                director.show_interpreter = False
            return True

        elif symbol == pyglet.window.key.S and (modifiers & pyglet.window.key.MOD_ACCEL):
            import time
            pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot-%d.png' % (int(time.time())))
            return True

        if symbol == pyglet.window.key.ESCAPE:
            director.pop()
            return True
Beispiel #29
0
 def set_2d(self):
     """ Configure OpenGL to draw in 2d.
     """
     width, height = self.get_size()
     glDisable(GL_DEPTH_TEST)
     glViewport(0, 0, width, height)
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     glOrtho(0, width, 0, height, -1, 1)
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
Beispiel #30
0
 def set_alpha_blending(self, on=True):
     """
     Enables/Disables alpha blending in OpenGL
     using the GL_ONE_MINUS_SRC_ALPHA algorithm.
     On by default.
     """
     if on:
         gl.glEnable(gl.GL_BLEND)
         gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     else:
         gl.glDisable(gl.GL_BLEND)
Beispiel #31
0
 def __init__(self, *args, **kwargs):
     super(GameWindow, self).__init__(*args, **kwargs)
     gl.glClearColor(0.4, 0.4, 0.4, 1.0)
     # gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     # gl.glEnable(gl.GL_BLEND)
     # gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_LINE_SMOOTH)
     clock.schedule_interval(lambda dt: self.dispatch_event('on_update', dt), 0.01)
     self.x, self.y = 0, 0
     self._translation_acc_x, self._translation_acc_y = 0.0, 0.0
Beispiel #32
0
 def set_alpha_blending(self, on=True):
     """
     Enables/Disables alpha blending in OpenGL
     using the GL_ONE_MINUS_SRC_ALPHA algorithm.
     On by default.
     """
     if on:
         gl.glEnable(gl.GL_BLEND)
         gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
     else:
         gl.glDisable(gl.GL_BLEND)
Beispiel #33
0
 def set_2d(self):
     width, height = self.get_size()
     glDisable(GL_CULL_FACE)
     glDisable(GL_DEPTH_TEST)
     viewport = self.get_viewport_size()
     glViewport(0, 0, max(1, viewport[0]), max(1, viewport[1]))
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     glOrtho(0, max(1, width), 0, max(1, height), -1, 1)
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
Beispiel #34
0
    def _startOfFlip(self):
        """Custom :py:class:`~Rift._startOfFlip` for HMD rendering. This
        finalizes the HMD texture before diverting drawing operations back to
        the on-screen window. This allows :py:class:`~Rift.flip` to swap the
        on-screen and HMD buffers when called. This function always returns
        `True`.

        Returns
        -------
        True

        """
        # nop if we are still setting up the window
        if not hasattr(self, '_eyeBuffers'):
            return True

        # direct draw being used, don't do FBO blit
        if self._directDraw:
            return True

        # Switch off multi-sampling
        # GL.glDisable(GL.GL_MULTISAMPLE)
        oldColor = self.color
        self.setColor((-1, -1, -1))
        self.setBuffer('back', clear=True)

        self._prepareFBOrender()
        # need blit the framebuffer object to the actual back buffer

        # unbind the framebuffer as the render target
        GL.glDisable(GL.GL_BLEND)
        stencilOn = self.stencilTest
        self.stencilTest = False

        # before flipping need to copy the renderBuffer to the
        # frameBuffer
        GL.glActiveTexture(GL.GL_TEXTURE0)
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glColor3f(1.0, 1.0, 1.0)  # glColor multiplies with texture
        GL.glColorMask(True, True, True, True)

        # blit the textures to the back buffer
        for eye in ('left', 'right'):
            self._blitEyeBuffer(eye)

        GL.glEnable(GL.GL_BLEND)
        self._finishFBOrender()

        self.stencilTest = stencilOn

        self.setColor(oldColor)

        # This always returns True
        return True
Beispiel #35
0
    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.F and (modifiers & pyglet.window.key.MOD_ACCEL):
            director.window.set_fullscreen(not director.window.fullscreen)
            return True

        elif symbol == pyglet.window.key.P and (modifiers & pyglet.window.key.MOD_ACCEL):
            import cocos.scenes.pause as pause
            pause_sc = pause.get_pause_scene()
            if pause:
                director.push(pause_sc)
            return True

        elif symbol == pyglet.window.key.W and (modifiers & pyglet.window.key.MOD_ACCEL):
            # import wired
            if not self.wired:
                gl.glDisable(gl.GL_TEXTURE_2D)
                gl.glPolygonMode(gl.GL_FRONT, gl.GL_LINE)
                gl.glPolygonMode(gl.GL_BACK, gl.GL_LINE)
                # wired.wired.install()
                # wired.wired.uset4F('color', 1.0, 1.0, 1.0, 1.0 )
                self.wired = True
            else:
                gl.glEnable(gl.GL_TEXTURE_2D)
                gl.glPolygonMode(gl.GL_FRONT, gl.GL_FILL)
                gl.glPolygonMode(gl.GL_BACK, gl.GL_FILL)
                self.wired = False
                # wired.wired.uninstall()
            return True

        elif symbol == pyglet.window.key.X and (modifiers & pyglet.window.key.MOD_ACCEL):
            director.show_FPS = not director.show_FPS
            return True

        elif symbol == pyglet.window.key.I and (modifiers & pyglet.window.key.MOD_ACCEL):
            from .layer import PythonInterpreterLayer

            if not director.show_interpreter:
                if director.python_interpreter is None:
                    director.python_interpreter = cocos.scene.Scene(PythonInterpreterLayer())
                director.python_interpreter.on_enter()
                director.show_interpreter = True
            else:
                director.python_interpreter.on_exit()
                director.show_interpreter = False
            return True

        elif symbol == pyglet.window.key.S and (modifiers & pyglet.window.key.MOD_ACCEL):
            import time
            pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot-%d.png' % (int(time.time())))
            return True

        if symbol == pyglet.window.key.ESCAPE:
            director.pop()
            return True
Beispiel #36
0
 def on_draw(self):
     self.clear()
     self.camera.update()
     self.border.update()
     gl.glEnable(gl.GL_DEPTH_TEST)
     self.axis.update()
     self.terrain.update()
     for model in self.models:
         model.update(self.step)
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glTranslatef(self.width / 2 - 160, self.height / -2 + 20, 0)
     self.clock.draw()
Beispiel #37
0
    def render_mesh(self, segment: bool, enable_leds: bool):
        self.mesh.render(segment=segment)
        if enable_leds and self.kind == MapFormat1Constants.KIND_DUCKIEBOT:
            # attrs =
            # gl.glPushAttrib(gl.GL_ALL_ATTRIB_BITS)
            s_main = 0.01  # 1 cm sphere
            # LIGHT_MULT_MAIN = 10
            s_halo = 0.04
            height = 0.05
            positions = {
                "front_left": [0.1, -0.05, height],
                "front_right": [0.1, +0.05, height],
                "center": [0.1, +0.0, height],
                "back_left": [-0.1, -0.05, height],
                "back_right": [-0.1, +0.05, height],
            }
            if isinstance(self, DuckiebotObj):
                colors = self.leds_color
            else:
                colors = {
                    "center": (0, 0, 1),
                    "front_left": (0, 0, 1),
                    "front_right": (0, 0, 1),
                    "back_left": (0, 0, 1),
                    "back_right": (0, 0, 1),
                }
            for light_name, (px, py, pz) in positions.items():
                color = np.clip(colors[light_name], 0, +1)
                color_intensity = float(np.mean(color))
                gl.glPushMatrix()

                gl.glTranslatef(px, pz, py)

                gl.glEnable(gl.GL_BLEND)
                # gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)

                sphere = gluNewQuadric()

                gl.glColor4f(color[0], color[1], color[2], 1.0)
                gluSphere(sphere, s_main, 10, 10)

                gl.glColor4f(color[0], color[1], color[2], 0.2)

                s_halo_effective = color_intensity * s_halo

                gluSphere(sphere, s_halo_effective, 10, 10)

                gl.glColor4f(1.0, 1.0, 1.0, 1.0)
                gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO)
                gl.glDisable(gl.GL_BLEND)

                gl.glPopMatrix()
Beispiel #38
0
    def draw_fallback(self):
        """Called instead of :meth:`draw` when quads are used instead of
        Point Sprite.
        """
        self.make_delta_pos_to_vertex()
        self.update_vertexs_from_pos()
        self.update_per_vertex_colors()

        gl.glPushMatrix()
        self.transform()

        # color preserve - at least intel 945G needs that
        gl.glPushAttrib(gl.GL_CURRENT_BIT)

        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.texture.id)

        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        vertexs_ptr = PointerToNumpy(self.vertexs)
        gl.glVertexPointer(2, gl.GL_FLOAT, 0, vertexs_ptr)

        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        color_ptr = PointerToNumpy(self.per_vertex_colors)
        # gl.glColorPointer(4, gl.GL_UNSIGNED_BYTE, 0, color_ptr)
        gl.glColorPointer(4, gl.GL_FLOAT, 0, color_ptr)

        gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        tex_coord_ptr = PointerToNumpy(self.tex_coords)
        gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, tex_coord_ptr)

        gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
        gl.glEnable(gl.GL_BLEND)
        if self.blend_additive:
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)
        else:
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glDrawArrays(gl.GL_QUADS, 0, len(self.vertexs) * 4)

        # un -blend
        gl.glPopAttrib()

        # color restore
        gl.glPopAttrib()

        # disable states
        gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
        gl.glDisableClientState(gl.GL_COLOR_ARRAY)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        gl.glDisable(gl.GL_TEXTURE_2D)

        gl.glPopMatrix()
Beispiel #39
0
    def _text_glyphs_gl(self):
        if not self._text_dlist:
            dl_index = glGenLists(1)
            glNewList(dl_index, GL_COMPILE)

            # stime=getTime()

            # self._text_box._te_start_gl()

            ###
            glActiveTexture(GL_TEXTURE0)
            glEnable(GL_TEXTURE_2D)
            glBindTexture(
                GL_TEXTURE_2D, self._text_box._current_glfont.atlas.texid)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
            glTranslatef(self._position[0], -self._position[1], 0)
            glPushMatrix()

            ###

            getLineInfoByIndex = self._text_document.getLineInfoByIndex
            active_text_style_dlist = self._current_font_display_lists.get
            cell_width, cell_height = self._cell_size
            num_cols, num_rows = self._shape
            line_spacing = self._text_box._getPixelTextLineSpacing()
            line_count = self.getRowCountWithText()

            glColor4f(*self._text_box._toRGBA(self._font_color))

            for r in range(line_count):
                cline, line_length, line_display_list, line_ords = getLineInfoByIndex(
                    r)
                if line_display_list[0] == 0:
                    line_display_list[0:line_length] = [
                        active_text_style_dlist(c) for c in line_ords]

                glTranslatef(cline._trans_left * cell_width, -
                             int(line_spacing/2.0 + cline._trans_top * cell_height), 0)
                glCallLists(line_length, GL_UNSIGNED_INT,
                            line_display_list[0:line_length].ctypes)
                cline._trans_left = 0
                glTranslatef(-line_length * cell_width - cline._trans_left * cell_width, -
                             cell_height + int(line_spacing/2.0 + cline._trans_top * cell_height), 0)

                ###
            glPopMatrix()
            glBindTexture(GL_TEXTURE_2D, 0)
            glDisable(GL_TEXTURE_2D)

            glEndList()
            self._text_dlist = dl_index
        glCallList(self._text_dlist)
 def draw_transition(self, percentage_done):
     if self.destination is None:
         self.source.alpha = 1 - percentage_done
         self.source.render()
     elif self.source is None:
         self.destination.alpha = percentage_done
         self.destination.render()
     elif self.source and self.destination:
         gl.glDisable(gl.GL_BLEND)
         self.source.render()
         gl.glEnable(gl.GL_BLEND)
         self.destination.alpha = percentage_done
         self.destination.render()
Beispiel #41
0
    def set_2d(self):
        """ Configure Opengl.GL to draw in 2d.

        """
        width, height = self.get_size()
        gl.glDisable(gl.GL_DEPTH_TEST)
        viewport = self.get_viewport_size()
        gl.glViewport(0, 0, max(1, viewport[0]), max(1, viewport[1]))
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.glOrtho(0, max(1, width), 0, max(1, height), -1, 1)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
Beispiel #42
0
def DrawRectangle(rect, color):
    '''Draw a rectangle'''

    vertarray = VertsForRectangle(rect)

    LineIndicies = [0, 1, 1, 2, 2, 3, 3, 0]

    gl.glDisable(gl.GL_TEXTURE_2D)
    pyglet.gl.glColor4f(color[0], color[1], color[2], color[3])
    pyglet.graphics.draw_indexed(
        len(vertarray) / 3, gl.GL_LINES, LineIndicies, ('v3f', vertarray))

    pyglet.gl.glColor4f(1.0, 1.0, 1.0, 1.0)
Beispiel #43
0
    def render(self):
        for idx, vlist in enumerate(self.vlists):
            texture = self.textures[idx]

            if texture:
                glEnable(GL_TEXTURE_2D)
                glBindTexture(texture.target, texture.id)
            else:
                glDisable(GL_TEXTURE_2D)

            vlist.draw(GL_TRIANGLES)

        glDisable(GL_TEXTURE_2D)
Beispiel #44
0
 def render_img(img, x, y, w, h):
     img_data = pyglet.image.ImageData(
         img.shape[1], img.shape[0], 'RGB', img.tobytes())
     tex = img_data.get_texture()
     gl.glEnable(gl.GL_TEXTURE_2D)
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
     gl.glBindTexture(gl.GL_TEXTURE_2D, tex.id)
     pyglet.graphics.draw_indexed(4, gl.GL_TRIANGLE_STRIP,
         [0, 1, 2, 0, 2, 3],
         ('v2f', (x, y+h, x+w, y+h, x+w, y, x, y)),
         ('t3f', tex.tex_coords),
     )
     gl.glDisable(gl.GL_TEXTURE_2D)
Beispiel #45
0
    def _setup_2d(self):
        w, h = self.get_size()
        gl.glDisable(gl.GL_DEPTH_TEST)

        viewport = self.get_viewport_size()
        gl.glViewport(0, 0, max(1, viewport[0]), max(1, viewport[1]))

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.glOrtho(0, max(1, w), 0, max(1, h), -1, 1)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
 def world_projection(self):
     """
     Project the world.
     """
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glViewport(0, 0, self.win.width, self.win.height)
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     width_ratio = self.win.width / self.win.height
     gl.gluOrtho2D(-self.zoom * width_ratio, self.zoom * width_ratio,
                   -self.zoom, self.zoom)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
Beispiel #47
0
def quad_aligned(x, y, w, h, color):
    quad_data = pyglet.graphics.vertex_list_indexed(
                 4,
                 [0, 1, 2, 2, 3, 0],
                 ('v2i', (x, y,
                          x + w, y,
                          x + w, y + h,
                          x, y + h)),
                 ('c4B', color * 4))

    gl.glEnable(gl.GL_BLEND)
    quad_data.draw(pyglet.gl.GL_TRIANGLES)
    gl.glDisable(gl.GL_BLEND)
Beispiel #48
0
    def disable(self, *args):
        """
        Disable one or more context flags::

            # Single flag
            ctx.disable(ctx.BLEND)
            # Multiple flags
            ctx.disable(ctx.DEPTH_TEST, ctx.CULL_FACE)
        """
        self._flags -= set(args)

        for flag in args:
            gl.glDisable(flag)
Beispiel #49
0
    def draw(self, uniforms, entity, models, textures=(), color=(1.0, 1.0, 1.0), *args, **kwargs):
        glUseProgram(self)
        glDisable(GL_DEPTH_TEST)

        # Draw objects once as invisible to set stencil values.
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE)  # Don't write any color values to color buffer.
        glStencilMask(0xFF)  # Enable writing.


        model = models[entity.model]

        model.positions.enable()
        model.indices.enable()

        glUniformMatrix4fv(
            self.uniforms[b'perspective'], 1, GL_TRUE, uniforms.get(b'perspective').ctypes.data_as(POINTER(GLfloat))
        )
        glUniformMatrix4fv(
            self.uniforms[b'view'], 1, GL_TRUE, uniforms.get(b'view').ctypes.data_as(POINTER(GLfloat))
        )
        glUniform3f(self.uniforms[b'color'], *color)

        glUniformMatrix4fv(
            self.uniforms[b'transformation'], 1, GL_TRUE,
            entity.get_transformation_matrix().ctypes.data_as(POINTER(GLfloat))
        )

        model.draw()

        # Draw again with larger model.
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)

        glStencilFunc(GL_NOTEQUAL, 1, 0xFF)  # Update with 1's where the objects are rendered.
        glStencilMask(0x00)  # Value that AND's the value written to buffer. 0x00 basically disables writing to stencil.

        glUniformMatrix4fv(
            self.uniforms[b'transformation'], 1, GL_TRUE,
            create_transformation_matrix(
                *entity.location, *entity.rotation, *(entity.scale + 0.05)
            ).ctypes.data_as(POINTER(GLfloat))
        )

        model.draw()

        glBindBuffer(GL_ARRAY_BUFFER, 0)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)

        glDisableVertexAttribArray(0)

        glEnable(GL_DEPTH_TEST)
        glStencilMask(0xFF)
Beispiel #50
0
    def enable_only(self, *args):
        """
        Enable only some flags. This will disable all other flags.
        This is a simple way to ensure that context flag states
        are not lingering from other sections of your code base::

            # Ensure all flags are disabled (enable no flags)
            ctx.enable_only()
            # Make sure only blending is enabled
            ctx.enable_only(ctx.BLEND)
            # Make sure only depth test and culling is enabled
            ctx.enable_only(ctx.DEPTH_TEST, ctx.CULL_FACE)        
        """
        self._flags = set(args)

        if self.BLEND in self._flags:
            gl.glEnable(self.BLEND)
        else:
            gl.glDisable(self.BLEND)

        if self.DEPTH_TEST in self._flags:
            gl.glEnable(self.DEPTH_TEST)
        else:
            gl.glDisable(self.DEPTH_TEST)

        if self.CULL_FACE in self._flags:
            gl.glEnable(self.CULL_FACE)
        else:
            gl.glDisable(self.CULL_FACE)

        if self.PROGRAM_POINT_SIZE in self._flags:
            gl.glEnable(self.PROGRAM_POINT_SIZE)
        else:
            gl.glDisable(self.PROGRAM_POINT_SIZE)
Beispiel #51
0
def DrawTriangles(verts, Triangles):
    LineIndicies = LineIndiciesFromTri(Triangles)

    zCoords = numpy.ones((len(verts), 1), dtype=verts.dtype)
    Points = numpy.hstack((verts, zCoords))

    FlatPoints = Points.ravel().tolist()
    vertarray = (gl.GLfloat * len(FlatPoints))(*FlatPoints)

    gl.glDisable(gl.GL_TEXTURE_2D)
    pyglet.gl.glColor4f(1.0, 0, 0, 1.0)
    pyglet.graphics.draw_indexed(
        len(vertarray) // 3, gl.GL_LINES, LineIndicies, ('v3f', vertarray))
    pyglet.gl.glColor4f(1.0, 1.0, 1.0, 1.0)
Beispiel #52
0
    def multi_draw(*args, **kwargs):
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glClearColor(0, 0, 0, 0)
        gl.glColor4f(1, 1, 1, 1)

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        if not buffers:
            buffers.append(image.get_buffer_manager())
        x, y, w, h = buffers[0].get_viewport()

        #Draw lowres version
        gl.glViewport(0, 0, 256, 256)
        func(*args, **kwargs)
        texes.append(buffers[0].get_color_buffer().texture)
        if len(texes) > num_texes:
            texes.pop(0)

        #Lay down copies of lowres version
        gl.glViewport(x, y, w, h)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        if texes:
            alphas = range(1, len(texes) + 1)
            alphas = [float(f) / sum(alphas) for f in alphas]
            for tex, alpha in zip(texes, alphas):
                gl.glBindTexture(tex.target, tex.id)

                gl.glEnable(gl.GL_TEXTURE_2D)
                gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                                   gl.GL_LINEAR)

                gl.glColor4f(1, 1, 1, alpha)
                gl.glBegin(gl.GL_QUADS)
                gl.glTexCoord2f(0, 0)
                gl.glVertex3f(0, 0, -.5)
                gl.glTexCoord2f(1, 0)
                gl.glVertex3f(w, 0, -.5)
                gl.glTexCoord2f(1, 1)
                gl.glVertex3f(w, h, -.5)
                gl.glTexCoord2f(0, 1)
                gl.glVertex3f(0, h, -.5)
                gl.glEnd()
                gl.glDisable(gl.GL_TEXTURE_2D)

        #Draw real thing
        gl.glColor4f(1, 1, 1, 1)
        func(*args, **kwargs)
Beispiel #53
0
    def init_model(self, scene):
        """ Add the pyramid normals and vertices to the View

        :param scene: The view to render the model to.
        :type scene: pyglet_helper.objects.View
        """
        # Note that this model is also used by arrow!
        scene.pyramid_model.gl_compile_begin()

        vertices = [[0, .5, .5],
                    [0, -.5, .5],
                    [0, -.5, -.5],
                    [0, .5, -.5],
                    [1, 0, 0]]
        triangle_indices = [0, 0, 0] * 6
        triangle_indices[0] = [3, 0, 4]  # top
        triangle_indices[1] = [1, 2, 4]  # bottom
        triangle_indices[2] = [0, 1, 4]  # front
        triangle_indices[3] = [3, 4, 2]  # back
        triangle_indices[4] = [0, 3, 2]  # left (base) 1
        triangle_indices[5] = [0, 2, 1]  # left (base) 2

        normals = [[1, 2, 0], [1, -2, 0], [1, 0, 2], [1, 0, -2], [-1, 0, 0],
                   [-1, 0, 0]]

        gl.glEnable(gl.GL_CULL_FACE)
        gl.glBegin(gl.GL_TRIANGLES)

        # Inside
        for face in range(0, 6):
            gl.glNormal3f(-normals[face][0], -normals[face][1], -normals[face][2])
            for vertex in range(0, 3):
                #print triangle_indices[face]
                #print vertices[triangle_indices[face]][2 - vertex]
                vert = [gl.GLfloat(i) for i in
                        vertices[triangle_indices[face][2 - vertex]]]
                gl.glVertex3f(*vert)

        # Outside
        for face in range(0, 6):
            gl.glNormal3fv(*[gl.GLfloat(i) for i in normals[face]])
            for vertex in range(0, 3):
                gl.glVertex3f(*[gl.GLfloat(i) for i in vertices[triangle_indices[
                                face][vertex]]])

        gl.glEnd()
        gl.glDisable(gl.GL_CULL_FACE)
        self.compiled = True

        scene.pyramid_model.gl_compile_end()
def draw_texture(texture):
    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glBindTexture(gl.GL_TEXTURE_2D, texture)

    gl.glTranslatef(50, 50, 0)
    gl.glScalef(7, 7, 1)

    pyglet.graphics.draw_indexed(
        4, gl.GL_TRIANGLES, [0, 1, 2, 2, 1, 3],
        ('v2i', (0, 0, BUF_WIDTH, 0, 0, BUF_HEIGHT, BUF_WIDTH, BUF_HEIGHT)),
        ('t2f', (0, 0, 1, 0, 0, 1, 1, 1)))

    gl.glBindTexture(gl.GL_TEXTURE_2D, 0)
    gl.glDisable(gl.GL_TEXTURE_2D)
Beispiel #55
0
 def draw_question(self):
     if not self.parent.visible:
         return
     gl.glDisable(gl.GL_TEXTURE_2D)
     x, y = self.x, self.y
     draw_border(x, y, self.width, self.height)
     self.questionLabel.draw()
     pressed = self.player.mouse.left
     over = self.overBox
     for id, answer in enumerate(self.answers):
         state = id == over and pressed
         draw_border(answer.x + 6, answer.y + 2, self.width - 12, 
             answer.content_height + 4, state)
         answer.draw()
Beispiel #56
0
    def multi_draw(*args, **kwargs):
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glClearColor(0, 0, 0, 0)
        gl.glColor4f(1, 1, 1, 1)

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        if not buffers:
            buffers.append(image.get_buffer_manager())
        x, y, w, h = buffers[0].get_viewport()

        #Draw lowres version
        gl.glViewport(0, 0, 256, 256)
        func(*args, **kwargs)
        ctex[0] = buffers[0].get_color_buffer().texture

        #Lay down copies of lowres version
        gl.glViewport(x, y, w, h)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glBindTexture(ctex[0].target, ctex[0].id)
        gl.glEnable(gl.GL_TEXTURE_2D)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_LINEAR)
        if not disp_list:
            disp_list.append(gl.glGenLists(1))
            gl.glNewList(disp_list[0], gl.GL_COMPILE)
            for u in range(-3, 4, 3):
                for v in range(-3, 4, 3):
                    gl.glColor4f(1, 1, 1, (20.0 - u**2 - v**2) / 72)
                    gl.glBegin(gl.GL_QUADS)
                    gl.glTexCoord2f(0, 0)
                    gl.glVertex3f(u, v, -.5)
                    gl.glTexCoord2f(1, 0)
                    gl.glVertex3f(u + w, v, -.5)
                    gl.glTexCoord2f(1, 1)
                    gl.glVertex3f(u + w, v + h, -.5)
                    gl.glTexCoord2f(0, 1)
                    gl.glVertex3f(u, v + h, -.5)
                    gl.glEnd()
            gl.glEndList()
        gl.glCallList(disp_list[0])
        gl.glDisable(gl.GL_TEXTURE_2D)

        #Draw real thing
        gl.glColor4f(1, 1, 1, 1)
        func(*args, **kwargs)
Beispiel #57
0
	def draw_translucent_fancy(self):
		gl.glDepthMask(gl.GL_FALSE)
		gl.glFrontFace(gl.GL_CW)
		gl.glEnable(gl.GL_BLEND)

		for render_chunk in self.sorted_chunks:
			render_chunk.draw_translucent(gl.GL_TRIANGLES)
		
		gl.glFrontFace(gl.GL_CCW)
		
		for render_chunk in self.sorted_chunks:
			render_chunk.draw_translucent(gl.GL_TRIANGLES)

		gl.glDisable(gl.GL_BLEND)
		gl.glDepthMask(gl.GL_TRUE)
Beispiel #58
0
        def on_draw():
            gl.glEnable(gl.GL_BLEND)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            gl.gluOrtho2D(0, 1, 1, 0)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glViewport(0, 0, self.width, self.height)

            gl.glEnable(gl.GL_TEXTURE_2D)
            gl.glBindTexture(self.texture.target, self.texture.id)
            self.draw(0, 0, 1, 1)
            gl.glDisable(gl.GL_TEXTURE_2D)
Beispiel #59
0
def point_sprites_available():
    """returns a bool telling if point sprites are available

    For development and diagonostic cocos.particle.forced_point_sprites could
    be set to force the desired return value
    """
    if forced_point_sprites is not None:
        return forced_point_sprites
    have_point_sprites = True
    try:
        gl.glEnable(gl.GL_POINT_SPRITE)
        gl.glDisable(gl.GL_POINT_SPRITE)
    except:
        have_point_sprites = False
    return have_point_sprites
Beispiel #60
0
    def init_ortho(self):
        # disable shaders
        gl.glUseProgram(0)
        gl.glDisable(gl.GL_LIGHTING)

        # store the projection matrix to restore later
        gl.glMatrixMode(gl.GL_PROJECTION)

        # load orthographic projection matrix
        gl.glLoadIdentity()
        gl.glOrtho(0, self.width, 0, self.height, -1, 500)

        # reset modelview
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()