gnome-games r8335 - in trunk/glchess: data glade src/lib src/lib/gtkui src/lib/scene src/lib/scene/opengl src/lib/ui
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8335 - in trunk/glchess: data glade src/lib src/lib/gtkui src/lib/scene src/lib/scene/opengl src/lib/ui
- Date: Thu, 27 Nov 2008 10:46:30 +0000 (UTC)
Author: rancell
Date: Thu Nov 27 10:46:30 2008
New Revision: 8335
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8335&view=rev
Log:
Added anti-aliasing support (Bug #445711)
Modified:
trunk/glchess/data/glchess.schemas.in
trunk/glchess/glade/preferences.glade
trunk/glchess/src/lib/config.py
trunk/glchess/src/lib/display.py
trunk/glchess/src/lib/gtkui/chessview.py
trunk/glchess/src/lib/gtkui/dialogs.py
trunk/glchess/src/lib/gtkui/gtkui.py
trunk/glchess/src/lib/scene/__init__.py
trunk/glchess/src/lib/scene/opengl/opengl.py
trunk/glchess/src/lib/ui/ui.py
Modified: trunk/glchess/data/glchess.schemas.in
==============================================================================
--- trunk/glchess/data/glchess.schemas.in (original)
+++ trunk/glchess/data/glchess.schemas.in Thu Nov 27 10:46:30 2008
@@ -86,6 +86,18 @@
</schema>
<schema>
+ <key>/schemas/apps/glchess/show_3d_smooth</key>
+ <applyto>/apps/glchess/show_3d_smooth</applyto>
+ <owner>glchess</owner>
+ <type>bool</type>
+ <default>FALSE</default>
+ <locale name="C">
+ <short>A flag to smooth (anti-alias) the 3D display</short>
+ <long>A flag to smooth (anti-alias) the 3D display</long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/glchess/show_move_hints</key>
<applyto>/apps/glchess/show_move_hints</applyto>
<owner>glchess</owner>
Modified: trunk/glchess/glade/preferences.glade
==============================================================================
--- trunk/glchess/glade/preferences.glade (original)
+++ trunk/glchess/glade/preferences.glade Thu Nov 27 10:46:30 2008
@@ -2,6 +2,7 @@
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
+<requires lib="gnome"/>
<widget class="GtkDialog" id="preferences">
<property name="title" translatable="yes" comments="Title for preferences dialog">Preferences</property>
@@ -268,6 +269,66 @@
</child>
<child>
+ <widget class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkLabel" id="label6">
+ <property name="visible">True</property>
+ <property name="label"> </property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkCheckButton" id="show_3d_smooth">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="tooltip" translatable="yes" comments="Preferences Dialog: Tooltip for 3D Chess smooth view option">Smooth edges of the 3D elements (anti-alias)</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes" comments="Preferences Dialog: Check box for selecting if the 3D view is smoothed (anti-aliased)">_Smooth Display</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="active">False</property>
+ <property name="inconsistent">False</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="_on_3d_smooth_toggled" last_modification_time="Thu, 27 Nov 2008 09:51:48 GMT"/>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
<widget class="GtkCheckButton" id="show_toolbar">
<property name="visible">True</property>
<property name="tooltip" translatable="yes" comments="Preferences Dialog: Tooltip for Show Toolbar option">Show or hide the toolbar</property>
Modified: trunk/glchess/src/lib/config.py
==============================================================================
--- trunk/glchess/src/lib/config.py (original)
+++ trunk/glchess/src/lib/config.py Thu Nov 27 10:46:30 2008
@@ -75,6 +75,7 @@
'maximised': False,
'fullscreen': False,
'show_3d': False,
+ 'show_3d_smooth': False,
'show_move_hints': True,
'move_format': 'human',
'promotion_type': 'queen',
Modified: trunk/glchess/src/lib/display.py
==============================================================================
--- trunk/glchess/src/lib/display.py (original)
+++ trunk/glchess/src/lib/display.py Thu Nov 27 10:46:30 2008
@@ -277,7 +277,7 @@
"""Called by scene.SceneFeedback"""
if self.controller is not None:
self.controller.render()
-
+
def showBoardNumbering(self, showNumbering):
"""Called by ui.ViewFeedback"""
self.scene.showBoardNumbering(showNumbering)
@@ -345,6 +345,7 @@
self.selectedCoord = None
self.showHints = False
self.showNumbering = False
+ self.doSmooth = False
self.highlightParams = (None, None, None, None)
self.changedHighlight = True
@@ -455,6 +456,11 @@
"""Called by ui.ViewFeedback"""
self.showNumbering = showNumbering
self.scene.controller.showBoardNumbering(showNumbering)
+
+ def showSmooth(self, doSmooth):
+ """Called by ui.ViewFeedback"""
+ self.doSmooth = doSmooth
+ self.scene.controller.showSmooth(doSmooth)
def updateScene(self, sceneClass):
"""
@@ -470,6 +476,7 @@
self.reshape(self.width, self.height)
self.setMoveNumber(self.moveNumber)
self.showBoardNumbering(self.showNumbering)
+ self.showSmooth(self.doSmooth)
self.updateRotation(animate = False)
def renderGL(self):
Modified: trunk/glchess/src/lib/gtkui/chessview.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/chessview.py (original)
+++ trunk/glchess/src/lib/gtkui/chessview.py Thu Nov 27 10:46:30 2008
@@ -12,6 +12,8 @@
# Optionally use OpenGL support
openGLErrors = []
+haveGLDepthSupport = True
+haveGLAccumSupport = True
try:
import OpenGL.GL
except:
@@ -24,11 +26,14 @@
# Translators: Error message displayed when 3D mode is not available due to no Python GTKGLExt libraries
openGLErrors.append(_('No Python GTKGLExt support'))
else:
- display_mode = (gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DEPTH | gtk.gdkgl.MODE_DOUBLE)
+ display_mode = (gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DEPTH | gtk.gdkgl.MODE_DOUBLE | gtk.gdkgl.MODE_ACCUM)
try:
glConfig = gtk.gdkgl.Config(mode = display_mode)
except gtk.gdkgl.NoMatches:
display_mode &= ~gtk.gdkgl.MODE_DOUBLE
+ display_mode &= ~gtk.gdkgl.MODE_ACCUM
+ haveGLAccumSupport = False
+ haveGLDepthSupport = False
try:
glConfig = gtk.gdkgl.Config(mode = display_mode)
except gtk.gdkgl.NoMatches:
Modified: trunk/glchess/src/lib/gtkui/dialogs.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/dialogs.py (original)
+++ trunk/glchess/src/lib/gtkui/dialogs.py Thu Nov 27 10:46:30 2008
@@ -630,7 +630,7 @@
promotionModel.set(iter, 0, label, 1, key)
# Watch for config changes
- for key in ['show_3d', 'show_toolbar', 'show_history',
+ for key in ['show_3d', 'show_3d_smooth', 'show_toolbar', 'show_history',
'show_move_hints', 'show_numbering',
'move_format', 'board_view', 'promotion_type']:
glchess.config.watch(key, self.__applyConfig)
@@ -646,7 +646,11 @@
"""
if name == 'show_3d':
self.__gui.get_widget('show_3d').set_active(value)
+ self.__gui.get_widget('show_3d_smooth').set_sensitive(value)
+ elif name == 'show_3d_smooth':
+ self.__gui.get_widget('show_3d_smooth').set_active(value)
+
elif name == 'show_toolbar':
self.__gui.get_widget('show_toolbar').set_active(value)
@@ -729,6 +733,10 @@
def _on_3d_view_activate(self, widget):
"""Gtk+ callback"""
glchess.config.set('show_3d', widget.get_active())
+
+ def _on_3d_smooth_toggled(self, widget):
+ """Gtk+ callback"""
+ glchess.config.set('show_3d_smooth', widget.get_active())
def _on_show_toolbar_activate(self, widget):
"""Gtk+ callback"""
Modified: trunk/glchess/src/lib/gtkui/gtkui.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/gtkui.py (original)
+++ trunk/glchess/src/lib/gtkui/gtkui.py Thu Nov 27 10:46:30 2008
@@ -259,7 +259,7 @@
# Watch for config changes
for key in ['show_toolbar', 'show_history', 'fullscreen',
- 'show_3d', 'show_comments', 'show_numbering',
+ 'show_3d', 'show_3d_smooth', 'show_comments', 'show_numbering',
'show_move_hints',
'width', 'height',
'move_format', 'promotion_type', 'board_view',
@@ -406,7 +406,7 @@
This method will not return.
"""
# Load configuration
- for name in ['show_toolbar', 'show_history', 'show_3d',
+ for name in ['show_toolbar', 'show_history', 'show_3d', 'show_3d_smooth',
'show_comments', 'show_numbering', 'show_move_hints',
'move_format', 'promotion_type', 'board_view', 'maximised',
'enable_networking']:
@@ -603,6 +603,11 @@
self.__renderGL = value
self.__getWidget('menu_view_3d').set_active(value)
self.view.viewWidget.setRenderGL(value)
+
+ elif name == 'show_3d_smooth':
+ if not chessview.haveGLAccumSupport:
+ value = False
+ self.view.feedback.showSmooth(value)
elif name == 'show_comments':
self.view.setShowComments(value)
Modified: trunk/glchess/src/lib/scene/__init__.py
==============================================================================
--- trunk/glchess/src/lib/scene/__init__.py (original)
+++ trunk/glchess/src/lib/scene/__init__.py Thu Nov 27 10:46:30 2008
@@ -105,6 +105,9 @@
"""
pass
+ def showSmooth(self, doNumbering):
+ pass
+
def showBoardNumbering(self, showNumbering):
"""
"""
Modified: trunk/glchess/src/lib/scene/opengl/opengl.py
==============================================================================
--- trunk/glchess/src/lib/scene/opengl/opengl.py (original)
+++ trunk/glchess/src/lib/scene/opengl/opengl.py Thu Nov 27 10:46:30 2008
@@ -47,6 +47,34 @@
glchess.scene.HIGHLIGHT_THREATENED: (1.0, 0.8, 0.8),
glchess.scene.HIGHLIGHT_CAN_TAKE: (1.0, 0.2, 0.2)}
+import math
+def accFrustum(left, right, bottom, top,
+ near, far,
+ pixdx, pixdy,
+ eyedx, eyedy,
+ focus):
+ viewport = glGetIntegerv(GL_VIEWPORT)
+
+ xwsize = right - left
+ ywsize = top - bottom
+ dx = -(pixdx*xwsize/viewport[2] + eyedx*near/focus)
+ dy = -(pixdy*ywsize/viewport[3] + eyedy*near/focus)
+
+ glFrustum(left + dx, right + dx, bottom + dy, top + dy, near, far)
+ glTranslatef(-eyedx, -eyedy, 0.0)
+
+def accPerspective(fovy, aspect,
+ near, far,
+ pixdx, pixdy,
+ eyedx, eyedy,
+ focus):
+ fov2 = ((fovy*math.pi) / 180.0) / 2.0
+ top = near / (math.cos(fov2) / math.sin(fov2))
+ bottom = -top
+ right = top * aspect
+ left = -right
+ accFrustum(left, right, bottom, top, near, far, pixdx, pixdy, eyedx, eyedy, focus)
+
class ChessPiece(glchess.scene.ChessPiece):
"""
"""
@@ -189,6 +217,8 @@
highlights = None
_animationQueue = []
+
+ jitters = ((0.0, 0.0),)
showNumbering = False
numberingTexture = None
@@ -254,7 +284,16 @@
"""Extends glchess.scene.Scene"""
self.showNumbering = showNumbering
self.feedback.onRedraw()
-
+
+ def showSmooth(self, doSmooth):
+ if doSmooth:
+ #self.jitters = ((-0.25, 0.25), (0.25, -0.25))
+ self.jitters = ((0.0033922635, 0.3317967229), (0.2806016275, -0.2495619123), (-0.273817106, -0.086844639))
+ #self.jitters = ((-0.175, -0.25), (-0.375, 0.25), (0.375, -0.25), (0.125, 0.25))
+ else:
+ self.jitters = ((0.0, 0.0),)
+ self.feedback.onRedraw()
+
def reshape(self, width, height):
"""Resize the viewport into the scene.
@@ -264,6 +303,7 @@
self.viewportWidth = int(width)
self.viewportHeight = int(height)
self.viewportAspect = float(self.viewportWidth) / float(self.viewportHeight)
+ glViewport(0, 0, self.viewportWidth, self.viewportHeight)
self.feedback.onRedraw()
def setBoardRotation(self, angle, animate = True):
@@ -300,46 +340,61 @@
This requires an OpenGL context.
"""
glClearColor(*BACKGROUND_COLOUR)
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
-
- # Set the projection for this scene
- self.setViewport()
-
- # Do camera and board rotation/translation
- glEnable(GL_DEPTH_TEST)
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- self.transformCamera()
+ if len(self.jitters) > 1:
+ glClear(GL_ACCUM_BUFFER_BIT)
glLightfv(GL_LIGHT0, GL_AMBIENT, LIGHT_AMBIENT_COLOUR)
glLightfv(GL_LIGHT0, GL_DIFFUSE, LIGHT_DIFFUSE_COLOUR)
glLightfv(GL_LIGHT0, GL_SPECULAR, LIGHT_SPECULAR_COLOUR)
- glLightfv(GL_LIGHT0, GL_POSITION, self.lightPos)
- glEnable(GL_LIGHTING)
- glEnable(GL_LIGHT0)
- self.transformBoard()
-
- glEnable(GL_DEPTH_TEST)
- glEnable(GL_CULL_FACE)
+ for jitter in self.jitters:
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
+
+ # Set the projection for this scene
+ glMatrixMode(GL_PROJECTION)
+ glLoadIdentity()
+ if len(self.jitters) > 1:
+ accPerspective(60.0, self.viewportAspect, 0.1, 1000, jitter[0], jitter[1], 0, 0, 1)
+ else:
+ gluPerspective(60.0, self.viewportAspect, 0.1, 1000)
+
+ # Do camera and board rotation/translation
+ glMatrixMode(GL_MODELVIEW)
+ glLoadIdentity()
+ self.transformCamera()
+
+ glLightfv(GL_LIGHT0, GL_POSITION, self.lightPos)
+ glEnable(GL_LIGHTING)
+ glEnable(GL_LIGHT0)
+
+ self.transformBoard()
+
+ glEnable(GL_DEPTH_TEST)
+ glEnable(GL_CULL_FACE)
- glEnable(GL_TEXTURE_2D)
- glEnable(GL_COLOR_MATERIAL)
- self.drawBoard()
- glDisable(GL_COLOR_MATERIAL)
- glDisable(GL_TEXTURE_2D)
+ glEnable(GL_TEXTURE_2D)
+ glEnable(GL_COLOR_MATERIAL)
+ self.drawBoard()
+ glDisable(GL_COLOR_MATERIAL)
+ glDisable(GL_TEXTURE_2D)
- if self.showNumbering:
- self.drawNumbering()
+ if self.showNumbering:
+ self.drawNumbering()
- # WORKAROUND: Mesa is corrupting polygons on the bottom of the models
- # It could be because the depth buffer has a low bit depth?
- glClear(GL_DEPTH_BUFFER_BIT)
+ # WORKAROUND: Mesa is corrupting polygons on the bottom of the models
+ # It could be because the depth buffer has a low bit depth?
+ glClear(GL_DEPTH_BUFFER_BIT)
- if self.throbberEnabled:
- self.drawThrobber()
- else:
- self.drawPieces()
+ if self.throbberEnabled:
+ self.drawThrobber()
+ else:
+ self.drawPieces()
+
+ if len(self.jitters) > 1:
+ glAccum(GL_ACCUM, 1.0 / len(self.jitters))
+
+ if len(self.jitters) > 1:
+ glAccum(GL_RETURN, 1)
def getSquare(self, x, y):
"""Find the chess square at a given 2D location.
@@ -360,7 +415,7 @@
glRenderMode(GL_SELECT)
glInitNames()
-
+
# Create pixel picking region near cursor location
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
@@ -565,13 +620,6 @@
glDisable(GL_BLEND)
- def setViewport(self):
- """Perform the projection matrix transformation for the current viewport"""
- glViewport(0, 0, self.viewportWidth, self.viewportHeight)
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- gluPerspective(60.0, self.viewportAspect, 0.1, 1000)
-
def transformCamera(self):
"""Perform the camera matrix transformation"""
gluLookAt(0.0, 90.0, 45.0,
Modified: trunk/glchess/src/lib/ui/ui.py
==============================================================================
--- trunk/glchess/src/lib/ui/ui.py (original)
+++ trunk/glchess/src/lib/ui/ui.py Thu Nov 27 10:46:30 2008
@@ -126,6 +126,9 @@
'showHints' sets if move hints should be shown (boolean).
"""
assert(False)
+
+ def showSmooth(self, doNumbering):
+ pass
def saveGame(self, path):
"""Called when the user requests the game in this view to be saved.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]