[Solved] Font overlay with custom shader cannot display

Problems building or running the engine, queries about how to use features etc.
Post Reply
xuzhongxing
Gnoblar
Posts: 4
Joined: Wed Nov 28, 2018 1:57 pm

[Solved] Font overlay with custom shader cannot display

Post by xuzhongxing » Sat Jul 13, 2019 4:10 am

Ogre Version: 1.11.3
Operating System: Ubuntu 19.04
Render System: GL3Plus

I am using gl3+ render system. So I need to render font overlay with my own shader. But there is nothing showed.

I manually load fonts and set my own shaders:

Code: Select all

    Ogre::ResourceManager::ResourceMapIterator iter = Ogre::FontManager::getSingleton().getResourceIterator();
    while (iter.hasMoreElements()) {
        std::cout << "load font" << std::endl;
        Ogre::ResourcePtr r = iter.getNext();
        r->load();
    }

    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName("Fonts/Arial");
    Ogre::Pass* p = material->getTechnique(0)->getPass(0);
    p->setVertexProgram("tex_color_vs");
    p->setFragmentProgram("tex_color_fs");
Then I created overlay:

Code: Select all

    Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
    // Create an overlay
    Ogre::Overlay* overlay = overlayManager.create("OverlayName");

    // Create a text area
    Ogre::TextAreaOverlayElement* textArea = static_cast< Ogre::TextAreaOverlayElement*>(
            overlayManager.createOverlayElement("TextArea", "TextAreaName"));
    textArea->setMetricsMode(Ogre::GMM_PIXELS);
    textArea->setPosition(0, 0);
    textArea->setDimensions(100, 100);
    textArea->setCaption("HelloWorld");
    textArea->setCharHeight(16);
    textArea->setFontName("Arial");
    textArea->setColourBottom(Ogre::ColourValue(1, 0, 0));
    textArea->setColourTop(Ogre::ColourValue(0, 0, 1));
    textArea->setMaterialName("Fonts/Arial");

    // Create a panel
    Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*>(
            overlayManager.createOverlayElement("Panel", "PanelName"));
    panel->setMetricsMode(Ogre::GMM_PIXELS);
    panel->setPosition( 100, 100 );
    panel->setDimensions( 100, 100 );
    panel->setMaterialName("Tenon/Green");
    panel->addChild(textArea);

    // Add the panel to the overlay
    overlay->add2D(panel);

    // Show the overlay
    overlay->show();
My vertex shader:

Code: Select all

#version 450 core

uniform mat4 worldViewProj;
uniform sampler2D tex0;

layout (location=0) in vec4 position;
layout (location=3) in vec4 colour;
layout (location=8) in vec2 uv0;

out vec4 fsColor;

void main() {
    gl_Position = worldViewProj * position;
    vec4 texColor = texture(tex0, uv0);
    fsColor = vec4(colour.rgb, texColor.a);
}
My fragment shader:

Code: Select all

#version 450 core

in vec4 vcolor;
layout(location = 0) out vec4 fragColor;

void main() {
    fragColor = vcolor;
}
Last edited by xuzhongxing on Sun Jul 14, 2019 2:43 am, edited 1 time in total.
0 x

xuzhongxing
Gnoblar
Posts: 4
Joined: Wed Nov 28, 2018 1:57 pm

Re: Font overlay with custom shader cannot display

Post by xuzhongxing » Sun Jul 14, 2019 2:42 am

Solved myself.

I should sample in the fragment shader, not in the vertex shader.

New vertex shader:

Code: Select all

#version 450 core

uniform mat4 worldViewProj;

layout (location=0) in vec4 position;
layout (location=3) in vec4 colour;
layout (location=8) in vec2 uv0;

out vec4 vcolor;
out vec2 uv;

void main() {
    gl_Position = worldViewProj * position;
    vcolor = colour;
    uv = uv0;
}

New fragment shader:

Code: Select all

#version 450 core
uniform sampler2D tex0;

in vec4 vcolor;
in vec2 uv;

layout(location = 0) out vec4 fragColor;

void main() {
    vec4 texColor = texture(tex0, uv);
    fragColor = vec4(vcolor.rgb, texColor.a);
}
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 836
Joined: Sun Mar 30, 2014 2:51 pm
x 147
Contact:

Re: [Solved] Font overlay with custom shader cannot display

Post by paroj » Sun Jul 14, 2019 5:21 pm

note that if you enable the RTSS, these shaders will be automatically generated for you.
0 x

Post Reply