How to fix RenderableObject Projection & Manual Texture

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

How to fix RenderableObject Projection & Manual Texture

Post by IndieGuy11 »

Hello, I pretty much got to this point (the same as devxkh): http://www.ogre3d.org/forums/viewtopic. ... 01#p536905

However, my implamentation acts a bit different, as you can see.

I used dark_sylinc suggestions on way #2... and the projection is upside down. Not sure how I can fix this.

Also, as you can see, the font is not being loaded. From the previous thread it was said:
Hi,

When loading from JSON, Ogre will use the HlmsTextureManager (which is a texture manager built on top of the regular TextureManager); thus it won't see the font texture living in TextureManager.
You can set it manually from C++ though (I know it's a hassle though, that needs improving)
How can I set this manually? Any examples? Front is being loaded via:
// Source: https://bitbucket.org/LMCrashy/ogreimgu ... ew-default
// Auther: Jean-Baptiste Griffo (I think?)

Code: Select all

void ImgGuiRenderable::createFontTexture()
    {
        // Build texture atlas
        ImGuiIO& io = ImGui::GetIO();
        unsigned char* pixels;
        int width, height;
        io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

        mFontTex = Ogre::TextureManager::getSingleton().createManual("ImguiFontTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, 1, 1, Ogre::PF_R8G8B8A8);

        const Ogre::PixelBox & lockBox = mFontTex->getBuffer()->lock(Ogre::Image::Box(0, 0, width, height), Ogre::v1::HardwareBuffer::HBL_DISCARD);
        size_t texDepth = Ogre::PixelUtil::getNumElemBytes(lockBox.format);

        memcpy(lockBox.data, pixels, width*height*texDepth);
        mFontTex->getBuffer()->unlock();
    }
Thanks!
Attachments
WeirdGUI.png
Last edited by IndieGuy11 on Fri Sep 08, 2017 1:25 am, edited 2 times in total.
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

Re: How to fix RenderableObject Projection

Post by IndieGuy11 »

Update.

I can fix the projection by changing it via setCustomProjectionMatrix:

Code: Select all

Ogre::Matrix4 Test(
            2.0f / 1920, 0.0f, 0.0f, -1.0f,
            0.0f, -2.0f / 1080, 0.0f, 1.0f,
            0.0f, 0.0f, -1.0f, 0.0f,
            0.0f, 0.0f, 0.0f, 1.0f);
 changeCamera->setCustomProjectionMatrix(true, Test);
However, I would be interested in learning how to do this a different way, as this seems a bit hacky, and compositor would be great to fix this!

So, the last thing to do is fix this font issue ...
Attachments
WeirdGUI.png
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

Re: How to fix RenderableObject Projection & Manual Texture

Post by IndieGuy11 »

So ... I basically just saved the texture to a file to be able to use it.

I would still like to know how to do it though, thanks! Heres a picture.

Cheers.
Attachments
WeirdGUI.png
User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

Re: How to fix RenderableObject Projection

Post by devxkh »

IndieGuy11 wrote:However, I would be interested in learning how to do this a different way, as this seems a bit hacky, and compositor would be great to fix this!

So, the last thing to do is fix this font issue ...
set font:

Code: Select all

setDatablock("HlmsUnlitImgui");
 	Ogre::HlmsUnlitDatablock *datablock = static_cast<Ogre::HlmsUnlitDatablock*>(m_guiRenderer.getGraphicsManager().getRoot()->getHlmsManager()->getDatablock("HlmsUnlitImgui")); 
	datablock->setTexture(0, 0, mFontTex); 
From my point of view, the best/easiest solution for such ui problems is to set the projection matrix per renderable (like in my pullrequest).
Sadly, mathias won't merge it, because of the additional overhead (what i don't understand)...

So i thought about making my own renderable, hlms implementation, only for the ui stuff if i have the time.


Would you share your code. Maybe it helps me and others?
My little OGRE engine -> FrankE WIP
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

Re: How to fix RenderableObject Projection

Post by IndieGuy11 »

devxkh wrote:
IndieGuy11 wrote:However, I would be interested in learning how to do this a different way, as this seems a bit hacky, and compositor would be great to fix this!

So, the last thing to do is fix this font issue ...
set font:

Code: Select all

setDatablock("HlmsUnlitImgui");
 	Ogre::HlmsUnlitDatablock *datablock = static_cast<Ogre::HlmsUnlitDatablock*>(m_guiRenderer.getGraphicsManager().getRoot()->getHlmsManager()->getDatablock("HlmsUnlitImgui")); 
	datablock->setTexture(0, 0, mFontTex); 
From my point of view, the best/easiest solution for such ui problems is to set the projection matrix per renderable (like in my pullrequest).
Sadly, mathias won't merge it, because of the additional overhead (what i don't understand)...

So i thought about making my own renderable, hlms implementation, only for the ui stuff if i have the time.


Would you share your code. Maybe it helps me and others?
Hello!

Sure, I have no problem providing snippet code. Honestly, I just followed the example, and I also looked at what you did and others have done. But I cant do that until I tested it, and until I worked out all the issues I have. I have another thread on this issue, as I am crashing when I am deleting the index and vertex buffers. However, in the example they do not free these, so I am wondering if I have to do this or will the destruction be taken care of automatically?

I noticed that each example, creates a predetermined buffer rather than the actual amount of indexes, and vertices. Is this on purpose?

One other thing is, the VertexArrayObject, can we pushback multiple of these? mVaoPerLod[0]?

And of course, it seems like with this new moveable object, I have to look into if you can modify the vertices because destroying everything and creating renderables every frame seems like a waste!

Thanks!
Post Reply