jonwright / pyopengltk

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

cannot import name 'OpenGLFrame' from 'pyopengltk' | MacOS | #12

Open ajh123 opened 4 years ago

ajh123 commented 4 years ago

@jonwright , @einarf Im running Python 3.7.3 on macOS Catalina, I tried to import the OpenGLFrame like this

from OpenGL import GL
from pyopengltk import OpenGLFrame

Which resulted in this error cannot import name 'OpenGLFrame' from 'pyopengltk'

Edit: after that i tried to make a frame like this

class AppOgl(OpenGLFrame):

    def initgl(self):
        """Initalize gl states when the frame is created"""
        GL.glViewport(0, 0, self.width, self.height)
        GL.glClearColor(0.0, 1.0, 0.0, 0.0)    
        self.start = time.time()
        self.nframes = 0

    def redraw(self):
        """Render a single frame"""
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)
        tm = time.time() - self.start
        self.nframes += 1
        print("fps",self.nframes / tm, end="\r" )

if __name__ == '__main__':
    root = tkinter.Tk()
    app = AppOgl(root, width=320, height=200)
    app.pack(fill=tkinter.BOTH, expand=tkinter.YES)
    app.animate = 1
    app.after(100, app.printContext)
    app.mainloop()

Edit 2 : Which still resulted in this error cannot import name 'OpenGLFrame' from 'pyopengltk'

Edit 3: I used pip to install this

einarf commented 4 years ago

Yep. There is still work ongoing to support OS X for the tk window. I think the version I tried to make was using CGL, but I think I'll have to try again using AGL: https://github.com/jonwright/pyopengltk/pull/11

Do feel free to give it a go yourself if you need OS X support. A lot can for example be learned from looking at how pyglet uses AGL when creating OS X context.