MCPcopy Create free account
hub / github.com/aardappel/treesheets / AddGraphics

Function AddGraphics

lobster/src/graphics.cpp:142–1127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142void AddGraphics(NativeRegistry &nfr) {
143
144nfr("gl_window", "title,xs,ys,fullscreen,novsync,samples", "SIII?I?I?", "S?",
145 "opens a window for OpenGL rendering. returns error string if any problems, nil"
146 " otherwise.",
147 [](VM &vm, Value &title, Value &xs, Value &ys, Value &fullscreen, Value &novsync,
148 Value &samples) {
149 if (graphics_initialized)
150 vm.BuiltinError("cannot call gl_window() twice");
151 string err = SDLInit(title.sval()->strv(), int2(intp2(xs.ival(), ys.ival())),
152 fullscreen.ival() != 0, novsync.ival() == 0,
153 max(1, samples.intval()));
154 if (err.empty()) {
155 err = LoadMaterialFile("data/shaders/default.materials");
156 }
157 if (!err.empty()) {
158 LOG_INFO(err);
159 return Value(vm.NewString(err));
160 }
161 colorshader = LookupShader("color");
162 assert(colorshader);
163 LOG_INFO("graphics fully initialized...");
164 graphics_initialized = true;
165 return Value();
166 });
167
168nfr("gl_require_version", "major,minor", "II", "",
169 "Call this before gl_window to request a certain version of OpenGL context."
170 " Currently only works on win/nix, minimum is 3.2.",
171 [](VM &, Value &major, Value &minor) {
172 SDLRequireGLVersion(major.intval(), minor.intval());
173 return Value();
174 });
175
176nfr("gl_load_materials", "materialdefs,inline", "SI?", "S?",
177 "loads an additional materials file (data/shaders/default.materials is already loaded by default"
178 " by gl_window()). if inline is true, materialdefs is not a filename, but the actual"
179 " materials. returns error string if any problems, nil otherwise.",
180 [](VM &vm, Value &fn, Value &isinline) {
181 TestGL(vm);
182 auto err = isinline.True() ? ParseMaterialFile(fn.sval()->strv())
183 : LoadMaterialFile(fn.sval()->strv());
184 return err[0] ? Value(vm.NewString(err)) : Value();
185 });
186
187nfr("gl_frame", "", "", "B",
188 "advances rendering by one frame, swaps buffers, and collects new input events."
189 " returns true if the closebutton on the window was pressed",
190 [](VM &vm) {
191 TestGL(vm);
192 EngineSuspendIfNeeded();
193 auto cb = GraphicsFrameStart();
194 vm.vml.LogFrame();
195 return Value(!cb);
196 });
197
198nfr("gl_log_frame", "delta", "F", "",
199 "call this function instead of gl_frame() to simulate a frame based program from"

Callers

nothing calls this directly

Calls 15

SDLInitFunction · 0.85
maxFunction · 0.85
LoadMaterialFileFunction · 0.85
LookupShaderFunction · 0.85
SDLRequireGLVersionFunction · 0.85
TestGLFunction · 0.85
ParseMaterialFileFunction · 0.85
EngineSuspendIfNeededFunction · 0.85
GraphicsFrameStartFunction · 0.85
SDLUpdateTimeFunction · 0.85
GraphicsShutDownFunction · 0.85
SDLTitleFunction · 0.85

Tested by

no test coverage detected