Ejemplo n.º 1
0
    def _layerProjectLocalToScreen(self):
        """Maps self.coordLocal to self.coordScreen within OpenGL."""
        if self._scissorBox is None and self.localBounds is None:
            return
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        # gluOrtho2D declares the render space for the corners of the window.
        # So, we want to set it up in such a way that our layer renders in
        # the right place.  In other words, determine window corners that
        # map cl -> cs.  All clipping, etc is already handled by the coordsLocal
        # getter.
        cs = self.coordsScreen
        cl = self.coordsLocal
        sw = self.scene.width
        sh = self.scene.height

        # Determine the window width and height.  We want a local-sized chunk
        # of this to correspond to a screen-sized chunk of the screen.  That is,
        # cl[2] / ww == cs[2] / sw
        ww = cl[2] * sw / cs[2]
        wh = cl[3] * sh / cs[3]

        # cs[0] / sw = (x - nx) / ww
        nx = cl[0] - cs[0] * ww / sw
        ny = cl[1] - cs[1] * wh / sh
        gl.gluOrtho2D(nx, nx + ww, ny, ny + wh)
        gl.glMatrixMode(gl.GL_MODELVIEW)
Ejemplo n.º 2
0
Archivo: game.py Proyecto: Terrub/RLA
    def render_to_window(self):
        """
        Renders the game to the current window
        """
        window = self.window
        camera = self.camera

        y = camera.y
        x = camera.x

        x1 = x
        x2 = window.width + x
        y1 = y
        y2 = window.height + y

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(x1, x2, y1, y2)

        glClear(GL_COLOR_BUFFER_BIT)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.draw_world()
        self.draw_hud()

        window.flip()
Ejemplo n.º 3
0
    def _set_texture(self, t):
        self._texture = t
        from pyglet import gl
        try:
            gl.glFramebufferTexture2DEXT(
                gl.GL_FRAMEBUFFER_EXT,
                gl.GL_COLOR_ATTACHMENT0_EXT,
                t.target, t.id, 0,
            )
        except gl.GLException:
            # HACK: Some Intel card return errno == 1286L
            # which means GL_INVALID_FRAMEBUFFER_OPERATION_EXT
            # but IT ACTUALLY WORKS FINE!!
            pass

        gl.glViewport(0, 0, t.width, t.height)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluOrtho2D(0, t.width, 0, t.height)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        # ATI cards hack
        gl.glBegin(gl.GL_LINES)
        gl.glEnd()
Ejemplo n.º 4
0
    def paint(self, func):
        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,
            self.width,
            0,
            self.height
        )

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

        gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT,
                                self.col_buffer.gl_buffer)

        gl.glFramebufferTexture2DEXT(
            gl.GL_DRAW_FRAMEBUFFER_EXT,
            gl.GL_COLOR_ATTACHMENT0_EXT,
            self.texture.target, self.texture.id, 0)

        func()

        gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, 0)
Ejemplo n.º 5
0
    def _layerProjectLocalToScreen(self):
        """Maps self.coordLocal to self.coordScreen within OpenGL."""
        if self._scissorBox is None and self.localBounds is None:
            return
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        # gluOrtho2D declares the render space for the corners of the window.
        # So, we want to set it up in such a way that our layer renders in
        # the right place.  In other words, determine window corners that
        # map cl -> cs.  All clipping, etc is already handled by the coordsLocal
        # getter.
        cs = self.coordsScreen
        cl = self.coordsLocal
        sw = self.scene.width
        sh = self.scene.height

        # Determine the window width and height.  We want a local-sized chunk
        # of this to correspond to a screen-sized chunk of the screen.  That is,
        # cl[2] / ww == cs[2] / sw
        ww = cl[2] * sw / cs[2]
        wh = cl[3] * sh / cs[3]

        # cs[0] / sw = (x - nx) / ww
        nx = cl[0] - cs[0] * ww / sw
        ny = cl[1] - cs[1] * wh / sh
        gl.gluOrtho2D(nx, nx+ww, ny, ny+wh)
        gl.glMatrixMode(gl.GL_MODELVIEW)
