Render to texture widgets

Brocan

20-04-2010 16:52:18

I need some like "RTT Demo". I've looked to layer unit test, but it's too complex for my needs.

My system is easy, i need to render to texture one window with the berkelium plugin, and attach it to a material that I want to apply to a plane. This way i can move the widget throught the scene.

It's possible make it? If yes, the widget still recieves mouse inputs? I've trying without success. :cry:

Thanks for all! :D

Altren

20-04-2010 22:26:33

If you need to move your window on 3D plane than UnitTest_Layers is not too complex for your needs and it's exactly what you need, because you need raytracing and retreaving texture coordinate and then translating it to widget on a 3D object.

If you don't need moving your window in 3D then there is much more simple variant showed in UnitTest_RTTLayer.

Brocan

21-04-2010 07:26:55

=)

I'll try, thanks!

Brocan

07-06-2010 08:08:25

Hi again!

I'm trying to make this work, but I can't do it. I want to create a plane that contains the rendered widget.

I'm using the MyGUI_RTTLayer implementation provided. When I start MyGUI I run:

mGUIOgreRenderer = new MyGUI::OgrePlatform();
mGUIOgreRenderer->initialise(RenderSystem::getSingletonPtr()->getOgreRenderWindow(),
RenderSystem::getSingletonPtr()->getOgreSceneMgr());
mGUIRoot = new MyGUI::Gui();
mGUIRoot->initialise();
MyGUI::FactoryManager::getInstance().registerFactory<MyGUI::RTTLayer>("Layer");
MyGUI::ResourceManager::getInstance().load("Layers_RTT.xml");


Layers_RTT.xml is copied from Layers.xml from UnitTest_RTTLayer.

And for creating the plane:

mWindow = GuiSystem::getSingletonPtr()->getMyGUIRoot()->createWidget<MyGUI::Window>("DefaultClient", MyGUI::IntCoord(left, top, w, h), MyGUI::Align::Stretch, "RTTLayer1");
mBrowser = mWindow->createWidgetT("BerkeliumWidget", "Canvas", MyGUI::IntCoord(4, 4, mWindow->getWidth()-8, mWindow->getHeight()-8), MyGUI::Align::Stretch);
mBrowser->setNeedKeyFocus(true);
mBrowser->setVisible(true);

Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("BrowserMaterial",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::Technique *technique = material->createTechnique();
technique->createPass();
material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
material->getTechnique(0)->getPass(0)->createTextureUnitState("RTTTexture1");

Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
Ogre::MeshManager::getSingleton().createPlane("browserPlane",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
640,480,1,1,true,1,5,5,Ogre::Vector3::UNIT_Z);

Ogre::SceneManager *mSceneMgr = System::RenderSystem::getSingleton().getOgreSceneMgr();
Ogre::Entity *ent = mSceneMgr->createEntity("browserentity", "browserPlane");
Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, 0, -1000));
node->attachObject(ent);
node->rotate(Ogre::Vector3::UNIT_X, Ogre::Degree(90));

ent->setMaterialName("BrowserMaterial");


But if the texture size is set to 640x480 the material is black with white rectangles, and if the texture size is 256x256 the material is black.

Ogre.log and MyGUI.log doesn't seems to have anything extrange. Any ideas of what i'm doing wrong? :D

Thanks in advance :D

PD: Have you any ideas of the problem related with berkelium widget that I described in this post? It's very important :cry:
viewtopic.php?p=71758#p71758

Brocan

08-06-2010 08:33:15

Well, the last problem was solved. The new problem is that the berkelium widget doesn't render to texture, always is white. :?

Brocan

11-06-2010 12:47:35

Well, I've found a small bug with the Berkelium Widget and the RTTLayer.

If the layer has the berkelium widget, this widget doesn't update property the isOutOfDate variable. So when the web page updates, or the gifs are moving or anything, the layer never updates.

