Draw Line

edited May 2013 in Help request
I am trying to draw a line and I see nothing. Here is what I've done.

I know the math is good, because I started with object and got a rectangle at points I expected.

I saw a post that Draw functions worked only in RENDER event handler, so I did that. I made a call from Run function without success either. I know code gets executed.

I am not sure if I should use screen coordinates or world coordinates.
void DrawDirectionLine(orxOBJECT *obj)
        orxVECTOR a, b; // a is a start point; b is the end point of direction line
        orxObject_GetPosition(obj, &a);
        orxVector_Sub(&b, &data->movable->target, &a);
        //orxRender_GetScreenPosition(&a, _viewport, &a);
        //orxRender_GetScreenPosition(&b, _viewport, &b);
        orxRGBA color;
        orxRGBA_Set(1., 1., 1., .5);
        a.fZ = b.fZ = -0.6;
        orxDisplay_DrawLine(&a, &b, color);
        //orxLOG("Draw line");

orxSTATUS orxFASTCALL HandleRenderEvent(const orxEVENT *currentEvent)
        case orxRENDER_EVENT_START: {
            traverseScene(_scene, DrawDirectionLine);
    return orxSTATUS_SUCCESS;

status = status == orxSTATUS_SUCCESS && orxEvent_AddHandler(orxEVENT_TYPE_RENDER, HandleRenderEvent);


  • edited May 2013
    If you use the latest from the hg repository, draw calls can be issued at any time from anywhere.

    However direct draw calls are not as optimized as using objects, if it's for a game feature, I'd recommend using an object instead, scaling it from point A to point B and using whichever texture you want, including "pixel".

    All draw calls are in screen space, your code with the GetScreenPosition not commented out looks fine to me, is your DrawDirectionLine function called every frame?

    Ah, actually here's the issue, I think: orxRGBA is the traditionnal 8bits/channel internal color representation, ie. with values ranging from 0 to 255, not working with normalized floating point values.

    Try with
    orxDisplay_DrawLine(&a, &b, orxRGBA_Set(255, 255, 255, 128));
  • edited May 2013
    I had an interesting side effect.

    Draw line worked in Run method of 01_Object tutorial, but it failed in my project.

    I traced it down to background color option in INI file:
    BackgroundColor   = (210, 180, 140)

    When I have BackgroundColor set, draw line would not work. Draw line worked the moment I commented out BackgroundColor.

    I don't necessary think it is a bug, but sure would like to understand the role of Viewport background color.

    Another interesting behavior observation: draw line does not get drawn if there is an object in the same space. I ended up placing code to draw line from current cursor position. I have an area that has no objects, so it is all black. Draw line gets displayed there. The moment I move cursor into area filled with objects like background and game objects line disappears. Is it expected behavior?

    As far as my goal. I will use the object to draw line. For some reason I did not think straight and did not figure out how to make a directed line out of object with pixel. I slept on it and it is all clear now :)
  • edited May 2013
    Ah yes, any draw call issued within the Run callback will happen before the rendering kicks in (which is the first part of the frame).

    That means if you request a background color for your viewport, it'll happen after your draw calls, same for any object getting rendered, they'll be displayed on top of your draw calls.

    The best way for that is to issue your draw calls in an ordered fashion. If you want them on top of the objects rendered by a camera/viewport, listen to the matching orxRENDER_EVENT_VIEWPORT_STOP and issue your calls from there.
Sign In or Register to comment.