Ejemplo n.º 6
0
Archivo: geom.py Proyecto: Knio/miru
def get_vlist(geom, batch=None, group=None, data=None):
        """Get a "new" C{pyglet.graphics.VertexList} for this
        geometry.  If a batch is given, vertex list will be added to the batch
        """
        # projection with one world coordinate unit equal to one screen pixel
        # glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, windowWidth, 0, windowHeight);
        window = pyglet.window.get_platform().get_default_display().get_windows()[0]
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluOrtho2D(0,
                      window.width,
                      0,
                      window.height)
        _data = [('v3f', geom.vertex_data)]
        if hasattr(geom, 'normal_data'):
            _data.append(('n3f', geom.normal_data))
        if hasattr(geom, 'texcoord_data'):
            _data.append(('t2f', geom.texcoord_data))
        if data:
            _data.extend(data)
        count = len(geom.vertex_data) // geom.vertex_pitch
        indexed = hasattr(geom, 'indices')
        if batch:
            if indexed:
                return batch.add_indexed( count,
                        geom.drawing_mode, group, geom.indices, *_data)
            return batch.add( count,
                    geom.drawing_mode, group, *_data)
        if indexed:
            return pyglet.graphics.vertex_list_indexed( count, geom.indices, *_data )
        return pyglet.graphics.vertex_list( count, *_data)
Ejemplo n.º 7
0
    def world_projection(self, aspect):
        """
        Sets OpenGL projection and modelview matrices such that the window
        is centered on self.(x,y), shows at least scale world units in every
        direction, and is oriented by angle.
        """
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        if aspect < 1:
            gluOrtho2D(
                -self.scale,
                +self.scale,
                -self.scale / aspect,
                +self.scale / aspect)
        else:
            gluOrtho2D(
                -self.scale * aspect,
                +self.scale * aspect,
                -self.scale,
                +self.scale)

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(
            self.x, self.y, +1.0,
            self.x, self.y, -1.0,
            sin(self.angle), cos(self.angle), 0.0)
Ejemplo n.º 8
0
Archivo: camera.py Proyecto: msarch/py
 def hud_mode(self):
     "Set matrices ready for drawing HUD, like fps counter"
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     gluOrtho2D(0, self.win_width, 0, self.win_height)
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
Ejemplo n.º 9
0
def gl_setup():  # general GL setup
    glMatrixMode(GL_PROJECTION)
    glMatrixMode(GL_MODELVIEW)
    gluOrtho2D(0, WIDTH, 0, HEIGHT)  # dont understand, check this                # TODO
    glLoadIdentity()
    glTranslatef(CENTX, CENTY, 0)
    glClear(GL_COLOR_BUFFER_BIT)
Ejemplo n.º 10
0
    def world_projection(self):
        """
        Sets OpenGL projection and modelview matrices such that the window
        is centered on self.(x,y), shows at least 'scale' world units in every
        direction, and is oriented by rot.
        """
        left = bottom = -self.scale
        right = top = self.scale
        aspect = self.width / self.height
        if aspect >= 1:
            # landscape
            left *= aspect
            right *= aspect
        else:
            # portrait
            bottom /= aspect
            top /= aspect
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(left, right, bottom, top)

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(
            self.x, self.y, +1.0,
            self.x, self.y, -1.0,
            sin(self.rot), cos(self.rot), 0.0)
Ejemplo n.º 11
0
    def render(self, return_rgb_array=False):
        glClearColor(1, 1, 1, 1)
        self.window.clear()
        self.window.switch_to()
        self.window.dispatch_events()
        self.transform.enable()
        for geom in self.geoms:
            geom.render()
        for geom in self.onetime_geoms:
            geom.render()
        self.transform.disable()

        pyglet.gl.glMatrixMode(pyglet.gl.GL_PROJECTION)
        pyglet.gl.glLoadIdentity()
        gluOrtho2D(0, self.window.width, 0, self.window.height)
        for geom in self.text_lines:
            geom.render()

        arr = None
        if return_rgb_array:
            buffer = pyglet.image.get_buffer_manager().get_color_buffer()
            image_data = buffer.get_image_data()
            arr = np.frombuffer(image_data.get_data(), dtype=np.uint8)
            # In https://github.com/openai/gym-http-api/issues/2, we
            # discovered that someone using Xmonad on Arch was having
            # a window of size 598 x 398, though a 600 x 400 window
            # was requested. (Guess Xmonad was preserving a pixel for
            # the boundary.) So we use the buffer height/width rather
            # than the requested one.
            arr = arr.reshape(buffer.height, buffer.width, 4)
            arr = arr[::-1, :, 0:3]
        self.window.flip()
        self.onetime_geoms = []
        return arr
