Archived

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

Procedural textures with D3D

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites