Results 1 to 6 of 6

Thread: Multiple Textures in Opengl... Or not?

  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    Multiple Textures in Opengl... Or not?

    Working on a new rendering system to render characters from TTF files to a GL texture for fast drawing brings up the following:

    In terms of performance which is faster or has the lower memory usage, if there is a difference: 256 very small textures each with one character in an array (easy access via ASCII code ) or a very big texture with 255 characters in it and a function to calculate co-ordinates?

    Just a thought... Although I might implement both if there is wither has better CPU/memory footprints. I simply can't seem to find much info on this one.

    Bonus question: If I load a font in size 12, is that 12 pixels high? Or is there some other conversion. I think it differs by DPI but if it is not rendered and is on a gl texture in memory is that also affected?

    cheers,
    code_glitch
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #2
    256 very small textures each with one character in an array
    Bad idea, if you want to render more than 1-2 words.

    If I load a font in size 12, is that 12 pixels high?
    No, this size is depends on DPI.

  3. #3
    Quote Originally Posted by code_glitch View Post
    Working on a new rendering system to render characters from TTF files to a GL texture for fast drawing brings up the following:

    In terms of performance which is faster or has the lower memory usage, if there is a difference: 256 very small textures each with one character in an array (easy access via ASCII code ) or a very big texture with 255 characters in it and a function to calculate co-ordinates?

    Just a thought... Although I might implement both if there is wither has better CPU/memory footprints. I simply can't seem to find much info on this one.

    Bonus question: If I load a font in size 12, is that 12 pixels high? Or is there some other conversion. I think it differs by DPI but if it is not rendered and is on a gl texture in memory is that also affected?

    cheers,
    code_glitch
    Hey mate

    To get optimal OpenGL (or most graphical rendering libraries) performance, it is best to pack multiple smaller textures into one big (usually power of 2 dimemsions X & Y) texture.

    Then just get the smaller rectangles, or whatever coordinates UV you are using to pull out your quads/triangles, etc. from the larger texture and render them

    You can try my image packer program I wrote (complete program including image load/save DLLs):

    http://fpc4gp2x.eonclash.com/downloa...ge%20Packer.7z

    and the updated .exe file:
    http://fpc4gp2x.eonclash.com/downloads/imagepacker.exe

    It allows you to import and pack multiple smaller images into one big image which you can then export as a single image.

    You can also save as xml or ini, the locations in the larger rectangle of all the smaller sprites for easy access later on

    cheers,
    Paul

  4. #4
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    So thats the first one solved... If I wanted pixel dimensions, since I am currently using sdl_ttf for file format support I remember there being a sdl_getrenderedheight/width correct? I assume I could use that for spacing...
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  5. #5
    what i did was divide texture in 28 x 32 grid for each 256-32 characters (Spacebar is no character, you can manually move caret forward). You can draw each character in the middle of their cell, so you don't need to worry about spacing and relations between them.

    For 256x256 texture it would mean 8x9 pixels for each character, leaving a little empty space at bottom. It is well enough for common fonts. 512x512 would allow more detail with 16x18 character size, at great cost of memory use. Still i'd rather use the memory for this rather than draw fonts geometrically. Simple quad will always be 100 times faster to render especially if you optimize it with arrays, displaylists or such.

  6. #6
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    The idea was to fix the slowness of nice fonts from sdl_ttf. sdl_ttf is nice for loading and thats about it. Thus if we load the font with sdl and then draw a greyscale version to a texture and the free the sdl font, we can simply do a glcolor and quad draw from the texture which should be 1.5million times faster... Still, it seems my co-ord calculations are not quite up to scratch yet as I am getting bits of garbled letters everywhere
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •