Results 1 to 7 of 7

Thread: Drawing differences when using CL_GUIManager*

  1. #1

    Default Drawing differences when using CL_GUIManager*


    I'm writing a game with some people and one of them had this ugly Intel GMA card. Problem is solved for now and this thread is not about that again, but the solution was to draw the game scene in two different ways.

    Please look at the attached file. On the left side are two screenshots generated by CL_GUIWindowManagerTexture working on top of CL_DisplayWindow. On the right side are two screenshots generated by direct drawing to CL_DisplayWindow. Drawing routines are all the same. The only difference is that in first case I'm using CL_GraphicsContext given by CL_GUIComponent::func_render() and in second case this context origin is CL_DisplayWindow itself.

    Few words about visible differences:
    1. Debug strings are drawn by CL_Font::draw_text(). On GUI drawing they are less readable than in direct drawing.
    2. This is a sand texture and it doesn't have any black border in reality.
    3. Speed meter transparency is slightly different.
    4. Smoke clouds shows the biggest difference. In direct drawing they are brighter (and this is really how it should look like).

    Did I do something wrong? Is the issue known? If asked I can provide a minimalistic proof code.
    Attached Images Attached Images  

  2. #2
    ClanLib Developer
    Join Date
    May 2007


    Which version of ClanLib are you using?

    ClanLib 2.1.0 or ClanLib 2.1.1 (SVN) or ClanLib 2.2 (SVN)

    Maybe it's connected to Magnus Norddahl's comment in " "

    ... But I would have thought the fonts would still work

  3. #3


    Currently 2.1.1 from svn, but problem occurs also in 2.1.0. I'll double check that tomorrow.
    Edit: I'm using GL2.

  4. #4
    Master Sorcerer
    Join Date
    Sep 2006


    There are two important changes in 2.2 SVN that may (or may not) explain what you are seeing here. They are:

    1. The blending mode for the window textures was changed to do alpha blending more correctly
    2. The clearing of the window texture before calling the func_render() routines was broken

    The first change makes any transparency drawn onto the texture correct. It used to use this equation:

    dest.rgba = src.a*src.rgba + (1-src.a)*dest.rgba

    But now it uses this equation:

    dest.rgb = src.a*src.rgb + (1-src.a)*dest.rgb
    dest.a = src.a + (1-src.a)*dest.a

    Technically this changes the window texture to be in what is known as pre-multiplied alpha format. But more importantly, it changes what the RGB and alpha components of a pixel are.

    In pre-multiplied alpha, the RGB components is best understood as the color and intensity of some light, while "one minus the alpha component" says how much of the existing light passes through. The old blending mode gave the alpha component in the window texture a rubbish value, causing the rendering of the final window texture not to be correct when using transparency.

    The second change fixes what was originally in the texture when the func_render() function is called. It failed to clear the texture properly with rgba(0,0,0,0) and thus any transparency in your window may been affected.

    Both changes are easilly back-ported to 2.1 - its only a few lines that need to be changed to fix it. However, it was discovered that the GL1 target does not support the OpenGL extension required to do a separate blending rule for the alpha component, so this problem would have to be resolved before being able to make it an official patch.

  5. #5
    ClanLib Developer
    Join Date
    May 2007


    That makes sense.

    For now, maybe a preferable option would be to adjust your drawing method as follows:

    Using the Blend example (in 2.1 SVN) for reference:

    	wm.func_repaint().set(this, &App::wm_repaint);
    	while (!quit)
    void App::wm_repaint()
    So, your main drawing code is not a part of a GUI component

    That's how I always draw non-gui code when also using ClanGUI.

    That also may explain why I don't have problems with the GUI for ClanLib 2.1

    Personally I find that using ClanGUI to draw to the screen has potential pitfalls (if you change the CL_FrameBuffer, CL_BlendMode, CL_PolygonRasterizer, CL_BufferControl etc). By having it outside ClanGUI, you do not need to care about the GUI state. Also you can do post-processing effects to the GUI texture.

    Hope that also works for you.

  6. #6
    ClanLib Developer
    Join Date
    May 2007


    I have updated ClanLib 2.1.1 (Release) to fix the "The clearing of the window texture before calling the func_render() routines was broken" problem
    Last edited by rombust; 12-10-2009 at 11:45 AM. Reason: ClanLib 2.1.1 has been released

  7. #7


    Thanks for your feedback. Now I clearly understand the problem.
    @rombust: I will do as you said, thanks!

Similar Threads

  1. Drawing 2D objects in a 3D space
    By rombust in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 05-15-2009, 05:55 PM
  2. Drawing and Erasing Surfaces
    By jmguy02 in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 04-07-2009, 05:32 AM
  3. Drawing pixels
    By knutsj in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 06-17-2008, 11:43 PM
  4. Redirect GUI drawing?
    By madmark in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 10-06-2007, 04:25 AM
  5. Drawing/displaying problem
    By shade37337 in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 10-21-2006, 05:11 PM



Posting Permissions

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