Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

matt-meeks
Copy link

  • Backface culling (frontface also available)
  • Simple dot product based lighting
  • Double terminal "pixel" density by using half block character with both foreground and background colors
  • Hide terminal cursor
  • Early exit of row when no longer inside triangle

int main(void)
{
signal(SIGINT, sig_handler);
printf("\033[?25l");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide cursor at start

void sig_handler(int signo)
{
if (signo == SIGINT) {
printf("\033[?25h");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show cursor when exiting

demos/vc.c Outdated
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");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\u2584 is the lower half block: ▄

@@ -109,7 +164,7 @@ Olivec_Canvas vc_render(float dt)
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), (v<<(3*8)));
}
}
}
} else if (has_entered) break;
Copy link
Author

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.

@matt-meeks matt-meeks marked this pull request as ready for review April 15, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants