Exemplo n.º 1
0
    def __init__(self, visions):
        self.visions = visions

        W, H = RENDER_SIZE
        pyglet.window.Window.__init__(self,
                                      caption='(pineal renderer)',
                                      fullscreen=0,
                                      width=W,
                                      height=H,
                                      vsync=0,
                                      visible=0)

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

        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)

        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glShadeModel(gl.GL_SMOOTH)

        self.texture = None
Exemplo n.º 2
0
def _draw_rects(shape_list, vertex_vbo_id, texture_coord_vbo_id):
    """
    Draw a set of rectangles using vertex buffers. This is more efficient
    than drawing them individually.
    """
    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_TEXTURE_2D)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST)

    # 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, vertex_vbo_id)
    GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)
    GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
    GL.glVertexPointer(2, GL.GL_FLOAT, 0, 0)

    GL.glBindBuffer(GL.GL_ARRAY_BUFFER, texture_coord_vbo_id)

    offset = 0
    for shape in shape_list:
        if shape.can_cache:
            texture_coord_vbo_id = None

            GL.glColor4f(1, 1, 1, shape.alpha)

            _render_rect_filled(shape, offset,
                                shape.texture.texture_id, texture_coord_vbo_id)

            offset += 4
        else:
            shape.draw()
Exemplo n.º 3
0
    def draw(self, scale, pos):
        LINE_COLOUR = (255, 255, 255)

        # gl.glEnable(gl.GL_DEPTH_TEST);
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)

        gl.glBegin(gl.GL_LINES)
        for link in self.links:
            if link.highlight:
                gl.glColor3ub(*self.colour)
                gl.glColor3ub(*self.colour)
            else:
                gl.glColor3ub(*LINE_COLOUR)
                gl.glColor3ub(*LINE_COLOUR)
            if link.highlight:
                depth = 0.5
            else:
                depth = 0.5
            gl.glVertex3f(*util.add_tup(pos, util.scale_tup(link.points[0].pos, scale)) + (depth,))
            gl.glVertex3f(*util.add_tup(pos, util.scale_tup(link.points[1].pos, scale)) + (depth,))
            print util.add_tup(pos, util.scale_tup(link.points[0].pos, scale))
        gl.glEnd()
Exemplo n.º 4
0
def draw_rectangle_outline(center_x, center_y, width, height, color,
                           border_width=1, tilt_angle=0):
    """
    Draw a rectangle outline.

    Args:
        :x: x coordinate of top left rectangle point.
        :y: y coordinate of top left rectangle point.
        :width: width of the rectangle.
        :height: height of the rectangle.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :border_width: width of the lines, in pixels.
        :angle: rotation of the rectangle. Defaults to zero.
    Returns:
        None
    Raises:
        None

    Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> arcade.draw_rectangle_outline(278, 150, 45, 105, \
arcade.color.BRITISH_RACING_GREEN, 2)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """

    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    GL.glLoadIdentity()
    GL.glTranslatef(center_x, center_y, 0)
    if tilt_angle:
        GL.glRotatef(tilt_angle, 0, 0, 1)

    # Set line width
    GL.glLineWidth(border_width)

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_LINE_LOOP)
    GL.glVertex3f(-width // 2, -height // 2, 0.5)
    GL.glVertex3f(width // 2, -height // 2, 0.5)
    GL.glVertex3f(width // 2, height // 2, 0.5)
    GL.glVertex3f(-width // 2, height // 2, 0.5)
    GL.glEnd()
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
Arquivo: effects.py Projeto: Knio/miru
 def enable(self):
     gl.glEnable(gl.GL_FOG)
     gl.glFogfv(gl.GL_FOG_COLOR, self.color)
     gl.glFogf(gl.GL_FOG_START, self.start)
     gl.glFogf(gl.GL_FOG_END, self.end)
     if self.density is not None:
         gl.glFogf(gl.GL_FOG_DENSITY, self.density)
     if self.hint is not None:
         gl.glHint(gl.GL_FOG_HINT, self.hint)
     gl.glFogi(gl.GL_FOG_MODE, self.equation)
Exemplo n.º 8
0
def draw_lines(point_list, color, border_width=1):
    """
    Draw a set of lines.

    Draw a line between each pair of points specified.

    Args:
        :point_list: List of points making up the lines. Each point is
         in a list. So it is a list of lists.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :border_width: Width of the line in pixels.
    Returns:
        None
    Raises:
        None

    Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> point_list = ((390, 450), \
(450, 450), \
(390, 480), \
(450, 480), \
(390, 510), \
(450, 510))
    >>> arcade.draw_lines(point_list, arcade.color.BLUE, 3)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """
    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    GL.glLoadIdentity()

    # Set line width
    GL.glLineWidth(border_width)

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_LINES)
    for point in point_list:
        GL.glVertex3f(point[0], point[1], 0.5)
    GL.glEnd()
Exemplo n.º 9
0
def new_renderer(visions, size):
    """
    Offscreen windows where render stuff
    """
    W, H = size
    window = new_window(caption='(pineal renderer)',
                        width=W,
                        height=H,
                        visible=0)

    window.visions = visions

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

    gl.glEnable(gl.GL_LINE_SMOOTH)
    gl.glEnable(gl.GL_POLYGON_SMOOTH)
    gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
    gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)

    window.texture = None

    # pyglet.clock.schedule_interval(window.update, 1.0/128.0)
    # pyglet.clock.set_fps_limit(30)

    @window.event
    def on_draw():
        pyglet.clock.tick()
        window.clear()

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        (w, h) = window.get_size()
        gl.glScalef(
            float(min(w, h))/w,
            -float(min(w, h))/h,
            1
        )

        gl.gluPerspective(45.0, 1, 0.1, 1000.0)
        gl.gluLookAt(0, 0, 2.4,
                     0, 0, 0,
                     0, 1, 0)

        for vision in window.visions.values():
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glLoadIdentity()
            vision()

        buf = pyglet.image.get_buffer_manager().get_color_buffer()
        rawimage = buf.get_image_data()
        window.texture = rawimage.get_texture()

    return window
Exemplo n.º 10
0
    def init(self):
        '''
        Set all initial OpenGL state, such as enabling DEPTH_TEST.
        '''
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)

        self.backface_culling = True
Exemplo n.º 11
0
    def init_gl(self):
        """
        Perform the magic incantations to create an OpenGL scene.
        """
        # the background color
        gl.glClearColor(.97, .97, .97, 1.0)

        max_depth = (np.abs(self.scene.bounds).max(axis=1)**2).sum()**.5
        max_depth = np.clip(max_depth, 500.00, np.inf)
        gl.glDepthRange(0.0, max_depth)

        gl.glClearDepth(1.0)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glDepthFunc(gl.GL_LEQUAL)

        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_LIGHT1)

        # put the light at one corner of the scenes AABB
        gl.glLightfv(
            gl.GL_LIGHT0, gl.GL_POSITION,
            rendering.vector_to_gl(np.append(self.scene.bounds[1], 0)))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR,
                     rendering.vector_to_gl(.5, .5, 1, 1))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE,
                     rendering.vector_to_gl(1, 1, 1, .75))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT,
                     rendering.vector_to_gl(.1, .1, .1, .2))

        gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE)
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glShadeModel(gl.GL_SMOOTH)

        gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT,
                        rendering.vector_to_gl(0.192250, 0.192250, 0.192250))
        gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE,
                        rendering.vector_to_gl(0.507540, 0.507540, 0.507540))
        gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR,
                        rendering.vector_to_gl(.5082730, .5082730, .5082730))

        gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0)

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

        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)

        gl.glLineWidth(1.5)
        gl.glPointSize(4)
