Create a texture2d with contents of other textures

Member
Posts: 93
Joined: 2008.11
Post: #1
Hi guys!

I have a texture based font engine here. it works good but I have to create textures using the font glyphs from the texture map(s).
I started to develop a generic quad class which should provide ways to:
1) init with some rectangular size (to fit all glyphs for example). creates a texture2d
2) change the contents of the texture2d with contents (texels) from other textures (texture2d pixels from say location 46,128 with size 20x24)
3) draw the resulting texture onto the screen (just like Texture2D class does) - no problem here

I was looking into glCopyTexSubImage2D and the rest but they all seem to draw TO the texture from the ReadBuffer.
I even created a local framebuffer and tried to use it as the readbuffer but had no much luck yet.

Does anyone have an example for this? maybe some code from your own texture based font engine?

Thanks in advance!
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #2
Hi,

Code:
- (void) copyFrame:(int)frameId toPoint:(CGPoint)inPoint fromTexture:(TMFramedTexture*)texture {
    CGSize frameSize = CGSizeMake( texture.contentSize.width/[texture cols], texture.contentSize.height/[texture rows] );
        
    // This will draw the frame into the buffer
    glEnable(GL_BLEND);
    [texture drawFrame:frameId inRect:CGRectMake(0, 0, frameSize.width, frameSize.height)];
    glDisable(GL_BLEND);
    
        // And this will copy the rendered frame back to our quad
    glBindTexture(GL_TEXTURE_2D, m_unName);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, inPoint.x, inPoint.y, 0, 0, frameSize.width, frameSize.height);        
}

Have this code. It works only if you render into the bounds of the quad.. so if inPoint.x or inPoint.y is less than 0 it will fail (not draw at all. just transparent).

Maybe I'm totally wrong and this is not the way it should be done?
Any ideas?

TIA,
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #3
Nevermind. Found the right way to do this.
I was surprised to see that this question was already answered before and I even can see myself commenting in that post!
Thanks goes to Flash, again Smile Here is the link if anyone is interested: http://www.idevgames.com/forum/showthread.php?t=16776

Regards!
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #4
godexsoft Wrote:Hi guys!

I have a texture based font engine here. it works good but I have to create textures using the font glyphs from the texture map(s).
I started to develop a generic quad class which should provide ways to:
1) init with some rectangular size (to fit all glyphs for example). creates a texture2d
2) change the contents of the texture2d with contents (texels) from other textures (texture2d pixels from say location 46,128 with size 20x24)
3) draw the resulting texture onto the screen (just like Texture2D class does) - no problem here

I was looking into glCopyTexSubImage2D and the rest but they all seem to draw TO the texture from the ReadBuffer.
I even created a local framebuffer and tried to use it as the readbuffer but had no much luck yet.

Does anyone have an example for this? maybe some code from your own texture based font engine?

Thanks in advance!
Alex

The question is why would you want to create a separate texture since you could just as easily draw your glyphs to the screen using the original texture.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #5
warmi Wrote:The question is why would you want to create a separate texture since you could just as easily draw your glyphs to the screen using the original texture.

Hi,

Because constructing and calculating the textured string out of the texture maps every frame is painful. I could probably create another class which would hold a array of pointers to the right glyphs.. but creating a texture and later just drawing it is better in my eyes :-)

Regards,
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #6
It depends, if you are displaying a few simple labels which don't change often then yeah, but if you are displaying text which changes frequently (i.e score numbers or such) then this is going to be way slower.

If I were you I would simply create a font class which holds mappings of each character in your font to a set of uv coordinates and draw your quads directly off of that class.
Much simpler and faster - the problem with 2d drawing is not the number of quads you are drawing (vertices) but the fill rate which means drawing a quad for each letter is going to be generally faster then drawing these letters into a separate texture and drawing that texture again.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #7
warmi Wrote:It depends, if you are displaying a few simple labels which don't change often then yeah, but if you are displaying text which changes frequently (i.e score numbers or such) then this is going to be way slower.

If I were you I would simply create a font class which holds mappings of each character in your font to a set of uv coordinates and draw your quads directly off of that class.
Much simpler and faster - the problem with 2d drawing is not the number of quads you are drawing (vertices) but the fill rate which means drawing a quad for each letter is going to be generally faster then drawing these letters into a separate texture and drawing that texture again.

That's interesting!

I never thought about creating textures for frequently changing texts (like score, combo etc.). It's all about labels and other static GUI elements.

See, finding the right uv coordinates is not the biggest problem. Finding the Glyphs from a string is much worse.. it's actually going through some maps (dictionaries) which may be very fast but still not as fast as rendering a single texture.. or I'm wrong here?
What could be fast and probably that's the way to go is create a FontString class which will hold a vector of glyphs corresponding to the given font and the string for which it was created. That way we don't need to create a new texture and don't need to search for the right glyphs (uv coordinates in the texture for this font->page) every time. How do you think?

Thanks,
Alex

TapMania - iPhone StepMania // Human knowledge belongs to the world!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Texture2d crash lander ajrs84 0 2,913 Apr 1, 2012 08:54 AM
Last Post: ajrs84
  Problem using Texture2D sub-section bendell 0 2,543 Mar 20, 2010 02:06 AM
Last Post: bendell
  OpenGL ES and Texture2D Talyn 37 32,658 Jul 30, 2009 09:34 AM
Last Post: Splat21
  Texture2d with strings kendric 10 5,612 Jul 14, 2009 09:28 PM
Last Post: warmi
  Texture2D and other transparent objects kappolo 9 6,653 Apr 17, 2009 12:07 PM
Last Post: AnotherJake