-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backface culling, basic lighting, terminal improvements #29
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#include "assets/utahTeapot.c" | ||
#define VC_TERM_SCALE_DOWN_FACTOR 10 | ||
#define BACKFACE_CULLING | ||
#define LIGHTING | ||
#include "model3d.c" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -541,20 +541,30 @@ static void vc_term_compress_pixels(Olivec_Canvas oc) | |
} | ||
} | ||
|
||
void sig_handler(int signo) | ||
{ | ||
if (signo == SIGINT) { | ||
printf("\033[?25h"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Show cursor when exiting |
||
exit(0); | ||
} | ||
} | ||
|
||
int main(void) | ||
{ | ||
signal(SIGINT, sig_handler); | ||
printf("\033[?25l"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hide cursor at start |
||
for (;;) { | ||
vc_term_compress_pixels(vc_render(1.f/60.f)); | ||
for (size_t y = 0; y < vc_term_scaled_down_height; ++y) { | ||
for (size_t y = 0; y < vc_term_scaled_down_height - 1; y = y + 2) { | ||
for (size_t x = 0; x < vc_term_scaled_down_width; ++x) { | ||
// TODO: explore the idea of figuring out aspect ratio of the character using escape ANSI codes of the terminal and rendering the image accordingly | ||
printf("\033[48;5;%dm ", vc_term_char_canvas[y*vc_term_scaled_down_width + x]); | ||
printf("\033[48;5;%dm\033[38;5;%dm%s", vc_term_char_canvas[y*vc_term_scaled_down_width + x], vc_term_char_canvas[y*vc_term_scaled_down_width + vc_term_scaled_down_width + x], "\u2584"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. \u2584 is the lower half block: ▄ |
||
} | ||
printf("\033[0m\n"); | ||
} | ||
|
||
usleep(1000*1000/60); | ||
printf("\033[%zuA", vc_term_scaled_down_height); | ||
printf("\033[%zuA", vc_term_scaled_down_height / 2); | ||
printf("\033[%zuD", vc_term_scaled_down_width); | ||
} | ||
return 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exit early if the triangle was previously entered since it isn't possible to re-enter.