Ejemplo n.º 12
0
Archivo: camera.py Proyecto: msarch/py
    def update(self):
        self.x += (self.target_x - self.x) * 0.1
        self.y += (self.target_y - self.y) * 0.1
        self.scale += (self.target_scale - self.scale) * 0.1
        self.angle += (self.target_angle - self.angle) * 0.1

        "Set projection and modelview matrices ready for rendering"

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        gluOrtho2D(
            -self.scale * self.aspect,
            +self.scale * self.aspect,
            -self.scale,
            +self.scale)

        # Set modelview matrix to move, scale & rotate to camera position"
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(
            self.x, self.y, +1.0,
            self.x, self.y, -1.0,
            sin(self.angle), cos(self.angle), 0.0)
        print 'gluLookAt:', self.x,self.y, self.angle
Ejemplo n.º 13
0
def bind_texture_region(texture, x, y, w, h, premultiplied=False, flip=False):
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                       gl.GL_NEAREST)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                       gl.GL_NEAREST)
    gl.glEnable(gl.GL_SCISSOR_TEST)

    gl.glEnable(gl.GL_BLEND)
    if premultiplied:
        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)

    else:
        gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA,
                               gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    gl.glViewport(x, y, w, h)
    gl.glScissor(x, y, w, h)

    gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT,
                            Manager.col_buffer.gl_buffer)

    gl.glFramebufferTexture2DEXT(gl.GL_DRAW_FRAMEBUFFER_EXT,
                                 gl.GL_COLOR_ATTACHMENT0_EXT, texture.target,
                                 texture.id, 0)

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    if flip:
        gl.gluOrtho2D(0, w, h, 0)
    else:
        gl.gluOrtho2D(0, w, 0, h)
Ejemplo n.º 14
0
    def _set_texture(self, t):
        self._texture = t
        from pyglet import gl
        try:
            gl.glFramebufferTexture2DEXT(
                gl.GL_FRAMEBUFFER_EXT,
                gl.GL_COLOR_ATTACHMENT0_EXT,
                t.target,
                t.id,
                0,
            )
        except gl.GLException:
            # HACK: Some Intel card return errno == 1286L
            # which means GL_INVALID_FRAMEBUFFER_OPERATION_EXT
            # but IT ACTUALLY WORKS FINE!!
            pass

        gl.glViewport(0, 0, t.width, t.height)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluOrtho2D(0, t.width, 0, t.height)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        # ATI cards hack
        gl.glBegin(gl.GL_LINES)
        gl.glEnd()
Ejemplo n.º 15
0
    def set_state(self):
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.gluOrtho2D(0, self.window.width, 0, self.window.height)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        gl.glLoadIdentity()
Ejemplo n.º 16
0
def bind_window(w, h):
    gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, 0)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    gl.glViewport(0, 0, w, h)
    gl.glScissor(0, 0, w, h);
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluOrtho2D(0, w, h, 0)
Ejemplo n.º 17
0
 def enable_2d(self):
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     gl.gluOrtho2D(0.0, self.width, 0.0, self.height)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_CULL_FACE)
     gl.glDisable(gl.GL_LIGHTING)
Ejemplo n.º 18
0
    def set_state(self):
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.gluOrtho2D(0, self.window.width, 0, self.window.height)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        gl.glLoadIdentity()
Ejemplo n.º 19
0
def bind_window(w, h):
    gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, 0)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    gl.glViewport(0, 0, w, h)
    gl.glScissor(0, 0, w, h)
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    gl.gluOrtho2D(0, w, h, 0)
Ejemplo n.º 20
0
 def worldProjection(self):
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     widthRatio = self.win.width / self.win.height
     gluOrtho2D(
         -self.zoom * widthRatio,
         self.zoom * widthRatio,
         -self.zoom,
         self.zoom)
