-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkinterwithopengl.py
More file actions
30 lines (24 loc) · 880 Bytes
/
tkinterwithopengl.py
File metadata and controls
30 lines (24 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time
import tkinter
from OpenGL import GL
from pyopengltk import OpenGLFrame
class AppOgl(OpenGLFrame):
def initgl(self):
"""Initialize GL states when the frame is created."""
GL.glViewport(0, 0, self.width, self.height)
GL.glClearColor(0.2, 1.0, 0.2, 0.0) # Green background
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 # Enable animation loop
app.after(100, app.printContext) # Optional: Print GL context info
app.mainloop()