By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,399 Members | 886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,399 IT Pros & Developers. It's quick & easy.

pyopengl help

P: 1
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
Share this question for a faster answer!
Share on Google+

Post your reply

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