pygame / test / image__save_gl_surface_test.py

import pygame, unittest, os, test_utils
from pygame.locals import *

CUBE_POINTS = (
    (0.5, -0.5, -0.5),  (0.5, 0.5, -0.5),
    (-0.5, 0.5, -0.5),  (-0.5, -0.5, -0.5),
    (0.5, -0.5, 0.5),   (0.5, 0.5, 0.5),
    (-0.5, -0.5, 0.5),  (-0.5, 0.5, 0.5)
)

CUBE_QUAD_VERTS = (
    (0, 1, 2, 3), (3, 2, 7, 6), (6, 7, 5, 4),
    (4, 5, 1, 0), (1, 5, 7, 2), (4, 0, 3, 6)
)

try:
    from OpenGL.GL import *
    from OpenGL.GLU import *

    def drawcube():
        glBegin(GL_QUADS)
        for face in CUBE_QUAD_VERTS:
            for vert in face:
                glVertex3fv(CUBE_POINTS[vert])
        glEnd()

    class GL_ImageSave(unittest.TestCase):
        def test_image_save_works_with_opengl_surfaces(self):
            pygame.init()
            screen = pygame.display.set_mode((640,480), OPENGL|DOUBLEBUF)

            drawcube()
            pygame.display.flip()

            tmp_dir = test_utils.get_tmp_dir()
            tmp_file = os.path.join(tmp_dir, "opengl_save_surface_test.png")

            pygame.image.save(screen, tmp_file)

            self.assert_(os.path.exists(tmp_file))

            os.remove(tmp_file)

except ImportError:
    print 'GL test requires PyOpenGL'

if __name__ == '__main__': 
    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.