예제 #1
0
 def __init__(self,
              content_manager,
              asset_name,
              width=1000,
              height=750,
              config=None):  # pylint: disable-msg=W0231
     pyglet.window.Window.__init__(self,
                                   width=width,
                                   height=height,
                                   resizable=True,
                                   config=config)
     self.gl_setup()
     self.art_object = AO(content_manager, asset_name)
     self.tbcam = TrackballCamera()
     self.fps_display = pyglet.clock.ClockDisplay(color=(0.5, 0.5, 0.5,
                                                         1.0))
예제 #2
0
파일: show_ao.py 프로젝트: 0x0ade/Fezzer-2
 def __init__(self, content_manager, asset_name, width=1000, height=750, config=None):  # pylint: disable-msg=W0231
     pyglet.window.Window.__init__(self, width=width, height=height, resizable=True, config=config)
     self.gl_setup()
     self.art_object = AO(content_manager, asset_name)
     self.tbcam = TrackballCamera()
     self.fps_display = pyglet.clock.ClockDisplay(color=(0.5, 0.5, 0.5, 1.0))
예제 #3
0
class AOWindow(pyglet.window.Window):  # pylint: disable-msg=W0223
    wireframe = False
    lighting = True
    culling = False
    texturing = True

    def __init__(self,
                 content_manager,
                 asset_name,
                 width=1000,
                 height=750,
                 config=None):  # pylint: disable-msg=W0231
        pyglet.window.Window.__init__(self,
                                      width=width,
                                      height=height,
                                      resizable=True,
                                      config=config)
        self.gl_setup()
        self.art_object = AO(content_manager, asset_name)
        self.tbcam = TrackballCamera()
        self.fps_display = pyglet.clock.ClockDisplay(color=(0.5, 0.5, 0.5,
                                                            1.0))

    @staticmethod
    def gl_setup():
        glClearColor(0.3926, 0.5843, 0.9294, 1.0)
        glClearDepth(1.0)
        glColor3f(1.0, 1.0, 1.0)

        glDisable(GL_CULL_FACE)
        glFrontFace(GL_CW)

        glEnable(GL_DEPTH_TEST)

        glShadeModel(GL_SMOOTH)

        glPolygonOffset(1, 1)

        glDisable(GL_LIGHTING)

        glEnable(GL_LIGHT0)
        glLightfv(GL_LIGHT0, GL_POSITION, vec_args(0.5, 0.5, 10.0, 1.0))
        glLightfv(GL_LIGHT0, GL_AMBIENT, vec_args(0.5, 0.5, 0.5, 1.0))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, vec_args(1.0, 1.0, 1.0, 1.0))

    def on_resize(self, width, height):
        # Override the default on_resize handler to create a 3D projection
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(45.0,
                       float(self.width) / float(self.height), 0.1, 100.0)
        self.tbcam.update_modelview()
        glMatrixMode(GL_MODELVIEW)
        return pyglet.event.EVENT_HANDLED

    def on_draw(self):  # pylint: disable-msg=W0221
        self.clear()

        if self.culling:
            glEnable(GL_CULL_FACE)
        if self.lighting:
            glEnable(GL_LIGHTING)
        if self.wireframe:
            glEnable(GL_POLYGON_OFFSET_FILL)
            glColor3f(1.0, 1.0, 1.0)
            self.art_object.draw(self.texturing)
            glDisable(GL_POLYGON_OFFSET_FILL)

            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            glColor3f(0.0, 0.0, 0.0)
            glDisable(GL_LIGHTING)
            self.art_object.draw(False)
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glColor3f(1.0, 1.0, 1.0)
            self.art_object.draw(self.texturing)
        glDisable(GL_CULL_FACE)
        glDisable(GL_LIGHTING)

    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.W:
            self.wireframe = not self.wireframe
        elif symbol == pyglet.window.key.L:
            self.lighting = not self.lighting
        elif symbol == pyglet.window.key.C:
            self.culling = not self.culling
        elif symbol == pyglet.window.key.T:
            self.texturing = not self.texturing
        elif symbol == pyglet.window.key.ESCAPE:
            self.dispatch_event('on_close')

    #noinspection PyUnresolvedReferences,PyUnusedLocal
    def on_mouse_press(self, x, y, button,
                       modifiers):  # pylint: disable-msg=W0221,C0103
        if button == pyglet.window.mouse.LEFT:
            self.tbcam.mouse_roll(norm1(x, self.width), norm1(y, self.height),
                                  False)
        elif button == pyglet.window.mouse.RIGHT:
            self.tbcam.mouse_zoom(norm1(x, self.width), norm1(y, self.height),
                                  False)

    #noinspection PyUnresolvedReferences,PyUnusedLocal
    def on_mouse_drag(self, x, y, dx, dy, buttons,
                      modifiers):  # pylint: disable-msg=W0221,C0103
        if buttons & pyglet.window.mouse.LEFT:
            self.tbcam.mouse_roll(norm1(x, self.width), norm1(y, self.height))
        elif buttons & pyglet.window.mouse.RIGHT:
            self.tbcam.mouse_zoom(norm1(x, self.width), norm1(y, self.height))
