Horde3D

Next-Generation Graphics Engine
It is currently 02.05.2025, 15:08

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: 28.05.2008, 23:38 
Offline

Joined: 15.05.2008, 05:32
Posts: 46
Location: California
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 :)


Top
 Profile  
Reply with quote  
PostPosted: 29.05.2008, 02:36 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
if you don't want customizable font type/size/charset. generating the font every time app starts is not a good idea


Top
 Profile  
Reply with quote  
PostPosted: 29.05.2008, 02:40 
Offline

Joined: 15.05.2008, 05:32
Posts: 46
Location: California
I want to port the system I already have to Horde, any suggestions on how to do it? Less work for me is better :)


Top
 Profile  
Reply with quote  
PostPosted: 29.05.2008, 04:46 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
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.


Top
 Profile  
Reply with quote  
PostPosted: 29.05.2008, 10:41 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
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?


Top
 Profile  
Reply with quote  
PostPosted: 30.05.2008, 02:23 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
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:


Top
 Profile  
Reply with quote  
PostPosted: 30.05.2008, 02:48 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
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/


Top
 Profile  
Reply with quote  
PostPosted: 30.05.2008, 05:21 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
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


Top
 Profile  
Reply with quote  
PostPosted: 30.05.2008, 16:03 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
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.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 30.05.2008, 18:12 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
@darkangel
actually, good idea :D


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 79 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group