~ubuntu-branches/ubuntu/precise/fofix-dfsg/precise

« back to all changes in this revision

Viewing changes to src/SvgTest.py

  • Committer: Bazaar Package Importer
  • Author(s): Christian Hammers
  • Date: 2010-02-21 12:09:32 UTC
  • Revision ID: james.westby@ubuntu.com-20100221120932-6bh992d2u8dtj9gr
Tags: upstream-3.121
Import upstream version 3.121

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
import Config
 
27
import Version
 
28
from OpenGL.GL import *
 
29
from OpenGL.GLU import *
 
30
 
 
31
class SvgTest(unittest.TestCase):
 
32
  def testRendering(self):
 
33
    self.svg.transform.translate(256, 256)
 
34
    self.svg.transform.rotate(3.141592)
 
35
    self.svg.draw()
 
36
    self.e.video.flip()
 
37
 
 
38
  def testRenderToTexture(self):
 
39
    scale = 4
 
40
    fullwidth, fullheight = 512, 512
 
41
    width, height = int(fullwidth / scale), int(fullheight / scale)
 
42
    t = Texture()
 
43
    self.e.svg.setProjection((0, 0, fullwidth, fullheight))
 
44
    
 
45
    glViewport(0, 0, width, height)
 
46
    glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
 
47
    self.svg.transform.translate(width * scale / 2, height * scale / 2)
 
48
    self.svg.transform.rotate(3.141592)
 
49
    self.svg.draw()
 
50
 
 
51
    glViewport(0, 0, fullwidth, fullheight)
 
52
    glMatrixMode(GL_PROJECTION)
 
53
    glLoadIdentity()
 
54
    gluOrtho2D(0.0, 1.0, 0.0, 1.0)
 
55
    glMatrixMode(GL_MODELVIEW)
 
56
    glLoadIdentity()
 
57
 
 
58
    t.bind()
 
59
    glEnable(GL_TEXTURE_2D)
 
60
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
 
61
 
 
62
    glClear(GL_COLOR_BUFFER_BIT)
 
63
    glColor3f(1.0, 1.0, 1.0)
 
64
    glBegin(GL_TRIANGLE_STRIP)
 
65
    glTexCoord2f(0.0, 0.0)
 
66
    glVertex2f(0.0, 0.0)
 
67
    glTexCoord2f(1.0, 0.0)
 
68
    glVertex2f(1.0, 0.0)
 
69
    glTexCoord2f(0.0, 1.0)
 
70
    glVertex2f(0.0, 1.0)
 
71
    glTexCoord2f(1.0, 1.0)
 
72
    glVertex2f(1.0, 1.0)
 
73
    glEnd()
 
74
 
 
75
    self.e.video.flip()
 
76
    import time
 
77
    time.sleep(2)
 
78
 
 
79
  def setUp(self):
 
80
    config = Config.load(Version.appName() + ".ini", setAsDefault = True)
 
81
    self.e = GameEngine(config)
 
82
    self.e.loadImgDrawing(self, "svg", "mfhlogo.png")
 
83
 
 
84
    while not self.svg:
 
85
      self.e.run()
 
86
 
 
87
    glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
 
88
 
 
89
if __name__ == "__main__":
 
90
  unittest.main()