Procedural textures with D3D

Started by
5 comments, last by starstoffe 21 years, 10 months ago
i''m converting one of my old OpenGL programs that uses procedural textures to D3D, but I can''t get my head around how to fill the D3D texture! is it just me or is the DirectX 8.1 SDK helpfiles abit too uncomprehensive? I use D3DXCreateTexture to create an empty texture. where do I go from here? is there no way to just get a plain pointer to the pixeldata? please help! /stoffe
Advertisement
see

IDirect3DTexture8::LockRect, IDirect3DTexture8::UnlockRect
I think you have to call the LockRect() method of the texture or something to get a pointer to the pixel data.
Use the FunctionFill D3DX functions/

Something like:


void MyFill(D3DXVECTOR4 *pOut,
CONST D3DXVECTOR2 *pTex,
CONST D3DXVECTOR2 *pPixSize,
void *mydata)
{
//your produceder here. pOut is your ouput color, pTex->x, pTex->y ar e your noramlized texture coordinates (i.e. 0 to 1).
}

Then call
D3DXFillTexture(MyTexture,MyFill,NULL (or myData if you need it))

Note that the texcoords start in the CENTER of the texel, not 0,0. This function will convert in to any format your texture is, and gets called for every texel at every mip level. There is a Cube and a Volume version as well.

EvilDecl81
thanks for the help everyone! i went with the lockrect version.
it works fine now, though I''m abit puzzled by the fact that the Pitch of the locked rect is 1024 bytes, when my 256 pixels wide texture is in the 24bit format D3DFMT_R8G8B8. shouldn''t the pitch be 768 bytes then?
I think the upper 8 bits is always 256 or 0xFF when using 24bit formats..
The whole point in the pitch is that it may be different from width*bpp. In this case the driver is aligning each line of texels to 1024 bytes to speed things up. You don''t need to worry that the pitch is different from width*bpp, so long as you use it correctly (pData = y*lPitch for each line).

Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)

This topic is closed to new replies.

Advertisement