Ejemplo n.º 21
0
 def focus(self):
     try:
         gl.glMatrixMode(gl.GL_PROJECTION)
         gl.glLoadIdentity()
         gl.gluOrtho2D(0, settings.GAME_WIDTH + PANEL_WIDTH, 0, settings.GAME_HEIGHT + HUD_HEIGHT)
         gl.glMatrixMode(gl.GL_MODELVIEW)
         gl.glLoadIdentity()
     except Exception, e:
         time.sleep(0.0001)
         print(e, traceback.print_exc())
Ejemplo n.º 22
0
 def focus(self):
     try:
         gl.glMatrixMode(gl.GL_PROJECTION)
         gl.glLoadIdentity()
         gl.gluOrtho2D(0, settings.GAME_WIDTH, 0, settings.GAME_HEIGHT + HUD_HEIGHT)
         gl.glMatrixMode(gl.GL_MODELVIEW)
         gl.glLoadIdentity()
     except Exception as e:
         time.sleep(0.0001)
         logger.error("%s\n\t%s"  %(e, traceback.format_exc()))
Ejemplo n.º 23
0
Archivo: pygtest.py Proyecto: emblem/bb
    def on_resize(self, w, h):
        gl.glViewport(0, 0, w, h)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()

        vw = max(1, w / float(h)) * .5
        vh = max(1, h / float(w)) * .5

        gl.gluOrtho2D(-vw, vw, -vh + .9 * vh, vh + .9 * vh)
        gl.glMatrixMode(gl.GL_MODELVIEW)
Ejemplo n.º 24
0
    def hud_projection(self, size):
        """
        Sets OpenGL pojection and modelview matrices such that the window
        renders (0,0) to (size.x, size,y)
        """
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(0, size[0], 0, size[1])
Ejemplo n.º 25
0
        def draw_label(width, height):
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()

            gl.gluOrtho2D(0, width, height, 0)

            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glViewport(0, 0, width, height)

            self.label.draw()
Ejemplo n.º 26
0
    def __enter__(self):
        w, h = self.size
        cx, cy = self.center
        dx, dy = 0.5*self.get_pixel_extent()*(w, h)

        gl.glViewport(0, 0, w, h)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluOrtho2D(cx-dx, cx+dx, cy-dy, cy+dy)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
Ejemplo n.º 27
0
	def draw(self, selected_unit):
		glLoadIdentity()
		gluOrtho2D(0, self.window.width, 0, self.window.height)
		if selected_unit is not None:
			if self.action_gui_batch is None:
				self.build_action_gui(selected_unit)
			if self.action_gui_batch is not None:
				self.action_gui_batch.draw()
			if self.status_gui_batch is None:
				self.build_status_gui()
			self.status_box.set_text(selected_unit.status)
			self.status_gui_batch.draw()
Ejemplo n.º 28
0
    def ui_mode(self):
        gl.glDisable(gl.GL_DEPTH_TEST)
        gl.glDisable(gl.GL_CULL_FACE)
        gl.glDisable(gl.GL_TEXTURE_2D)
        gl.glDisable(gl.GL_LIGHTING)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.gluOrtho2D(-self.w / 2, self.w / 2, -self.h / 2, self.h / 2)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
Ejemplo n.º 29
0
    def focus(self, width, height):
        "Set projection and modelview matrices ready for rendering"

        # Set projection matrix suitable for 2D rendering"
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        aspect = width / height
        gluOrtho2D(-self.scale * aspect, +self.scale * aspect, -self.scale, +self.scale)

        # Set modelview matrix to move, scale & rotate to camera position"
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(self.x, self.y, +1.0, self.x, self.y, -1.0, sin(self.angle), cos(self.angle), 0.0)
Ejemplo n.º 30
0
    def focus(self, width, height):
        "Set projection and model view matrices ready for rendering"
        # Set projection matrix suitable for 2D rendering"
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        aspect = width / height
        gluOrtho2D(-self.scale * aspect, +self.scale * aspect, -self.scale,
                   +self.scale)

        # Set model view matrix to move, scale & rotate to camera position"
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(self.x, self.y, 1.0, self.x, self.y, -1.0, 0.0, 1.0, 0.0)
Ejemplo n.º 31
0
 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()
