[cogl/wip/lionel/introspection: 5/6] examples: add gjs example
- From: Lionel Landwerlin <llandwerlin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/lionel/introspection: 5/6] examples: add gjs example
- Date: Mon, 24 Feb 2014 00:04:25 +0000 (UTC)
commit f48a4e3948697bfb15e5f6054dc654c7ee6b9216
Author: Lionel Landwerlin <llandwerlin gmail com>
Date: Sun Feb 23 22:56:02 2014 +0000
examples: add gjs example
examples/Makefile.am | 1 +
examples/cogl-gjs.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 5fd9232..794949d 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -120,6 +120,7 @@ noinst_PROGRAMS = $(programs)
endif
EXTRA_DIST = \
+ cogl-gjs.js \
crate.jpg \
emscripten-example-js.h \
emscripten-example-js-library.js \
diff --git a/examples/cogl-gjs.js b/examples/cogl-gjs.js
new file mode 100644
index 0000000..d67b418
--- /dev/null
+++ b/examples/cogl-gjs.js
@@ -0,0 +1,46 @@
+const Cogl = imports.gi.Cogl;
+const GLib = imports.gi.GLib;
+const Lang = imports.lang;
+
+let renderer = new Cogl.Renderer();
+let display = new Cogl.Display(renderer, new Cogl.OnscreenTemplate());
+let ctx = new Cogl.Context(display);
+
+// Should be able to replace the 3 previous lines with :
+// let ctx = new Cogl.Context(null);
+// But crashing for some reason.
+
+// GLib mainloop integration
+let gsource = Cogl.glib_renderer_source_new(renderer, 0);
+let loop = GLib.MainLoop.new(null, false);
+gsource.attach(loop.get_context());
+
+// Onscreen creation
+let onscreen = new Cogl.Onscreen(ctx, 800, 600);
+onscreen.show();
+
+// Drawing pipeline
+let crate = Cogl.Texture2D.new_from_file(ctx, 'crate.jpg');
+let pipeline = new Cogl.Pipeline(ctx);
+pipeline.set_layer_texture(0, crate);
+let clearColor = new Cogl.Color();
+clearColor.init_from_4f(0, 0, 0, 1.0);
+
+// Redraw callback
+let closure = onscreen.add_dirty_callback(Lang.bind(this, function() {
+ onscreen.clear(Cogl.BufferBit.COLOR, clearColor);
+ onscreen.draw_rectangle(pipeline, -1, -1, 1, 1);
+ onscreen.swap_buffers();
+ return true;
+}), null);
+
+// Quit after 5s
+let tm = GLib.timeout_source_new(5000);
+tm.set_callback(Lang.bind(this, function() {
+ loop.quit();
+ return false;
+}), null);
+tm.attach(loop.get_context());
+
+// Run!
+loop.run();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]