Jump to content

Rendering Text to an Image


Dan
 Share

Recommended Posts

I am trying to streamline a function for making character labels. My old routine takes too long because it uses the NVidea tools to create dds files for each image as each entity is created. For a few players, that's fine, but for thousands it can take a long time. I found a way to create an image in Leadwerks using the copy buffer commands, but it is not working for text. I have attached an image that shows how I am currently making the labels and the new way which shows that the letters seem to be there but are not being drawn correctly. Any help would be greatly appreciated because it seems like this should be possible - I'm just not doing the buffers correctly or something. Here is my code:

 

 

TTexture generateImage(string title, int width, int height)

{

TBuffer lastBuffer = CurrentBuffer();

 

static TBuffer buffer = CreateBuffer(width, height, BUFFER_COLOR|BUFFER_DEPTH);

SetBuffer(buffer);

 

SetColor(Vec4(1, 0, 0, 0)); // red

 

ClearBuffer();

 

//SetBlend(BLEND_ALPHA); // when I uncomment this, the text is completely transparent.

SetColor(1, 1, 1, 0);

DrawText(0, 0, str(title.c_str()));

SetBlend(0);

 

// end image generation

TTexture image = GetColorBuffer(buffer);

 

SetBuffer(lastBuffer);

 

return image;

}

 

In main I call the following:

 

// make label

TMesh label = CreatePlane();

 

TMaterial labelMat = LoadMaterial("media/Icons/Label/blank.mat");

 

SetFont(LoadFont("media/Fonts/Impact40"));

 

string display1 = "Player 100";

int textWidth = TextWidth(str(display1.c_str()));

int textHeight = FontHeight();

 

TTexture labeltex = generateImage(display1, textWidth, textHeight);

 

SetMaterialTexture ( labelMat, labeltex, 0 );

 

PaintEntity(label, labelMat);

 

ScaleEntity(label, Vec3(0.25f, 1.0f, 1.0f));

 

Here is the image in case the last one did not come across.

Windows XP SP3

Intel Core2 Extreme 3GHz

2GB DDR2 RAM

2x NVIDIA GeForce GTX 280 in SLI

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...