Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

RelisH

Loading only part of an image to a texture?

This topic is 6199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!