void glopEnd(GLContext * c, GLParam * param) { (void) param; gl_assert(c->in_begin == 1); if (c->begin_type == GL_LINE_LOOP) { if (c->vertex_cnt >= 3) { gl_draw_line(c, &c->vertex[0], &c->vertex[2]); } } else if (c->begin_type == GL_POLYGON) { int i = c->vertex_cnt; while (i >= 3) { i--; gl_draw_triangle(c, &c->vertex[i], &c->vertex[0], &c->vertex[i - 1]); } } c->in_begin = 0; }
void GameChat::draw_player_chat(GameState* gs) const { perf_timer_begin(FUNCNAME); const font_data& font = gs->primary_font(); const int padding = 5; int line_sep = font.h + 2; int view_w = gs->view().width, view_h = gs->view().height; int chat_w = view_w, chat_h = 100; int chat_x = 0, chat_y = 0; //h - chat_h - TILE_SIZE; int text_x = chat_x + padding, text_y = chat_y + padding; gl_draw_rectangle(chat_x, chat_y, chat_w, chat_h, COL_CONSOLE_BOX.with_alpha(50 * fade_out)); bool draw_typed_message = is_typing || !typed_message.empty(); int start_msg = 0; int message_space = chat_h - padding * 2 - (draw_typed_message ? line_sep : 0); int msgs_in_screen = message_space / line_sep; if (messages.size() > msgs_in_screen) { start_msg = messages.size() - msgs_in_screen; } for (int i = start_msg; i < messages.size(); i++) { messages[i].draw(font, fade_out, text_x, text_y); text_y += line_sep; } if (draw_typed_message) { int type_y = chat_y + chat_h - padding - line_sep; gl_draw_line(chat_x, type_y, chat_x + chat_w, type_y, Colour(200, 200, 200, fade_out * 180)); typed_message.draw(font, fade_out, text_x, type_y + padding - 1); } perf_timer_end(FUNCNAME); }
void glopVertex(GLContext * c, GLParam * p) { GLVertex *v; int n, i, cnt; gl_assert(c->in_begin != 0); n = c->vertex_n; cnt = c->vertex_cnt; cnt++; c->vertex_cnt = cnt; /* quick fix to avoid crashes on large polygons */ if (n >= c->vertex_max) { GLVertex *newarray; c->vertex_max <<= 1; /* just double size */ newarray = gl_malloc(sizeof(GLVertex) * c->vertex_max); if (!newarray) { gl_fatal_error("unable to allocate GLVertex array.\n"); } memcpy(newarray, c->vertex, n * sizeof(GLVertex)); gl_free(c->vertex); c->vertex = newarray; } /* new vertex entry */ v = &c->vertex[n]; n++; v->coord.X = p[1].f; v->coord.Y = p[2].f; v->coord.Z = p[3].f; v->coord.W = p[4].f; gl_vertex_transform(c, v); /* color */ if (c->lighting_enabled) { gl_shade_vertex(c, v); } else { v->color = c->current_color; } /* tex coords */ if (c->texture_2d_enabled) { if (c->apply_texture_matrix) { gl_M4_MulV4(&v->tex_coord, c->matrix_stack_ptr[2], &c->current_tex_coord); } else { v->tex_coord = c->current_tex_coord; } } /* precompute the mapping to the viewport */ if (v->clip_code == 0) gl_transform_to_viewport(c, v); /* edge flag */ v->edge_flag = c->current_edge_flag; switch (c->begin_type) { case GL_POINTS: gl_draw_point(c, &c->vertex[0]); n = 0; break; case GL_LINES: if (n == 2) { gl_draw_line(c, &c->vertex[0], &c->vertex[1]); n = 0; } break; case GL_LINE_STRIP: case GL_LINE_LOOP: if (n == 1) { c->vertex[2] = c->vertex[0]; } else if (n == 2) { gl_draw_line(c, &c->vertex[0], &c->vertex[1]); c->vertex[0] = c->vertex[1]; n = 1; } break; case GL_TRIANGLES: if (n == 3) { gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); n = 0; } break; case GL_TRIANGLE_STRIP: if (cnt >= 3) { if (n == 3) n = 0; /* needed to respect triangle orientation */ switch(cnt & 1) { case 0: gl_draw_triangle(c,&c->vertex[2],&c->vertex[1],&c->vertex[0]); break; default: case 1: gl_draw_triangle(c,&c->vertex[0],&c->vertex[1],&c->vertex[2]); break; } } break; case GL_TRIANGLE_FAN: if (n == 3) { gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); c->vertex[1] = c->vertex[2]; n = 2; } break; case GL_QUADS: if (n == 4) { c->vertex[2].edge_flag = 0; gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); c->vertex[2].edge_flag = 1; c->vertex[0].edge_flag = 0; gl_draw_triangle(c, &c->vertex[0], &c->vertex[2], &c->vertex[3]); n = 0; } break; case GL_QUAD_STRIP: if (n == 4) { gl_draw_triangle(c, &c->vertex[0], &c->vertex[1], &c->vertex[2]); gl_draw_triangle(c, &c->vertex[1], &c->vertex[3], &c->vertex[2]); for (i = 0; i < 2; i++) c->vertex[i] = c->vertex[i + 2]; n = 2; } break; case GL_POLYGON: break; default: gl_fatal_error("glBegin: type %x not handled\n", c->begin_type); } c->vertex_n = n; }