Exemplo n.º 12
0
def _generic_draw_line_strip(point_list: PointList,
                             color: Color,
                             line_width: float = 1,
                             mode: int = gl.GL_LINE_STRIP):
    """
    Draw a line strip. A line strip is a set of continuously connected
    line segments.

    Args:
        :point_list: List of points making up the line. Each point is
         in a list. So it is a list of lists.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :border_width: Width of the line in pixels.
    Returns:
        None
    Raises:
        None
    """
    program = shader.program(
        vertex_shader=line_vertex_shader,
        fragment_shader=line_fragment_shader,
    )
    buffer_type = np.dtype([('vertex', '2f4'), ('color', '4B')])
    data = np.zeros(len(point_list), dtype=buffer_type)

    data['vertex'] = point_list

    color = get_four_byte_color(color)
    data['color'] = color

    vbo = shader.buffer(data.tobytes())
    vbo_desc = shader.BufferDescription(vbo,
                                        '2f 4B', ('in_vert', 'in_color'),
                                        normalized=['in_color'])

    vao_content = [vbo_desc]

    vao = shader.vertex_array(program, vao_content)
    with vao:
        program['Projection'] = get_projection().flatten()

        gl.glLineWidth(line_width)
        gl.glPointSize(line_width)

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)

        vao.render(mode=mode)
Exemplo n.º 13
0
def on_draw():
    window.clear()
    gl.glColor4f(1.0,0,0,1.0)
    #glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    #glEnable (GL_BLEND)
    gl.glEnable (gl.GL_LINE_SMOOTH);
    gl.glHint (gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)
    gl.glLineWidth (3)
    pts = []
    for (x,y) in turtle.points:
         pts.append(x)
         pts.append(y)
    pyglet.graphics.draw(len(turtle.points), pyglet.gl.GL_LINE_STRIP, ('v2f', tuple(pts)))
Exemplo n.º 14
0
def draw_line(start_x, start_y, end_x, end_y, color, border_width=1):

    """
    Draw a line.

    Args:
        :start_x: x position of line starting point.
        :start_y: y position of line starting point.
        :end_x: x position of line ending point.
        :end_y: y position of line ending point.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :border_width: Width of the line in pixels.
    Returns:
        None
    Raises:
        None

    Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> arcade.draw_line(270, 495, 300, 450, arcade.color.WOOD_BROWN, 3)
    >>> color = (127, 0, 127, 127)
    >>> arcade.draw_line(280, 495, 320, 450, color, 3)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """
    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    GL.glLoadIdentity()

    # Set line width
    GL.glLineWidth(border_width)

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_LINES)
    GL.glVertex3f(start_x, start_y, 0.5)
    GL.glVertex3f(end_x, end_y, 0.5)
    GL.glEnd()
Exemplo n.º 15
0
    def __init__(self):
        self.window = pyglet.window.Window(width=const.GAME_WIDTH,
                                           height=const.GAME_HEIGHT,
                                           vsync=False,
                                           caption="Porcupyne",
                                           resizable=True)
        self.window.invalid = False

        # resource.path = ['.']

        res = resources.Resource()
        res.load_directory('gamedata')

        self.player1 = Ball(self, res)
        self.bg = BG(res)
        platform_width = 200
        platform_height = 96

        def get_points(x, y):
            x -= platform_width / 2.0
            y -= platform_height / 2.0
            return (((x, y), (x, y + platform_height), (x + platform_width,
                                                        y + platform_height),
                     (x + platform_width, y)))

        self.platforms = [
            Platform(get_points(0, -128), res),
            Platform(get_points(128, 0), res),
            Platform(get_points(-270, -50), res),
            Platform(get_points(-320, 150), res),
            Platform(((225, 48), (400, 160), (400, 48)), res)
        ]
        self.controller = Controller(self.window, self.player1)
        self.fps_display = font.Text(pyglet.font.load('', 18, bold=True),
                                     '',
                                     color=(0.5, 0.5, 0.5, 0.5),
                                     x=-150,
                                     y=-100)

        ft = font.load('Arial', 10)
        color = (0, 0, 0, 1)
        self.debug_text = [
            font.Text(ft, x=-150, y=100, color=color),
            font.Text(ft, x=-150, y=85, color=color),
            font.Text(ft, x=-150, y=70, color=color)
        ]

        # alpha channels¨
        rabbyt.set_default_attribs()
        glEnable(GL_LINE_SMOOTH)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
Exemplo n.º 16
0
def init_gl():
    gl.glClearDepth(1.0)

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

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glDepthFunc(gl.GL_LEQUAL)
    gl.glShadeModel(gl.GL_SMOOTH)
    gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)

    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_REPEAT)
Exemplo n.º 17
0
    def initialize_gl(self):
        import pyglet.gl as gl

        # Set clear color
        gl.glClearColor(0, 0, 0, 0)

        # Set antialiasing
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)

        # Set alpha blending
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
Exemplo n.º 18
0
def draw_polygon_outline(point_list, color, border_width=1):
    """
    Draw a polygon outline. Also known as a "line loop."

    Args:
        :point_list: List of points making up the lines. Each point is
         in a list. So it is a list of lists.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :border_width: Width of the line in pixels.
    Returns:
        None
    Raises:
        None

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> point_list = ((30, 240), \
(45, 240), \
(60, 255), \
(60, 285), \
(45, 300), \
(30, 300))
    >>> arcade.draw_polygon_outline(point_list, arcade.color.SPANISH_VIOLET, 3)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """
    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    # Set line width
    GL.glLineWidth(border_width)

    GL.glLoadIdentity()

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_LINE_LOOP)
    for point in point_list:
        GL.glVertex3f(point[0], point[1], 0.5)
    GL.glEnd()
