Archived

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

How to load raw texture data??

This topic is 5672 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

Hi, I have to make lightmap textures from some data I have stored in a cubic array of bytes, but I'm uncertain which command I should be looking to use to fill an empty texture with information in this raw form. I would like to understand how to use the fill texture function as I think it's the most appropriate function for the job going by what I've read. I'm confused though how I'm supposed to set up my 'user defined function' to fill the texture.
      
D3DXFillTexture
Uses a user-provided function to fill each texel of each mip level of a given texture.

HRESULT D3DXFillTexture(
  LPDIRECT3DTEXTURE8 pTexture,
  LPD3DXFILL2D       pFunction,
  LPVOID             pData
);

Parameters
pTexture 
[out, retval] Pointer to an IDirect3DTexture8 interface, representing the filled texture. 
pFunction 
[in] Pointer to a LPD3DXFILL2D user-provided evaluator function, which will be used to compute the value of each texel. 
pData 
[in] Pointer to an arbitrary block of user-defined data. This pointer will be passed to the function provided in pFunction. 
Return Values
If the function succeeds, the return value is D3D_OK.

If the function fails, the return value can be the following values.

D3DERR_INVALIDCALL 


Requirements
  Header: Declared in D3dx8tex.h.
  Import Library: Use D3dx8.lib.

LPD3DXFILL2D
Function type used by the texture fill functions.

VOID (*LPD3DXFILL2D)(
  D3DXVECTOR4* pOut,
  D3DXVECTOR2* pTexCoord,
  D3DXVECTOR2* pTexelSize,
  LPVOID       pData
  );

Parameters
pOut 
[out] Pointer to a vector, which the function uses to return its result. X, Y, Z, and W will be mapped to R, G, B, and A respectively. 
pTexCoord 
[in] Pointer to a vector containing the coordinates of the texel currently being evaluated. Texture coordinate components for texture and volume textures range from 0 to 1. Texture coordinate components for cube textures range from -1 to 1. 
pTexelSize 
[in] Pointer to a vector containing the dimensions of the current texel. 
pData 
[in] Pointer to user data. 
Requirements
  Header: Declared in D3dx8tex.h.

See Also
D3DXFillTexture Requirements
  Header: Declared in D3dx8tex.h.
See Also
D3DXFillTexture

      
Now thats what the SDK says about the function and the user defined function, but as i can find no sample code anywhere using this user defined function I'm a little confused as to how to make it. I tried setting up my own function as I assumed it should work but got something (very roughly) along the lines of "cannot convert void (_D3D_STRUCT)(D3DXVECTOR4* pOut...... etc to void (*_cdecl) ((_D3DSTRUCT)DD3DXVECTOR4* pOut....... etc" the "(*_cdecl)" bit being what I see as the important part of the error as the rest of it was identical and should therefore I guess have been set up fine. My data is stored in this format byte pImageBits[128][128][3]; the data held is for a 24-bit 128x128 texture representing a lightmap stored in a quake 3 *.BSP file. So can anyone perhaps give me a rough idea of how to set up my functions to fill the texture with this raw data using the mentioned function (or another way if this is not the best), or point me in the direction of a good sample of how to do so. I have looked on google to try to find help, but aside from the SDK I have only seen sample code that was commented in some foreign language therfore it was no help at all (though I tried setting my function up as his code was and got that error.) thanks for any help, Steve [edited by - mephs on June 27, 2002 12:05:57 AM] [edited by - mephs on June 28, 2002 4:29:10 AM]

Share this post


Link to post
Share on other sites
I''ve never used the D3DXFillTexture function, but for my light map generation I just locked the surface and did all the processing myself in one go.

I''d imagine this is whats happening in the utility function too.

Share this post


Link to post
Share on other sites
Okay well I've figured out how to write to the surface using the lock texture function but I'm finding that no matter how I set up my pointer, the texture for the lightmap is being distorted.

      
// Read in the RGB data for each lightmap

fread(&pLightmaps[i], 1, sizeof(tBSPLightmap), fp);

// Create a 128 x 128 24-bit texture

if(FAILED(D3DXCreateTexture(m_Graphics->GetDevice(), 128, 128,0,0,D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &m_lightmaps[i])))
PostQuitMessage(0);

// Grab a texture surface to draw our lightmap on

IDirect3DSurface8 *TextureSurface;

if(FAILED(m_lightmaps[i]->GetSurfaceLevel(0, &TextureSurface)))
PostQuitMessage(0);

D3DLOCKED_RECT pLockedRect;
RECT rectangleToLock;
rectangleToLock.top = 0.0f;
rectangleToLock.left = 0.0f;
rectangleToLock.bottom = 128.0f;
rectangleToLock.right = 128.0f;


// Lock the entire 128 x 128 surface

if(FAILED(TextureSurface->LockRect(&pLockedRect,NULL,0 )))
PostQuitMessage(0);

// A Pointer to the buffer

DWORD* pData = (DWORD*)(pLockedRect.pBits);

for(int q = 0; q<128; q++) {
//memcpy ((void *)pLockedRect,pLightmaps[i].imageBits,sizeof(pLightmaps[i].imageBits)Pitch);

for(int p = 0; p<128; p++) {
// Copy the lightmap RGB data from the array into the appropriate place in memory for this surface

pData[q+(p*(pLockedRect.Pitch)/4)] = D3DCOLOR_XRGB(pLightmaps[i].imageBits[p][q][0],pLightmaps[i].imageBits[p][q][1],pLightmaps[i].imageBits[p][q][2]);
}
}


if(FAILED(TextureSurface->UnlockRect()))
PostQuitMessage(0);
TextureSurface->Release();

}


Thats my function to turn the data into a lightmap, and heres is how the texture turns out once lightmapping is applied (and yes my multitexturing is working fine (tested with a loaded texture file previously)


Part of the trouble I believe may be in that the texture supposedly is a 24 bit texture, wheras Direct3D isnt as good at dealing with 24 bit textures so I had to create a 32 bit texture (you can't cast the locked surface into a 24-bit pointer only 32 or 16)

[edited by - mephs on June 28, 2002 11:39:10 AM]

[edited by - mephs on June 28, 2002 11:43:52 AM]

Share this post


Link to post
Share on other sites
Ahh, never mind...



yaay me again

fixed it with a bit of bitshifting

Share this post


Link to post
Share on other sites
I have the same problem, with my program (i''m working on a simple BSP Viewer that read Quake 3 level).
Can you post the working function to read lightmaps?
Thanks.

Share this post


Link to post
Share on other sites