int main(int argc, char** argv) { cairo_surface_t *sfc; cairo_t *ctx; int x, y; struct timespec ts = {0, 500000000}; int running; x = y = 0; sfc = cairo_create_x11_surface(&x, &y); ctx = cairo_create(sfc); cairo_set_antialias(ctx, CAIRO_ANTIALIAS_NONE); mesh_t* m = mesh_create(x, y); for (running = 1; running;) { cairo_push_group(ctx); cairo_set_source_rgb(ctx, 0.1, 0.1, 0.1); cairo_paint(ctx); mesh_draw(ctx, m); cairo_pop_group_to_source(ctx); cairo_paint(ctx); cairo_surface_flush(sfc); int event=0; switch (event=cairo_check_event(sfc, 0)) { case 0xff53: // right cursor break; case 0xff51: // left cursor break; case 0xff1b: // Esc case -1: // left mouse button running = 0; break; } nanosleep(&ts, NULL); } mesh_free(m); cairo_destroy(ctx); cairo_close_x11_surface(sfc); return 0; }
/** * Draw a single object. * * Returns: true on success. **/ static int draw_op_do_draw(object_t *object, float cspace[16], float clip[16], object_t *quad) { uniform_t *un; float trans[16]; float fl[16]; if (! state_material_active(object->mat)) return 1; if (object->type == OBJ_NODE) return 1; if (object->type == OBJ_CAMERA) return 1; object_get_total_transform(object, trans); matrix_multiply(cspace, trans, fl); un = uniform_create(UNIFORM_MAT4, "transform", fl); shader_set_temp_uniform(un); uniform_ungrab(un); un = uniform_create(UNIFORM_MAT4, "clip_transform", clip); shader_set_temp_uniform(un); uniform_ungrab(un); if (object->type == OBJ_MESH) { draw_op_add_mesh(object->mesh); return mesh_draw(object->mesh); } memcpy(fl, object->light_color, 3 * sizeof(float)); fl[3] = 1; un = uniform_create(UNIFORM_VEC4, "light_color", fl); shader_set_temp_uniform(un); uniform_ungrab(un); draw_op_add_mesh(quad->mesh); return mesh_draw(quad->mesh); }
static void bldg_draw(const bldg_s *bldg) { // Check if in view dist int hx = (bldg->pos[0]>>18); int hz = (bldg->pos[2]>>18); hx -= hmap_visx; hz -= hmap_visz; if(hx < 0) hx = -hx; if(hz < 0) hz = -hz; if(hx > VISRANGE || hz > VISRANGE) return; mat4_load_identity(&mat_obj); mat4_translate_vec3(&mat_obj, (vec3 *)&bldg->pos); //mat4_translate_imm3(&mat_obj, 0, hmap_get(bldg->pos[0], bldg->pos[2]), 0); mesh_draw(bldg->mesh, 0); }