Last active
June 12, 2018 14:42
-
-
Save saitoha/607ffa3856d1bafb418fdb0a6f71bd24 to your computer and use it in GitHub Desktop.
Sixelize "cube" demo at Marzac/le3d(https://github.com/Marzac/le3d)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This patch is in public domain.