Ejemplo n.º 32
0
 def translateForPixels(self, x, y):
     """Returns a context manager that translates to x, y in local coords and
     then changes the scaling so that subsequent rendering happens in
     pixel space.  Useful to get around scaling."""
     cs = (0, 0, self.scene.width, self.scene.height)
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glPushMatrix()
     gl.glLoadIdentity()
     gl.gluOrtho2D(cs[0], cs[2], cs[1], cs[3])
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glPushMatrix()
     gl.glLoadIdentity()
     s = self._layerMapToScreen(x, y)
     gl.glTranslatef(s[0], s[1], 0.0)
     return _RestoreProjectionAndModelview()
Ejemplo n.º 33
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)
Ejemplo n.º 34
0
 def translateForPixels(self, x, y):
     """Returns a context manager that translates to x, y in local coords and
     then changes the scaling so that subsequent rendering happens in
     pixel space.  Useful to get around scaling."""
     cs = (0, 0, self.scene.width, self.scene.height)
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glPushMatrix()
     gl.glLoadIdentity()
     gl.gluOrtho2D(cs[0], cs[2], cs[1], cs[3])
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glPushMatrix()
     gl.glLoadIdentity()
     s = self._layerMapToScreen(x, y)
     gl.glTranslatef(s[0], s[1], 0.0)
     return _RestoreProjectionAndModelview()
Ejemplo n.º 35
0
        def draw_label(width, height):
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()

            gl.gluOrtho2D(
                0,
                width,
                height,
                0
            )

            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            gl.glViewport(0, 0, width, height)

            self.label.draw()
Ejemplo n.º 36
0
Archivo: field.py Proyecto: msarch/py
    def focus(cls):
        # Set projection matrix suitable for 2D rendering"
        #glMatrixMode(GL_PROJECTION)
        #glLoadIdentity()
        #gluOrtho2D( -SCALE * ASPECT, SCALE * ASPECT,-SCALE,SCALE)

        ## Set modelview matrix to move, scale & rotate to camera position"
        #glMatrixMode(GL_MODELVIEW)
        #glLoadIdentity()
        #gluLookAt( CENTX, CENTY, +1.0, CENTX, CENTY, -1.0, 0, 1, 0.0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(0, WIDTH, 0, HEIGHT)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
Ejemplo n.º 37
0
Archivo: field.py Proyecto: msarch/py
    def focus(cls):
        # Set projection matrix suitable for 2D rendering"
        #glMatrixMode(GL_PROJECTION)
        #glLoadIdentity()
        #gluOrtho2D( -SCALE * ASPECT, SCALE * ASPECT,-SCALE,SCALE)

        ## Set modelview matrix to move, scale & rotate to camera position"
        #glMatrixMode(GL_MODELVIEW)
        #glLoadIdentity()
        #gluLookAt( CENTX, CENTY, +1.0, CENTX, CENTY, -1.0, 0, 1, 0.0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(0, WIDTH, 0, HEIGHT)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
Ejemplo n.º 38
0
    def __enter__(self):
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_TEXTURE_2D)

        gl.glEnable(gl.GL_BLEND)
        gl.glDisable(gl.GL_CULL_FACE)
        gl.glDisable(gl.GL_DEPTH_TEST)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.gluOrtho2D (0, self.frustum_width, 0, self.frustum_height)

        gl.glMatrixMode (gl.GL_MODELVIEW)
        gl.glPushMatrix()
        gl.glLoadIdentity()
Ejemplo n.º 39
0
	def update(self, dt):
		self.window.clear()
		self.clock += dt

		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()
		glMatrixMode(GL_MODELVIEW)
		glLoadIdentity()

		gluOrtho2D(*self.camera.ortho_matrix)

		self.update_terrain()
		self.update_terrain_improvements()
		self.update_buildings(dt)
		self.update_units(dt)

		self.hud.draw(self.tile_map.selected_unit)
Ejemplo n.º 40
0
 def focus(self, window_width, window_height):
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     aspect = window_width / window_height
     gl.gluOrtho2D(-self.scale * aspect, +self.scale * aspect, -self.scale, +self.scale)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     gl.gluLookAt(
         self.x,
         self.y,
         1.0,  # camera position
         self.x,
         self.y,
         -1.0,  # thing we're looking at
         math.sin(self.angle),
         math.cos(self.angle),
         0.0,
     )
Ejemplo n.º 41
0
    def bind(self):
        assert Framebuffer.current_fbo is None
        from pyglet import gl
        t = self.texture
        gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, self.fbo_id)
        gl.glPushAttrib(gl.GL_VIEWPORT_BIT | gl.GL_TRANSFORM_BIT)
        if t:
            gl.glViewport(0, 0, t.width, t.height)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        if t:
            gl.glLoadIdentity()
            gl.gluOrtho2D(0, t.width, 0, t.height)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        if t:
            gl.glLoadIdentity()

        Framebuffer.current_fbo = self
Ejemplo n.º 42
0
    def bind(self):
        assert Framebuffer.current_fbo is None
        from pyglet import gl
        t = self.texture
        gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, self.fbo_id)
        gl.glPushAttrib(gl.GL_VIEWPORT_BIT | gl.GL_TRANSFORM_BIT)
        if t:
            gl.glViewport(0, 0, t.width, t.height)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        if t:
            gl.glLoadIdentity()
            gl.gluOrtho2D(0, t.width, 0, t.height)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        if t:
            gl.glLoadIdentity()

        Framebuffer.current_fbo = self
Ejemplo n.º 43
0
    def update(self):
        self.x += (self.target_x - self.x) * 0.1
        self.y += (self.target_y - self.y) * 0.1
        self.scale += (self.target_scale - self.scale) * 0.1
        self.angle += (self.target_angle - self.angle) * 0.1

        "Set projection and modelview matrices ready for rendering"

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        gluOrtho2D(-self.scale * self.aspect, +self.scale * self.aspect,
                   -self.scale, +self.scale)

        # Set modelview matrix to move, scale & rotate to camera position"
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt(self.x, self.y, +1.0, self.x, self.y, -1.0, sin(self.angle),
                  cos(self.angle), 0.0)
        print 'gluLookAt:', self.x, self.y, self.angle
Ejemplo n.º 44
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)
Ejemplo n.º 45
0
def bind_texture_region(texture, x, y, w, h, premultiplied=False, flip=False):
    gl.glTexParameteri(
        gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
    gl.glTexParameteri(
        gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
    gl.glEnable(gl.GL_SCISSOR_TEST)

    gl.glEnable(gl.GL_BLEND)
    if premultiplied:
        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)

    else:
        gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA,
                               gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    gl.glViewport(x, y, w, h)
    gl.glScissor(x, y, w, h)

    gl.glBindFramebufferEXT(
        gl.GL_DRAW_FRAMEBUFFER_EXT,
        Manager.col_buffer.gl_buffer
    )

    gl.glFramebufferTexture2DEXT(
        gl.GL_DRAW_FRAMEBUFFER_EXT,
        gl.GL_COLOR_ATTACHMENT0_EXT,
        texture.target,
        texture.id,
        0
    )

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    if flip:
        gl.gluOrtho2D(0, w, h, 0)
    else:
        gl.gluOrtho2D(0, w, 0, h)
Ejemplo n.º 46
0
    def updateProjection(self):
        """
        Recalculates the necessary projection.
        """
        gl.glViewport(0, 0, self.window.width, self.window.height)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()

        ratio = float(self.window.width) / self.window.height

        extents = b2Vec2(ratio * 25.0, 25.0)
        extents *= self._viewZoom

        lower = self._viewCenter - extents
        upper = self._viewCenter + extents

        # L/R/B/T
        gl.gluOrtho2D(lower.x, upper.x, lower.y, upper.y)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
Ejemplo n.º 47
0
    def updateProjection(self):
        """
        Recalculates the necessary projection.
        """
        gl.glViewport(0, 0, self.width, self.height)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()

        ratio = float(self.width) / self.height

        extents = box2d.b2Vec2(ratio * 25.0, 25.0)
        extents *= self._viewZoom

        lower = self._viewCenter - extents
        upper = self._viewCenter + extents

        # L/R/B/T
        gl.gluOrtho2D(lower.x, upper.x, lower.y, upper.y)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
Ejemplo n.º 48
0
    def paint(self, func):
        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, self.width, 0, self.height)

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

        gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT,
                                self.col_buffer.gl_buffer)

        gl.glFramebufferTexture2DEXT(gl.GL_DRAW_FRAMEBUFFER_EXT,
                                     gl.GL_COLOR_ATTACHMENT0_EXT,
                                     self.texture.target, self.texture.id, 0)

        func()

        gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, 0)