I've solved it in the RTTLayer, but, the bug is in the berkelium widget, i hope you can solve it :)

void RTTLayer::renderToTarget(IRenderTarget* _target, bool _update)
{
//bool out_date = false;

//for (VectorILayerNode::iterator iter=mChildItems.begin(); iter!=mChildItems.end(); ++iter)
//{
// if ((*iter)->castType<LayerNode>()->isOutOfDate())
// {
// out_date = true;
// break;
// }
//}

bool out_date = true; //berkelium widget is outOfDate only the first time, after this, it never is out of date, so force for repaint the layer always
if (out_date || _update)
{
MyGUI::IRenderTarget* target = mTexture->getRenderTarget();
if (target != nullptr)
{
target->begin();
for (VectorILayerNode::iterator iter=mChildItems.begin(); iter!=mChildItems.end(); ++iter)
{
(*iter)->renderToTarget(target, _update);
}

target->end();
}
}
}

Brocan

14-06-2010 14:55:48

I again :D

I'm working in raycasting, i've started with your scene object from UnitTest_Layers.

Two main questions:
- How do you get the intersection with the mesh in the world if you don't transform the retrieved vertex?

I see "GetMeshInformation(entity->getMesh(), mVertexCount, mVertices, mIndexCount, mIndices, mTextureCoords, Ogre::Vector3::ZERO, Ogre::Quaternion::IDENTITY, Ogre::Vector3::UNIT_SCALE, mMaterialName);"

When it must be: "GetMeshInformation(entity->getMesh(), mVertexCount, mVertices, mIndexCount, mIndices, mTextureCoords, mEntity->getParentNode()->getPosition(), mEntity->getParentNode()->getOrientation(), mEntity->getParentNode()->_getDerivedScale(), mMaterialName);" to transform the vertex to world coordinates.

- And the second question, when you have discover the X,Y positions of the rayquery, how do you pass it to your widgets? because my RTT widget (berkelium widget) recieves screen coordinates provided by injectMouseMoved, not the transformed coordinates provided by pickPositionInObject from RTTLayer class.

Thanks in advance!

Altren

14-06-2010 17:25:53

Layer picking works next way:
- retieve intersection (Vector3 in world) between ray from cursor and mesh.
- get triangle that contain that intersection (three Vector3 in world).
- then using UV of triangle verticies calculate UV of our intersection.
- that UV is position on mesh, usually from 0. to 1. (texture scale also handled in RTTLayer).
- multiply that UV position by RTTLayer size to get mouse position.

May be 3D positions is not in world coordinates, but it doesn't really matter, because you only need them to be in same coordinate system.

About X and Y positions - try to use simple widgets first and see if they works. I'm not sure, but berkelium may have some weird code that determines mouse position.

Brocan

15-06-2010 12:38:57

About X and Y positions - try to use simple widgets first and see if they works. I'm not sure, but berkelium may have some weird code that determines mouse position.

I've just tryed with a simple window, and it works, so, is a problem related to the way that casted coordinates are passed to berkelium :D

