Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 104 lines (65 sloc) 2.011 kb
9b10489 William Adams Adding Khronos interfaces
authored
1 package.path = package.path..";..\\?.lua;..\\Win32\\?.lua";
2
3 local ffi = require "ffi"
4 local bit = require "bit"
5 local bor = bit.bor
6
7 local NativeWindow = require "User32Window"
8 local EGL = require "egl_utils"
9
10 local OpenVG = require "OpenVG"
11 local OpenVGUtils = require "OpenVG_Utils"
12 local ogm = require "OglMan"
13 local RenderClass = require"Drawing"
14
15
16
17
18 local dpy = EglDisplay.new(nil, EGL.EGL_OPENVG_API);
19 assert(dpy, "EglDisplay not created");
20
21 local screenWidth = 640;
22 local screenHeight = 480;
23
24
25
26 local Renderer = RenderClass.new(dpy, screenWidth, screenHeight);
27
28
29
30 local drawLines = function()
31 Renderer:StrokeWidth(1);
32 Renderer:SetStroke(250,250,250,1);
33 Renderer:Line(1,1, screenWidth/2, screenHeight/2);
34
35 end
36
37 local drawRectangles = function()
38 Renderer:Fill(230, 23, 23, 1);
39 Renderer:Rect(10,10,100,100);
40 end
41
42 local drawEllipses = function()
43 Renderer:PushTransform();
44
45 Renderer:Translate(screenWidth/2, screenHeight/2);
46 Renderer:Fill(44, 77, 232, 1); -- Big blue marble
47 Renderer:Circle(0, 0, screenHeight/2); -- The "world"
48 Renderer:Fill(255, 255, 255, 1); -- White text
49
50 Renderer:PopTransform();
51 end
52
53 local tick = function(ticker, tickCount)
54 print("Tick: ", tickCount);
55
56 Renderer:Begin();
57
58 Renderer:Background(0, 0, 0); -- Black background
59
60 drawEllipses();
61 drawRectangles();
62 drawLines();
63
64 Renderer:End();
65 end
66
67
68
69 -- Create a window
70 local winParams = {
71 ClassName = "EGLWindow",
72 Title = "EGL Window",
73 Origin = {10,10},
74 Extent = {screenWidth, screenHeight},
75 FrameRate = 3,
76
77 OnTickDelegate = tick;
78 };
79
80
81 -- create an EGL window surface
82 local win = NativeWindow.new(winParams)
83 assert(win, "Window not created");
84
85 local surf = dpy:CreateWindowSurface(win:GetHandle())
86
87 -- Make the context current
88 dpy:MakeCurrent();
89
90 glViewport(0,0,screenWidth,screenHeight);
91 glMatrixMode(GL_PROJECTION);
92 glLoadIdentity();
93
94 local ratio = screenWidth/screenHeight;
95 glFrustum(-ratio, ratio, -1, 1, 1, 10);
96
97
98 -- Now, finally do some drawing
99 win:Run();
100
101
102 -- free up the display
103 dpy:free();
Something went wrong with that request. Please try again.