Results 1 to 8 of 8

Thread: Translucent GUI components

  1. #1

    Default Translucent GUI components

    I'd like to fade-in some standard GUI components when they're required by my game. Does anyone know how I can go about this?

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I could be wrong, as I have not tried the following:

    If you are using the texture WM :-

    1) You can draw the window images manually
    Code:
    iirc...
    std::vector<CL_GUIWindowManagerTextureWindow> windows = wm.get_windows();
    CL_GUIWindowManagerTextureWindow texture_window = windows[index];
    CL_Subtexture subtexture = texture_window.get_texture();
    CL_Image image(gc, subtexture);
    image.set_alpha(fade_Value)
    image.draw(texture_window.get_geometry())
    .. I have not checked that
    2) Adjust the GUI API so you can set the CL_Colorf for RGBA for each components

  3. #3

    Default

    I think suggestion #1 won't work for me because I want only some of the GUI elements to be fading in at a given time (My actual game view, for example, is derived from CL_GUIComponent)

    P.S. I may be totally misunderstanding you. Apologies in advance if so.

  4. #4

    Default

    It'd be cool if I could just do a set_opacity(float) on a CL_GUIComponent

    If I'm not mistaken, that would require a change to CL_GUIComponent::render()

    This is basically what it does now:
    Code:
    CL_GUIComponent::render(gc)
    {
        if (func_render.is_null() == false)
        {
            func_render.invoke(gc, clip_rect);
        }
    }
    This is what I think it'd have to do:
    Code:
    CL_GUIComponent::render(gc)
    {
        if (func_render.is_null() == false)
        {
            if (this->opacity < 1.0f)
            {
                CL_SomeThing fake_gc;
                func_render.invoke(fake_gc, clip_rect);
                gc.draw_somehow_with_alpha(fake_gc, this->opacity);
            }
            else
            {
                func_render.invoke(gc, clip_rect);
            }
        }
    }
    Is that something that's even possible? Am I totally out to lunch?

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    No, you're quite right. It would need to create 'fake' gc before it could make components translucent like that.

    The hard part is creating such a fake gc, since theoretically the component could be using any shader program it wants to. So the tranlucency is virtually impossible to add unless the code is able to patch custom GLSL code.

    All the standard components only use CL_Draw, CL_Font, CL_Image, CL_Sprite and CL_GUIThemePart to do their rendering, so if those can be patched to respect a opacity property on a graphic context, then you would probably be able to obtain the effect you are seeking.

  6. #6

    Default

    Awesome. Thanks for the help

    I've decided to cut my losses and make some custom GUI components which do basically same stuff as the built in components, only with my own transparency support built in.

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    For personal interest can you let me know how easy your method is of creating user components with an opacity setting.

    It sounds like a nice idea for a smooth looking GUI for a game.

    Also I guess you can do extra effects as well as fading.
    For example, if the text / image is drawn normally using CL_Colorf(r,g,b,a):

    CL_Colorf(red - timed_value/2, green - timed_value/2, blue - timed_value/4, 1.0f - timed_value);
    would make the component fade with a shade of blue

  8. #8

    Default

    Quote Originally Posted by Magnus Norddahl View Post
    All the standard components only use CL_Draw, CL_Font, CL_Image, CL_Sprite and CL_GUIThemePart to do their rendering, so if those can be patched to respect a opacity property on a graphic context, then you would probably be able to obtain the effect you are seeking.
    If this method were to be used, could there be some difficulties?
    For example, let's say you wanted to draw two pure white circles overlapping. If you apply the alpha value to each draw operation individually, then the spot where they overlap will be brighter than the spots where they don't overlap, and it'll end up looking like a venn diagram.

    So I don't think I could just patch draw/font/image/etc the individual components would have to know to construct everything up first, and put down the whole thing on the gc at the same time with the alpha value applied. Right?
    Last edited by Daniel Benoy; 08-09-2010 at 04:18 PM. Reason: Grammar

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •