Exemple #1
0
def on_key_press(symbol, modifiers):
    mode_f = mode_b = None
    shade_model = None

    if symbol == key._1:
        gl.glEnable(gl.GL_LINE_STIPPLE)

    elif symbol == key._2:
        gl.glDisable(gl.GL_LINE_STIPPLE)

    elif symbol == key._3:
        mode_f = mode_b = gl.GL_FILL
        shade_model = gl.GL_FLAT

    elif symbol == key._4:
        mode_f = gl.GL_POINT
        mode_b = gl.GL_LINE
        shade_model = gl.GL_SMOOTH

    elif symbol == key._5:
        gl.glEnable(gl.GL_POINT_SMOOTH)

    elif symbol == key._6:
        gl.glDisable(gl.GL_POINT_SMOOTH)

    elif symbol == key._7:
        mode_f = mode_b = gl.GL_FILL
        shade_model = gl.GL_SMOOTH

    if mode_f is not None:
        gl.glPolygonMode(gl.GL_FRONT, mode_f)
        gl.glPolygonMode(gl.GL_BACK, mode_b)
        gl.glShadeModel(shade_model)
Exemple #2
0
    def init_gl(self):
        gl.glClearColor(.93, .93, 1, 1)
        #glColor3f(1, 0, 0)

        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) 
Exemple #3
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
Exemple #4
0
 def init_gl(self):
     gl.glClearColor(.93, .93, 1, 1)
     # glColor3f(1, 0, 0)
     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)
Exemple #5
0
 def _InitGLState(self):
     gl.glEnable(gl.GL_BLEND)
     gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE)
     gl.glEnable(gl.GL_TEXTURE_2D)
     gl.glShadeModel(gl.GL_SMOOTH)
     gl.glClearColor(0, 0, 0, 1)
     #Rotated images can have a z-distance of more than one
     gl.glDepthRangef(0,2)
Exemple #6
0
 def _InitGLState(self):
     gl.glEnable(gl.GL_BLEND)
     gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE)
     gl.glEnable(gl.GL_TEXTURE_2D)
     gl.glShadeModel(gl.GL_SMOOTH)
     gl.glClearColor(0, 0, 0, 1)
     # Rotated images can have a z-distance of more than one
     gl.glDepthRangef(0, 2)
Exemple #7
0
 def on_resize(self, width, height):
     """
     The window was resized.
     """
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     gluPerspective(FOV, width / height, NEAR_PLANE, FAR_PLANE)
     glMatrixMode(GL_MODELVIEW)
     glShadeModel(GL_SMOOTH)
Exemple #8
0
def gl_enable_color_material():
    # do some openGL things
    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_float([0.192250, 0.192250, 0.192250]))
    gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, gl_float([0.507540, 0.507540, 0.507540]))
    gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, gl_float([.5082730, .5082730, .5082730]))
    gl.glMaterialf(gl.GL_FRONT, gl.GL_SHININESS, .4 * 128.0)
Exemple #9
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)
Exemple #10
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)
Exemple #11
0
    def _gl_enable_color_material():
        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)
Exemple #12
0
 def draw_lem (self):
     with push_attrib(gl.GL_DEPTH_BUFFER_BIT | gl.GL_LIGHTING_BIT):
         gl.glDepthMask(gl.GL_TRUE)
         gl.glEnable(gl.GL_DEPTH_TEST)
         gl.glEnable(gl.GL_LIGHTING)
         gl.glEnable(gl.GL_LIGHT0)
         gl.glEnable(gl.GL_NORMALIZE)
         gl.glShadeModel(gl.GL_SMOOTH)
         gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, float_ctype_array(1.0, 1.0, 1.0, 1.0))
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, float_ctype_array(0.0, 0.0, 0.0, 1.0))
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, float_ctype_array(1.0, 1.0, 1.0, 1.0))
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, float_ctype_array(0.5, 0.5, 0.5, 1.0))
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, float_ctype_array(1.0, 1.0, 1.0, 0.0))
         self.draw_lem_model()
