Skip to content

Instantly share code, notes, and snippets.

@saitoha
Created June 12, 2018 14:58
Show Gist options
  • Save saitoha/1593fae95cc9bc420f851ffe26e22bdc to your computer and use it in GitHub Desktop.
Save saitoha/1593fae95cc9bc420f851ffe26e22bdc to your computer and use it in GitHub Desktop.
Sixelize "destroyer" demo at Marzac/le3d(https://github.com/Marzac/le3d)
diff --git a/examples/destroyer/CMakeLists.txt b/examples/destroyer/CMakeLists.txt
index 7ac2cba..2c0912a 100644
--- a/examples/destroyer/CMakeLists.txt
+++ b/examples/destroyer/CMakeLists.txt
@@ -22,6 +22,7 @@ target_link_libraries(
destroyer
PRIVATE
le3d
+ sixel
)
target_include_directories(
destroyer
diff --git a/examples/destroyer/destroyer.cpp b/examples/destroyer/destroyer.cpp
index 9a2552c..dd35425 100644
--- a/examples/destroyer/destroyer.cpp
+++ b/examples/destroyer/destroyer.cpp
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
+#include <sixel.h>
/*****************************************************************************/
#define FPS_DESIRED 60
@@ -42,8 +43,8 @@
#define PLAYER_WEAPON_RELOAD 0.33f
#define LAUNCHER_WEAPON_RELOAD 0.33f
-const int resoX = 1024;
-const int resoY = 768;
+const int resoX = 600;
+const int resoY = 400;
#define uint unsigned int
/*****************************************************************************/
@@ -240,16 +241,18 @@ int main()
LeGamePad::setup();
// Create application objects
- LeWindow window = LeWindow("Destroy The Destroyer", resoX, resoY, true);
- LeDraw draw = LeDraw(window.getContext(), resoX, resoY);
LeRenderer renderer = LeRenderer(resoX, resoY);
LeRasterizer rasterizer = LeRasterizer(resoX, resoY);
LeGamePad pad = LeGamePad(0);
+ SIXELSTATUS status;
+ sixel_encoder_t *encoder = NULL;
+
+ status = sixel_encoder_new(&encoder, NULL);
+ if (SIXEL_FAILED(status))
+ return 1;
- rasterizer.background = LeColor::rgb(0x000000);
-// Register keyboard handler
- window.registerKeyCallback(keyHandler);
+ rasterizer.background = LeColor::rgb(0x000000);
// Load the assets (textures then 3D models)
bmpCache.loadDirectory("assets");
@@ -302,14 +305,21 @@ int main()
pad.init();
sceneInit(pad);
- while (sys.running && window.visible) {
+ while (sys.running) {
// Process OS messages
sys.update();
- window.update();
// Wait for next frame
timing.waitNextFrame();
- draw.setPixels(rasterizer.getPixels());
+ printf("\033[H");
+ fflush(stdout);
+ status = sixel_encoder_encode_bytes(
+ encoder,
+ (unsigned char *)rasterizer.getPixels(),
+ rasterizer.frame.tx, rasterizer.frame.ty,
+ SIXEL_PIXELFORMAT_BGRA8888, NULL, 256);
+ if (SIXEL_FAILED(status))
+ break;
// Update scene
int tmpButtons = pad.buttons;
@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