예제 #1
0
파일: SDL_glue.c 프로젝트: gfxprim/gfxprim
int main(void)
{
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
        fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    display = SDL_SetVideoMode(W, H, 0, SDL_SWSURFACE);

    if (display == NULL) {
        fprintf(stderr, "Could not open display: %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    GP_ContextFromSDLSurface(&context, display);

    black_pixel     = GP_RGBToContextPixel(0x00, 0x00, 0x00, &context);
    darkgray_pixel  = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, &context);

    redraw_screen();
    SDL_Flip(display);

    event_loop();

    SDL_Quit();
    return 0;
}
예제 #2
0
static void redraw(struct GP_Context *context)
{
	GP_Pixel white_pixel, black_pixel;

	black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context);
	white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context);

	GP_Fill(context, black_pixel);
	GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel);
	GP_Line(context, 0, context->h - 1, context->w - 1, 0, white_pixel);
}
예제 #3
0
static void redraw(GP_Backend *self)
{
	GP_Context *context = self->context;
	GP_Pixel white_pixel, black_pixel;

	black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context);
	white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context);

	GP_Fill(context, black_pixel);
	GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel);
	GP_Line(context, 0, context->h - 1, context->w - 1, 0, white_pixel);

	/* Update the backend screen */
	GP_BackendFlip(self);
}
예제 #4
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";

	if (argc > 1)
		font = GP_FontFaceLoad(argv[1], 0, 20);

	print_instructions();

	win = GP_BackendInit(backend_opts, "Font Align Test");

	if (win == NULL) {
		fprintf(stderr, "Failed to initalize backend '%s'\n",
		        backend_opts);
		return 1;
	}

	black_pixel    = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context);
	red_pixel      = GP_RGBToContextPixel(0xff, 0x00, 0x00, win->context);
	blue_pixel     = GP_RGBToContextPixel(0x00, 0x00, 0xff, win->context);
	green_pixel    = GP_RGBToContextPixel(0x00, 0xff, 0x00, win->context);
	yellow_pixel   = GP_RGBToContextPixel(0xff, 0xff, 0x00, win->context);
	white_pixel   = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context);
	darkgray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win->context);

	redraw_screen();
	GP_BackendFlip(win);
	event_loop();

	return 0;
}
예제 #5
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";

	print_instructions();

	if (argc > 1) {
		font_path = argv[1];
		fprintf(stderr, "\nLoading font '%s'\n", argv[1]);
		font = GP_FontFaceLoad(argv[1], 0, font_h);
	}

	win = GP_BackendInit(backend_opts, "Font Test");

	if (win == NULL) {
		fprintf(stderr, "Failed to initalize backend '%s'\n",
		        backend_opts);
		return 1;
	}

	white_pixel     = GP_RGBToContextPixel(0xff, 0xff, 0xff, win->context);
	gray_pixel      = GP_RGBToContextPixel(0xbe, 0xbe, 0xbe, win->context);
	dark_gray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win->context);
	black_pixel     = GP_RGBToContextPixel(0x00, 0x00, 0x00, win->context);
	red_pixel       = GP_RGBToContextPixel(0xff, 0x00, 0x00, win->context);
	blue_pixel      = GP_RGBToContextPixel(0x00, 0x00, 0xff, win->context);

	redraw_screen();
	GP_BackendFlip(win);

	event_loop();

	return 0;
}
예제 #6
0
static void redraw(GP_Backend *backend)
{
	GP_Context *context = backend->context;

	/* Now draw some testing patters */
	black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context);
	white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context);
	red_pixel   = GP_RGBToContextPixel(0xff, 0x00, 0x00, context);
	blue_pixel  = GP_RGBToContextPixel(0x00, 0x00, 0xff, context);
	green_pixel = GP_RGBToContextPixel(0x00, 0xff, 0x00, context);

	GP_Fill(context, white_pixel);

	unsigned int i, j;
	for (i = 0; i < 40; i++) {
		GP_HLineXYW(context, 0, i, i, black_pixel);
		GP_HLineXYW(context, 1, i + 40, i, black_pixel);
		GP_HLineXYW(context, 2, i + 80, i, black_pixel);
		GP_HLineXYW(context, 3, i + 120, i, black_pixel);
		GP_HLineXYW(context, 4, i + 160, i, black_pixel);
		GP_HLineXYW(context, 5, i + 200, i, black_pixel);
		GP_HLineXYW(context, 6, i + 240, i, black_pixel);
		GP_HLineXYW(context, 7, i + 280, i, black_pixel);
	}

	for (i = 0; i < 256; i++) {
		for (j = 0; j < 256; j++) {
			uint8_t val = 1.00 * sqrt(i*i + j*j)/sqrt(2) + 0.5;

			GP_Pixel pix = GP_RGBToContextPixel(i, j, val, context);
			GP_PutPixel(context, i + 60, j + 10, pix);
		}
	}

	GP_Text(context, NULL, 60, 270, GP_VALIGN_BELOW|GP_ALIGN_RIGHT,
	        black_pixel, white_pixel, "Lorem Ipsum dolor sit...");

	GP_Text(context, NULL, 60, 290, GP_VALIGN_BELOW|GP_ALIGN_RIGHT,
	        red_pixel, white_pixel, "Lorem Ipsum dolor sit...");

	GP_Text(context, NULL, 60, 310, GP_VALIGN_BELOW|GP_ALIGN_RIGHT,
	        green_pixel, white_pixel, "Lorem Ipsum dolor sit...");

	GP_Text(context, NULL, 60, 330, GP_VALIGN_BELOW|GP_ALIGN_RIGHT,
	        blue_pixel, white_pixel, "Lorem Ipsum dolor sit...");

	/* Update the backend screen */
	GP_BackendFlip(backend);
}
예제 #7
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";

	if (argc == 1) {
		fprintf(stderr, "No file specified\n");
		return 1;
	}

	if (argc > 2)
		font = GP_FontFaceLoad(argv[2], 0, 16);

	if (!read_file_head(argv[1]))
		return 1;

	backend = GP_BackendInit(backend_opts, "File View");

	if (backend == NULL) {
		fprintf(stderr, "Failed to initalize backend '%s'\n",
		        backend_opts);
		return 1;
	}

	win = backend->context;

	white_pixel     = GP_RGBToContextPixel(0xff, 0xff, 0xff, win);
	gray_pixel      = GP_RGBToContextPixel(0xbe, 0xbe, 0xbe, win);
	dark_gray_pixel = GP_RGBToContextPixel(0x7f, 0x7f, 0x7f, win);
	black_pixel     = GP_RGBToContextPixel(0x00, 0x00, 0x00, win);
	red_pixel       = GP_RGBToContextPixel(0xff, 0x00, 0x00, win);
	blue_pixel      = GP_RGBToContextPixel(0x00, 0x00, 0xff, win);

	redraw_screen();
	GP_BackendFlip(backend);

	event_loop();

	return 0;
}
예제 #8
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";
	int opt;
	int pause_flag = 0;
	int particles = 160;

	while ((opt = getopt(argc, argv, "b:n:")) != -1) {
		switch (opt) {
		case 'b':
			backend_opts = optarg;
		break;
		case 'n':
			particles = atoi(optarg);
		break;
		default:
			fprintf(stderr, "Invalid paramter '%c'\n", opt);
		}
	}