Exemplo n.º 19
0
 def init_gl_fog(self):
     """Configure the OpenGL fog properties."""
     # Enable fog. Fog "blends a fog color with each rasterized pixel fragment's
     # post-texturing color."
     glEnable(GL_FOG)
     # Set the fog color.
     glFogfv(GL_FOG_COLOR, (GLfloat * 4)(0.5, 0.69, 1.0, 1))
     # Say we have no preference between rendering speed and quality.
     glHint(GL_FOG_HINT, GL_DONT_CARE)
     # Specify the equation used to compute the blending factor.
     glFogi(GL_FOG_MODE, GL_LINEAR)
     # How close and far away fog starts and ends. The closer the start and end,
     # the denser the fog in the fog range.
     glFogf(GL_FOG_START, 20.0)
     glFogf(GL_FOG_END, 60.0)
Exemplo n.º 20
0
    def draw(self):
        # program['Projection'].write(get_projection().tobytes())

        with self.vao:
            gl.glLineWidth(self.line_width)

            gl.glEnable(gl.GL_BLEND)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
            gl.glEnable(gl.GL_LINE_SMOOTH)
            gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
            gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
            gl.glEnable(gl.GL_PRIMITIVE_RESTART)
            gl.glPrimitiveRestartIndex(2**32 - 1)

            self.vao.render(mode=self.mode)
Exemplo n.º 21
0
 def init_gl_fog(self):
     """Configure the OpenGL fog properties."""
     # Enable fog. Fog "blends a fog color with each rasterized pixel fragment's
     # post-texturing color."
     glEnable(GL_FOG)
     # Set the fog color.
     glFogfv(GL_FOG_COLOR, (GLfloat * 4)(0.5, 0.69, 1.0, 1))
     # Say we have no preference between rendering speed and quality.
     glHint(GL_FOG_HINT, GL_DONT_CARE)
     # Specify the equation used to compute the blending factor.
     glFogi(GL_FOG_MODE, GL_LINEAR)
     # How close and far away fog starts and ends. The closer the start and end,
     # the denser the fog in the fog range.
     glFogf(GL_FOG_START, 20.0)
     glFogf(GL_FOG_END, 60.0)
Exemplo n.º 22
0
    def _initialize_opengl(self):
        # Initialize Modelview matrix
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        # Set antialiasing
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)

        # Set alpha blending
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        gl.glViewport(0, 0, 1024, 800)
Exemplo n.º 23
0
def draw_rectangle_filled(center_x, center_y, width, height, color,
                          tilt_angle=0):
    """
    Draw a filled-in rectangle.

    Args:
        :x: x coordinate of top left rectangle point.
        :y: y coordinate of top left rectangle point.
        :width: width of the rectangle.
        :height: height of the rectangle.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :angle: rotation of the rectangle. Defaults to zero.

    Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> arcade.draw_rectangle_filled(390, 150, 45, 105, arcade.color.BLUSH)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """

    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glLoadIdentity()
    GL.glTranslatef(center_x, center_y, 0)
    if tilt_angle:
        GL.glRotatef(tilt_angle, 0, 0, 1)

    GL.glBegin(GL.GL_QUADS)
    GL.glVertex3f(-width // 2, -height // 2, 0.5)
    GL.glVertex3f(width // 2, -height // 2, 0.5)
    GL.glVertex3f(width // 2, height // 2, 0.5)
    GL.glVertex3f(-width // 2, height // 2, 0.5)
    GL.glEnd()
Exemplo n.º 24
0
    def draw(self):
        """
        Draw everything in the list.
        """
        # gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glLoadIdentity()

        gl.glTranslatef(self.center_x, self.center_y, 0)
        if self.angle:
            gl.glRotatef(self.angle, 0, 0, 1)

        last_color = None
        last_line_width = None

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)

        for shape in self.shape_list:
            if shape.vbo_color_id is not None:
                gl.glEnableClientState(gl.GL_COLOR_ARRAY)
            else:
                gl.glDisableClientState(gl.GL_COLOR_ARRAY)
                if last_color is None or last_color != shape.color:
                    last_color = shape.color

                    if len(shape.color) == 4:
                        gl.glColor4ub(shape.color[0], shape.color[1],
                                      shape.color[2], shape.color[3])
                        gl.glEnable(gl.GL_BLEND)
                        gl.glBlendFunc(gl.GL_SRC_ALPHA,
                                       gl.GL_ONE_MINUS_SRC_ALPHA)
                    elif len(shape.color) == 3:
                        gl.glDisable(gl.GL_BLEND)
                        gl.glColor4ub(shape.color[0], shape.color[1],
                                      shape.color[2], 255)

            if shape.line_width and last_line_width != shape.line_width:
                last_line_width = shape.line_width
                gl.glLineWidth(shape.line_width)

            if shape.vbo_color_id is None:
                stripped_render(shape)
            else:
                stripped_render_with_colors(shape)
Exemplo n.º 25
0
    def init_gl(self, on_init=None, **kwargs):
        gl.glClearColor(.97, .97, .97, 1.0)
        max_depth = (np.abs(self.scene.bounds).max(axis=1)**2).sum()**.5
        max_depth = np.clip(max_depth, 500.00, np.inf)
        gl.glDepthRange(0.0, max_depth)

        gl.glClearDepth(1.0)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glDepthFunc(gl.GL_LEQUAL)

        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_LIGHT1)

        # put the light at one corner of the scenes AABB
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION,
                     _gl_vector(np.append(self.scene.bounds[1], 0)))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, _gl_vector(.5, .5, 1, 1))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, _gl_vector(1, 1, 1, .75))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, _gl_vector(.1, .1, .1, .2))

        gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE)
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glShadeModel(gl.GL_SMOOTH)

        gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT,
                        _gl_vector(0.192250, 0.192250, 0.192250))
        gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE,
                        _gl_vector(0.507540, 0.507540, 0.507540))
        gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR,
                        _gl_vector(.5082730, .5082730, .5082730))

        gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0)

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

        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)

        gl.glLineWidth(1.5)
        gl.glPointSize(4)

        if on_init:
            on_init(gl, **kwargs)
