Loading raw pixel data on a d3d8 texture

Started by
0 comments, last by MatuX 22 years, 3 months ago
I have been loading pixel data from my own propietary graphical file format in DD7 using Lock and Unlock without any problems, supporting any bit depth and really fast texture loading times. Now we''re using DX8 and the DX8 SDK help says I can''t lock textures in video memory, so, how am U supposed to load textures from my own files in DX8? With further investigation I came to conclusion that I need to create a DX8 surface, lock it, load the image, unlock it and then CopyRect it to the DX8 texture. Isn''t there a way to load my textures right into the DX8 texture without doing any copy stuff?
Advertisement
You can create a texture, get the surface, lock it, load your data, unlock it, and then use it throughout your app without locking it again (unless you really want to)

if (FAILED(m_pD3DDevice->CreateTexture(2, 2, 0, 0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&m_pCheckerTexture)))
return FALSE;

//Set the checker pattern. First get the surface and lock the
//whole rectangle.
m_pCheckerTexture->GetSurfaceLevel(0, &pWorkSurface);
pWorkSurface->LockRect(&WorkRect, NULL, 0);

//set the first 4 bytes to 0xff (white) and
//the second 4 bytes to 0x00 (black), then increment by the pitch
//and so the reverse for the second row. In most cases, the pitch
//will probably be 8, but that''s not guaranteed.
memset((BYTE *)WorkRect.pBits, 0xff, 4);
memset((BYTE *)WorkRect.pBits + 4, 0x00, 4);
memset((BYTE *)WorkRect.pBits + WorkRect.Pitch, 0x00, 4);
memset((BYTE *)WorkRect.pBits + WorkRect.Pitch + 4, 0xff, 4);

//Now unlock the rect and release the surface.
pWorkSurface->UnlockRect();
pWorkSurface->Release();
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials

This topic is closed to new replies.

Advertisement