   Textures from mulitple images
  Hello, I am having some trouble on the correct way to create textures from more than 1 source image file. The basics of what I am working with is a compiled sprite file made up of about 10,000 32x32 images and DX8 (d3dxsprite). What I would like to do is figure out which tiles i currently need onscreen, pull them from the sprite file (this part is all working), then stick them on a texture. The problem is, I dont know how to put more than 1 image on a texture. The only other option i can really think of is creating a seperate texture for each tile, which sounds rediculous considering there could be 1000 different tiles drawn at any given time. I am looking for a method to do something like '10399.png goes to texture 2 starting at x32/y0' and ive yet to find any information that points me in the correct direction. If this is way off base please feel free to poke fun (after pointing me to the proper information :p)thanks   
  You can combine your images into larger (256x256 maybe) images. Then you just set your texture coordinates to something other than -1.0,-1.0 to 1.0,1.0. For example, if you combined 4 pictures you'd use -1.0,-1.0 to 0.0,0.0 for one of the smaller pictures. Using 256x256 you'd get something like 150 images instead of 10,000 if my math is right.In sprites I believe your draw call takes in a RECT that specifies the portion of a texture to use, so just create a RECT instead of passing in NULL.   ;  Well thats what i am trying to avoid. I would rather have my compiled sprite file and pull the individual images 1 at a time. This makes it extremly simple to change the images when needed and add new ones without having to alter larger images. It also makes the user less able to alter the images used because they are compiled in 1 larger file rather than simple bitmaps that they could open.   ;  Not sure how you'd do this in DirectX, but like OpenGL, you can probably just take the pixel data from all your images and put it in a large enough array, and create a texture from the data contained in the array. You'll need to know the colour depths of the images and so on.   ;  I do this in my engine. I create a large texture to store everything on (The actual size is determined by the maximum available texture size and the amout of texture memory available), then when I load a texture, I copy it onto this larger sheet, and adjust the texture coordinates so it renders properly. I just lock both surfaces and copy the bits directly, but you can use UpdateTexture() as well.   ;  @Evil Steve - I'm trying to do something similar at the moment and was just wondering how you go about deciding where on the texture to put the sprites?Ideally I'd like to be able to load arbirtarily sized images amd have them automatically placed on one large texture, but I am struggling to find a way to organise them on this texture efficiently so not too much space gets wasted.[EDIT] I've just been thinking that if I decided on a minimum multiple size for the images, say 16x16, then created a "map" of the texture, with a bool to mark each 16x16 square as used or not, I could then, when adding a new image, search left-right top-down across the map till I found a free square, then check right and down from that square to see if it was big enough for the image, then if so, put the image in and mark all those squares as used in the map or if not, keep searching across and down.That sounds reasonable but if anyone has any better ideas, they would be appreciated.Thanks[Edited by - EasilyConfused on July 31, 2006 4:14:23 AM];Quote:Original post by EasilyConfused@Evil Steve - I'm trying to do something similar at the moment and was just wondering how you go about deciding where on the texture to put the sprites?Ideally I'd like to be able to load arbirtarily sized images amd have them automatically placed on one large texture, but I am struggling to find a way to organise them on this texture efficiently so not too much space gets wasted.[EDIT] I've just been thinking that if I decided on a minimum multiple size for the images, say 16x16, then created a "map" of the texture, with a bool to mark each 16x16 square as used or not, I could then, when adding a new image, search left-right top-down across the map till I found a free square, then check right and down from that square to see if it was big enough for the image, then if so, put the image in and mark all those squares as used in the map or if not, keep searching across and down.That sounds reasonable but if anyone has any better ideas, they would be appreciated.ThanksYup, that's exactly what I do. The only difference is that I use a DWORD and bitflags to mark a space as used or not. The main sheet is split into 256x256 blocks, and each block can contain 32x32, 64x64, 128x128 or 256x256 sprites, so I can make sure everything fits together nicely.I'll try to remember to post my code when I get home (Although most of it is engine-specific, the general idea is the same).   ;  Coming back to this problem, I seem to be having troubles getting updatetexture to work properly. I can add new tiles to the larger texture, however they ignore my specified rect and are allways placed starting at 0,0. (basically they all draw on top of each other)i seem to be unable to find a single line of sample code using updatetexture also. Short code, but unfortunatly i cant get it working..  m_Texture->AddDirtyRect(&pDirtyRect);  if(FAILED(Graphics->GetDeviceCOM()->UpdateTexture( Texture, m_Texture)))return FALSE;;  dont want this lost in the shuffle just yet ;)   