Render *anything* over CEGUI [Solved]

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Zeir
Gnoblar
Posts: 8
Joined: Fri Jun 24, 2005 10:48 pm
Location: Israel

Render *anything* over CEGUI [Solved]

Post by Zeir »

Hey guys,
i've been trying for a while now to make a particle system appear over my cegui windows,
at some point i got it to work just by setting the render queue group of the particles to 101,

Code: Select all

mPS->setRenderQueueGroup(101);
yesterday i noticed that my lovely particles weren't showing at all, after hours of investigation (and attemps at rolling my code back to a version where it worked) i pretty much gave up, so hoping someone here would have any useful information for me :)

at the moment my best guess is that OgreCEGUIRenderer is doing some state changes that prevent anything from being rendered properly after it.

from OgreCEGUIRenderer.cpp:

Code: Select all

void OgreCEGUIRenderer::initRenderStates(void)
{
	using namespace Ogre;

	// set-up matrices
	d_render_sys->_setWorldMatrix(Matrix4::IDENTITY);
	d_render_sys->_setViewMatrix(Matrix4::IDENTITY);
	d_render_sys->_setProjectionMatrix(Matrix4::IDENTITY);

	// initialise render settings
	d_render_sys->setLightingEnabled(false);
	d_render_sys->_setDepthBufferParams(false, false);
	d_render_sys->_setCullingMode(CULL_NONE);
	d_render_sys->_setFog(FOG_NONE);
	d_render_sys->_setColourBufferWriteEnabled(true, true, true, true);
	d_render_sys->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
	d_render_sys->unbindGpuProgram(GPT_VERTEX_PROGRAM);
	d_render_sys->setShadingType(SO_GOURAUD);
	d_render_sys->_setPolygonMode(PM_SOLID);

	// initialise texture settings
	d_render_sys->_setTextureCoordCalculation(0, TEXCALC_NONE);
	d_render_sys->_setTextureCoordSet(0, 0);
	d_render_sys->_setTextureUnitFiltering(0, FO_LINEAR, FO_LINEAR, FO_POINT);
	d_render_sys->_setTextureAddressingMode(0, d_uvwAddressMode);
	d_render_sys->_setTextureMatrix(0, Matrix4::IDENTITY);
	d_render_sys->_setAlphaRejectSettings(CMPF_ALWAYS_PASS, 0);
	d_render_sys->_setTextureBlendMode(0, d_colourBlendMode);
	d_render_sys->_setTextureBlendMode(0, d_alphaBlendMode);
	d_render_sys->_disableTextureUnitsFrom(1);

	// enable alpha blending
	d_render_sys->_setSceneBlending(SBF_SOURCE_ALPHA, SBF_ONE_MINUS_SOURCE_ALPHA);
}
This function is called from OgreCEGUIRenderer::doRender();
(Before each time the UI is rendered)

i tried registering a RenderQueueListener and setting those states back after the RenderQueueGroup i used for the CEGUI ended but unfortunatly i had no luck there either. (I guess it is possible i didnt set the right ones, or used the right values, etc)

One more thing i found out is that i could only get the cegui to render on a queue that had other entities (or particles, whatever) set to it. (except if set to 100, RENDER_QUEUE_OVERLAY), this behaviour wasn't very clear to me but maybe it will be to someone else :oops:


Hopefully this is enough information for someone to try and help me out here :)

any help would be appriciated, thanks in advance :D
Last edited by Zeir on Wed Nov 22, 2006 3:36 pm, edited 2 times in total.
Zeir
Gnoblar
Posts: 8
Joined: Fri Jun 24, 2005 10:48 pm
Location: Israel

Post by Zeir »

Ok, after a few more hours of fiddling i found out how to do this
so posting it here for anyone who might need it in the future.

what i did was set the CEGUI to user renderqueue 95 (for the sake of the example)

Code: Select all

mGUIRenderer = new CEGUI::OgreCEGUIRenderer(window, 95, false, 0, Game::getSingleton()->getSceneManager());
then i registered a render queue listener and reset view and projection matrix once the cegui was done rendering:

Code: Select all

void Game::renderQueueEnded(uint8 queueGroupId, const String& invocation, bool& repeatThisInvocation) {
	if (queueGroupId == 95) {
			mRoot->getRenderSystem()->_setProjectionMatrix(mCamera->getProjectionMatrixRS());
			mRoot->getRenderSystem()->_setViewMatrix(mCamera->getViewMatrix());
	}
}
So all in all was a pretty simple fix, my main problem was that i used
mCamera->getProjectionMatrix() instead of mCamera->getProjectionMatrixRS(). :oops:
good thing i decided to take a better look at the API ;)

hope someone will find this usefull, and if anyone wants to wiki it, or even implement some reset option into the OgreCEGUIRenderer (it uses the renderqueue listener to draw as well, so easy to implement).

Z.
8)