[Fluxus] Quick Text Overlay Hack

Scott alcoholiday at gmail.com
Tue Jul 7 12:59:31 PDT 2009


No worries - I had trouble posting it to the group when I embedded pictures,
so I hope I didn't end up spamming multiple times as I kept trying new ways
to get the reflector to accept the post.

This was truly a hack, and just walks a vector right using the same code as
the FPS display. This was more just me practicing writing extensions the
Fluxus way and solving my immediate problem.

Once I was half we through with this, I came to the conclusion that it would
make more sense to write into a texture, and then put that texture on a poly
in camera space.

I can't say I totally grokked what Gabor did for his overlay function (for
that matter, I don't really understand how the scenegraph -vs- immediate
mode stuff interacts!), but something like that as you point out is a more
general solution. And obviously, my needs for text display would be
addressed if the onscreen editor was implemented from Scheme since I could
just use the display code directly.

-Scott

FYI here's the guts of what I added to Renderer.cpp:

    // Overlays a variable sized ascii display on top of rendered window
    if (m_OverlayDisplay && !PickMode && m_OverlayDisplayVector)
    {
      int lines = SCHEME_VEC_SIZE(m_OverlayDisplayVector);
      double top = Cam.GetTop();
      double bot = Cam.GetBottom();
      double rowHeight = (top-bot)/lines;
      int i=0;
      for (double y=top; y>bot; i++, y-=rowHeight)
      {
        PushState();
        GetState()->Transform.translate(Cam.GetLeft(),y,0);
        GetState()->Colour=m_OverlayColour;
        if(SCHEME_CHAR_STRINGP(SCHEME_VEC_ELS(m_OverlayDisplayVector)[i])){

DrawText(SCHEME_BYTE_STR_VAL(scheme_char_string_to_byte_string(SCHEME_VEC_ELS(m_OverlayDisplayVector)[i])));
        }
        PopState();
      }
    }


On Tue, Jul 7, 2009 at 1:34 AM, Dave Griffiths <dave at pawfal.org> wrote:

> Hi Scott,
>
> Sorry, I should have replied earlier to your message, but I've been
> travelling around...
>
> That text looks really good - although it may be indeed be a better idea
> to use type primitives - this is essentially what the scratchpad uses
> (the code is currently just duplicated), so they are fast enough. My
> long term aim is to rewrite the editor so it's written in scheme using
> real type primitives and I can take the code out of the scratchpad.
>
> What are you currently using to render the text? - it might be good to
> make this into a new text drawing primitive, maybe replacing the old
> (build-text) one.
>
> It seems a common need to have an overlay method to do things in screen
> space now - this should be possible by getting the camera matrix and
> essentially parenting primitives to it. It would be better to have a
> standard way of doing this, rather than having it hardcoded into
> primitives like the image prim.
>
> I'll have a look into providing something like (overlay-transform) which
> will allow such positioning to happen in screen space - eg:
>
> (define (build-screen-text x y str)
>    (with-state
>        (concat (overlay-transform))
>        (transform (vector x y 0))
>        (build-type my-screen-font str)))
>
> I need to do a load of gui work on the groworld game which will need
> this too. I'll also make the gui reusable so we'll have some basic menu
> widgets and things availible. I already have a text entry widget and
> draggable objects in scheme bricks that need moving to the fluxus
> collection.
>
> cheers,
>
> dave
>
> On Mon, 2009-07-06 at 10:19 -0700, Scott wrote:
> > (set-overlay-colour (vector 1.0 1.0 0.0 0.8))
> > (set-overlay-vector (vector
> > "To: Fluxus"
> > "From: Scott <alcoholiday at gmail.com>"
> > "Subject: Quick Text Overlay Hack"
> > " "
> > ""
> > "Hey Guys! I added the support for a text overlay. I'm using mostly
> > for"
> > "debug info, pop up menus and things like that."
> > ""
> > "Currently it just supports one non-proportional font, since I want
> > to"
> > "be able to line things up."
> > ""
> > "The api is really simple:"
> > "(show-overlay 1) ;; turns it on"
> > "(set-overlay-colour (vector 1.0 1.0 0.0 0.8)) ;; a nice 0.8 alpha
> > yellow"
> > "(set-overlay-vector (vector \"Your Text Here\""
> > "                            \"Your Second line of text here\""
> > "                            \"etc...\"))"
> > ""
> > "It's a little CPU intensive right now, but it would be easy to"
> > "optimize it more if folks can use it."
> > "-Scott"
> >
> >
> 20090706-th69rtk4yh97iwanwfxs4ir6cn.jpg20090706-qwqiwyasmt811g3g9ywgdmncjw.jpg
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pawfal.org/pipermail/fluxus-pawfal.org/attachments/20090707/c5390f7d/attachment-0001.html>


More information about the Fluxus mailing list