Ejemplo n.º 49
0
 def hud_mode(self, width, height):
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     gluOrtho2D(0, width, 0, height)
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
Ejemplo n.º 50
0
 def render(self):
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     gluOrtho2D(*self.rect())
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
Ejemplo n.º 51
0
    def on_draw(self):
        self.update_bottom_toolbar()

        # Main area:

        # Window background color
        gl.glClearColor(33 / 255, 33 / 255, 33 / 255, 1)

        # Set viewport
        gl.glViewport(0, 0, self.width, self.height)

        # Initialize Projection matrix
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()

        # Set orthographic projection matrix
        gl.gluOrtho2D(self.left, self.right, self.bottom, self.top)

        # Initialize Modelview matrix
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        # Clear window with ClearColor
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        # Draw blank canvas
        self.canvas_bg_sprite.draw()

        # Draw pixels
        if pixel_batch:
            pixel_batch.draw()

        # ???
        if holder_patch:
            holder_patch.draw()

        # Draw pixel cursor
        if not self.pixel_cursor_sprite == None:
            self.pixel_cursor_sprite.draw()

        # Draw grid lines
        if options["grid_on"] and self.zoom_level < 0.5:
            draw_grid(self.width, self.height)

        # Bottom toolbar:

        # Set viewport
        gl.glViewport(0, 0, self.width, 20)

        # Initialize Projection matrix
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()

        # Set orthographic projection matrix
        gl.gluOrtho2D(0, self.width, 0, 20)

        # Initialize Modelview matrix
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        # Draw bottom toolbar
        self.bottom_toolbar_bg_sprite.draw()
        self.size_label.draw()
        self.zoom_label.draw()
        if self.mouse_on_canvas:
            self.position_label.draw()

        # Top toolbar:

        # Set viewport
        gl.glViewport(0, self.height - 80, self.width, 80)

        # Initialize Projection matrix
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()

        # Set orthographic projection matrix
        gl.gluOrtho2D(0, self.width, 0, 80)

        # Initialize Modelview matrix
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        # Draw background for top toolbar
        self.top_toolbar_bg_sprite.draw()

        # Draw top toolbar palette
        top_toolbar_batch.draw()

        # Draw color selection displays
        self.palette_colorleft_sprite.draw()
        self.palette_colorright_sprite.draw()
        self.colorleft_label.draw()
        self.colorright_label.draw()
Ejemplo n.º 52
0
 def label_projection(self):
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     gl.gluOrtho2D(0, self.win.width, 0, self.win.height)
Ejemplo n.º 53
0
Archivo: field.py Proyecto: msarch/py
def view_setup():  # general GL setup
    glMatrixMode(GL_PROJECTION)
    glMatrixMode(GL_MODELVIEW)
    gluOrtho2D(0, WIDTH, 0, HEIGHT)
    glLoadIdentity()
    glTranslatef(CENTX, CENTY, 0)
