Hey Nathan,
On my machine (a PowerBook G4) your circles game seems to have a
strange moire pattern inside of it. One thing you might want to take
a look at is trying a different blend source/destination/equation.
I cooked up an interesting example from the Beginning OpenGL book last
night which I was mentioning on the list in an earlier post. To
change the source/destination and equation just press 's', 'd' and 'e'
respectively while the program is running.
--Patrick.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
from pyglet.gl import *
from pyglet import window
from pyglet import clock
from pyglet.window import key
from pyglet import font
DISK_DEG_PER_S = 90.0
DISK_LIMIT = 3.0
m_diskPos = 0.0
m_diskRot = 0.0
m_pDisk = None
m_srcFactor = GL_SRC_ALPHA
m_dstFactor = GL_ONE_MINUS_SRC_ALPHA
m_blendEquation = GL_FUNC_ADD
myglBlendEquation = None
myglBlendColor = None
increment = 0.4
def Init():
global m_pDisk, myglBlendEquation, myglBlendColor
glEnable(GL_DEPTH_TEST)
m_pDisk = gluNewQuadric()
# XXX - is there a better way of doing this?
if 'glBlendEquationEXT' in globals():
myglBlendEquation = glBlendEquationEXT
if 'glBlendColorEXT' in globals():
myglBlendColor = glBlendColorEXT
myglBlendColor(0.5, 0.5, 0.5, 0.5)
def SetupProjection(width, height):
if not height:
height = 1
# set up the viewport
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(52.0, 1.0 * width / height, 1.0, 1000.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def Prepare(dt):
global increment, m_diskPos, m_diskRot
if dt > 1.0:
dt = 1.0
if m_diskPos > DISK_LIMIT or m_diskPos < -DISK_LIMIT:
increment *= -1.0
m_diskPos += increment * dt
m_diskRot += DISK_DEG_PER_S * dt
if m_diskRot > 360.0:
m_diskRot = 0.0
def Shutdown():
pass
def Render():
global m_srcFactor, m_dstFactor, m_blendEquation, myglBlendEquation
global m_diskPos, m_diskRot, m_pDisk
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
glLoadIdentity()
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
glBlendFunc(m_srcFactor, m_dstFactor)
if myglBlendEquation:
myglBlendEquation(m_blendEquation)
glColor4f(0.4, 0.8, 0.6, 0.7)
gluDisk(m_pDisk, 0.0, 4.0, 64, 16)
glEnable(GL_BLEND)
glTranslatef(0.0, m_diskPos, 2.0)
glRotatef(m_diskRot, 1.0, 0.0, 0.0)
glColor4f(0.7, 0.3, 0.5, 0.6)
gluDisk(m_pDisk, 0.5, 2.0, 32, 16)
glDisable(GL_BLEND)
def NextBlendEquation():
blendTable = {
GL_FUNC_ADD : GL_FUNC_SUBTRACT,
GL_FUNC_SUBTRACT : GL_FUNC_REVERSE_SUBTRACT,
GL_FUNC_REVERSE_SUBTRACT : GL_MIN,
GL_MIN : GL_MAX,
GL_MAX : GL_FUNC_ADD
}
global m_blendEquation
m_blendEquation = blendTable[m_blendEquation]
def NextSourceFactor():
sourceFactorTable = {
GL_ONE : GL_SRC_COLOR,
GL_SRC_ALPHA_SATURATE : GL_CONSTANT_COLOR,
GL_ONE_MINUS_CONSTANT_ALPHA : GL_ZERO
}
global m_srcFactor
if sourceFactorTable.has_key(m_srcFactor):
m_srcFactor = sourceFactorTable[m_srcFactor]
else:
m_srcFactor += 1
def NextDestFactor():
destFactorTable = {
GL_ONE : GL_SRC_COLOR,
GL_ONE_MINUS_DST_COLOR : GL_CONSTANT_COLOR,
GL_ONE_MINUS_CONSTANT_ALPHA : GL_ZERO,
}
global m_dstFactor
if destFactorTable.has_key(m_dstFactor):
m_dstFactor = destFactorTable[m_dstFactor]
else:
m_dstFactor += 1
def GetBlendEquation():
blendEquationTable = {
GL_FUNC_ADD : 'GL_FUNC_ADD',
GL_FUNC_SUBTRACT : 'GL_FUNC_SUBTRACT',
GL_FUNC_REVERSE_SUBTRACT : 'GL_FUNC_REVERSE_SUBTRACT',
GL_MIN : 'GL_MIN',
GL_MAX : 'GL_MAX',
}
global m_blendEquation
if blendEquationTable.has_key(m_blendEquation):
return blendEquationTable[m_blendEquation]
else:
return "Something's wrong here..."
def GetSourceFactor():
sourceFactorStringTable = {
GL_ZERO : 'GL_ZERO',
GL_ONE : 'GL_ONE',
GL_SRC_COLOR : 'GL_SRC_COLOR',
GL_ONE_MINUS_SRC_COLOR : 'GL_ONE_MINUS_SRC_COLOR',
GL_SRC_ALPHA : 'GL_SRC_ALPHA',
GL_ONE_MINUS_SRC_ALPHA : 'GL_ONE_MINUS_SRC_ALPHA',
GL_DST_ALPHA : 'GL_DST_ALPHA',
GL_ONE_MINUS_DST_ALPHA : 'GL_ONE_MINUS_DST_ALPHA',
GL_DST_COLOR : 'GL_DST_COLOR',
GL_ONE_MINUS_DST_COLOR : 'GL_ONE_MINUS_DST_COLOR',
GL_SRC_ALPHA_SATURATE : 'GL_SRC_ALPHA_SATURATE',
GL_CONSTANT_COLOR : 'GL_CONSTANT_COLOR',
GL_ONE_MINUS_CONSTANT_COLOR : 'GL_ONE_MINUS_CONSTANT_COLOR',
GL_CONSTANT_ALPHA : 'GL_CONSTANT_ALPHA',
GL_ONE_MINUS_CONSTANT_ALPHA : 'GL_ONE_MINUS_CONSTANT_ALPHA',
}
global m_srcFactor
if sourceFactorStringTable.has_key(m_srcFactor):
return sourceFactorStringTable[m_srcFactor]
else:
return "Something's wrong here..."
def GetDestFactor():
destFactorStringTable = {
GL_ZERO : 'GL_ZERO',
GL_ONE : 'GL_ONE',
GL_SRC_COLOR : 'GL_SRC_COLOR',
GL_ONE_MINUS_SRC_COLOR : 'GL_ONE_MINUS_SRC_COLOR',
GL_SRC_ALPHA : 'GL_SRC_ALPHA',
GL_ONE_MINUS_SRC_ALPHA : 'GL_ONE_MINUS_SRC_ALPHA',
GL_DST_ALPHA : 'GL_DST_ALPHA',
GL_ONE_MINUS_DST_ALPHA : 'GL_ONE_MINUS_DST_ALPHA',
GL_DST_COLOR : 'GL_DST_COLOR',
GL_ONE_MINUS_DST_COLOR : 'GL_ONE_MINUS_DST_COLOR',
GL_CONSTANT_COLOR : 'GL_CONSTANT_COLOR',
GL_ONE_MINUS_CONSTANT_COLOR : 'GL_ONE_MINUS_CONSTANT_COLOR',
GL_CONSTANT_ALPHA : 'GL_CONSTANT_ALPHA',
GL_ONE_MINUS_CONSTANT_ALPHA : 'GL_ONE_MINUS_CONSTANT_ALPHA',
}
global m_dstFactor
if destFactorStringTable.has_key(m_dstFactor):
return destFactorStringTable[m_dstFactor]
else:
return "Something's wrong here..."
def KeyboardHandler(symbol, modifiers):
if symbol == key.ESCAPE:
win.has_exit = True
elif symbol == key.S:
NextSourceFactor()
elif symbol == key.D:
NextDestFactor()
elif symbol == key.E:
NextBlendEquation()
def mode2d(width, height):
global myglBlendEquation
glLoadIdentity()
glPushAttrib(GL_ENABLE_BIT)
myglBlendEquation(GL_FUNC_ADD)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glDisable(GL_LIGHTING)
glDisable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(0, width, 0, height, -1, 1)
glMatrixMode(GL_MODELVIEW)
def mode3d():
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopAttrib()
def main():
global win
win = window.Window(width=800, height=600, visible=False)
win.on_resize = SetupProjection
win.on_key_press = KeyboardHandler
ft = font.load('Arial', 12)
srcText = font.Text(ft, x=5, y=60)
destText = font.Text(ft, x=5, y=40)
blendText = font.Text(ft, x=5, y=20)
Init()
win.set_visible()
while not win.has_exit:
win.dispatch_events()
tick = clock.tick()
Prepare(tick)
Render()
mode2d(win.width, win.height)
srcText.text = "Source: %s" % GetSourceFactor()
srcText.draw()
destText.text = "Destination: %s" % GetDestFactor()
destText.draw()
blendText.text = "Blend Equation: %s" % GetBlendEquation()
blendText.draw()
mode3d()
win.flip()
Shutdown()
if __name__ == '__main__':
main()