示例#1
1
文件: gui_main.cpp 项目: ands/scanner
int main(int argc, char **argv)
{
	if (!glfwInit()) {
		printf("Failed to init GLFW.");
		return -1;
	}
	glfwSetErrorCallback(errorcb);
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
	GLFWwindow* window = glfwCreateWindow(1024, 768, "scanner", NULL, NULL);
	if (!window) {
		glfwTerminate();
		return -1;
	}
	glfwSetKeyCallback(window, key);
	glfwSetCharCallback(window, charevent);
	glfwSetCursorPosCallback(window, cursorpos);
	glfwSetMouseButtonCallback(window, mousebutton);
	glfwSetScrollCallback(window, scrollevent);
	glfwMakeContextCurrent(window);
	glfwSwapInterval(1); // vsync

	glewExperimental = GL_TRUE;
	if(glewInit() != GLEW_OK) {
		printf("Could not init glew.\n");
		return -1;
	}
	glGetError(); // GLEW generates GL error because it calls glGetString(GL_EXTENSIONS).

	struct NVGcontext* vg = nvgCreateGL2(NVG_ANTIALIAS);
	if (vg == NULL) {
		printf("Could not init nanovg.\n");
		return -1;
	}

	UIcontext *uictx = uiCreateContext(4096, 1 << 20);
	uiMakeCurrent(uictx);
	uiSetHandler(ui_handler);
	uiInit(vg, "oui-blendish/DejaVuSans.ttf", "oui-blendish/blender_icons16.png");

	gui_init(vg);

	glfwSetTime(0);
	while (!glfwWindowShouldClose(window))
	{
		double mx, my;
		glfwGetCursorPos(window, &mx, &my);
		int winWidth, winHeight;
		glfwGetWindowSize(window, &winWidth, &winHeight);
		int fbWidth, fbHeight;
		glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
		float pxRatio = (float)fbWidth / (float)winWidth;

		gui_frame(vg, winWidth, winHeight, pxRatio, glfwGetTime());

		glfwSwapBuffers(window);
		glfwPollEvents();
	}

	gui_quit(vg);

	uiDestroyContext(uictx);
	nvgDeleteGL2(vg);
	glfwTerminate();
	return 0;
}
//Quit for States
void
state_quit ()
{
  gui_quit ();
  handlers[state].proc_quit ();
  unset_shader ();
}
示例#3
0
void de_init(void) {
	extern Uint32 average_loop_time;

	cleanup_video();
	cleanup_music();
	cleanup_audio();
	uninit_plugins();

	gui_quit();

	/* close the main eaf archive file */
	if (eaf_close_file(epiar_eaf) != 0) {
		printf("Couldn't close epiar.eaf file.\n");
	} else {
		epiar_eaf = NULL;
	}
	if (eaf_close_file(main_eaf) != 0) {
		printf("Couldn't close main.eaf file.\n");
	} else {
		main_eaf = NULL;
	}

	assert(game_path != NULL);
	free(game_path);
	game_path = NULL;

	if (average_loop_time == 0) average_loop_time = 18; /* in case they quit on menu */
#ifndef NDEBUG
	fprintf(stdout, "Average fps: %f\n", average_session_fps);
#endif
}
示例#4
0
文件: crack.c 项目: chinaktv/gxgui
static int on_MainWindow_keypress(GuiWidget *widget, void *userdata)
{
    KEY *c = (KEY *)userdata;
    printf("the key =%d\n", *c);
    if (*c == 'q' || *c == 182)
        gui_quit();

    return 0;
}
示例#5
0
文件: nbody.c 项目: Hkau/kth
int main(int argc, char* argv[])
{
	parse_args(argc, argv); // Done differently depending on application

	nbody_init(num_bodies);

	gui_init("nbody1");

/*	// Make some clumped bodies with initial velocity for a more interesting simulation
	for(i = 0; i < num_bodies/4; ++i)
	{
		body[i].pos.x = -50 + rand() % 20;
		body[i].pos.y = -50 + rand() % 20;
		body[i].pos.z = -50 + rand() % 20;
		body[i].vel.x = 0.05;
	}
	for(i = num_bodies/4; i < num_bodies/2; ++i)
	{
		body[i].pos.x = 30 + rand() % 20;
		body[i].pos.y = 30 + rand() % 20;
		body[i].pos.z = 30 + rand() % 20;
		body[i].vel.x = -0.05;
	}*/

	float delta = 0.f;

	clock_t start = times(NULL);

	client_start();

	int iterations = 0;
	while(gui_update())
	{
		// simulate stuff
		delta += turbo;
		while(delta >= 1.f)
		{
			// random mass flip
			//if(allow_negative)
			//		body[rand() % num_bodies].mass *= -1.f;

			calc_forces();

			add_velocity();

			delta -= 1.f;
			++iterations;
		}

		// if there's a limit, count down and break if reached
		if(num_steps > 0 && (--num_steps == 0))
			break;
	}

	clock_t stop = times(NULL);

	fputs(argv[0], stdout);
	int i;
	for(i = 1; i < argc; ++i)
	{
		fputc(' ', stdout);
		fputs(argv[i], stdout);
	}

	long ticks_per_sec = sysconf(_SC_CLK_TCK);
	printf("\n%d iterations.\n", iterations);
	clock_t time = stop - start;
	printf("elapsed: %f seconds.\navg: %f seconds per iteration.\n", ((float)(time))/ticks_per_sec, ((float)(time))/ticks_per_sec/iterations);

	client_exit();
	gui_quit();

	free(body);

	return 0;
}