Crystal Space
Welcome, Guest. Please login or register.
July 25, 2014, 05:09:53 pm

Login with username, password and session length
Search:     Advanced search
9005 Posts in 2043 Topics by 8231 Members
Latest Member: Loiselelias
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Rendering text to a texture
« previous next »
Pages: [1] Print
Author Topic: Rendering text to a texture  (Read 2192 times)
eventhorizon5
Jr. Member
**
Posts: 53


View Profile WWW
« on: April 28, 2009, 02:26:55 am »

Hi,
I'm writing a function for my app that draws text directly onto a texture (it's for elevator buttons and floor indicators; currently I'm using lots of image files), and was wondering if there was a preferred way of doing this.  Originally (since I'm still working a lot with CS 1.2) I started setting everything up to use the iGraphics2D::CreateOffscreenCanvas function (where I'd allocate a buffer the same size as the original image, blit the texture onto it, draw text, etc to create a new image) but noticed it was marked deprecated in 1.4.  I'm looking over the iGraphics3D::SetRenderTarget function (which replaces it) and am mainly wondering if there's another facility in the API for doing this kind of work, or if I should just try to work with that function.  Thanks

-eventhorizon
Logged
res
Develazyoper
CS Developer
Full Member
*****
Posts: 206


View Profile Email
« Reply #1 on: May 26, 2009, 01:11:22 pm »

SetRenderTarget() is the right way to render to a texture.
Logged
eventhorizon5
Jr. Member
**
Posts: 53


View Profile WWW
« Reply #2 on: August 26, 2009, 05:28:18 pm »

I finally started working on this, and here's the code I have so far.  I'm trying to do everything within a single function, instead of using csProxTexture.  The first block containing LoadTexture is within another function, in case you're wondering why the code searches for the texture right after that (so it's intentional).  The goal is to write text onto a loaded texture, but for now I'm testing it by trying to draw a line.

Code:
if (!loader->LoadTexture(name, filename))
{
ReportError("Error loading texture");
return false;
}

csRef<iTextureWrapper> tex = engine->GetTextureList()->FindByName(name);
if (!tex)
return false;

g3d->SetRenderTarget(tex->GetTextureHandle());
if (!g3d->BeginDraw (CSDRAW_2DGRAPHICS)) return false;
g2d->DrawLine(1, 1, 100, 100, g2d->FindRGB(255, 255, 255));
g3d->FinishDraw();
//g3d->UnsetRenderTargets();

This is all done before Prepare() is run, but the supposedly modified texture isn't changed from this code (on Windows at least).  On Linux, the app crashes later on when trying to render the texture.  I've also tried switching engine contexts, which doesn't help.  Is there something I'm doing wrong here?

-eventhorizon
Logged
eventhorizon5
Jr. Member
**
Posts: 53


View Profile WWW
« Reply #3 on: September 08, 2009, 11:20:49 pm »

Never mind - I figured it out.  It was mainly the way I was creating the texture, but also had to do with 2 bugs in CS (one seems to have been recently fixed in SVN, and I'm about to report the 2nd one with a patch).

-eventhorizon
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 4.147 seconds with 16 queries.