Sign in to follow this  

Writing to Texture

Recommended Posts

Ok I have a 256x256 texture of 32bits created like so: pD3DDevice->CreateTexture( 256, //Width 256, //Height, 0, //Level D3DUSAGE_DYNAMIC, //Usage D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pTexture, NULL ); Now I want to write to it: D3DLOCKED_RECT LockedRect; m_pTextureD3D->LockRect( 0, &LockedRect, NULL, 0 ); unsigned32* pTest = (unsigned32*)LockedRect.pBits; for ( unsigned32 j = 0; j < 10; j++ ) { pTest[j] = 0xffff0000; } Basically I want the first 4 "texels" to be red. But for some reason it writes 4 rows. Can anyone help me explain this?

Share this post

Link to post
Share on other sites
Your code is fine. I guess you haven't set up proper texture coords when rendering the texture. 4 rows instead of 4 pixels sound line your texture is stretched vertically, tex.y is possibly zero everywhere.

Bye, Thomas

Share this post

Link to post
Share on other sites
Actually I have the texture coordinates setup correctly:

m_pVLRect->SetPosition( Vector3( 1.0f, 1.0f, 0.0f ), 0 );
m_pVLRect->SetTexCoor0( 0.0f, 0.0f, 0 );
m_pVLRect->SetPosition( Vector3( 2.0f, 1.0f, 0.0f ), 1 );
m_pVLRect->SetTexCoor0( 1.0f, 0.0f, 1 );
m_pVLRect->SetPosition( Vector3( 1.0f, 0.0f, 0.0f ), 2 );
m_pVLRect->SetTexCoor0( 0.0f, 1.0f, 2 );
m_pVLRect->SetPosition( Vector3( 2.0f, 0.0f, 0.0f ), 3 );
m_pVLRect->SetTexCoor0( 1.0f, 1.0f, 3 );

*Ignore the code context, just look at the vertex positions and tex coords. I render this as a triangle strip with 2 primitives.

Share this post

Link to post
Share on other sites
Have you tried writing the texture back out to disk via D3DXSaveTextureToFile()? Can always be a useful way to verify your manipulation.

Could just be the way you've posted your code, but you're creating pTexture but you're locking m_pTextureD3D - is that correct?

You're not checking your HRESULT's (unless you stripped them from the posted code?) - are you sure all function calls are succeeding?

The code you posted doesn't call Unlock() on the texture. Rendering will almost certainly fail and the debug runtime is likely to be screaming and shouting at you about it. Are you using the debug runtimes? If so, what (if any) messages are you getting?


Share this post

Link to post
Share on other sites
jollyjeffers, the mistakes in the posted code isn't in the actual code. I was just in a hurry when I posted. Anyway, the "real mistake" is here:

void VertexListP1TexD3D9::SetTexCoor0( Real32 Tu, Real32 Tv, const MemSize Index )
VertexP1Tex* pData = NULL;
m_pVertexBuffer->GetDataPointer( (void**)&pData );
pData[ Index ].Tu = Tu;
pData[ Index ].Tu = Tv; //look here, stupid me!!!!!

Schrompf was right, tex.y is most likely zero in this case.

Thanks guys.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this