void con_render(renderer_t r) { unsigned int width, height; if ( NULL == con_default ) return; renderer_size(r, &width, &height); if ( CONSOLE_HIDDEN == con_default->state) { /* todo: draw the "last 4 lines" */ } else { float pitchx, pitchy; int i, offs, cursor_screen_offs; font_get_pitch(con_default->font, &pitchx, &pitchy); int const num_lines = con_display_lines; int const visible_height = pitchy * (num_lines + 1); int const border_top = height - visible_height - 5; if (con_default->conback) { glEnable(GL_TEXTURE_2D); texture_bind(con_default->conback); /* try toggling disabling blend - looks nice in different ways in each setting */ /* glDisable(GL_BLEND); */ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin(GL_QUADS); glColor4f(1,1,1,1); glTexCoord2f(0, 0); glVertex2i(0, border_top); glTexCoord2f(1, 0); glVertex2i(width, border_top); glTexCoord2f(1, 1); glVertex2i(width, height); glTexCoord2f(0, 1); glVertex2i(0, height); glEnd(); glEnable(GL_BLEND); } else { glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); glColor4f(0, 1.f, 0, 0.f); glVertex2i(0, border_top); glVertex2i(width, border_top); glVertex2i(width, height); glVertex2i(0, height); glEnd(); glEnable(GL_TEXTURE_2D); } offs = (con_default->lines_size % CONSOLE_MAX_LINES) - num_lines; for(i = 0; i < num_lines; i++, offs++) { if (offs < 0 && con_default->lines_size < CONSOLE_MAX_LINES) { /* well, this line hasn't actually been typed, so do nothing. */ } else { if (offs < 0) offs += CONSOLE_MAX_LINES; font_print(con_default->font, 0, border_top + i * pitchy, con_default->lines[offs % CONSOLE_MAX_LINES]); } } /* offset the input line if it's wider than the screen can show. we also keep a buffer of 3 characters at the "other side" of it, so that inplace editing is a bit more sensible. */ /* todo: blatantly should be able to move the character "within" the buffer within a current line when offset, and only scroll when at the left- or right- edges. */ /* should probably do this with a "current line display window" type concept. */ offs = 0; cursor_screen_offs = con_default->cursor_offs; if (pitchx * con_default->cursor_offs > width) { offs = con_default->cursor_offs - (width / pitchx) + 3; offs = offs < 0 ? 0 : offs; cursor_screen_offs = (width / pitchx) - 3; } font_print(con_default->font, 0, height - pitchy, &con_default->input_line[offs]); /* flashing cursor */ if (SDL_GetTicks() % 1000 < 500) { glBegin(GL_QUADS); glColor4f(1,1,1,1); glVertex2i(cursor_screen_offs * pitchx, height); glVertex2i(cursor_screen_offs * pitchx + pitchx, height); glVertex2i(cursor_screen_offs * pitchx + pitchx, height - 2); glVertex2i(cursor_screen_offs * pitchx, height - 2); glEnd(); } } }
static void get_screen_centre(renderer_t r, float h, vec3_t out) { unsigned int x, y; renderer_size(r, &x, &y); renderer_unproject(r, out, x / 2, y / 2, h); }