Exemple #13
0
    def OnInitGL(self, call_reshape=True):
        '''Initialize OpenGL for use in the window.'''
        if self.GLinitialized:
            return
        self.GLinitialized = True
        # create a pyglet context for this panel
        self.pygletcontext = gl.Context(gl.current_context)
        self.pygletcontext.canvas = self
        self.pygletcontext.set_current()
        # normal gl init
        glClearColor(0, 0, 0, 1)
        glColor3f(1, 0, 0)
        glEnable(GL_DEPTH_TEST)
        glClearDepth(1.0)
        glDepthFunc(GL_LEQUAL)
        glEnable(GL_CULL_FACE)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        # Uncomment this line for a wireframe view
        # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Simple light setup.  On Windows GL_LIGHT0 is enabled by default,
        # but this is not the case on Linux or Mac, so remember to always
        # include it.
        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHT1)

        glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0))
        glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 1, 1))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1))
        glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1))
        glShadeModel(GL_SMOOTH)

        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                     vec(0.5, 0, 0.3, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)
        glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9))
        if call_reshape:
            self.OnReshape()
        if hasattr(self.parent, "filenames") and self.parent.filenames:
            for filename in self.parent.filenames:
                self.parent.load_file(filename)
            self.parent.autoplate()
            if hasattr(self.parent, "loadcb"):
                self.parent.loadcb()
            self.parent.filenames = None
Exemple #14
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)
Exemple #15
0
    def OnInitGL(self, call_reshape = True):
        '''Initialize OpenGL for use in the window.'''
        if self.GLinitialized:
            return
        self.GLinitialized = True
        # create a pyglet context for this panel
        self.pygletcontext = gl.Context(gl.current_context)
        self.pygletcontext.canvas = self
        self.pygletcontext.set_current()
        # normal gl init
        glClearColor(0, 0, 0, 1)
        glColor3f(1, 0, 0)
        glEnable(GL_DEPTH_TEST)
        glClearDepth(1.0)
        glDepthFunc(GL_LEQUAL)
        glEnable(GL_CULL_FACE)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        # Uncomment this line for a wireframe view
        # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Simple light setup.  On Windows GL_LIGHT0 is enabled by default,
        # but this is not the case on Linux or Mac, so remember to always
        # include it.
        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHT1)

        glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0))
        glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 1, 1))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1))
        glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1))
        glShadeModel(GL_SMOOTH)

        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec(0.5, 0, 0.3, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)
        glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9))
        if call_reshape:
            self.OnReshape()
        if hasattr(self.parent, "filenames") and self.parent.filenames:
            for filename in self.parent.filenames:
                self.parent.load_file(filename)
            self.parent.autoplate()
            if hasattr(self.parent, "loadcb"):
                self.parent.loadcb()
            self.parent.filenames = None
Exemple #16
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)
Exemple #17
0
 def draw_lem(self):
     with push_attrib(gl.GL_DEPTH_BUFFER_BIT | gl.GL_LIGHTING_BIT):
         gl.glDepthMask(gl.GL_TRUE)
         gl.glEnable(gl.GL_DEPTH_TEST)
         gl.glEnable(gl.GL_LIGHTING)
         gl.glEnable(gl.GL_LIGHT0)
         gl.glEnable(gl.GL_NORMALIZE)
         gl.glShadeModel(gl.GL_SMOOTH)
         gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,
                           float_ctype_array(1.0, 1.0, 1.0, 1.0))
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT,
                      float_ctype_array(0.0, 0.0, 0.0, 1.0))
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE,
                      float_ctype_array(1.0, 1.0, 1.0, 1.0))
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR,
                      float_ctype_array(0.5, 0.5, 0.5, 1.0))
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION,
                      float_ctype_array(1.0, 1.0, 1.0, 0.0))
         self.draw_lem_model()
Exemple #18
0
    def start(self):
        # run setup from sketch
        self.setup()

        glShadeModel(GL_SMOOTH)  # smooth shading of polygons

        event_loop = pyglet.app.EventLoop()

        def update(dt):
            for i in Globals.WINDOWMANAGER.windows:
                i.drawsettings.reset()

            if Globals.LOOP:
                self.draw()
            if not Globals.RUNNING:
                event_loop.exit()

        pyglet.clock.set_fps_limit(Globals.FPS)
        pyglet.clock.schedule_interval(update, 1 / Globals.FPS)
        event_loop.run()
