This is probably trivial but ...
If the screen is created on top of another window then if loses focus
and re-activated it shows but it's contents are lost. Seems the window
is not refreshing its contents.

<code>
#!/usr/bin/env python

'''
A pyglet (http://www.pyglet.org) tutorial based loosely on Nehe's
Lesson 3.
Add color to the polygons
See the original source and C based tutorial at http://nehe.gamedev.net
'''

import pyglet
from pyglet.window import key
pyglet.options['debug_gl'] =
False                                             # Disable error
checking for increased performance
from pyglet.gl import *

class MainWindow(pyglet.window.Window):
    def __init__(self):
        '''
        todo:
        Config must be set with older graphics cards since
        the number of samples per pixel defaults to 0 (confirm?)
        Note that double_buffer = True is set by default
        Set alpha_size = 8 to create a window with an alpha channel
        The visibility of the window is delayed until after
initialization
        '''
        config = Config \
        (
            samples = 2, \
            alpha_size = 8, \
        )
        super(MainWindow, self).__init__ \
        (
            width = 640, \
            height = 480, \
            resizable = True, \
            caption = 'Lesson 3: F2 toggles fullscreen, ESC exits', \
            visible = False,
            config = config, \
        )
        self.FullScreen = self.fullscreen
        self.InitGL(self.width,self.height)
        self.Center()
        self.set_visible(True)

    def on_draw(self):
        '''
        built-in pyglet event
        '''
        self.clear
()                                                           # Clear
the screen and the depth buffer
        glLoadIdentity()                                                        
                   #
Reset the view
        glTranslatef(-1.5, 0.0,
-6.0)                                          # Move left 1.5 units
and into the screen 6.0 units
        glBegin(GL_TRIANGLES)                                                   
                   #
Drawing using triangles
        glColor3f
(1.0,0.0,0.0)                                                 # Set
the color to red
        glVertex3f(0.0, 1.0, 0.0)
# Top
        glColor3f
(0.0,1.0,0.0)                                                 # Set
the color to green
        glVertex3f(-1.0,-1.0,
0.0)                                             # Bottom left
        glColor3f
(0.0,0.0,1.0)                                                 # Set
the color to blue
        glVertex3f( 1.0,-1.0,
0.0)                                             # Bottom Right
        glEnd
()                                                                #
Finished drawing the triangle
        glTranslatef(3.0, 0.0,
0.0)                                            # Move right 3.0
units.
        glColor3f
(0.5,0.5,1.0)                                                 # Set
the color to blue one time only
        glBegin
(GL_QUADS)                                                      #
Start drawing a 4 sided polygon
        glVertex3f(-1.0, 1.0,
0.0)                                             # Top left
        glVertex3f(1.0, 1.0,
0.0)                                              # Top right
        glVertex3f(1.0, -1.0,
0.0)                                             # Bottom right
        glVertex3f(-1.0, -1.0,
0.0)                                            # Bottom left
        glEnd
()                                                                # We
are done with the polygon

    def on_resize(self, width, height):
        '''
        built-in pyglet event
        '''
        if height == 0:                                                         
                   #
Prevent a divide by zero if the window is too small
            height = 1
        glViewport(0, 0, width,
height)                                        # Reset the current
viewport and perspective transformation
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(45.0, float(width)/float(height), 0.1, 100.0)
        glMatrixMode(GL_MODELVIEW)

    def on_key_press(self, symbol, modifiers):
        '''
        built-in pyglet event
        '''
        if symbol == key.F2:
            self.FullScreen = not
self.FullScreen                              # Toggle fullscreen
            self.set_mouse_visible(not
self.FullScreen)                        # Toggle mouse visibility
depending on fullscreen
            self.set_fullscreen(self.FullScreen)
        elif symbol == key.ESCAPE:
            self.close()

    def Center(self):
        '''
        Center the window on the screen
        '''
        x = (self.screen.width-self.width)//2
        y = (self.screen.height-self.height)//2
        self.set_location(x,y)

    def InitGL(self, width,
height):
        '''
        A general OpenGL initialization function.
        Sets all of the initial parameters.
        We call this right after our OpenGL window is created.
        '''
        glShadeModel
(GL_SMOOTH)                                                # Enables
smooth color shading
        glClearColor(0.0, 0.0, 0.0,
0.0)                                       # This will clear the
background color to black
        glClearDepth
(1.0)                                                      # Enables
clearing of the depth buffer
        glEnable
(GL_DEPTH_TEST)                                                #
Enables depth testing
        glDepthFunc
(GL_LEQUAL)                                                 # The type
of depth test to do
        glHint(GL_PERSPECTIVE_CORRECTION_HINT,
GL_NICEST)                      # Really nice perspective calculations

if __name__ == '__main__':
    window = MainWindow()
    pyglet.app.run()

</code>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to