Sign in to follow this  
Meldinoor

Loading part of a Bitmap

Recommended Posts

Hey,

Could you please be more specific ? What is it you want to do exactly ? Are you willing to transform part of a source bitmap into a Direct3D texture ? If so, you can still check a previous answer that is related to it.
Please let us know.
StratBoy61

Share this post


Link to post
Share on other sites
Yeah, that's pretty much what I'm trying to do, except I'm writing it in C#. I thought there would be some simple function in Direct3D to load part of a bitmap, but I couldn't find it. Until now I've loaded textures using Direct3D.TextureLoader.FromFile but then I wanted to store several textures on the same bitmap file.
I'll try something similar to what you suggested in the other thread, but I'll be thankful for more ideas.

Share this post


Link to post
Share on other sites
Quote:
Original post by Meldinoor
Yeah, that's pretty much what I'm trying to do, except I'm writing it in C#. I thought there would be some simple function in Direct3D to load part of a bitmap, but I couldn't find it. Until now I've loaded textures using Direct3D.TextureLoader.FromFile but then I wanted to store several textures on the same bitmap file.
I'll try something similar to what you suggested in the other thread, but I'll be thankful for more ideas.


From an efficiency point of view, if you have several textures in a single bitmap it may be advantageous to load them all into one texture (if the size is feasible, which I believe these days is a texture about 2048x2048) and use texture co-ordinates when mapping different textures.

This means you can batch larger numbers of primitives since you do not need to keep changing the texture.

In terms of a simpler answer to your question, I know next to nothing about using C# with Direct3D, but if I were approaching this with C++ and Direct3D, I'd consider accessing the relevant surface of the texture, using the surface to get old of a GDI-style device context, using the GDI to load the bitmap and then using GDI calls to CopyRect bits of the source bitmap into your texture surface.

I've never tried that though so I could be rambling nonsense. The approach I've used for loading several bitmaps onto one texture, which is the opposite problem but in some ways similar, has been to lock the texture and directly write pixels from a DIB of the bitmap into the texture memory. If you have specified your pixel format, this is not too painful with C++, but again I can't speak for C#.

Lots of speculative ramblings there. I hope something in the above was of some use [smile].

Share this post


Link to post
Share on other sites
Quote:
Original post by xgalaxy
This depends on what you want exactly. Do you want a new texture resource with just that sub image or do you just want to draw part of an image?


I want a new texture resource. I guess I could just copy the pixels off the bitmap that I want, but I wonder what methods others have used for this. Basically what I'm doing is animations for sprites in a 2D-Isometric game and I determined that loading a large bitmap once and using parts of it for each object's animation frames would be more efficient than repeatedly loading it into memory. Should I simply use for-loops to copy the pixels I want off the original resource?

Meldinoor

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this