예제 #4
0
파일: show_ao.py 프로젝트: 0x0ade/Fezzer-2
class AOWindow(pyglet.window.Window):  # pylint: disable-msg=W0223
    wireframe = False
    lighting = True
    culling = False
    texturing = True

    def __init__(self, content_manager, asset_name, width=1000, height=750, config=None):  # pylint: disable-msg=W0231
        pyglet.window.Window.__init__(self, width=width, height=height, resizable=True, config=config)
        self.gl_setup()
        self.art_object = AO(content_manager, asset_name)
        self.tbcam = TrackballCamera()
        self.fps_display = pyglet.clock.ClockDisplay(color=(0.5, 0.5, 0.5, 1.0))

    @staticmethod
    def gl_setup():
        glClearColor(0.3926, 0.5843, 0.9294, 1.0)
        glClearDepth(1.0)
        glColor3f(1.0, 1.0, 1.0)

        glDisable(GL_CULL_FACE)
        glFrontFace(GL_CW)

        glEnable(GL_DEPTH_TEST)

        glShadeModel(GL_SMOOTH)

        glPolygonOffset(1, 1)

        glDisable(GL_LIGHTING)

        glEnable(GL_LIGHT0)
        glLightfv(GL_LIGHT0, GL_POSITION, vec_args(0.5, 0.5, 10.0, 1.0))
        glLightfv(GL_LIGHT0, GL_AMBIENT, vec_args(0.5, 0.5, 0.5, 1.0))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, vec_args(1.0, 1.0, 1.0, 1.0))

    def on_resize(self, width, height):
        # Override the default on_resize handler to create a 3D projection
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(45.0, float(self.width) / float(self.height), 0.1, 100.0)
        self.tbcam.update_modelview()
        glMatrixMode(GL_MODELVIEW)
        return pyglet.event.EVENT_HANDLED

    def on_draw(self):  # pylint: disable-msg=W0221
        self.clear()

        if self.culling:
            glEnable(GL_CULL_FACE)
        if self.lighting:
            glEnable(GL_LIGHTING)
        if self.wireframe:
            glEnable(GL_POLYGON_OFFSET_FILL)
            glColor3f(1.0, 1.0, 1.0)
            self.art_object.draw(self.texturing)
            glDisable(GL_POLYGON_OFFSET_FILL)

            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            glColor3f(0.0, 0.0, 0.0)
            glDisable(GL_LIGHTING)
            self.art_object.draw(False)
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glColor3f(1.0, 1.0, 1.0)
            self.art_object.draw(self.texturing)
        glDisable(GL_CULL_FACE)
        glDisable(GL_LIGHTING)

    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.W:
            self.wireframe = not self.wireframe
        elif symbol == pyglet.window.key.L:
            self.lighting = not self.lighting
        elif symbol == pyglet.window.key.C:
            self.culling = not self.culling
        elif symbol == pyglet.window.key.T:
            self.texturing = not self.texturing
        elif symbol == pyglet.window.key.ESCAPE:
            self.dispatch_event('on_close')

    #noinspection PyUnresolvedReferences,PyUnusedLocal
    def on_mouse_press(self, x, y, button, modifiers):  # pylint: disable-msg=W0221,C0103
        if button == pyglet.window.mouse.LEFT:
            self.tbcam.mouse_roll(
                norm1(x, self.width),
                norm1(y, self.height),
                False)
        elif button == pyglet.window.mouse.RIGHT:
            self.tbcam.mouse_zoom(
                norm1(x, self.width),
                norm1(y, self.height),
                False)

    #noinspection PyUnresolvedReferences,PyUnusedLocal
    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):  # pylint: disable-msg=W0221,C0103
        if buttons & pyglet.window.mouse.LEFT:
            self.tbcam.mouse_roll(
                norm1(x, self.width),
                norm1(y, self.height))
        elif buttons & pyglet.window.mouse.RIGHT:
            self.tbcam.mouse_zoom(
                norm1(x, self.width),
                norm1(y, self.height))