Exemplo n.º 26
0
    def __init__(self):
        self.window = pyglet.window.Window(width = const.GAME_WIDTH, 
            height = const.GAME_HEIGHT, vsync = False, caption = "Porcupyne", 
            resizable = True)
        self.window.invalid = False

        # resource.path = ['.']

        res = resources.Resource()
        res.load_directory('gamedata')

        self.player1 = Ball(self, res)
        self.bg = BG(res)
        platform_width = 200
        platform_height = 96
        def get_points(x, y):
            x -= platform_width / 2.0
            y -= platform_height / 2.0
            return ((
                (x, y), 
                (x, y + platform_height), 
                (x + platform_width, y + platform_height),
                (x + platform_width, y)))

        self.platforms = [
            Platform(get_points(0, -128), res),
            Platform(get_points(128, 0), res),
            Platform(get_points(-270, -50), res),
            Platform(get_points(-320, 150), res),
            Platform((
                (225, 48), (400, 160), (400, 48)
                ), res)
        ]
        self.controller = Controller(self.window, self.player1)
        self.fps_display = font.Text(pyglet.font.load('', 18, bold = True), '', 
            color=(0.5, 0.5, 0.5, 0.5), x=-150, y=-100)

        ft = font.load('Arial', 10)
        color = (0, 0, 0, 1)
        self.debug_text = [font.Text(ft, x=-150, y=100, color = color),
                      font.Text(ft, x=-150, y=85, color = color),
                      font.Text(ft, x=-150, y=70, color = color)]
        
        # alpha channels¨
        rabbyt.set_default_attribs()
        glEnable(GL_LINE_SMOOTH)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
Exemplo n.º 27
0
def draw_polygon_filled(point_list, color):
    """
    Draw a polygon that is filled in.

    Args:
        :point_list: List of points making up the lines. Each point is
         in a list. So it is a list of lists.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
    Returns:
        None
    Raises:
        None

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> point_list = ((150, 240), \
(165, 240), \
(180, 255), \
(180, 285), \
(165, 300), \
(150, 300))
    >>> arcade.draw_polygon_filled(point_list, arcade.color.SPANISH_VIOLET)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """
    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    GL.glLoadIdentity()

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_POLYGON)
    for point in point_list:
        GL.glVertex3f(point[0], point[1], 0.5)
    GL.glEnd()
Exemplo n.º 28
0
    def draw(self):
        """
        Draw this shape. Drawing this way isn't as fast as drawing multiple
        shapes batched together in a ShapeElementList.
        """
        assert(self.line_width == 1)
        gl.glLineWidth(self.line_width)

        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
        gl.glEnable(gl.GL_PRIMITIVE_RESTART)
        gl.glPrimitiveRestartIndex(2 ** 32 - 1)

        self.vao.render(self.program, mode=self.mode)
Exemplo n.º 29
0
    def on_draw(self):
        gl.glEnable( gl.GL_POLYGON_SMOOTH )
        #gl.glHint( gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST ) 
        gl.glHint( gl.GL_POLYGON_SMOOTH_HINT, gl.GL_DONT_CARE ) 

        gl.glEnable( gl.GL_LINE_SMOOTH )

        gl.glEnable(gl.GL_MULTISAMPLE)

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

        grey = 0.9
        gl.glClearColor(grey, grey, grey, 0.0)

        gl.glPushMatrix()

        # I don't really know what the direction conventions for glTranslate are,
        # so the minus signs are from experimenting.
        #gl.glTranslatef(-self.viewportOrigin[0], -self.viewportOrigin[1], 0.0)
        
        self.clear()
        #self.grassBatch.draw()
        #self.wallImgBatch.draw()

        g = self.gameElements

        # Should I be pushing most of this code into GameElements?

        self.runner.on_draw()
        for z in self.zombies:
            #z.on_draw()
            pass
        

        gl.glPushMatrix()
        gl.glTranslatef(300, 300, 0.0)
        #gl.glScalef(0.5, 0.5, 0.0)
        self.countdowntimer.draw()
        gl.glPopMatrix()

        
        gl.glPopMatrix()
Exemplo n.º 30
0
def run():
	pyglet.options['audio'] = AUDIO_DRIVERS
	pyglet.options['debug_gl'] = False

	parser = OptionParser(description="%s: %s" % (APP_NAME, PROJECT_DESC),
		epilog='Project website: %s' % PROJECT_URL,
		version='%s %s' % (APP_NAME, VERSION),
	)
	parser.add_option("-f", "--fullscreen",
		dest="fullscreen",
		default=False,
		action="store_true",
	)
	parser.add_option("-d", "--debug",
		dest="debug",
		default=False,
		action="store_true",
	)
	options, args = parser.parse_args()

	if options.debug:
		logging.basicConfig(level=logging.DEBUG)
		logging.debug("Debug enabled")
		logging.debug("Options: %s" % options)

	gl.glEnable(gl.GL_BLEND)                                                            
	gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
	gl.glEnable(gl.GL_LINE_SMOOTH);                                                     
	gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE) 

	# depth testing
	#gl.glEnable(gl.GL_DEPTH_TEST)

	plib.director.director.init(width=WIDTH, 
		height=HEIGHT, 
		fullscreen=options.fullscreen, 
		caption=APP_NAME,
		debug=options.debug)

	plib.director.director.on_cleanup = on_cleanup

	app.init()

	plib.director.director.run()
Exemplo n.º 31
0
    def init_gl(self):
        gl.glClearColor(.93, .93, 1, 1)

        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_LIGHT1)

        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, _gl_vector(.5, .5, 1, 0))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, _gl_vector(.5, .5, 1, 1))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, _gl_vector(1, 1, 1, 1))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, _gl_vector(1, 0, .5, 0))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, _gl_vector(.5, .5, .5, 1))
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, _gl_vector(1, 1, 1, 1))

        gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE)
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glShadeModel(gl.GL_SMOOTH)

        gl.glMaterialfv(gl.GL_FRONT,
                        gl.GL_AMBIENT,
                        _gl_vector(0.192250, 0.192250, 0.192250))
        gl.glMaterialfv(gl.GL_FRONT,
                        gl.GL_DIFFUSE,
                        _gl_vector(0.507540, 0.507540, 0.507540))
        gl.glMaterialfv(gl.GL_FRONT,
                        gl.GL_SPECULAR,
                        _gl_vector(.5082730, .5082730, .5082730))

        gl.glMaterialf(gl.GL_FRONT,
                       gl.GL_SHININESS,
                       .4 * 128.0)

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

        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)

        gl.glLineWidth(1.5)
        gl.glPointSize(4)
