void gr_opengl_print_screen(const char *filename)
{
	char tmp[MAX_PATH_LEN];
	GLubyte *pixels = NULL;
	GLuint pbo = 0;

	// save to a "screenshots" directory and tack on the filename
	snprintf(tmp, MAX_PATH_LEN-1, "screenshots/%s.png", filename);

    _mkdir(os_get_config_path("screenshots").c_str());

//	glReadBuffer(GL_FRONT);

	// now for the data
	if (Use_PBOs) {
		Assert( !pbo );
		glGenBuffers(1, &pbo);

		if ( !pbo ) {
			return;
		}

		glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
		glBufferData(GL_PIXEL_PACK_BUFFER, (gr_screen.max_w * gr_screen.max_h * 4), NULL, GL_STATIC_READ);

		glReadBuffer(GL_FRONT);
		glReadPixels(0, 0, gr_screen.max_w, gr_screen.max_h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);

		// map the image data so that we can save it to file
		pixels = (GLubyte*) glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
	} else {
		pixels = (GLubyte*) vm_malloc(gr_screen.max_w * gr_screen.max_h * 4, memory::quiet_alloc);

		if (pixels == NULL) {
			return;
		}

		glReadPixels(0, 0, gr_screen.max_w, gr_screen.max_h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
		glFlush();
	}

	if (!png_write_bitmap(os_get_config_path(tmp).c_str(), gr_screen.max_w, gr_screen.max_h, true, pixels)) {
		ReleaseWarning(LOCATION, "Failed to write screenshot to \"%s\".", os_get_config_path(tmp).c_str());
	}
	
	if (pbo) {
		glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
		pixels = NULL;
		glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
		glDeleteBuffers(1, &pbo);
	}

	if (pixels != NULL) {
		vm_free(pixels);
	}
}
示例#2
0
		void Warning(const char* filename, int line, const char* format, ...)
		{
#ifndef NDEBUG
			SCP_string msg;
			va_list args;

			va_start(args, format);
			vsprintf(msg, format, args);
			va_end(args);

			ReleaseWarning(filename, line, "%s", msg.c_str());
#endif
		}
bool RocketSystemInterface::LogMessage(Rocket::Core::Log::Type type, const Rocket::Core::String& message)
{
	switch (type) {
	case Log::LT_ERROR:
		ReleaseWarning(LOCATION, "libRocket error: %s", message.CString());
		break;
	case Log::LT_WARNING:
		Warning(LOCATION, "libRocket warning: %s", message.CString());
		break;
	case Log::LT_ASSERT:
		os::dialogs::AssertMessage("libRocket assertion", LOCATION, "%s", message.CString());
		break;
	case Log::LT_ALWAYS:
	case Log::LT_INFO:
	case Log::LT_DEBUG:
		// These always go into the standard log
		mprintf(("libRocket message: %s\n", message.CString()));
		break;
	default:
		break;
	}
	// We never break into the debugger
	return false;
}