Skip to content

Instantly share code, notes, and snippets.

@saitoha
Created June 12, 2018 14:01
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/068cbcaf2a71c9966af2149ae3f2b0bd to your computer and use it in GitHub Desktop.
Save saitoha/068cbcaf2a71c9966af2149ae3f2b0bd to your computer and use it in GitHub Desktop.
sixelized output for ssloy/tinyrenderer (https://github.com/ssloy/tinyrenderer)
diff --git a/Makefile b/Makefile
index 0b0a469..5cbdce8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
SYSCONF_LINK = g++
CPPFLAGS = -Wall -Wextra -Weffc++ -pedantic -std=c++98
LDFLAGS = -O3
-LIBS = -lm
+LIBS = -lm -lsixel
DESTDIR = ./
TARGET = main
diff --git a/main.cpp b/main.cpp
index 8ce61dd..436c734 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,7 @@
#include <vector>
#include <limits>
#include <iostream>
+#include <sixel.h>
#include "tgaimage.h"
#include "model.h"
#include "geometry.h"
@@ -86,8 +87,14 @@ int main(int argc, char** argv) {
delete model;
}
frame.flip_vertically(); // to place the origin in the bottom left corner of the image
- frame.write_tga_file("framebuffer.tga");
-
+ sixel_encoder_t *encoder = NULL;
+ if (SIXEL_SUCCEEDED(sixel_encoder_new(&encoder, NULL))) {
+ if (SIXEL_FAILED(sixel_encoder_encode_bytes(
+ encoder, frame.buffer(), width, height, SIXEL_PIXELFORMAT_BGR888, NULL, (-1)))) {
+ std::cerr << "failed to output sixels.\n";
+ }
+ sixel_encoder_unref(encoder);
+ }
delete [] zbuffer;
return 0;
}
@saitoha
Copy link
Author

saitoha commented Jun 12, 2018

$ make && ./main obj/african_head/.obj obj/.obj
screen shot 2018-06-12 at 22 58 43

This patch is in Public Domain. Have fun!

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