aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiley Beckett <rbeckettvt@gmail.com>2025-10-17 19:41:49 -0400
committerRiley Beckett <rbeckettvt@gmail.com>2025-10-17 19:41:49 -0400
commit3e6eeaaf599f1082c02279bb9269de9644cdfab3 (patch)
treedacb95bef435c0eeafd8247d7fcfcadc8e5fb2bb
parent90123fe5eb84061f9756d38bc6a5c8775798309b (diff)
add glScissor
-rw-r--r--README.md1
-rw-r--r--graphics.c34
2 files changed, 29 insertions, 6 deletions
diff --git a/README.md b/README.md
index 0ee86d1..0894a7a 100644
--- a/README.md
+++ b/README.md
@@ -7,3 +7,4 @@ To build: `make`
- [ ] "Selection"
- [ ] Output results and exit code
- [ ] Scrolling
+- [ ] Unicode
diff --git a/graphics.c b/graphics.c
index f9695ba..d701c02 100644
--- a/graphics.c
+++ b/graphics.c
@@ -117,6 +117,8 @@ bool init_gl(client_state* state) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_SCISSOR_TEST);
+
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(MessageCallback, 0);
@@ -130,6 +132,7 @@ bool init_gl(client_state* state) {
void render_frame(client_state *state) {
// set up frame
glViewport(0, 0, state->width, state->height);
+ glScissor(0, 0, state->width, state->height);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -139,26 +142,45 @@ void render_frame(client_state *state) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, state->atlas.texture);
- float pen_x = 5.0f;
+
+ float pen_x = state->line_height / 4.0f;
float pen_y = state->line_height * state->lines - state->atlas.vert_shift;
+ if (state->lines > 0) {
+ glScissor(pen_x, pen_y + state->atlas.vert_shift, state->width, state->line_height);
+ }
+ else {
+ glScissor(pen_x, pen_y + state->atlas.vert_shift, state->width / 3.0f - pen_x, state->line_height);
+ }
// draw input buffer
glBindVertexArray(state->input_buffer_grafix.vao);
glUniform2f(state->offset_uniform, pen_x, pen_y);
glDrawElements(GL_TRIANGLES, state->input_buffer_grafix.num_elements, GL_UNSIGNED_INT, 0);
// shift pen
- if (state->lines > 0) pen_y -= state->line_height;
- else pen_x = state->width / 3.0f;
+ if (state->lines > 0) {
+ glScissor(0, 0, state->width, pen_y);
+ pen_y -= state->line_height;
+ }
+ else {
+ pen_x += state->width / 3.0f;
+ glScissor(pen_x, 0, state->width, state->line_height);
+ }
+
+ pen_x += state->line_height / 4.0f;
// draw options
array_for_all(item_t, item, state->items) {
glBindVertexArray(item->text_buffer.vao);
glUniform2f(state->offset_uniform, pen_x, pen_y);
glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0);
-
+
// shift pen
- if (state->lines > 0) pen_y -= state->line_height;
- else pen_x += item->pixel_len + (state->line_height / 2.0f);
+ if (state->lines > 0) {
+ pen_y -= state->line_height;
+ }
+ else {
+ pen_x += item->pixel_len + (state->line_height / 2.0f);
+ }
}
// present screen