Display transparent layer

edited October 2011 in Help request
Hello everyone, I have a small problem. I rendered a scene where I have a few objects loaded from config file and I need to display a transparent layer over them. I thought that I can create an empty object in the code and set him black color with 50% alpha channel and than it's going to display automatically, but I was wrong.

I tried to find how objects are rendering in engine, but I didn't find anything (the engine code is really complex). So what is my question, I need manually create in code some colored rectangle and render it with transparency. I don't want to load any resources from config file.

Thank all of you for your suggestions.


  • edited October 2011
    Hi Reemon!

    Well, if you create an empty object, it doesn't have any visuals (aka orxGRAPHIC), so nothing will get rendered. Objects are multi-purpose containers and visuals are totally optional.

    So yes, there are many way to do it programmaticaly, even by creating an orxGRAPHIC yourself, or even by listening to render events and issueing rendering calls yourself, but there's a much easier way to do that, via config (no resource loading).

    Orx has a special "texture" called pixel which is a simple 1x1 white texture. So, let's say you want to cover the full viewport with that tranparent layer, here's what you'd do:

    In config:
    Graphic = BlackLayerG
    Color = (0, 0, 0)
    Alpha = 0.5
    ParentCamera = Camera; Or whichever name you used for your camera :)
    UseParentSpace = true; This way both scale and position will be expressed in parent camera's space
    Scale = 1.0; Covering the full camera frustum
    Position = (0.0, 0.0, 0.001); Assuming you want the layer on top of everything (ie. very close to your camera)
    Texture = pixel

    In code:
    orxObject_CreateFromConfig("BlackLayer"); // You now should have your transparent black layer on top of all your other objects

    If that doesn't suit your needs, please let me know. :)
  • edited October 2011
    Of course you can set/modify the config info programmatically at runtime and you can also add simple orxFXs to get easy fade-in/fade-out transitions (that's what I do in all my games actually).
  • edited October 2011
    Yeah, It's work great. I didn't know that orx has an internal texture named pixel. I thought that I always have to write some pathname to Texture, anyway I know orx little bit more now. Thanks for your helpful advice.
  • edited October 2011
    My pleasure!

    The texture 'pixel' is mentioned in the CreationTemplate.ini file, but it's very easy to miss.

    You can also modify/create textures on the fly. An example of this can be found in the display/orxFont.c file: that's how we create the default font texture from a memory buffer.
Sign In or Register to comment.