Sign in to follow this  

pyopengl problems

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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()

Share this post


Link to post
Share on other sites

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this