Exemplo n.º 1
0
void MaratisPlayer::graphicLoop(void)
{
	MWindow * window = MWindow::getInstance();
	MEngine * engine = MEngine::getInstance();
	MRenderingContext * render = engine->getRenderingContext();

	// game
	MGame * game = engine->getGame();
	if(game)
	{
		if(game->isRunning())
		{
			render->disableScissorTest();
			render->setViewport(0, 0, window->getWidth(), window->getHeight());
			game->draw();
		}
		else
		{
			render->clear(M_BUFFER_COLOR);
		}
	}
	else
	{
		render->clear(M_BUFFER_COLOR);
	}
}
Exemplo n.º 2
0
void MGame::draw(void)
{
	MRenderingContext * render = MEngine::getInstance()->getRenderingContext();

	// get level
	MLevel * level = MEngine::getInstance()->getLevel();
	if(! level)
		return;

	// get current scene
	MScene * scene = level->getCurrentScene();
	if(! scene)
		return;

	// clear buffer
	render->enableDepthTest();

	if(scene->getCamerasNumber() == 0)
	{
		// draw scene with default camera
		MOCamera camera;
		
		render->setClearColor(*camera.getClearColor());
		render->clear(M_BUFFER_COLOR | M_BUFFER_DEPTH);

		camera.enable();
		camera.updateListener();
		scene->draw(&camera);
	}
	else
	{
		MOCamera * camera = NULL;
		unsigned int currentCamera = scene->getCurrentCamera();
		if(currentCamera < scene->getCamerasNumber())
			camera = scene->getCameraByIndex(currentCamera);
		else
			camera = scene->getCameraByIndex(0);
		
		render->setClearColor(*camera->getClearColor());
		render->clear(M_BUFFER_COLOR | M_BUFFER_DEPTH);

		camera->enable();
		camera->updateListener();
		scene->draw(camera);
	}
}
Exemplo n.º 3
0
void MGuiWindow::draw(void)
{
	MRenderingContext * render = MGui::getInstance()->getRenderingContext();

	if(! isVisible())
		return;
	
	MWindow * window = MWindow::getInstance();

	rescaleScrollingBar();
	render->enableScissorTest();
	render->setScissor((int)getPosition().x, window->getHeight() - (int)getPosition().y - (unsigned int)getScale().y, (unsigned int)getScale().x, (unsigned int)getScale().y);

	// normal clear
	if((getNormalColor().w >= 1.0f) && (! hasNormalTexture()))
	{
		render->setClearColor(getNormalColor());
		render->clear(M_BUFFER_COLOR);

		MGuiEvent guiEvent;
		guiEvent.type = MGUI_EVENT_DRAW;

		if(m_pointerEvent)
			m_pointerEvent(this, &guiEvent);

		// 2d mode
		set2dMode(render);
		render->disableDepthTest();
		render->disableCullFace();
		render->disableLighting();
		render->enableBlending();
		render->setBlendingMode(M_BLENDING_ALPHA);
		render->enableTexture();
	}
	else
	{
		// background
		set2dMode(render);
		render->disableDepthTest();
		render->disableCullFace();
		render->disableLighting();
		render->enableBlending();
		render->setBlendingMode(M_BLENDING_ALPHA);

		if(hasNormalTexture()) // texture clear
		{
			render->enableTexture();
			render->setColor4(getNormalColor());
			drawTexturedQuad(getNormalTexture());
		}
		else if(getNormalColor().w < 1.0f)
		{
			render->disableTexture();
			render->setColor4(getNormalColor());
			drawQuad();
		}

		if(m_pointerEvent)
		{
			MGuiEvent guiEvent;
			guiEvent.type = MGUI_EVENT_DRAW;
			m_pointerEvent(this, &guiEvent);

			// 2d mode
			set2dMode(render);
			render->disableDepthTest();
			render->disableCullFace();
			render->disableLighting();
			render->enableBlending();
			render->setBlendingMode(M_BLENDING_ALPHA);
			render->enableTexture();
		}
	}

	// gui
	render->pushMatrix();
	render->translate(MVector3(getPosition().x, getPosition().y, 0));

	render->pushMatrix();
	render->translate(MVector3(getScroll().x, getScroll().y, 0));

	// drawing
	unsigned int i;
	unsigned int oSize = m_objects.size();
	for(i=0; i<oSize; i++)
		m_objects[i]->draw();

	render->popMatrix();

	// draw shadows
	if(hasShadow())
	{
		render->disableScissorTest();
		drawShadow();
		render->enableScissorTest();
	}

	// scolling slides
	if(isHorizontalScroll())
		m_hScrollSlide.draw();

	if(isVerticalScroll())
		m_vScrollSlide.draw();

	render->popMatrix();
}