analitics

Pages

Friday, August 12, 2011

GLUT - Creating a fullscreen applications.

To create a fullscreen application must use the function:
glutGameModeString()
glutEnterGameMode()

Below is the source commented.
import sys
from OpenGL.GL import *
from OpenGL.GLUT import *

def main():
 
    # Initialize OpenGL
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
 
    # Configure the display output
    glutGameModeString("1024x600:32@60")

    # The application will enter fullscreen
    glutEnterGameMode()
 
    # Setup callbacks for keyboard and display
    glutKeyboardFunc(keyboard)
    glutDisplayFunc(display)
 
    # Enters the GLUT event processing loop
    glutMainLoop()
 
def keyboard(key, x, y):
    if key == 'q':
        sys.exit(0)

def display():
    glClear(GL_COLOR_BUFFER_BIT)

    # Draw a green line
    glBegin(GL_LINES)
    glColor3f(0.0,100.0,0.0)
    glVertex2f(1.0, 1.0)
    glVertex2f(-1.0, -1.0)
    glEnd()
 
    glutSwapBuffers()
 
if __name__ == "__main__":
    main()

Thursday, August 11, 2011

How to make working pygtk with python 2.7

As you know, PyGTK is a module that allows us to use the GTK interface.
A good start to use this module:
Articles
I do not know if I presented this module on the site, but now I will try to present it.
First, as it says on the official site:
"PyGTK lets you easily create applications with a graphical user interface Using the Python programming language."
The second time is easy to use because we can easily create interfaces using Glade.
Glade is a RAD tool.
This development tool to let us create user interfaces for the GTK + toolkit and the GNOME desktop environment.
The output is an xml file which is then used by PyGTK.
Read more on the official site: Glade RAD tool.
The tricky part is connecting with the python source code from the XML components.
You can download it here and install version 2.22 on Windows from here.
I use pygtk-all-in-one-2.22.6.win32-py2.7.msi to test pygtk.
Also, you need GTK 2.22 from here.
How to make working Python 2.7 with GTK?
Just right-click on My Computer, then select Properties.
Click the Advanced tab in the dialog that pops up, and click the Environment Variables button near the bottom.
Under System variables, click the New button and enter GTK_BASEPATH.
Now under variable named Path, and click the Edit button and add GTK_BASEPATH\bin;.
Click the OK buttons restart Windows XP.
Now it is working fine with Python 2.7.
Let's try this script:
#!/usr/bin/env python
import sys

try:
    import pygtk
    pygtk.require("2.0")
    print "pygtk 2.0 ok!"
except:
    print "pygtk 2.0 BAD!"
    pass
    
try:
    import gtk
    print "gtk ok!"
except:
    print "gtk BAD!"
    pass