The layer cast well the coordinates (coords are only passed to berkelium if i'm over it), but the final coordinates provided to berkelium aren't the casted coordinates in the layer but the absolute coordinates of the screen.

Brocan

16-06-2010 10:37:31

Solved with a hack in InputManager::injectMouseMoved and InputManager::updateFocus. I know that it isn't the right way, but at least it works.

The solution:

bool InputManager::injectMouseMove(int _absx, int _absy, int _absz)
{
....

updateMouseFocus();

//if ((mWidgetMouseFocus != nullptr) && (mWidgetMouseFocus->isEnabled()))
// onEventMouseMove(mWidgetMouseFocus, _absx, _absy);

return isFocusMouse();
}


void InputManager::updateMouseFocus()
{
....

if (oldMouseFocus == newMouseFocus)
{
if (oldMouseFocus != nullptr)
{
if (mLayerMouseFocus != nullptr)
{
IntPoint point = mLayerMouseFocus->getPosition(mMousePosition.left, mMousePosition.top);
//onEventMouseMove(newMouseFocus, mMousePosition.left, mMousePosition.top);
onEventMouseMove(newMouseFocus, point.left, point.top);
}
}
return;
}
...
}

Altren

16-06-2010 14:06:27

Hmm, what version of MyGUI do you use? I see this things fixed in MyGUI 3.0.1.

Brocan

16-06-2010 15:35:38

Hmm, what version of MyGUI do you use? I see this things fixed in MyGUI 3.0.1.

I don't remember now, I downloaded it from svn around march. I'm sure that is MyGUI 3.0.X. I will see tomorrow :D , and I will update the code from last version :D

Brocan

18-06-2010 12:03:18

Hmm, what version of MyGUI do you use? I see this things fixed in MyGUI 3.0.1.

I don't remember now, I downloaded it from svn around march. I'm sure that is MyGUI 3.0.X. I will see tomorrow :D , and I will update the code from last version :D


I'm running with this version:
// Define version
#define MYGUI_VERSION_MAJOR 3
#define MYGUI_VERSION_MINOR 1
#define MYGUI_VERSION_PATCH 0


The next question is, I want to create at runtime more render to texture layers to put more widgets renderer in different planes with different texture names and sizes. Is it possible or I need to made using the static way (putting a static number of rttlayers in Layers.xml)?

Altren

18-06-2010 14:13:34

Now it's possible only using the static way, or semi static way with generating xml with new additional layer and loading it.

Brocan

21-06-2010 08:17:02

Checked out the last trunk revision. Problem with positions in berkelium widget persists :|

Solved with:

Index: MyGUI_InputManager.cpp
===================================================================
--- MyGUI_InputManager.cpp (revision 3093)
+++ MyGUI_InputManager.cpp (working copy)
@@ -133,7 +133,8 @@
if (mLayerMouseFocus != nullptr)
{
IntPoint point = mLayerMouseFocus->getPosition(_absx, _absy);
- mWidgetMouseFocus->_riseMouseMove(_absx, _absy);
+ mWidgetMouseFocus->_riseMouseMove(point.left, point.top);
}
}
return isFocus;

Altren

21-06-2010 15:55:16

Thank you for fix. Applied.

Brocan

24-06-2010 07:50:52

New question! :lol:

When I move the RTTLayers that i have created, sometimes if two layers are overlapped I get that the plane, that contains one RTTL, that I send to front don't recieve the mouse inputs but the RTT in back does.

I think that is a problem related to the order of the layers, which keep their original order. It's possible to sort the layers or send one layer to the up?

Thanks in advance!

Brocan

28-06-2010 15:01:44

With the new version of berkelium: http://groups.google.com/group/platform ... 7681e53f11 the scroll doesn't works. Any idea?

Can be a problem related with the Buffer class?

Thanks in advance!

xadh00m

28-06-2010 18:20:30

Maybe its just one of the remaining issues with the latest Berkelium version?!

Known bugs--not yet reported to the bug tracker:
- all/glut_input: Scroll messages don't work properly. Force a repaint
by skipping by page.

Brocan

28-06-2010 23:38:37

Maybe its just one of the remaining issues with the latest Berkelium version?!

Known bugs--not yet reported to the bug tracker:
- all/glut_input: Scroll messages don't work properly. Force a repaint
by skipping by page.


Uhm, maybe, maybe, thanks for the info :D

Corak55

19-05-2014 17:11:04

Dear Brocan,

as I am working on raycasting too, please could you explain how you retireved the intersection or the ray with your mesh - and got the coordinates you pass to your widget?

When I use the function bool SceneObject::pickPositionInObject in SceneObject.cpp I can just ask, wheater the mouse is over the mesh, but the isIntersectMesh-Function is never processed completely as the first for-loop has a condition thats impossible to fullfill.