[Sidefx-houdini-list] Drawing text in the viewport

Michael Scarpa michael at scarpa.name
Tue Sep 13 10:42:45 EDT 2011

Hello Edward,

many thanks for your reply.

> > ISSUE #1: RE_Render::putMultiLineString()
> > -----------------------------------------
> setViewportFontOffset() affects the "xmove" and "ymove" parameters of glBitmap() while textMove3W() affects the values sent to glRasterPos().

That's good to know.

> putMultiLineString() tokenizes the input string for rendering by separating via new line characters ('\n'). I'm not quite sure how it would behave if the string contains carriage return ('\r') characters. I'd double-check that you don't have carriage returns.

I used Houdini's own dialog to edit a string attribute I was using, which made me confident I was using the right characters for new lines.  After receiving your message, I went a step further and hard-coded the string to "line1\nline2".  When using RE_OGLRender::putMultiLineString(), only the first line is drawn.  Since the rest of the text does not show up, I assume that it does correctly break the string into multiple lines, but only draws the first one.  If I pass the exact same string to RE_OGLRender::putString(), I get the text "line1line2" drawn in the viewport, showing that the new line character is simply ignored.  So it does not look like an issue with the character I'm using.

> When calling putMultiLineString(), textMoveW() is called to update the raster position. That's likely why it is necessary to call textMoveW() again if putLineLineString() is not behaving as you would expect.

I'm sorry, but I don't quite understand what you mean.  How would I call textMoveW() "again"?  I only call it once for ALL the lines to be drawn, right?  My code was:

ren.textMove3W(-0.02, 0.04, 0.0); // Offset to position above drawn shapes.
ren.putMultiLineString("This is a test.\nSecond line."); // Draw the string.

Where would I have to call textMoveW()?

> > ISSUE #2: Flying point numbers
> > ------------------------------
> The point numbers (and various geometry "decorations") are affected by the setViewportFontOffset() values. Try restoring the original viewport font offset values before exiting your hook function to the values that were set upon entry.

Yes, I suspected as much, and I did, by checking the values with RE_OGLRender::getViewportFontOffsetX() and RE_OGLRender::getViewportFontOffsetY(), storing them, and then setting them again after my drawing.  This had no effect in regards to this issue.

Furthermore, the issue with the point numbers flying off happens also when the render hook does absolutely nothing, i.e. RE_RenderHook::renderWire() and RE_RenderHook::renderShaded() are both empty functions.  Fiddling with RE_OGLRender::setViewportFontOffset() is excluded in this scenario.

I have noticed after sending the previous email, that the issue seems to only occur when the points disappear off screen to the bottom or the left of the viewport, not if they are panned beyond the top or right edges.  In case that helps.

> I don't think you should be really touching the viewport font offset values though. Just make textMoveW() (or textMoveS()) calls to set the raster position before calling putString() or putMultiLineString(). To move to the next line, you should only need something like this:
> r->textMoveW(
>  r->getRasterX(),
>  r->getRasterY() - r->getViewportFont()->getHeight());

I just tried this out, but with poor results.  I must be missing something.  I tried the following:

ren.textMove3W(-0.02, 0.04, 0.0); // Offset to position above drawn shapes.
ren.textMoveW(ren.getRasterX(), ren.getRasterY() - ren.getViewportFont()->getHeight());
ren.putMultiLineString("This is a test."); // Draw the string.

What I understand from your email, this should draw the text about one text line higher above the position I chose with the first call.  In fact, though, the text does not appear at all.  I notice from the documentation, that RE_Font::getHeight() returns an integer, and as far as I understand from what I have been observing so far, that is and amount of pixels.  I'm not sure how using that in RE_OGLRender::textMoveW() (which expects floats) together with RE_OGLRender::rasterY() (which returns a float) works.  Could you explain what I am doing wrong here?

Thanks again for your reply and if you could spare the time to explain a bit further what I'm doing wrong, I would be very grateful.



More information about the Sidefx-houdini-list mailing list