471,354 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

pyopengl help

hi everyone,
i'm not sure if this is the best place for this post, but since i'm a novice at pyopengl, i thought this might be the place. i have this piece of code which is giving some errors and would like some feedback as to why this is so.
using pyopengl. i have a simple list and would like with my mousebutton select the one of the items from the list when the button is pressed. any help on this would be great.

thank you in advance...

import sys, math, time, string
from OpenGL.GLUT import *
from OpenGL.GL import *
from OpenGL.GLU import *
import random

letters = ['hello', 'no', 'yes']
print letters

def drawStrokeString(text, font=GLUT_STROKE_ROMAN):
for c in text:
glutStrokeCharacter(font, ord(c))

def draw():
glClear(GL_COLOR_BUFFER_BIT)
for a in letters:
glPushMatrix()
glTranslatef(a[3], a[3], 3)
glColor3fv(a[2])
glScalef(0.005, 0.005, 0.005)
drawStrokeString(a, GLUT_STROKE_MONO_ROMAN)
glPopMatrix()
glutSwapBuffers()


def reshape(width, height):
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0, width, 0, height)
glMatrixMode(GL_MODELVIEW)

def keyboard(key,x,y):
if key == chr(27):
sys.exit(0)

def mousebutton(button, state, x, y):
print button, state
if button == GLUT_LEFT_BUTTON and state == GLUT_DOWN:
letters.append([ x,glutGet(GLUT_WINDOW_HEIGHT)-y, [1,0,0] ])
elif button == GLUT_MIDDLE_BUTTON:
letters.append([ x,glutGet(GLUT_WINDOW_HEIGHT)-y, [0,1,0] ])
elif button == GLUT_RIGHT_BUTTON:
letters.append([ x,glutGet(GLUT_WINDOW_HEIGHT)-y, [0,0,1] ])
glutPostRedisplay()


glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(400, 400)
glutCreateWindow(sys.argv[0])
glutDisplayFunc(draw)
glutKeyboardFunc(keyboard)
glutMouseFunc(mousebutton)
glutReshapeFunc(reshape)
reshape(400,400)
glutMainLoop()
Dec 5 '07 #1
0 1104

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Timo Finnilä | last post: by
2 posts views Thread by Erik Max Francis | last post: by
5 posts views Thread by Sébastien Ramage | last post: by
1 post views Thread by joroy | last post: by
reply views Thread by sweetmelon | last post: by
reply views Thread by shirish | last post: by
2 posts views Thread by seb.haase | last post: by
reply views Thread by Colin J. Williams | last post: by
1 post views Thread by Clay Hobbs | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.