Exemple #19
0
 def setup_lights(self):
     if not self.do_lights:
         return
     glEnable(GL_LIGHTING)
     glDisable(GL_LIGHT0)
     glLightfv(GL_LIGHT0, GL_AMBIENT, vec(0.4, 0.4, 0.4, 1.0))
     glLightfv(GL_LIGHT0, GL_SPECULAR, vec(0, 0, 0, 0))
     glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(0, 0, 0, 0))
     glEnable(GL_LIGHT1)
     glLightfv(GL_LIGHT1, GL_AMBIENT, vec(0, 0, 0, 1.0))
     glLightfv(GL_LIGHT1, GL_SPECULAR, vec(0.6, 0.6, 0.6, 1.0))
     glLightfv(GL_LIGHT2, GL_DIFFUSE, vec(0.8, 0.8, 0.8, 1))
     glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 2, 3, 0))
     glEnable(GL_LIGHT2)
     glLightfv(GL_LIGHT2, GL_AMBIENT, vec(0, 0, 0, 1.0))
     glLightfv(GL_LIGHT2, GL_SPECULAR, vec(0.6, 0.6, 0.6, 1.0))
     glLightfv(GL_LIGHT2, GL_DIFFUSE, vec(0.8, 0.8, 0.8, 1))
     glLightfv(GL_LIGHT2, GL_POSITION, vec(-1, -1, 3, 0))
     glEnable(GL_NORMALIZE)
     glShadeModel(GL_SMOOTH)
Exemple #20
0
 def setup_lights(self):
     if not self.do_lights:
         return
     glEnable(GL_LIGHTING)
     glDisable(GL_LIGHT0)
     glLightfv(GL_LIGHT0, GL_AMBIENT, vec(0.4, 0.4, 0.4, 1.0))
     glLightfv(GL_LIGHT0, GL_SPECULAR, vec(0, 0, 0, 0))
     glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(0, 0, 0, 0))
     glEnable(GL_LIGHT1)
     glLightfv(GL_LIGHT1, GL_AMBIENT, vec(0, 0, 0, 1.0))
     glLightfv(GL_LIGHT1, GL_SPECULAR, vec(0.6, 0.6, 0.6, 1.0))
     glLightfv(GL_LIGHT2, GL_DIFFUSE, vec(0.8, 0.8, 0.8, 1))
     glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 2, 3, 0))
     glEnable(GL_LIGHT2)
     glLightfv(GL_LIGHT2, GL_AMBIENT, vec(0, 0, 0, 1.0))
     glLightfv(GL_LIGHT2, GL_SPECULAR, vec(0.6, 0.6, 0.6, 1.0))
     glLightfv(GL_LIGHT2, GL_DIFFUSE, vec(0.8, 0.8, 0.8, 1))
     glLightfv(GL_LIGHT2, GL_POSITION, vec(-1, -1, 3, 0))
     glEnable(GL_NORMALIZE)
     glShadeModel(GL_SMOOTH)
Exemple #21
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()
    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
Exemple #23
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()
Exemple #24
0
    def __init__(self, application, configuration={}):
        self.application   = application
        self.configuration = configuration

        self.log = logging.getLogger("GameWindow")

        platform = pyglet.window.get_platform()
        display  = platform.get_default_display()
        screen   = display.get_default_screen()
        screens  = display.get_screens()
        config   = screen.get_best_config(pyglet.gl.Config(
            #                alpha_size = self.alpha_size,
                ))
        context  = config.create_context(None)

        pyglet.window.Window.__init__(self, 
                vsync = False,
                context = context,
                )

        self.log.debug(u"Found %s screens: %s", len(screens), str(screens))

        self.set_fullscreen(
                self.configuration.get('fullscreen', False), 
                screens[self.configuration.get('screen', 0)],
                )
        if not self.fullscreen:
            self.set_size(
                    self.application.state.window_width, 
                    self.application.state.window_height
                    )

        gl.glClearColor(*self.background_color)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glShadeModel(gl.GL_SMOOTH)
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glEnable(gl.GL_LINE_SMOOTH)
Exemple #25
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()
Exemple #26
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()
Exemple #27
0
 def initializeGL(self):
         _import_gl()
         self.resizeGL(self.width(), self.height()) # probably not needed
         glClearColor(0.0, 0.0, 0.0, 0.0)
         glShadeModel(GL_FLAT)
