Example #1
0
int
main(int argc, char *argv[])
{
	try {

		gpc::fonts::rasterized_font rfont;
		{
			std::stringstream is(std::string(reinterpret_cast<const char *>(embedded_font), sizeof(embedded_font)), std::ios_base::in);
			cereal::BinaryInputArchive archive(is);
			archive(rfont);
		}
		text_renderer.setFont(rfont);

		SDL_Init(SDL_INIT_VIDEO);

		SDL_Window *window = SDL_CreateWindow("GPC Font Rasterizer Test App",
			SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			800, 600, SDL_WINDOW_OPENGL);
		if (!window) throw std::runtime_error("Failed to open window");

		SDL_GLContext glctx = SDL_GL_CreateContext(window);
		if (!glctx) throw std::runtime_error("Failed to create an OpenGL context for the window");

		SDL_GL_MakeCurrent(window, glctx);

		initGL();

		setViewport(800, 600);

		render(window);

		SDL_Event event;

		while (SDL_WaitEvent(&event)) {

			bool exit = false, must_render = false;

			switch (event.type){

			case SDL_KEYDOWN:
				if (event.key.keysym.sym == 27)
					exit = true;
				break;

			case SDL_KEYUP:
				break;

			case SDL_QUIT:
				exit = true;
				break;

			default:
				break;
			}

			if (exit) break;

			if (must_render) {
				render(window);
				must_render = false;
			}
		}

		SDL_Quit();
	}
	catch (const std::exception &e) {
		std::cerr << e.what() << std::endl;
	}

	return 0;
}