Skip to content

Commit 6ebfa48

Browse files
committed
From co-pilot
1 parent 74dd8be commit 6ebfa48

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

skia_opengl_rotating_rect.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import glfw
2+
import skia
3+
import time
4+
import math
5+
6+
# Initialize GLFW and create window
7+
if not glfw.init():
8+
raise RuntimeError("Failed to initialize GLFW")
9+
glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_API)
10+
window = glfw.create_window(640, 480, "Skia + OpenGL Example", None, None)
11+
if not window:
12+
glfw.terminate()
13+
raise RuntimeError("Failed to create window")
14+
glfw.make_context_current(window)
15+
16+
# Create Skia GPU context (OpenGL)
17+
context = skia.GrDirectContext.MakeGL()
18+
surface = skia.Surface.MakeRenderTarget(
19+
context,
20+
skia.Budgeted.kNo,
21+
skia.ImageInfo.Make(640, 480, skia.ColorType.kRGBA_8888_ColorType, skia.AlphaType.kPremul_AlphaType),
22+
0,
23+
skia.SurfaceProps()
24+
)
25+
26+
angle = 0.0
27+
while not glfw.window_should_close(window):
28+
glfw.poll_events()
29+
canvas = surface.getCanvas()
30+
canvas.clear(skia.ColorWHITE)
31+
32+
# Draw rotating rectangle
33+
paint = skia.Paint(Color=skia.ColorBLUE)
34+
canvas.save()
35+
canvas.translate(320, 240)
36+
canvas.rotate(angle)
37+
canvas.drawRect(skia.Rect.MakeLTRB(-100, -50, 100, 50), paint)
38+
canvas.restore()
39+
40+
surface.flushAndSubmit()
41+
glfw.swap_buffers(window)
42+
angle += 1.0
43+
time.sleep(1/60)
44+
45+
glfw.destroy_window(window)
46+
glfw.terminate()

0 commit comments

Comments
 (0)