Module SvgTest
[hide private]
[frames] | no frames]

Source Code for Module SvgTest

 1  ##################################################################### 
 2  # -*- coding: iso-8859-1 -*-                                        # 
 3  #                                                                   # 
 4  # Frets on Fire                                                     # 
 5  # Copyright (C) 2006 Sami Kyöstilä                                  # 
 6  #                                                                   # 
 7  # This program is free software; you can redistribute it and/or     # 
 8  # modify it under the terms of the GNU General Public License       # 
 9  # as published by the Free Software Foundation; either version 2    # 
10  # of the License, or (at your option) any later version.            # 
11  #                                                                   # 
12  # This program is distributed in the hope that it will be useful,   # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     # 
15  # GNU General Public License for more details.                      # 
16  #                                                                   # 
17  # You should have received a copy of the GNU General Public License # 
18  # along with this program; if not, write to the Free Software       # 
19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        # 
20  # MA  02110-1301, USA.                                              # 
21  ##################################################################### 
22   
23  import unittest 
24  from GameEngine import GameEngine 
25  from Texture import Texture 
26   
27  from OpenGL.GL import * 
28  from OpenGL.GLU import * 
29   
30 -class SvgTest(unittest.TestCase):
31 - def testRendering(self):
32 self.svg.transform.translate(256, 256) 33 self.svg.transform.rotate(3.141592) 34 self.svg.draw() 35 self.e.video.flip()
36
37 - def testRenderToTexture(self):
38 scale = 4 39 fullwidth, fullheight = 512, 512 40 width, height = int(fullwidth / scale), int(fullheight / scale) 41 t = Texture() 42 self.e.svg.setProjection((0, 0, fullwidth, fullheight)) 43 44 t.prepareRenderTarget(width, height) 45 t.setAsRenderTarget() 46 glViewport(0, 0, width, height) 47 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 48 self.svg.transform.translate(width * scale / 2, height * scale / 2) 49 self.svg.transform.rotate(3.141592) 50 self.svg.draw() 51 t.resetDefaultRenderTarget() 52 53 glViewport(0, 0, fullwidth, fullheight) 54 glMatrixMode(GL_PROJECTION) 55 glLoadIdentity() 56 gluOrtho2D(0.0, 1.0, 0.0, 1.0) 57 glMatrixMode(GL_MODELVIEW) 58 glLoadIdentity() 59 60 t.bind() 61 glEnable(GL_TEXTURE_2D) 62 if not t.framebuffer.emulated: 63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) 64 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) 65 66 glClear(GL_COLOR_BUFFER_BIT) 67 glColor3f(1.0, 1.0, 1.0) 68 glBegin(GL_TRIANGLE_STRIP) 69 glTexCoord2f(0.0, 0.0) 70 glVertex2f(0.0, 0.0) 71 glTexCoord2f(1.0, 0.0) 72 glVertex2f(1.0, 0.0) 73 glTexCoord2f(0.0, 1.0) 74 glVertex2f(0.0, 1.0) 75 glTexCoord2f(1.0, 1.0) 76 glVertex2f(1.0, 1.0) 77 glEnd() 78 79 self.e.video.flip() 80 import time 81 time.sleep(2)
82
83 - def setUp(self):
84 self.e = GameEngine() 85 self.e.loadSvgDrawing(self, "svg", "koopa.svg") 86 87 while not self.svg: 88 self.e.run() 89 90 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
91 92 if __name__ == "__main__": 93 unittest.main() 94