Loading only part of an image to a texture?

Started by
5 comments, last by RelisH 22 years, 3 months ago
It''s me again, with another newbie question. Anyway, how would I go about loading only one part of an image into a texture. For example, if I had a 64x32 bitmap, and wanted to load only the 32x32 rectangle covering the left half of the bitmap. Also, is it possible to do something similar with SetTexture()? What I mean is would it be possible to only set the texture to only half a 64x32 texture resource that was loaded? Thanks in advance!
-RelisH!
Advertisement
I think you would have to modify the mesh tu,tv values for the verticies? Why would you want to only display part of the texture to the mesh?
maybe if he was animating the face. having a bitmap with multiple textures in it is actually pretty damn useful.

as sdoherty55 said, you would modify the texture coordinates of the vertices. to get the coordinates of the texture for where you want to display it, use this formula:

(float)frame_x / (float)tex_width; for left side
((float)frame_x + (float)frame_width) / (float)tex_width; for right side
(float)frame_y / (float)tex_height; for top side
((float)frame_y + (float)frame_height) / (float)tex_height; for bottom side

if you know how to set up texture coordinates with your vertices, then plug the results to those in there and it should display properly. if not, e-mail me at david@neonstar.net and i''ll help you figure it out.

dave

--
david@neonstar.net
neonstar entertainment
--david@neonstar.netneonstar entertainment
Yeah I thought about tinkering with texture coordinates, but I was worried about efficiency. Perhaps I should verify, if I have a large texture (say 1024x1024) and then do set texture and only apply texture coordinates that use maybe a 16x16 region of it, would it be much slower than using a 16x16 which contains the same thing the 16x16 square from the big texture?

What I''m trying to create is a "special effects font" engine, which would display nicer looking text (compared to the regular 2d fonts which would render much faster but dont look at nice), I was thinking about loading a large character image file which would contain all of the characters and then pick out parts.

-RelisH!
well, i dunno how it works as far as efficiency goes. well, actually, it would probably be much more efficient to just use one texture and pull coords from it. switching textures for each character in a string of text isn''t very efficient, i assure you.

currently, my font engine loads the characters from a bitmap file and creates separate textures for each character it loads. this isn''t the most efficient way to do it, though. i just ripped the code from my sprite animation system to handle creating the frames and such. if you do go the "texture-per-character" route, make sure you create a texture size that is an exponent of 2, or you will have hell trying to get the characters to display right. just remember to calculate the tex coords like i showed you before.

now that i think about it, you''re gonna have to use funky tex coords either way if you want characters that have sizes that aren''t exponential to 2. your best bet is to just have one big texture. that would be the most efficient way, i''m sure.

once again, if you need some help, e-mail me.

dave

--
david@neonstar.net
neonstar entertainment
--david@neonstar.netneonstar entertainment
Keep in mind that not all graphics cards will do texture as large as 1024 by 1024. Not sure your target audience?
I was just using that as an example. I think I know what to do now, but I need to know how to chop one large texture (like a character bitmap) into small textures which would be for each character.
I don''t want have 100 little files, since creating that would take forever. Instead, I want to load one large file, and then load it into textures
-RelisH!

This topic is closed to new replies.

Advertisement