Exemple #28
0
    def generate_map(self):
        scene_radius = 95.0
        light_to_scene_distance = math.sqrt(
            light_pos[0]**2 + light_pos[1]**2 + light_pos[2]**2)
        near_plane = light_to_scene_distance - scene_radius
        field_of_view = math3d.radians_to_degrees(2.0 *
                                                  math.atan(scene_radius / float(light_to_scene_distance)))

        tmp = (gl.GLfloat * 16)()

        gl.glMatrixMode( gl.GL_PROJECTION )
        gl.glLoadIdentity()
        gl.gluPerspective( field_of_view, 1.0, near_plane,
                           near_plane + (2.0 * scene_radius) )
        gl.glGetFloatv( gl.GL_PROJECTION_MATRIX, tmp )
        gl.light_projection = euclid.Matrix4()
        gl.light_projection[0:16] = tmp[:]

        # Switch to light's point of view
        gl.glMatrixMode( gl.GL_MODELVIEW )
        gl.glLoadIdentity()
        gl.gluLookAt( self.light.pos.x, self.light.pos.y, self.light.pos.z,
                      0.0, 0.0, 0.0, 0.0, 1.0, 0.0 )
        gl.glGetFloatv( gl.GL_MODELVIEW_MATRIX, tmp )
        light_mview = euclid.Matrix4()
        light_mview[0:16] = tmp[:]

        #glViewport(0, 0, shadow_width, shadow_height)

        # Clear the depth buffer only
        gl.glClear( gl.GL_DEPTH_BUFFER_BIT )

        # Remember the current shade model
        gl.glPushAttrib( gl.GL_ENABLE_BIT )
        prev_shade_model = cypes.GLint()
        gl.glGetIntegerv( gl.GL_SHADE_MODEL, prev_shade_model )

        # All we care about here is resulting depth values
        gl.glShadeModel( gl.GL_FLAT )
        gl.glDisable( gl.GL_LIGHTING )
        gl.glDisable( gl.GL_COLOR_MATERIAL )
        gl.glDisable( gl.GL_NORMALIZE )
        gl.glColorMask( 0, 0, 0, 0 )

        # Overcome imprecision
        gl.glEnable( gl.GL_POLYGON_OFFSET_FILL )

        #draw_models(False)
        self.context.render( exclude=self.exclude_shadows )

        # Copy depth values into depth texture
        gl.glCopyTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_DEPTH_COMPONENT,
                             0, 0, shadow_width, shadow_height, 0 )

        # Restore normal drawing state
        gl.glShadeModel( gl.GL_SMOOTH )
        gl.glEnable( gl.GL_LIGHTING )
        gl.glEnable( gl.GL_COLOR_MATERIAL )
        gl.glEnable( gl.GL_NORMALIZE )
        gl.glColorMask( 1, 1, 1, 1 )
        gl.glDisable( gl.GL_POLYGON_OFFSET_FILL )

        # Setup up the texture matrix which will be use in eye-linear
        # texture mapping
        self.tex_matrix = euclid.Matrix4()
        self.tex_matrix.translate(0.5, 0.5, 0.5).scale(0.5, 0.5, 0.5)
        tmp_matrix.scale(0.5, 0.5, 0.5)
        tex_matrix = (tmp_matrix * light_projection) * light_mview
        self.tex_matrix.transpose()
        # Give us immediate access to ctypes arrays
        self.tex_matrix = (
            (gl.GLfloat * 4)(*self.tex_matrix[0:4]),
            (gl.GLfloat * 4)(*self.tex_matrix[4:8]),
            (gl.GLfloat * 4)(*self.tex_matrix[8:12]),
            (gl.GLfloat * 4)(*self.tex_matrix[12:16])
        )
Exemple #29
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)
Exemple #30
0
    def init_gl(self):
        """
        Perform the magic incantations to create an
        OpenGL scene using pyglet.
        """

        # 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 set but wrong!',
                          exc_info=True)

        # apply the background color
        gl.glClearColor(*background)

        # find the maximum depth based on
        # maximum length of scene AABB
        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)

        # do some openGL things
        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)

        # enable blending for transparency
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA,
                       gl.GL_ONE_MINUS_SRC_ALPHA)

        # make the lines from Path3D objects less ugly
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
        # set the width of lines to 1.5 pixels
        gl.glLineWidth(1.5)
        # set PointCloud markers to 4 pixels in size
        gl.glPointSize(4)

        # set up the viewer lights using self.scene
        self.update_lighting()