//	GP_SetDebugLevel(10);

	signal(SIGINT, sighandler);
	signal(SIGSEGV, sighandler);
	signal(SIGBUS, sighandler);
	signal(SIGABRT, sighandler);

	init_backend(backend_opts);

	context = backend->context;

	black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context);
	white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context);

	GP_Fill(context, black_pixel);
	GP_BackendFlip(backend);

	struct space *space;
	space = space_create(particles, 10<<8, 10<<8, (context->w - 10)<<8, (context->h - 10)<<8);

	for (;;) {
		if (backend->Poll)
			GP_BackendPoll(backend);

		usleep(1000);

		/* Read and parse events */
		GP_Event ev;

		while (GP_BackendGetEvent(backend, &ev)) {

			GP_EventDump(&ev);

			switch (ev.type) {
			case GP_EV_KEY:
				if (ev.code != GP_EV_KEY_DOWN)
					continue;

				switch (ev.val.key.key) {
				case GP_KEY_ESC:
				case GP_KEY_ENTER:
				case GP_KEY_Q:
					GP_BackendExit(backend);
					return 0;
				break;
				case GP_KEY_P:
					pause_flag = !pause_flag;
				break;
				case GP_KEY_G:
					space->gay = 1;
				break;
				case GP_KEY_T:
					space->gay = 0;
				break;
				}
			break;
			case GP_EV_SYS:
				switch(ev.code) {
				case GP_EV_SYS_QUIT:
					GP_BackendExit(backend);
					exit(0);
				break;
				case GP_EV_SYS_RESIZE:
					GP_BackendResizeAck(backend);
					space_destroy(space);
					space = space_create(particles,
					                     10<<8, 10<<8,
					                     (context->w - 10)<<8,
					                     (context->h - 10)<<8);
				break;
				}
			break;
			}
		}

		if (!pause_flag) {
			space_time_tick(space, 1);
			space_draw_particles(context, space);
			GP_BackendFlip(backend);
		}
	}

	GP_BackendExit(backend);

	return 0;
}