Ejemplo n.º 1
0
	bool GUI::Initialize(Renderer &renderer) {

		// -----------------------------------------------------------
		//  Load GUI textures
		// -----------------------------------------------------------
		Image img;

		// Load inactive texture
		img = loaders::loadImage("assets/gui_bw.tga", true);
		
		inactiveTexID = renderer.UploadTexture(img.bytes, img.width, img.height, img.bitsPerPixel);
		if (inactiveTexID == -1) return false;

		// Load active texture
		img = loaders::loadImage("assets/gui_over.tga", true);
		
		activeTexID = renderer.UploadTexture(img.bytes, img.width, img.height, img.bitsPerPixel);
		if (activeTexID == -1) return false;

		// Load over texture
		img = loaders::loadImage("assets/gui_down.tga", true);
		
		overTexID = renderer.UploadTexture(img.bytes, img.width, img.height, img.bitsPerPixel);
		if (overTexID == -1) return false;
	
		// Load GUI stencil
		img = loaders::loadImage("assets/gui_stencil_inv.tga", true);
		
		stencilTexID = renderer.UploadTexture(img.bytes, img.width, img.height, img.bitsPerPixel);
		if (stencilTexID == -1) return false;
		stencilMaskID = renderer.UploadStencilMask(stencilTexID);
		if (stencilMaskID == -1) return false;

		// -----------------------------------------------------------
		//  Initialize buttons
		// -----------------------------------------------------------
		okAction = OKButtonAction("OK Clicked!");
		if (!okBtn.Initialize(inactiveTexID, overTexID, activeTexID, AABB2D(glm::vec2(0.730914f, 0.69783f), glm::vec2(0.801001f, 0.767947f)), &okAction)) {
			return false;
		}

		// -----------------------------------------------------------
		//  Initialize cursors
		// -----------------------------------------------------------
		img = loaders::loadImage("assets/cursor_mouse.tga", false);
		Image imgDown = loaders::loadImage("assets/cursor_mouse_down.tga", false);
	
		if (!arrowCursor.Initialize(img, imgDown, glm::vec2(img.width, img.height), renderer.screenSize)) {
			return false;
		}

		// -----------------------------------------------------------
		//  Initialize map
		// -----------------------------------------------------------
		img = loaders::loadImage("assets/map.tga", true);
		
		mapTexID = renderer.UploadTexture(img.bytes, img.width, img.height, img.bitsPerPixel);
		if (mapTexID == -1) return false;

		map.Initialize(mapTexID, stencilMaskID, glm::vec2(10), glm::ivec2(128), AABB2D(glm::vec2(0.0225282, 0.0200334), glm::vec2(0.98373, 0.721202)));
		
		return true;
	}
Ejemplo n.º 2
0
int main()
{
	sf::RenderWindow window(sf::VideoMode(900, 600), "Path Tracing 2D");
	window.setVerticalSyncEnabled(true);

	glewInit();

	glMatrixMode(GL_PROJECTION);
	Matrix4x4f::OrthoMatrix(0.0f, 900.0f, 0.0f, 600.0f, -1.0f, 1.0f).GL_Load();

	SampleBuffer buffer;

	const float sampleScalar = 1.0f;

	const int downsampledWidth = window.getSize().x * sampleScalar;
	const int downsampledHeight = window.getSize().y * sampleScalar;

	if(!buffer.Create(downsampledWidth, downsampledHeight, "NONE NONE tracerShader.frag"))
		abort();

	buffer.Clear(AABB2D(Vec2f(-downsampledWidth, -downsampledHeight), Vec2f(downsampledWidth, downsampledHeight)));

	Light light;
	light.m_position = Vec3f(0.0f, 0.0f, 32.0f);
	light.m_color = Vec3f(10.0f, 10.0f, 10.0f);

	buffer.m_scene.m_lights.push_back(light);

	Polygon2D basePoly;
	basePoly.m_points.resize(4);
	basePoly.m_points[0] = Vec2f(-50.0f, -50.0f) * sampleScalar;
	basePoly.m_points[1] = Vec2f(50.0f, -50.0f) * sampleScalar;
	basePoly.m_points[2] = Vec2f(50.0f, 50.0f) * sampleScalar;
	basePoly.m_points[3] = Vec2f(-50.0f, 50.0f) * sampleScalar;

	buffer.Add(basePoly);

	Polygon2D basePoly2;
	basePoly2.m_points.resize(4);
	basePoly2.m_points[0] = Vec2f(-50.0f, 100.0f) * sampleScalar;
	basePoly2.m_points[1] = Vec2f(50.0f, 100.0f) * sampleScalar;
	basePoly2.m_points[2] = Vec2f(50.0f, 200.0f) * sampleScalar;
	basePoly2.m_points[3] = Vec2f(-50.0f, 200.0f) * sampleScalar;

	buffer.Add(basePoly2);

	buffer.Compile();
	buffer.Refresh();

	bool close = false;

	while(!close)
	{
		sf::Event event;

		while(window.pollEvent(event))
		{
			if(event.type == sf::Event::Closed)
				close = true;

			if(event.type == sf::Event::MouseMoved)
			{
				buffer.Refresh();

				buffer.m_scene.m_lights.back().m_position = Vec3f((event.mouseMove.x - 450) * sampleScalar, (300 - event.mouseMove.y) * sampleScalar, 32.0f);
			}
		}

		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
			close = true;

		for(size_t i = 0; i < 1; i++)
			buffer.Accumulate(Vec2f(0.0f, 0.0f), Vec2f(downsampledWidth, downsampledHeight), 0.0f);
		
		glFlush();

		glViewport(0, 0, window.getSize().x, window.getSize().y);
		buffer.RenderBuffer(Vec2f(0.0f, 0.0f), Vec2f(900.0f, 600.0f), 0.0f);

		window.display();
	}

	return 0;
}
Ejemplo n.º 3
0
///---------------------------------------------------------------------------------
/// fast
///---------------------------------------------------------------------------------
inline const AABB2D Interpolate( const AABB2D& start, const AABB2D& end, float fractionFromStartToEnd )
{
	Vector2 minsInterpolated = Interpolate( start.m_mins, end.m_mins, fractionFromStartToEnd );
	Vector2 maxsInterpolated = Interpolate( start.m_maxs, end.m_maxs, fractionFromStartToEnd );
	return AABB2D( minsInterpolated, maxsInterpolated );
}
Ejemplo n.º 4
0
	AABB2D	genAABB2D	(const Vector2 *pts, const size_t &n)
	{
		return AABB2D(min(pts, n), max(pts, n));
	}