Beispiel #1
0
void renderFull()
{
	char currPreset[1024];

	g15macro_log("Redrawing whole screen.\n");

	g15r_clearScreen(canvas,G15_COLOR_WHITE);
	drawXBM(canvas, (unsigned char*)g15macro_small_bits, g15macro_small_width, g15macro_small_height, 0, 0); // Logo
	renderHelp(); // Help box to the right
	// Draw indicator of currently selected preset
	memset(currPreset,0,sizeof(currPreset));
	snprintf(currPreset,1024,"Current:%s",getConfigName(currConfig));
	g15r_drawLine(canvas, 50, 2, 50, 11, G15_COLOR_BLACK); // Line separating logo from Current: <config>
	g15r_renderString (canvas, (unsigned char *)currPreset, 0, G15_TEXT_MED, 53, 4); // Current: <config>

	// Draw selection list
	renderSelectionList();
}
Beispiel #2
0
void renderLaunch() {
	if(verboseOutput) debug << "Entered renderLaunch!" << std::endl;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if(verboseOutput) debug << "renderLaunch - cleared color and depth buffer bits!" << std::endl;

	int height; glfwGetWindowSize(window, NULL, &height);
	util::renderText(-.85, 0.65, height / 6, { 1, 1, 1 }, "Drop a replay on-screen to watch it!");
	renderHelp(height);
	util::renderText(-.85, -0.84, height / 12, { 1, 1, 1 }, " - To view this help panel, hold h");

	if(verboseOutput) debug << "renderLaunch - rendered necessary text!" << std::endl;

	glfwSwapBuffers(window);
	if(verboseOutput) debug << "renderLaunch - swapped buffers!" << std::endl;
	glfwPollEvents();
	if(verboseOutput) debug << "renderLaunch - polled events!" << std::endl;
}
Beispiel #3
0
INT WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstnace, PSTR lpCmdLine, INT nCmdShow) {
#else
int main(int argc, const char ** argv) {
#endif

	std::string loc(argv[0]);
	std::replace(loc.begin(), loc.end(), '\\', '/');
	loc = loc.substr(0, loc.find_last_of('/'));
#ifdef _WIN32
	_chdir(loc.c_str());
#else
	if(chdir(loc.c_str())) return EXIT_FAILURE;
#endif

	//Open debug:
	debug.open("logs/debug.log", std::ios_base::out | std::ios_base::binary);
	if(!debug.is_open()) debug.open("debug.log", std::ios_base::out);
	debug.flush();

	//start GL context and O/S window using the GLFW helper library
	if(!glfwInit()) {
		debug << "Could not start GLFW3\n";
		return EXIT_FAILURE;
	}

	util::initShaderHandler(&debug);

	window = NULL;
	GLFWmonitor* primary = glfwGetPrimaryMonitor();
	const GLFWvidmode * mode = glfwGetVideoMode(primary);
	glfwWindowHint(GLFW_REFRESH_RATE, 60);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwSwapInterval(0);
	windowedWidth = mode->width * 3 / 4;
	windowedHeight = mode->height * 2 / 3;
	setWindowed();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glClearColor(0, 0, 0, 1);

	if(argc > 1) {
		if(strcmp(argv[1], "-v") == 0) {
			verboseOutput = true;
			if(argc == 3) {
				debug << "About to handle the drop of the provided (arg 3) file!" << std::endl;
				handleDrop(window, 1, (const char **)(argv + 2));
			}
			else {
				while(isLaunch && !glfwWindowShouldClose(window)) {
					debug << "About to enter renderLaunch!" << std::endl;
					renderLaunch();
				}
			}
		}
		else if(argc == 2) handleDrop(window, 1, (const char **)(argv + 1));
	}
	else {
		while(isLaunch && !glfwWindowShouldClose(window)) {
			renderLaunch();
		}
	}

	if(verboseOutput) {
		const char * glVersion = (const char * )glGetString(GL_VERSION);
		debug << glVersion;
		debug.flush();
	}

	glfwSwapInterval(1);

	clock_t c = clock();
	
	if(verboseOutput) debug << "Entering main render loop!" << std::endl;
	while(!glfwWindowShouldClose(window)) {
		if(hPressed) {
			float delta = float(clock() - c) / CLOCKS_PER_SEC;
			if(verboseOutput) debug << "[In help render loop] Frame time of " << delta << ".\n";
			c = clock();

			if(verboseOutput) debug << "About to clear color & depth buffer bits in render help loop" << std::endl;
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			if(verboseOutput) debug << "Getting window height from glfw in render help loop" << std::endl;
			int height; glfwGetWindowSize(window, NULL, &height);

			if(verboseOutput) debug << "Rendering text in render help loop" << std::endl;
			util::renderText(-.85, 0.65, height / 6, { 1, 1, 1 }, "Halite Visualizer Help!");

			renderHelp(height);

			if(verboseOutput) debug << "Swapping buffers in render help loop" << std::endl;
			glfwSwapBuffers(window);
			if(verboseOutput) debug << "Polling events in render help loop" << std::endl;
			glfwPollEvents();

		}
		else {
			//Limit render rate:
			float delta = float(clock() - c) / CLOCKS_PER_SEC;
			if(verboseOutput) debug << "[In game render loop] Frame time of " << delta << ".\n";
			c = clock();

			short turnNumberS = turnNumber;
			if(verboseOutput) debug << "About to render at turn #" << turnNumberS << std::endl;
			my_game->render(window, turnNumberS, graphZoom, mouseX, mouseY, tabPressed, mousePressed, xOffset, yOffset);
			if(verboseOutput) debug << "Just rendered turn #" << turnNumberS << std::endl;
			if(abs(turnNumber - float(turnNumberS) >= 1)) turnNumber = turnNumberS; //Means it's gone past the right edge

			//Poll events
			glfwPollEvents();
			if(verboseOutput) debug << "Polled events in render game loop!" << std::endl;

			if(upPressed && maxFps <= 120) maxFps += maxFps * delta;
			else if(downPressed && maxFps != 4) maxFps -= maxFps * delta;

			if(leftPressed) {
				if(shiftPressed) turnNumber -= 5 * maxFps * delta;
				else turnNumber -= maxFps * delta;
			}
			else if(rightPressed) {
				if(shiftPressed) turnNumber += 5 * maxFps * delta;
				else turnNumber += maxFps * delta;
			}
			else if(!isPaused && !tabPressed) turnNumber += maxFps * delta;
			if(turnNumber < 0) turnNumber = 0;

			if(wPressed) yOffset -= SHIFT;
			if(aPressed) xOffset += SHIFT;
			if(sPressed) yOffset += SHIFT;
			if(dPressed) xOffset -= SHIFT;

			if(verboseOutput) debug << "Finished iteration of render game loop!!" << std::endl;
		}
	}

	return EXIT_SUCCESS;
}