Horde3D
http://www.horde3d.org/forums/

Horde and Freetype - generating textures at run-time
http://www.horde3d.org/forums/viewtopic.php?f=2&t=349
Page 1 of 1

Author:  roarflolo [ 28.05.2008, 23:38 ]
Post subject:  Horde and Freetype - generating textures at run-time

I'm using Freetype to generate text textures as needed at run-time and I'm using OpenGL calls to draw these textures (glGenTextures, glBindTexture, glTexImage2D, glBegin, etc.).

I want to port this code to Horde, any suggestions on how to do it? Less work for me is better :)

Author:  kal [ 29.05.2008, 02:36 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

if you don't want customizable font type/size/charset. generating the font every time app starts is not a good idea

Author:  roarflolo [ 29.05.2008, 02:40 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

I want to port the system I already have to Horde, any suggestions on how to do it? Less work for me is better :)

Author:  DarkAngel [ 29.05.2008, 04:46 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

I'd do it as a "virtual texture file".

Edit your code where queryUnloadedResource / loadResource are called from.
Normally, the file-names returned from queryUnloadedResource are used to load files from disc, but you can edit this to generate a font-texture using freetype instead.

E.g. if queryUnloadedResource returns a path that begins with "freetype/", then instead of trying to open a file with that name, pass the file-name to your font generation routine.

I'm assuming freetype can produce a texture for you in system memory (not in OpenGL memory)?
If so, then create a TGA header structure, and append the image data from freetype. Then pass this whole memory block to loadResource.

Author:  kal [ 29.05.2008, 10:41 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

freetype can render any character in a font to a bitmap. so you gather those bitmaps (each for one single char) in a large bitmap(rgba data in memory for example).

one way is to check if you have font data on disk, if not generate and save rgba data to disk, and load it, This would avoid redundant font data creation. you may need some descriptive name like [font_name][font_size][resolution]

I read the doc. I couldn't find a function to create a texture using rgba data in memory. Is there one?

Author:  DarkAngel [ 30.05.2008, 02:23 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

kal wrote:
I read the doc. I couldn't find a function to create a texture using rgba data in memory. Is there one?

loadResource / updateResourceData. However, the RGBA data needs to be converted into a real file format (in memory still). The easiest way to do this is to attach a TGA header structure to the front of it :wink:

Author:  kal [ 30.05.2008, 02:48 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

oc but I meant without adding a header. a way to handle raw data would be nice.

edit: tga header
Quote:
Code:
  byte   *buf;
  buf = malloc( width*height*4 + 18);
  memset ( buf, 0, 18 );
  buf[2] = 2; // uncompressed type
  buf[12] = width & 255;
  buf[13] = width >> 8;
  buf[14] = height & 255;
  buf[15] = height >> 8;
  buf[16] = 32; // pixel size
  buf[17] = 8; // 8bit alpha


... and swap rgb to bgr

tga is not rgb (I dont know if you can do rgb tga files). unnecessary converssion for an opengl supported format IMHO
and doesnt loading an resource uses another memory location? (lazy me did not check :oops: )

http://local.wasp.uwa.edu.au/~pbourke/dataformats/tga/

Author:  DarkAngel [ 30.05.2008, 05:21 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

kal wrote:
oc but I meant without adding a header. a way to handle raw data would be nice.
Does anyone know of an existing image format good for storing raw data, without requiring as much moving around of data as my TGA suggestion currently would?

We could invent a new image format :mrgreen:
The only required header info would be the pixel format (RGBA, BGR, RGB16F, etc) and the width and height (and depth for 3d images?). This header-data could be written as a footer if it makes things easier...
Then we'd just need to extend Horde's image loader to check for this new raw format.
Code:
struct RawGLPixels
{
int pixelFormat;
int width, height, depth;
}
...
  byte   *buf;
  size_t size = width*height*4;
  buf = malloc( size  + sizeof(RawGLPixels) );
  GeneratePixelData( buf, width, height );

  RawGLPixels& footer  = *(RawGLPixels*)(buf + size);
  footer.pixelFormat = RGBA;
  footer.width = width;
  footer.height = height;
  footer.depth = 0;
...
  pass buf to Horde

Author:  swiftcoder [ 30.05.2008, 16:03 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

DarkAngel wrote:
kal wrote:
oc but I meant without adding a header. a way to handle raw data would be nice.
Does anyone know of an existing image format good for storing raw data, without requiring as much moving around of data as my TGA suggestion currently would?

As long as you don't need floating point formats, either BMP or uncompressed PNGs might do what you need. Both have a fairly standard RGB channel layout, IIRC.

Author:  kal [ 30.05.2008, 18:12 ]
Post subject:  Re: Horde and Freetype - generating textures at run-time

@darkangel
actually, good idea :D

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/