'Static' GUI causes text nodes to disappear (SOLVED)

I used @britzl’s documentation on https://github.com/britzl/publicexamples/tree/master/examples/gui_follows_go to instead create a static gui with the material, and skipped the object part of the documentation because I didn’t need it to follow an object, only to stay in one position. I created the material, the renderer and script, and set that as my default renderer. In the render script it only has a new gui_glue predicate.

function init(self)
    self.tile_pred = render.predicate({"tile"})
    self.gui_pred = render.predicate({"gui"})
    self.gui_glue_pred = render.predicate({"gui_glue"})
    self.text_pred = render.predicate({"text"})
    self.particle_pred = render.predicate({"particle"})

    self.clear_color = vmath.vector4(0, 0, 0, 0)
    self.clear_color.x = sys.get_config("render.clear_color_red", 0)
    self.clear_color.y = sys.get_config("render.clear_color_green", 0)
    self.clear_color.z = sys.get_config("render.clear_color_blue", 0)
    self.clear_color.w = sys.get_config("render.clear_color_alpha", 0)

    self.view = vmath.matrix4()
end

function update(self)
    render.set_depth_mask(true)
    render.set_stencil_mask(0xff)
    render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})

    render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
    render.set_view(self.view)

    render.set_depth_mask(false)
    render.disable_state(render.STATE_DEPTH_TEST)
    render.disable_state(render.STATE_STENCIL_TEST)
    render.enable_state(render.STATE_BLEND)
    render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
    render.disable_state(render.STATE_CULL_FACE)

    render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1))

    render.draw(self.tile_pred)
    render.draw(self.particle_pred)
    render.draw_debug3d()

    render.set_view(vmath.matrix4())
    render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1))

    render.enable_state(render.STATE_STENCIL_TEST)
    render.draw(self.gui_pred)
    render.draw(self.gui_glue_pred)
    render.draw(self.text_pred)
    render.disable_state(render.STATE_STENCIL_TEST)

    render.set_depth_mask(false)
    render.draw_debug2d()
end

function on_message(self, message_id, message)
    if message_id == hash("clear_color") then
        self.clear_color = message.color
    elseif message_id == hash("set_view_projection") then
        self.view = message.view
    end
end
  • First, after giving my GUI the material and setting Adjust Reference to “Disabled”, it doesn’t even work. When I move the camera, the GUI still sticks to the screen and won’t stay relative to it’s world position.

  • Second, text nodes disappear. I can see in my debug that they were created and given text. I did a test by switching the GUI back to the default GUI material, and they worked fine then.

If you don’t need it to follow a game object then why not create it as a normal gui with the normal gui material?

Sorry for the confusion. I meant follow as in move with its (changing) world position. What I should have said is that I don’t need the gui to move with a (moving) object, but stay in the same world position as it was when it was created.

As an example, I click on a moving car. A tooltip is created so that I can view it’s stats. The car would continue moving, but the tooltip would be in the same place as where I clicked the car so that I can read it.

Are you rendering it in world space? In my example I draw the detached_gui tag together with sprites and particles in world space. Are you doing the same thing? Your render script above doesn’t indicate that this is happening.

Some how when I copied the code over, I misplaced the detached_gui_pred and drew it during the STENCIL TEST. That fixed three-quarters of the problem. The text now renders, as well as the GUI being static in the world space, but the text nodes are now stuck to the screen.

As you can see, the text is slightly misaligned. That’s because I moved the camera around. When created the text is near the top and perfectly centered.

I’m assuming I’ll need to render a text_glue_pred as well? If so, how would I tell the text to render as so?

What would that be? The text nodes? Those should be drawn in the gui predicate.

Another solution for your case would be to ignore the gui altogether and draw your tooltip with sprites and label components.

1 Like

Yes, that would be the predicate for the text nodes.

Strange. They’re being built inside the same GUI collection that has the gui_glue material and predicate, but they’re not acting the same.

The problem with that is the amount of variability I plan on having. I plan to be able to change the size of it when I need a larger tooltip during the game, adapting the button sizes to the width of the tooltip as well as how much space their text takes up, use slice9 to compensate the gui graphics to the changes, and etc.

But the text nodes are rendered with the gui predicate together with the other node types (box, pie etc). The text predicate you see in the default render script is for the system font.

Before your comment I misunderstood the text predicate’s job. I’ll have to do some digging around to see why my text nodes aren’t reacting the same way the box nodes do, as shown in the photo.

P.S: The gray bar at the bottom of the tooltip should have two text nodes as well, but I assume they’re stuck to the camera in the lower left corner by the chat box.

@britzl Huzzah! I created a new font.material and set the font to use that and rendered it along with the gui_glue predicate. Everything shows up and is rooted in the world now.

1 Like