Exemplo n.º 32
0
    def on_draw(self):
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        #gl.glHint( gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST )
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_DONT_CARE)

        gl.glEnable(gl.GL_LINE_SMOOTH)

        gl.glEnable(gl.GL_MULTISAMPLE)

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

        grey = 0.9
        gl.glClearColor(grey, grey, grey, 0.0)

        gl.glPushMatrix()

        # I don't really know what the direction conventions for glTranslate are,
        # so the minus signs are from experimenting.
        #gl.glTranslatef(-self.viewportOrigin[0], -self.viewportOrigin[1], 0.0)

        self.clear()
        #self.grassBatch.draw()
        #self.wallImgBatch.draw()

        g = self.gameElements

        # Should I be pushing most of this code into GameElements?

        self.runner.on_draw()
        for z in self.zombies:
            #z.on_draw()
            pass

        gl.glPushMatrix()
        gl.glTranslatef(300, 300, 0.0)
        #gl.glScalef(0.5, 0.5, 0.0)
        self.countdowntimer.draw()
        gl.glPopMatrix()

        gl.glPopMatrix()
Exemplo n.º 33
0
def _draw_rects(shape_list: Iterable[Sprite], vertex_vbo_id: gl.GLuint,
                texture_coord_vbo_id: gl.GLuint):
    """
    Draw a set of rectangles using vertex buffers. This is more efficient
    than drawing them individually.
    """
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glEnable(gl.GL_TEXTURE_2D) # As soon as this happens, can't use drawing commands
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
    gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
    gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)

    # 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, vertex_vbo_id)
    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glVertexPointer(2, gl.GL_FLOAT, 0, 0)

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, texture_coord_vbo_id)

    offset = 0
    for shape in shape_list:
        if shape.can_cache:
            texture_coord_vbo_id = None

            gl.glColor4f(1, 1, 1, shape.alpha)

            _render_rect_filled(shape, offset,
                                shape.texture.texture_id, texture_coord_vbo_id)

            offset += 4
        else:
            shape.draw()
    gl.glDisable(gl.GL_TEXTURE_2D)
Exemplo n.º 34
0
    def __init__(self, width, height, display=None):
        display = get_display(display)

        self.width = width
        self.height = height

        self.window = pyglet.window.Window(width=width,
                                           height=height,
                                           display=display)
        self.window.on_close = self.window_closed_by_user
        self.geoms = []
        self.onetime_geoms = []
        self.transform = Transform()

        glEnable(GL_BLEND)
        # glEnable(GL_MULTISAMPLE)
        glEnable(GL_LINE_SMOOTH)
        # glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
        glLineWidth(2.0)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Exemplo n.º 35
0
    def setGL(self,cte):
        if cte == ANTI_ALIAS:
            gl.glEnable( gl.GL_BLEND)
            #~ gl.glBlendFunc(gl.GL_SRC_ALPHA_SATURATE, gl.GL_ONE);
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
            #~ gl.glBlendFunc(gl.GL_SRC_ALPHA_SATURATE, gl.GL_ONE);
            #~ gl.glEnable( gl.GL_MULTISAMPLE ); 
            

            #~ gl.glEnable(gl.GL_LINE_SMOOTH);
            #~ ;
            
            gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
            gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST);

            pass
    
#~ class GL_Group_SegmentFill(gr.Group):
#~ class GL_Group_SegmentFill(gr.Group):
    #~ def set_state(self):
        gl.glDisable(gl.GL_POLYGON_SMOOTH)
Exemplo n.º 36
0
def convert_cml2png(formula, output): 
    space = SpaceMock()
    batch = pyglet.graphics.Batch()
    img = Molecule(formula, space, batch, pos=(32,32), render_only=True)
    w, h, _ = img.cml.max_pos()
    width = int(w*64) + 64
    height = int(h*64) + 64
    config = gl.Config(double_buffer=True)
    window = pyglet.window.Window(width=width,height=height,visible=True,config=config)
    window.minimize()
    gl.glClearColor(250/256.0, 250/256.0, 250/256.0, 0)
    gl.glLineWidth(4)
    gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
    img.update()
    @window.event
    def on_draw():
        window.clear()
        batch.draw()
        pyglet.image.get_buffer_manager().get_color_buffer().save(output)
        window.close()
        pyglet.app.exit()
    pyglet.app.run()
Exemplo n.º 37
0
    def __init__(self, visuals, **args):
        self.visuals = visuals
        pyglet.window.Window.__init__(self, **args)

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

        gl.glEnable( gl.GL_VERTEX_ARRAY )

        gl.glEnable( gl.GL_LINE_SMOOTH )
        gl.glEnable( gl.GL_POLYGON_SMOOTH )
        gl.glHint( gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST )
        gl.glHint( gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST )

        gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)

        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glShadeModel(gl.GL_SMOOTH)

        self.texture = None
Exemplo n.º 38
0
def _draw_rects(shape_list: Iterable[Sprite], vertex_vbo_id: gl.GLuint,
                texture_coord_vbo_id: gl.GLuint):
    """
    Draw a set of rectangles using vertex buffers. This is more efficient
    than drawing them individually.
    """
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glEnable(gl.GL_TEXTURE_2D
                )  # As soon as this happens, can't use drawing commands
    gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
    gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)

    # 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, vertex_vbo_id)
    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glVertexPointer(2, gl.GL_FLOAT, 0, 0)

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, texture_coord_vbo_id)

    offset = 0
    for shape in shape_list:
        if shape.can_cache:
            texture_coord_vbo_id = None

            gl.glColor4f(1, 1, 1, shape.alpha)

            _render_rect_filled(shape, offset, shape.texture.texture_id,
                                texture_coord_vbo_id)

            offset += 4
        else:
            shape.draw()
    gl.glDisable(gl.GL_TEXTURE_2D)
Exemplo n.º 39
0
    def __init__(self, width=800, height=600):
        if settings['fullscreen']:
            pyglet.window.Window.__init__(self, fullscreen=True)
        else:
            pyglet.window.Window.__init__(self, width=width, height=height)
        self.set_caption("Elite Bungie Chopper Squadron")
        self.fps_display = pyglet.clock.ClockDisplay()
        self.keys = pyglet.window.key.KeyStateHandler(
        )  # What keys/commands are currently being pressed?
        self.push_handlers(self.keys)

        self.timer = util.fixedsteploop.FixedStepLoop(self.update, TIME_STEP,
                                                      MAX_CYCLES_PER_FRAME)

        self.game = game.Game(self.keys, self)
        self.game.load_stage("00", True)

        self.menu = menu.Menu(self)

        self.state = self.menu
        self.push_handlers(self.menu)
        self.timer.play()

        gl.glClearColor(128, 128, 255, 255)
        gl.glEnable(gl.GL_BLEND)
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glShadeModel(gl.GL_SMOOTH)  # Enables Smooth Shading
        gl.glBlendFunc(gl.GL_SRC_ALPHA,
                       gl.GL_ONE)  #Type Of Blending To Perform
        gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)
        #Really Nice Perspective Calculations
        gl.glHint(gl.GL_POINT_SMOOTH_HINT, gl.GL_NICEST)
        #Really Nice Point Smoothing
        gl.glDisable(gl.GL_DEPTH_TEST)

        self.clear()

        resources.chopper_blades.play()
