static void draw_object(int i, int j, int f, float a) { struct object *o = get_object(i); struct object_mesh *m = NULL; float alpha = get_entity_alpha(j) * a; init_object(i); glPushMatrix(); { /* Apply the local coordinate system transformation. */ transform_entity(j); /* Render this object. */ if (test_entity_aabb(j) >= 0) { glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT); { int k, n = vecnum(o->mv); /* Bind a vertex buffer or array. */ if (GL_has_vertex_buffer_object) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, o->buffer); draw_vert(0); } else draw_vert(vecget(o->vv, 0)); /* Draw each surface. */ for (k = 0; k < n; ++k) { m = (struct object_mesh *) vecget(o->mv, k); if (vecnum(m->fv) > 0 || vecnum(m->ev) > 0) draw_mesh(m, alpha); } } glPopAttrib(); glPopClientAttrib(); } /* Render all child entities in this coordinate system. */ draw_entity_tree(j, f, a * get_entity_alpha(j)); } glPopMatrix(); }
void distrib(t_dot beg, t_dot end, t_mlx mlx) { if (beg.x <= end.x && (end.x - beg.x) >= fabs(end.y - beg.y)) draw_line(beg, end, mlx); else if (beg.x > end.x && (end.x - beg.x) >= fabs(end.y - beg.y)) draw_line(end, beg, mlx); else if (beg.y <= end.y && (end.y - beg.y) >= fabs(end.x - beg.x)) draw_vert(beg, end, mlx); else if (beg.y > end.y && (end.y - beg.y) >= fabs(end.x - beg.x)) draw_vert(end, beg, mlx); }
// Draw a polygon (made up from lines) void draw_poly(struct window w, struct vert *v[], int c) { for(int i = 0; i < c; ++i) { line(w, *v[i], *v[(i + 1) % c]); draw_vert(w, *v[i], 0); } }
// Drwa a line void line(struct window w, struct vert from, struct vert to) { // Copy x and y from vertices float x1 = round(from.x); float y1 = round(from.y); float x2 = round( to.x); float y2 = round( to.y); // Bresenham's line rasterization const bool steep = (fabs(y2 - y1) > fabs(x2 - x1)); if(steep) { swap(x1, y1); swap(x2, y2); } if(x1 > x2) { swap(x1, x2); swap(y1, y2); } const float dx = x2 - x1; const float dy = fabs(y2 - y1); float error = dx / 2.0f; const int ystep = (y1 < y2) ? 1 : -1; int y = (int)y1; const int max_x = (int)x2; for(int x = (int)x1; x < max_x; ++x) { if(steep) draw_vert(w, new_vert(y, x), 0); else draw_vert(w, new_vert(x, y), 0); error -= dy; if(error < 0) { y += ystep; error += dx; } } }