Ejemplo n.º 54
0
        def on_draw(self):
            if (not self.e.period is None) and (not self.e.filename is None):
                if True:  #not os.path.isfile(self.e.filename):
                    if self.e.time() > self.e.period:
                        pyglet.app.exit()
            self.clear()
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            #                     gluOrtho2D sets up a two-dimensional orthographic viewing region.
            #          Parameters left, right
            #                             Specify the coordinates for the left and right vertical clipping planes.
            #                         bottom, top
            #                             Specify the coordinates for the bottom and top horizontal clipping planes.
            #                         Description
            #         gl.gluOrtho2D(-(self.W-1)/2*self.e.total_width, (self.W+1)/2*self.e.total_width, -self.e.total_width/2, self.e.total_width/2, 0, 0, 1);
            self.W = float(self.width) / self.height
            gl.gluOrtho2D(-self.W / 2 * self.e.total_width,
                          self.W / 2 * self.e.total_width,
                          -self.e.total_width / 2, self.e.total_width / 2, 0,
                          0, 1)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()

            #gl.glLineWidth () #p['line_width'])
            gl.glEnable(gl.GL_BLEND)
            gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
            gl.glColor3f(0., 0., 0.)

            if self.first_frame:
                #                 print(self.e.t0, self.e.t)
                self.e.t0 = time.time()
                self.e.t = self.e.time()
                #                 print(self.e.t0, self.e.t)
                self.first_frame = False

            dt = self.e.time() - self.e.t
            if 1. / self.e.desired_fps - dt > 0.:
                time.sleep(1. / self.e.desired_fps - dt)

            self.e.receive()
            X, Y, Theta = self.e.lames[0, :], self.e.lames[1, :], self.e.lames[
                2, :]
            dX, dY = np.cos(Theta) / 2., np.sin(Theta) / 2.
            #print(Theta)
            # coords = np.vstack((X-dX*self.e.lame_length, Y-dY*self.e.lame_length, X+dX*self.e.lame_length, Y+dY*self.e.lame_length))
            coords = np.vstack((
                X - dX * self.e.lame_length + dY * self.e.lame_width,
                Y - dY * self.e.lame_length - dX * self.e.lame_width,
                X + dX * self.e.lame_length + dY * self.e.lame_width,
                Y + dY * self.e.lame_length - dX * self.e.lame_width,
                X - dX * self.e.lame_length - dY * self.e.lame_width,
                Y - dY * self.e.lame_length + dX * self.e.lame_width,
                X + dX * self.e.lame_length - dY * self.e.lame_width,
                Y + dY * self.e.lame_length + dX * self.e.lame_width,
            ))
            #pyglet.graphics.draw(2*self.e.N_lame, gl.GL_LINES, ('v2f', coords.T.ravel().tolist()))
            if True:
                indices = np.array([
                    0, 1, 2, 1, 2, 3
                ])[:, np.newaxis] + 4 * np.arange(self.e.N_lame)
                pyglet.graphics.draw_indexed(
                    4 * self.e.N_lame, pyglet.gl.GL_TRIANGLES,
                    indices.T.ravel().tolist(),
                    ('v2f', coords.T.ravel().tolist()))
                #pyglet.graphics.draw(4*self.e.N_lame, gl.GL_QUADS, ('v2f', coords.T.ravel().tolist()))

            # carré
            if self.e.DEBUG:
                coords = np.array([[
                    -.5 * self.e.total_width, .5 * self.e.total_width,
                    .5 * self.e.total_width, -.5 * self.e.total_width
                ],
                                   [
                                       -.5 * self.e.total_width,
                                       -.5 * self.e.total_width,
                                       .5 * self.e.total_width,
                                       .5 * self.e.total_width
                                   ]])
                pyglet.graphics.draw(4, gl.GL_LINE_LOOP,
                                     ('v2f', coords.T.ravel().tolist()))
            # centres des lames
            if self.e.DEBUG:
                gl.glLineWidth(1.)
                gl.glColor3f(0., 0., 0.)
                pyglet.graphics.draw(
                    self.e.N_lame, gl.GL_POINTS,
                    ('v2f', self.e.lames[:2, :].T.ravel().tolist()))
                gl.glColor3f(1., 0., 0.)
                pyglet.graphics.draw(2, gl.GL_LINES, ('v2f', [0., 0., 1., 0.]))
                gl.glColor3f(0., 1., 0.)
                pyglet.graphics.draw(2, gl.GL_LINES, ('v2f', [0., 0., 0., 1.]))

            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()

            self.label.draw()
            self.text.draw()