Exemplo n.º 40
0
    def setup(self):
        self.camera = PlotCamera(self, ortho=self.ortho)
        self.controller = PlotController(self,
                invert_mouse_zoom=self.invert_mouse_zoom)
        self.push_handlers(self.controller)

        pgl.glClearColor(1.0, 1.0, 1.0, 0.0)
        pgl.glClearDepth(1.0)

        pgl.glDepthFunc(pgl.GL_LESS)
        pgl.glEnable(pgl.GL_DEPTH_TEST)

        pgl.glEnable(pgl.GL_LINE_SMOOTH)
        pgl.glShadeModel(pgl.GL_SMOOTH)
        pgl.glLineWidth(self.linewidth)

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

        if self.antialiasing:
            pgl.glHint(pgl.GL_LINE_SMOOTH_HINT, pgl.GL_NICEST)
            pgl.glHint(pgl.GL_POLYGON_SMOOTH_HINT, pgl.GL_NICEST)

        self.camera.setup_projection()
Exemplo n.º 41
0
    def __init__(self,
                 width,
                 height,
                 visible,
                 display=None,
                 background_rgb=(1, 1, 1)):
        display = get_display(display)

        self.width = width
        self.height = height
        self.background_rgb = background_rgb
        self.window = pyglet.window.Window(width=width,
                                           height=height,
                                           display=display,
                                           visible=visible)
        if not visible:
            # get around stupid bug (?) where OpenGL refuses to render anything
            # to FBOs until the window is displayed
            self.window.set_visible(True)
            self.window.set_visible(False)
        # need to use a second FBO to actually get image data
        self.render_fbo = get_offscreen_fbo(width, height, msaa_samples=1)
        self.no_msaa_fbo = get_offscreen_fbo(width, height, msaa_samples=1)
        self.window.on_close = self.window_closed_by_user
        self.isopen = True
        self.reset_geoms()
        self.transforms = Transform()

        gl.glEnable(gl.GL_BLEND)
        # tricks from OpenAI's multiagent particle env repo:
        # gl.glEnable(gl.GL_MULTISAMPLE)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        # gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
        gl.glLineWidth(2.0)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
Exemplo n.º 42
0
    def setup(self):
        self.camera = PlotCamera(self, ortho=self.ortho)
        self.controller = PlotController(self,
                invert_mouse_zoom=self.invert_mouse_zoom)
        self.push_handlers(self.controller)

        pgl.glClearColor(1.0, 1.0, 1.0, 0.0)
        pgl.glClearDepth(1.0)

        pgl.glDepthFunc(pgl.GL_LESS)
        pgl.glEnable(pgl.GL_DEPTH_TEST)

        pgl.glEnable(pgl.GL_LINE_SMOOTH)
        pgl.glShadeModel(pgl.GL_SMOOTH)
        pgl.glLineWidth(self.linewidth)

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

        if self.antialiasing:
            pgl.glHint(pgl.GL_LINE_SMOOTH_HINT, pgl.GL_NICEST)
            pgl.glHint(pgl.GL_POLYGON_SMOOTH_HINT, pgl.GL_NICEST)

        self.camera.setup_projection()
Exemplo n.º 43
0
 def __init__(self):
     self._stroke_color = (1, 1, 1, 1)
     self._fill_color = (1, 1, 1, 1)
     self._line_width = 1
     glEnable(GL_POINT_SMOOTH)
     glEnable(GL_LINE_SMOOTH)
     glEnable(GL_POLYGON_SMOOTH)
     glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
     glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
     glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
Exemplo n.º 44
0
    def set_state(self):
        super().set_state()

        # enable alpha colors
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        # enable anti-aliasing
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        gl.glHint(gl.GL_POINT_SMOOTH_HINT, self.quality)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, self.quality)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, self.quality)
Exemplo n.º 45
0
    def set_state(self):
        super().set_state()

        # enable alpha colors
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        # enable anti-aliasing
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        gl.glHint(gl.GL_POINT_SMOOTH_HINT, self.quality)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, self.quality)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, self.quality)
Exemplo n.º 46
0
    def __init__(self, my_gen):
        self.my_gen = my_gen
        super(MapGenWindow, self).__init__(width=800, height=800)
        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)

        self.landmass = self.my_gen.generate()
        self.draw_capitals = True

        self.labels = []
        self.batch = pyglet.graphics.Batch()

        self.update()

        pyglet.app.run()
Exemplo n.º 47
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()
Exemplo n.º 48
0
def _draw_rects(shape_list: List[Sprite], vertex_buffer: VertexBuffer,
                texture_coord_buffer: TextureCoordBuffer,
                color_buffer: ColorBuffer,
                change_x: float, change_y: float):
    """
    Draw a set of rectangles using vertex buffers. This is more efficient
    than drawing them individually.
    """

    if len(shape_list) == 0:
        return

    gl.glEnable(gl.GL_BLEND)
    gl.glEnable(gl.GL_TEXTURE_2D)  # As soon as this happens, can't use drawing commands
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_NEAREST)
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
    gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
    gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)

    vertex_buffer.bind()
    color_buffer.bind()
    texture_coord_buffer.bind()

    gl.glLoadIdentity()
    gl.glTranslatef(change_x, change_y, 0)

    # Ideally, we want to draw these in "batches."
    # We seek to find groups of squares with the same texture. Then draw
    # them all at once.

    last_texture_id = None
    batch_count = 0
    offset = 0
    batch_offset = 0
    texture_coord_vbo_id = None

    for shape in shape_list:

        if shape.texture.texture_id != last_texture_id:
            # Ok, if the 'if' triggered above, we are now looking at a different
            # texture than we looked at with the last loop. So draw the last
            # "batch" of squares. We'll start a new batch with the current
            # square but not draw it yet
            if batch_count > 0:
                _render_rect_filled(batch_offset,
                                    last_texture_id,
                                    texture_coord_vbo_id,
                                    batch_count)

            batch_count = 0
            batch_offset = offset
            last_texture_id = shape.texture.texture_id

        batch_count += 4
        offset += 4

    # Draw the last batch, if it exists
    _render_rect_filled(batch_offset,
                        last_texture_id,
                        texture_coord_vbo_id,
                        batch_count)

    # Must do this, or drawing commands won't work.
    gl.glDisable(gl.GL_TEXTURE_2D)
