[2.3] Rectangle2D not appearing on the screen

Problems building or running the engine, queries about how to use features etc.
knn217
Halfling
Posts: 78
Joined: Wed Jan 25, 2023 9:04 am
x 5

[2.3] Rectangle2D not appearing on the screen

Post by knn217 »

Ogre Version: 2.3
Operating System: Windows 11
Render System: Vulkan

Hello, I'm at the start of creating a simple GUI system, my 1st goal is to load an image on the screen.
I tried doing that with Rectangle2D but the image did not appear on screen, everything else is rendering normally though.
Here's the code:

Code: Select all

    Ogre::HlmsManager* hlmsManager = mRoot->getHlmsManager();

Ogre::HlmsUnlitDatablock* datablock = 0;

Ogre::HlmsSamplerblock samplerBlock;
samplerBlock.setAddressingMode(Ogre::TAM_WRAP);

Ogre::HlmsBlendblock blendBlock;
blendBlock.setBlendType(Ogre::SBT_TRANSPARENT_ALPHA);

Ogre::HlmsMacroblock macroBlock;
macroBlock.mDepthCheck = false;
macroBlock.mDepthWrite = false;

const Ogre::String datablockName = "RectDatablock";
OGRE_ASSERT(dynamic_cast<Ogre::HlmsUnlit*>(hlmsManager->getHlms(Ogre::HLMS_UNLIT)));
Ogre::HlmsUnlit* hlmsUnlit =
    static_cast<Ogre::HlmsUnlit*>(hlmsManager->getHlms(Ogre::HLMS_UNLIT));

datablock = static_cast<Ogre::HlmsUnlitDatablock*>(
    hlmsUnlit->createDatablock(Ogre::IdString(datablockName), datablockName, macroBlock,
        blendBlock, Ogre::HlmsParamVec()));
datablock->setTexture(0u, "leaf.png");
datablock->setSamplerblock(0, samplerBlock);

Ogre::Rectangle2D* Rect = mSceneMgr->createRectangle2D(Ogre::SCENE_DYNAMIC);    
Rect->initialize(Ogre::BT_DEFAULT, Ogre::Rectangle2D::GeometryFlagQuad);
Rect->setGeometry(Ogre::Vector2(0.0f, 0.0f), Ogre::Vector2(2.0f, 2.0f));
Rect->setRenderQueueGroup(10u); // Render after most stuff
Rect->setDatablock(datablock);

Ogre::SceneNode* rectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
rectNode->attachObject(Rect);
rectNode->setPosition(0, 0, 0);  

It worked when I did the same thing for Billboard and a planemesh, but Rectangle2D didn't appear for some reason.
I chose Rectangle2D for my GUI implementation since there seems to be a way to position it through screen coords, but since it's not visible I can't even test to see if that's possible

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5433
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1341

Re: [2.3] Rectangle2D not appearing on the screen

Post by dark_sylinc »

Hi!

Let me introduce to the great tool RenderDoc, which is amazing for diagnosing this type of bugs.

What I first did was copy your code into ShadowMapDebugging example and did a capture. I was already familiar with the example so it took me little time to find your draw call:

I'm highlighting the draw call but nothing changed on screen. Plus, the vertex count is 4, so it must be our rectangle.

This is good. It means you added to OgreNext correctly and it was submitted to the GPU. We just need to now understand why it's not showing up on screen.

I went to the Geometry tab to see its geometry and noticed the position was garbage data, or maybe the Rectangle is too small:

Was the Rectangle coordinates in 3D isntead of 2D? No, that makes little sense. I glossed over Rectangle2D source code and noticed Rectangle2D::setGeometry sets mChanged = true; but doesn't write any vertex buffer.

Aha! We forgot to call Rect->update();. We're missing that. I try again, but the rectangle is still not on screen.
However when I run another capture on RenderDoc:

YES! It's on screen, but it seems to be HW culled. That is probably an OgreNext bug and the winding order is wrong. It's understandable since Rectangle2D was made for 2D stuff so culling is often ignored.

We can quickly fix that via macroBlock.mCullMode = Ogre::CULL_NONE;:

Success!!!

TL;DR you were missing these two:

Code: Select all

Ogre::HlmsMacroblock macroBlock;
macroBlock.mDepthCheck = false;
macroBlock.mDepthWrite = false;
macroBlock.mCullMode = Ogre::CULL_NONE; // <--- missing this

Ogre::Rectangle2D *Rect = sceneManager->createRectangle2D( Ogre::SCENE_DYNAMIC );
Rect->initialize( Ogre::BT_DEFAULT, Ogre::Rectangle2D::GeometryFlagQuad );
Rect->setGeometry( Ogre::Vector2( 0.0f, 0.0f ), Ogre::Vector2( 2.0f, 2.0f ) );
Rect->update(); // <--- missing this
Rect->setRenderQueueGroup( 10u );  // Render after most stuff
Rect->setDatablock( datablock );

Cheers.

knn217
Halfling
Posts: 78
Joined: Wed Jan 25, 2023 9:04 am
x 5

Re: [2.3] Rectangle2D not appearing on the screen

Post by knn217 »

dark_sylinc wrote: Sun Jul 16, 2023 11:21 pm

Let me introduce to the great tool RenderDoc, which is amazing for diagnosing this type of bugs.

Thank you!
Your answer is very helpful and thorough, I'll learn to use RenderDoc for better insight of Ogre's rendering.