jonwright / pyopengltk

OpenGL frame for Python/Tkinter via ctypes and pyopengl
MIT License
52 stars 14 forks source link

Inherit GLU #26

Closed ShaunKulesa closed 3 years ago

ShaunKulesa commented 3 years ago

Hello, its me again from last year. I was wondering how to inherit GLU in a function I have in the OpenGLFrame class. I keep getting the error

GLU.gluPerspective(45, (self.width/self.height), 0.1, 50.0)
NameError: name 'GLU' is not defined

This is my code:

class AppOgl(OpenGLFrame):

    def initgl(self):
        GL.glLoadIdentity()
        GLU.gluPerspective(45, (self.width/self.height), 0.1, 50.0)
        GL.glTranslatef(0.0,0.0, -5)

    def redraw(self):
        GL.glRotatef(1, 3, 1, 1)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT)
        Cube()

    global view
    view = 0
    def mouse_wheel(event):
        global view
        if event.num == 5 or event.delta == -120:
            view += -1
            GLU.gluPerspective(45, (self.width/self.height), 0.1, 50.0)
            print(view)
        if event.num == 4 or event.delta == 120:
            view += 1
            GLU.gluPerspective(45, (self.width/self.height), 0.1, 50.0)
            print(view)
einarf commented 3 years ago

You just need to import GLU

from OpenGL import GL, GLU
ShaunKulesa commented 3 years ago

Lol! Silly me. Thanks.

ShaunKulesa commented 3 years ago

I just noticed it runs GLU.gluPerspective(45, (self.width/self.height), 0.1, 50.0)

without me even using the bind to run the event. app.bind("<MouseWheel>", AppOgl.mouse_wheel)

I took out app.bind("<MouseWheel>", AppOgl.mouse_wheel) and it still changes the perspective.

edit: i left it in the initgl