Loading large images on a Voodoo card

Started by
16 comments, last by Biberpelztrompete 22 years, 8 months ago
Hiya, can someone please tell me how to load a 800x600 background image into a texture ? Voodoo card support only 256x256 textures. So I think I have to split it up. But how to ? Thanx for your help
Advertisement
Splitting is the optimal answer. You could also just load it onto a surface and use CopyRects but that it slow. For the texture splitting here is what I do.

1. Read image size
2. Create surface that size
3. D3DXCheckTextureRequirements() to get max texture size
LOOP through as many tiles as needed
{
4. Create texture
5. GetSurfaceLevel() to get top surface
6. CopyRects from image surface to texture
7. Release texture surface
}

8. Release image surface

Jack
Thanx,
but may I ask how you want to read the images size ? The file can be a BMP a JPG .. whatever. I could''t find a function that simply reads the dimensions and the D3D_FORMAT ?
I used a fixed value to load the surface and it loads the image properly now. This is what i did :


lpD3DDevice->CreateImageSurface(800,600,D3DFMT_R8G8B8,&tempSurf);

res = D3DXLoadSurfaceFromFile(tempSurf,NULL,NULL,filename,
NULL,D3DX_FILTER_NONE,0xFFFFFFFF,&info);
if (FAILED(res)) return res;

pSprite->height = info.Height;
pSprite->width = info.Width;
pSprite->tex_row = INT(info.Width / 256)+1;
pSprite->tex_num = (INT(info.Height / 256)+1) * pSprite->tex_row;
pSprite->pTex = (LPDIRECT3DTEXTURE8 *)malloc(sizeof(LPDIRECT3DSURFACE8)*pSprite->tex_num);

for (int i=0;itex_num;i++)
{
res = D3DXCreateTexture(lpD3DDevice,256,256,1,0,info.Format,D3DPOOL_MANAGED,&tempTex);
if (FAILED(res)) return res;

tempTex->GetSurfaceLevel(0,&texSurf);
if (FAILED(res)) return res;

rc.left = (i % pSprite->tex_row) * 256;
rc.top = (i / pSprite->tex_row) * 256;
rc.right = rc.left + 255;
rc.bottom = rc.top + 255;

res = lpD3DDevice->CopyRects(tempSurf,&rc,0,texSurf,&point);
if (FAILED(res)) return res;

texSurf->Release();
}
I forgot to say that the code doesnt work anyway. the CopyRects() function returns D3DERR_INVALIDCALL and I can''t figure out why. If you do please let me know b/c this function angers me for about 3 days.
If the video card only supports 256x256 textures, then you should resize any textures to those dimensions. If your doing 2D blitting with a large texture, then do just that, a DirectDraw blit, and video cards can hold anysize 2D image (including voodoos). If you trying to load a large texture to put on a polygon, then limit the textures to the cards maximum size, otherwise for example, say you want to load a 512x512 texture, that would require it be split into 4 256x256 textures, and thus you would need to break up your polgon into 4 seperate polygons and call 4 DrawPrimitives, instead of just 1 as you intended with the 512x512 texture.

Possibility
Yeah thats exactly what I''m planning to do. I posted my splitting routine, but it doesnt work atm. I cant use a DD Blit anymore b/c I''m using DX8 now and DX8 doesn''t support DDraw routines any longer. So I need to load the files as textures.
I couldn''t find anyway to read the dimensions either so I create a small temp surface, then load the image onto it, read the param that shows the original image file size, release the temp surface and go from there.

As for CopyRects, one problem is your third param is 0 when it should be one for the number of rectangles -- I also don''t see you setting the points structure to x = 0; y = 0;


Possibility: the only way to do 2d bltting with DX8 is CopyRects and it is very slow. How I know: I tried it this week. My fps went from 36 to 30 with one 800x128 surface. When done as textures it has no noticable cost. In addition it is totally lacking in rotation, scaling, color format conversion, alpha, and just about everything else.

Jack
Yeah, I know that
I''m using CopyRects only to split up the large images into smaller ones. Then I draw them with ID3DXSprite.Draw. This function is really good.
I tried to set the 3.parameter to 1 and I defined point but still it doesn''t work. Someone who posted in this forum had the same problem and he said that ( in his opinion ) Voodoo cards do not allow CopyRects() and so they always return D3DERR_INVALIDCALL. I can''t think of anything else. Maybe you do.
Well I have personally run my code on a Banshee and it works...

Jack

This topic is closed to new replies.

Advertisement