Exemplo n.º 49
0
        self._title = caption

    def update_caption(self, mouse):
        """ 添加坐标显示 """
        caption = "{}  x: {}, y: {}".format(self._title, mouse.x, mouse.y)
        super().set_caption(caption)

    def clear(self):
        all_shapes.clear()
        super().clear()

    def show_axis(self):
        from pyleap import Line, Text
        for x in range(0, window.w, 100):
            Line(x, 0, x, window.h, 1, '#eeaa00').draw()
            Text(str(x), x + 2, 2, 10).draw()
        for y in range(0, window.h, 100):
            Line(0, y, window.w, y, 1, '#eeaa00').draw()
            Text(str(y), 2, y + 2, 10).draw()


window = Window()

# alpha
gl.glEnable(gl.GL_LINE_SMOOTH)
gl.glEnable(gl.GL_POLYGON_SMOOTH)
gl.glEnable(gl.GL_BLEND)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)
gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_DONT_CARE)
Exemplo n.º 50
0
def draw_ellipse_filled(center_x, center_y,
                        width, height, color, tilt_angle=0):
    """
    Draw a filled in ellipse.

    Args:
        :center_x: x position that is the center of the circle.
        :center_y: y position that is the center of the circle.
        :height: height of the ellipse.
        :width: width of the ellipse.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :angle: Angle in degrees to tilt the ellipse.
        :num_segments: number of triangle segments that make up this
         circle. Higher is better quality, but slower render time.
    Returns:
        None
    Raises:
        None

    Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> arcade.draw_ellipse_filled(60, 81, 15, 36, arcade.color.AMBER)
    >>> color = (127, 0, 127, 127)
    >>> arcade.draw_ellipse_filled(60, 144, 15, 36, color, 45)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """

    num_segments = 128

    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    GL.glLoadIdentity()
    GL.glTranslatef(center_x, center_y, 0)
    GL.glRotatef(tilt_angle, 0, 0, 1)

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_TRIANGLE_FAN)

    GL.glVertex3f(0, 0, 0.5)

    for i in range(num_segments + 1):
        theta = 2.0 * 3.1415926 * i / num_segments

        x = width * math.cos(theta)
        y = height * math.sin(theta)

        GL.glVertex3f(x, y, 0.5)

    GL.glEnd()
    GL.glLoadIdentity()
Exemplo n.º 51
0
def draw_ellipse_outline(center_x, center_y, width, height, color,
                         border_width=1, tilt_angle=0):
    """
    Draw the outline of an ellipse.

    Args:
        :center_x: x position that is the center of the circle.
        :center_y: y position that is the center of the circle.
        :height: height of the ellipse.
        :width: width of the ellipse.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :border_width: Width of the circle outline in pixels.
        :tilt_angle: Angle in degrees to tilt the ellipse.
    Returns:
        None
    Raises:
        None

    Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> arcade.draw_ellipse_outline(540, 273, 15, 36, arcade.color.AMBER, 3)
    >>> color = (127, 0, 127, 127)
    >>> arcade.draw_ellipse_outline(540, 336, 15, 36, color, 3, 45)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """

    num_segments = 128

    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    GL.glLoadIdentity()
    GL.glTranslatef(center_x, center_y, 0)
    GL.glRotatef(tilt_angle, 0, 0, 1)
    GL.glLineWidth(border_width)

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_LINE_LOOP)
    for i in range(num_segments):
        theta = 2.0 * 3.1415926 * i / num_segments

        x = width * math.cos(theta)
        y = height * math.sin(theta)

        GL.glVertex3f(x, y, 0.5)

    GL.glEnd()
    GL.glLoadIdentity()
Exemplo n.º 52
0
    def init_gl(self):
        """
        Perform the magic incantations to create an OpenGL scene.
        """

        # default background color is white-ish
        background = [.99, .99, .99, 1.0]
        # if user passed a background color use it
        if 'background' in self.kwargs:
            try:
                # convert to (4,) uint8 RGBA
                background = to_rgba(self.kwargs['background'])
                # convert to 0.0 - 1.0 float
                background = background.astype(np.float64) / 255.0
            except BaseException:
                log.error('background color wrong!', exc_info=True)
        # apply the background color
        gl.glClearColor(*background)

        max_depth = (np.abs(self.scene.bounds).max(axis=1)**2).sum()**.5
        max_depth = np.clip(max_depth, 500.00, np.inf)
        gl.glDepthRange(0.0, max_depth)

        gl.glClearDepth(1.0)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glDepthFunc(gl.GL_LEQUAL)

        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_LIGHT1)

        # put the light at one corner of the scenes AABB
        gl.glLightfv(
            gl.GL_LIGHT0, gl.GL_POSITION,
            rendering.vector_to_gl(np.append(self.scene.bounds[1], 0)))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR,
                     rendering.vector_to_gl(.5, .5, 1, 1))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE,
                     rendering.vector_to_gl(1, 1, 1, .75))
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT,
                     rendering.vector_to_gl(.1, .1, .1, .2))

        gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE)
        gl.glEnable(gl.GL_COLOR_MATERIAL)
        gl.glShadeModel(gl.GL_SMOOTH)

        gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT,
                        rendering.vector_to_gl(0.192250, 0.192250, 0.192250))
        gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE,
                        rendering.vector_to_gl(0.507540, 0.507540, 0.507540))
        gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR,
                        rendering.vector_to_gl(.5082730, .5082730, .5082730))

        gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0)

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

        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)

        gl.glLineWidth(1.5)
        gl.glPointSize(4)
