Skip to content

Instantly share code, notes, and snippets.

@saitoha
Last active June 12, 2018 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saitoha/607ffa3856d1bafb418fdb0a6f71bd24 to your computer and use it in GitHub Desktop.
Save saitoha/607ffa3856d1bafb418fdb0a6f71bd24 to your computer and use it in GitHub Desktop.
Sixelize "cube" demo at Marzac/le3d(https://github.com/Marzac/le3d)
diff --git a/examples/cube/CMakeLists.txt b/examples/cube/CMakeLists.txt
index 5521cac..cdc366c 100644
--- a/examples/cube/CMakeLists.txt
+++ b/examples/cube/CMakeLists.txt
@@ -22,6 +22,7 @@ target_link_libraries(
cube
PRIVATE
le3d
+ sixel
)
target_include_directories(
cube
diff --git a/examples/cube/cube.cpp b/examples/cube/cube.cpp
index 93a24bc..aed5761 100644
--- a/examples/cube/cube.cpp
+++ b/examples/cube/cube.cpp
@@ -12,6 +12,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <sixel.h>
/*****************************************************************************/
int main()
@@ -20,10 +21,18 @@ int main()
LeGamePad::setup();
/** Create application objects */
- LeWindow window = LeWindow("Le3d: cube example");
- LeDraw draw = LeDraw(window.getContext());
LeRenderer renderer = LeRenderer();
LeRasterizer rasterizer = LeRasterizer();
+ SIXELSTATUS status;
+ sixel_encoder_t *encoder;
+
+/** Initialize sixel encoder */
+ printf("\033c");
+ status = sixel_encoder_new(&encoder, NULL);
+ if (SIXEL_FAILED(status)) {
+ printf("%s\n", sixel_helper_format_error(status));
+ return 1;
+ }
/** Load the assets (textures then 3D models) */
bmpCache.loadDirectory("assets");
@@ -51,16 +60,23 @@ int main()
/** Program main loop */
- while (sys.running && window.visible) {
+ printf("\0337");
+ while (sys.running) {
/** Process OS messages */
sys.update();
- window.update();
/** Wait for next frame */
timing.waitNextFrame();
/** Copy render frame to window context */
- draw.setPixels(rasterizer.getPixels());
+ printf("\0338");
+ fflush(stdout);
+ status = sixel_encoder_encode_bytes(
+ encoder, (unsigned char*)rasterizer.getPixels(),
+ rasterizer.frame.tx, rasterizer.frame.ty,
+ SIXEL_PIXELFORMAT_BGRA8888, NULL, (-1));
+ if (SIXEL_FAILED(status))
+ break;
/** Update model transforms */
crate->angle += LeVertex(0.1f, 2.0f, 0.0f);
@@ -81,10 +97,6 @@ int main()
renderer.flush();
}
-/** Make a screenshot */
- LeBmpFile screenshot("screenshot.bmp");
- screenshot.save(&rasterizer.frame);
-
timing.lastFrame();
LeGamePad::release();
sys.terminate();
@saitoha
Copy link
Author

saitoha commented Jun 12, 2018

This patch is in public domain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment