示例#1
0
int main(int argc, char *argv[])
{
	struct shape * s[4];
	s[0] = triangle_create(3,4,5);
	s[1] = triangle_create(7,8,9);
	s[2] = rectangle_create(10,20);
	s[3] = rectangle_create(11,22);
	
	int i = 0;
	for (i = 0; i < 4; i++)
	{
		float area = shape_area(s[i]);
		int perimeter = shape_perimeter(s[i]);
		char *name = s[i]->s_name;

		printf("name:%s, area:%.2f, perimeter:%d\n", name, area, perimeter);
	}
	return 0;
}
示例#2
0
static struct demoapp *
demoapp_create(struct display *display)
{
	struct demoapp *app;

	app = calloc(1, sizeof *app);
	if (!app)
		return NULL;

	app->egl = egl_state_create(display_get_display(display));

	app->display = display;
	display_set_user_data(app->display, app);

	app->window = window_create(app->display);
	app->widget = frame_create(app->window, app);
	window_set_title(app->window, "Wayland Sub-surface Demo");

	window_set_key_handler(app->window, key_handler);
	window_set_user_data(app->window, app);
	window_set_keyboard_focus_handler(app->window, keyboard_focus_handler);

	widget_set_redraw_handler(app->widget, redraw_handler);
	widget_set_resize_handler(app->widget, resize_handler);

	app->subsurface = window_add_subsurface(app->window, app,
		int_to_mode(option_red_mode));
	widget_set_redraw_handler(app->subsurface, sub_redraw_handler);
	widget_set_resize_handler(app->subsurface, sub_resize_handler);

	if (app->egl && !option_no_triangle)
		app->triangle = triangle_create(app->window, app->egl);

	/* minimum size */
	widget_schedule_resize(app->widget, 100, 100);

	/* initial size */
	widget_schedule_resize(app->widget, 400, 300);

	app->animate = 1;

	return app;
}
示例#3
0
文件: main.c 项目: sjmelia/rasteriser
void init(SDL_Surface* screen)
{
    black = SDL_MapRGB(screen->format, 0,0,0);
    green = SDL_MapRGB(screen->format, 0,255,0);
    red = SDL_MapRGB(screen->format, 255,0,0);

    //transform = affine_create();

    r = ray_create(0, 0, 0, 0, 0, 0, 0, 0);
    r->origin->x = 0;
    r->origin->y = 0;
    r->origin->z = -8;
    r->origin->w = 0;

    rast = rasteriser_create(640, 480);
    float width = 640.0;
    float height = 480.0;
    rasteriser_perspective(rast, 60.0, (width / height), 1.0, 1024.0);
    
    //affine_rotate(rast->model_affine, 25, 0.0, 1.0, 0.0, 1.0); 
    back = triangle_create(
            0.0, 1.0, -4.0,
            1.0, -1.0, -5.0,
            -1.0, -1.0, -5.0);
    front = triangle_create(
            -1.0, -1.0, -3.0,
            1.0, -1.0, -3.0,
            0.0, 1.0, -4.0);
    left = triangle_create(
            -1.0, -1.0, -5.0,
            -1.0, -1.0, -3.0,
            0.0, 1.0, -4.0);
    right = triangle_create(
            0.0, 1.0, -4.0,
            1.0, -1.0, -3.0,
            1.0, -1.0, -5.0);

    bota = triangle_create(
            -1.0, 1.0, 1.0,
            1.0, 1.0, 1.0,
            -1.0, 1.0, -1.0);
    botb = triangle_create(
            -1.0, 1.0, -1.0,
            1.0, 1.0, -1.0,
            1.0, 1.0, 1.0);
}