Exemplo n.º 53
0
    def _initGL(self):
        gl.glClearColor(0.8, 0.8, 0.9, 0)
        gl.glClearDepth(1.0)  # Enables Clearing Of The Depth Buffer
        gl.glDepthFunc(gl.GL_LESS)  # The Type Of Depth Test To Do
        gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT,
                  gl.GL_NICEST)  # make stuff look nice
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
        if self.anti_alias:
            gl.glLineWidth(0.1)
        else:
            gl.glLineWidth(1.0)

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

        gl.glEnable(gl.GL_DEPTH_TEST)  # Enables Depth Testing
        gl.glEnable(gl.GL_LIGHTING)
        #gl.glEnable(gl.GL_NORMALIZE)
        #gl.glLightModeli(gl.GL_LIGHT_MODEL_TWO_SIDE, gl.GL_FALSE)

        if not gl.glUseProgram:
            print("Can't run shaders!")
            sys.exit(1)

        self.default_shader = compileProgram(
            compileShader(
                '''
                varying vec3 vN;
                varying vec3 v;
                void main(void)
                {
                   v = vec3(gl_ModelViewMatrix * gl_Vertex);
                   vN = normalize(gl_NormalMatrix * gl_Normal);
                   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
                }

            ''', gl.GL_VERTEX_SHADER),
            compileShader(
                '''
                varying vec3 vN;
                varying vec3 v;
                #define MAX_LIGHTS 1

                void main (void)
                {
                   vec3 N = normalize(vN);
                   vec4 finalColor = vec4(0.0, 0.0, 0.0, 0.0);

                   for (int i=0;i<MAX_LIGHTS;i++)
                   {
                      vec3 L = normalize(gl_LightSource[i].position.xyz - v);
                      vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
                      vec3 R = normalize(-reflect(L,N));

                      //calculate Ambient Term:
                      vec4 Iamb = gl_FrontLightProduct[i].ambient;
                      //calculate Diffuse Term:
                      vec4 Idiff = gl_FrontLightProduct[i].diffuse * max(dot(N,L), 0.0);
                      Idiff = clamp(Idiff, 0.0, 1.0);

                      // calculate Specular Term:
                      vec4 Ispec = gl_FrontLightProduct[i].specular
                             * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
                      Ispec = clamp(Ispec, 0.0, 1.0);

                      finalColor += Iamb + Idiff + Ispec;
                   }

                   // write Total Color:
                   gl_FragColor = gl_FrontLightModelProduct.sceneColor + finalColor;
                }
            ''', gl.GL_FRAGMENT_SHADER),
        )

        self.cube_list = Cube().getVerticeList()
        self.coord_list = Coord().getVerticeList()
        self.grid_list = Grid().getVerticeList()

        # fill later
        self.mesh_lists = {}  # type: Dict[str, Any]
Exemplo n.º 54
0
def draw_line_strip(point_list, color, border_width=1):
    """
    Draw a line strip. A line strip is a set of continuously connected
    line segments.

    Args:
        :point_list: List of points making up the line. Each point is
         in a list. So it is a list of lists.
        :color: color, specified in a list of 3 or 4 bytes in RGB or
         RGBA format.
        :border_width: Width of the line in pixels.
    Returns:
        None
    Raises:
        None

    Example:

    >>> import arcade
    >>> arcade.open_window("Drawing Example", 800, 600)
    >>> arcade.set_background_color(arcade.color.WHITE)
    >>> arcade.start_render()
    >>> point_list = ((510, 450), \
(570, 450), \
(510, 480), \
(570, 480), \
(510, 510), \
(570, 510))
    >>> arcade.draw_line_strip(point_list, arcade.color.TROPICAL_RAIN_FOREST, \
3)
    >>> color = (127, 0, 127, 127)
    >>> point_list = ((510, 455), \
(570, 455), \
(510, 485), \
(570, 485), \
(510, 515), \
(570, 515))
    >>> arcade.draw_line_strip(point_list, color, 3)
    >>> arcade.finish_render()
    >>> arcade.quick_run(0.25)
    """
    GL.glEnable(GL.GL_BLEND)
    GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
    GL.glEnable(GL.GL_LINE_SMOOTH)
    GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)
    GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST)

    # Set line width
    GL.glLineWidth(border_width)

    GL.glLoadIdentity()

    # Set color
    if len(color) == 4:
        GL.glColor4ub(color[0], color[1], color[2], color[3])
    elif len(color) == 3:
        GL.glColor4ub(color[0], color[1], color[2], 255)

    GL.glBegin(GL.GL_LINE_STRIP)
    for point in point_list:
        GL.glVertex3f(point[0], point[1], 0.5)
    GL.glEnd()
Exemplo n.º 55
0
def _draw_rects(shape_list: List[Sprite], vertex_vbo_id: gl.GLuint,
                texture_coord_vbo_id: gl.GLuint, change_x: float,
                change_y: float):
    """
    Draw a set of rectangles using vertex buffers. This is more efficient
    than drawing them individually.
    """

    if len(shape_list) == 0:
        return

    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    gl.glEnable(gl.GL_TEXTURE_2D
                )  # As soon as this happens, can't use drawing commands
    # gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
    # gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
                       gl.GL_NEAREST)
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                       gl.GL_NEAREST)
    gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
    gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST)

    # 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, vertex_vbo_id)
    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
    gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
    gl.glVertexPointer(2, gl.GL_FLOAT, 0, 0)

    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, texture_coord_vbo_id)

    last_alpha = shape_list[0].alpha
    gl.glColor4f(1, 1, 1, last_alpha)
    gl.glLoadIdentity()

    # gl.glLoadIdentity()
    gl.glTranslatef(change_x, change_y, 0)

    # Ideally, we want to draw these in "batches."
    # We seek to find groups of squares with the same texture. Then draw
    # them all at once.

    last_texture_id = None
    last_alpha = 1
    batch_count = 0
    offset = 0
    batch_offset = 0
    texture_coord_vbo_id = None

    for shape in shape_list:

        if shape.texture.texture_id != last_texture_id or shape.alpha != last_alpha:
            # Ok, if the 'if' triggered above, we are now looking at a different
            # texture than we looked at with the last loop. So draw the last
            # "batch" of squares. We'll start a new batch with the current
            # square but not draw it yet
            if batch_count > 0:
                gl.glColor4f(1, 1, 1, last_alpha)
                _render_rect_filled(batch_offset, last_texture_id,
                                    texture_coord_vbo_id, batch_count)

            batch_count = 0
            batch_offset = offset
            last_texture_id = shape.texture.texture_id
            last_alpha = shape.alpha

        batch_count += 4
        offset += 4

    # Draw the last batch, if it exists
    _render_rect_filled(batch_offset, last_texture_id, texture_coord_vbo_id,
                        batch_count)

    gl.glDisable(gl.GL_TEXTURE_2D)
Exemplo n.º 56
0
 def on_draw(self):
     gl.glEnable(gl.GL_BLEND)
     gl.glEnable(gl.GL_LINE_SMOOTH)
     gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)
     self.clear()
     self.gamePhase.draw(self)