Announcement

Collapse
No announcement yet.

Text as Textures

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Text as Textures

    Is there a way to place text on objects. This would be much like that of a texture. The only way I can think to achieve this is to create on the fly bitmaps of text, and apply them as a texture.

    Perhaps I am missing a simpler way to do this?

    Thank you.

  • #2
    Text as Texture Decal

    Originally posted by INOVxDev View Post
    Is there a way to place text on objects. This would be much like that of a texture. The only way I can think to achieve this is to create on the fly bitmaps of text, and apply them as a texture.
    Perhaps I am missing a simpler way to do this?
    That is the way to do it, but it's much simpler than it sounds, because we've automated the process in Open Inventor. Take a look at the SoRenderToTextureProperty node. You can plug this into an SoTexture2 node in place of a static image (see the renderToTextureProperty field). The render to texture node takes any scene graph in its node field, renders that scene graph as-needed and provides the resulting image to the texture node. In .iv file format pseudo-code the texture node might look like this:
    Code:
    Texture2 { 
      renderToTextureProperty
        RenderToTextureProperty {
          size 128 128
          component RGB_TRANSPARENCY
          node Separator {
            DirectionalLight {}
            Material { diffuseColor 0.5 1 0.5 }
            Font  { 
              size 1.2 
              renderStyle TEXTURE 
            }
            Text3 { 
              string "text!" 
              justification CENTER 
            }
          }
        }
    }
    Looking at the SoRenderToTextureProperty node:
    • The size field specifies the dimensions of the resulting image in pixels. It's somewhat arbitrary but a larger image size allows a higher quality image.
    • The component field specifies an RGB or (as in the above example) RGBA image. For an RGB image you can specify the background color. For an RGBA image the background is transparent. That makes sense here because we want to blend the text onto some geometry.
    • The node field contains the scene graph. Note this scene graph is completely separate from the scene graph being rendered, so it needs its own camera and light. In this case for simplicity we're using the default camera, which is an orthographic volume spanning -1 to 1. If your text string doesn't fit in this view volume you'll need to provide an explicit camera node (see SoOrthographicCamera). Then we provide a default directional light, set the material color, the text size and the string to render.


    If we slap that on a cube using DECAL, CLAMP_TO_BORDER, etc. it looks like this:
    Attached Files

    Comment


    • #3
      Hi.
      I know this is a very old thread, but I can't figure out how to apply the text texture only on one side of the object. Because in the example, you provided, the texture is visible on the other side of the object as well.

      Thank you!
      Attached Files
      Last edited by Kateryna; December 8, 2020, 04:11 PM.

      Comment


      • #4
        Originally posted by Kateryna View Post
        Hi.
        I know this is a very old thread, but I can't figure out how to apply the text texture only on one side of the object. Because in the example, you provided, the texture is visible on the other side of the object as well.
        Hi,
        Can we assume that you are applying the texture to a quadrilateral (rectangle specified with, for example, SoIndexedFaceSet) and not to an SoCube?
        That's the typical case.

        The short answer is: No, you can't apply the texture only to one side of the shape.
        It's just the way OpenGL works. We have the option to have two-sided lighting (or not), but no such option for texturing.

        That said... there are, as usual, a couple of tricks that may be helpful...
        1. Easy one: If it's acceptable to not see anything when looking at the back of the shape...
          Just enable "back face culling" (see SoShapeHints). The back face will not be rendered.
        2. More complicated: If you need the "back face" to be blank - render the shape using two rectangles.
          This is also the solution to the related question "How do I get the text texture to read left-to-right on the back face".
          You can do this with a single IndexedFaceSet containing two rectangles.
          The "catch" is that you can't simply use the front coordinates twice. The resulting rectangles would display depth-buffer artifacts. You need to specify the back face's coordinates with a small Z offset from the front face coordinates.
          The texture will be mapped onto the front and back faces, but you can prevent it from being visible on the back face using the texture coordinates.
          For the front face set texture coordinates from lower-left counterclockwise to [0,0],[1,0],[1,1],[0,1] as usual. For the back face set texture coordinates [1,1],[1,1],[1,1],[1,1].
          Then set the SoTexture node's 'wrapS' field to CLAMP.
        Let me know if you need some example code.

        One more thing... If you just need a text string displayed inside a "box". It is much simpler to use SoText3 plus an SoTextProperty node with 'style' = BACK_FRAME. That might be slightly more expensive to render, but the difference is probably not noticeable unless you have tens of thousands of strings. (With SoFont 'renderStyle' = TEXTURE you are rendering a textured quad in both cases.)
        Regards,
        Mike
        Last edited by mikeheck; December 8, 2020, 10:30 PM.

        Comment


        • #5
          Hi Mike,

          Thanks for your reply.

          Yes, solving this issue with SoShapeHints(back face culling) or just SoTextProperty won't work for me.

          I have rather a complex object described with SoIndexedFaceSet. It is similar to the cylinder but hollow inside(well, it has a bit different shape). So my initial problem was when applying the Texture I could see it on both sides of the cylinder and front/back each. For the first issue, I used a small hack by using the clipping plane and splitting object in two, and applying texture to each of them. I have no idea if this is the best solution though.

          I have tried applying the solution you proposed in item 2, but it looks like I am missing something. Is it possible for you to share an example (can be .iv file)? I am not quite understanding how to specify the two rectangles.

          Thanks!

          Comment


          • #6
            Originally posted by Kateryna View Post
            I have rather a complex object described with SoIndexedFaceSet. It is similar to the cylinder but hollow inside(well, it has a bit different shape). So my initial problem was when applying the Texture I could see it on both sides of the cylinder and front/back each. For the first issue, I used a small hack by using the clipping plane and splitting object in two, and applying texture to each of them. I have no idea if this is the best solution though.
            I understand. I didn't have any clues about your geometry, so I guessed it was the common case of applying a text string texture to a flag or label rectangle. In that case, when we talk about the "other side" of the object we usually mean the "front face" vs the "back face" (in the OpenGL sense). Solving that problem does require rendering the face twice (in order to apply different attributes to the front and and back).

            So you have an actual 3D shape, composed of multiple faces, and it has (in some sense) a front and a back. If you want to minimize development time, rendering the object twice with a clip plane is a perfectly good hack. There is a performance cost for rendering twice, but you can ignore that for relatively small objects. Another option, which requires more work upfront, is to explicitly specify texture coordinates for the object's vertices. That allows you to put (or not put) the texture wherever you want.

            I have tried applying the solution you proposed in item 2, but it looks like I am missing something. Is it possible for you to share an example (can be .iv file)? I am not quite understanding how to specify the two rectangles.
            I'm not sure the example is relevant now, but I'm happy to share it: Test_TextureOnBackFace.zip
            Regards,
            Mike

            Comment

            Working...
            X