HOWTO: Animate Textures in Direct3D Immediate ModeLast reviewed: September 5, 1997Article ID: Q153158 |
The information in this article applies to:
SUMMARYA texture in Direct3D immediate mode is stored in a DirectDraw surface with the DDSCAPS_TEXTURE flag set in the dwCaps field of the ddsCaps structure. Since the textures are stored in DirectDraw surfaces, you can alter the bits in these surfaces to perform texture animation in your Direct3D applications. To make changes to the pixels in a texture, you would lock down the DirectDraw surface associated with that texture with Lock() and then you would make the changes necessary. You would then load the revised texture on the video card when 3D hardware is used with IDirect3DTexture::Load(). The next time the execute buffer is executed with IDirect3DDevice::Execute(), the revised texture will be used when rendering.
MORE INFORMATIONIt is important to create a source texture DirectDraw surface in system memory and a destination DirectDraw surface (in video memory, if 3D hardware is present). The source surface should be created with the DDSCAPS_TEXTURE flag set and it should be created in system memory. The destination texture surface should be created with both the DDSCAPS_TEXTURE and DDSCAPS_ALLOCONLOAD flags set. The destination surface will created initially empty. You should call QueryInterface() on both the source and destination textures to get the IDirect3DTexture interface for the texture surfaces. After you have loaded the source texture surface with the bitmap data desired, you should call the destination texture's IDirect3DTexture::Load() method, specifying the source texture, to load the texture onto the destination surface. You can now call the destination texture's IDirect3DTexture::GetHandle() method to obtain a Direct3D texture handle to be used in the execute buffer. When you are done with your texture animation and these textures and surface are no longer required, you should call Release() on the source and destination textures as well as the source and destination surfaces. The following five steps describe how to implement texture animation in a rendering loop for a Direct3D immediate mode application:
Sample CodeHere is a code example to implement the steps above:
lpTexture->lpVtbl->Unload(lpTexture); ddsd.dwSize = sizeof(ddsd); if (lpSrcTextureSurf->lpVtbl->Lock(lpSrcTextureSurf, NULL, &ddsd, DDLOCK_WAIT, NULL) == DD_OK) { lpDst = (BYTE *)ddsd.lpSurface; // Modify the surface with the new texture bitmap. lpSrcTextureSurf->lpVtbl->Unlock(lpSrcTextureSurf,NULL); } lpTexture->lpVtbl->Load(lpTexture, lpSrcTexture); lpTexture->lpVtbl->GetHandle(lpTexture, lpDev, &TextureHandle); if (lpDev->lpVtbl->BeginScene(lpDev) != D3D_OK) return FALSE; if (lpDev->lpVtbl->Execute(lpDev, lpD3DExBuf, lpView, D3DEXECUTE_UNCLIPPED) != D3D_OK) return FALSE; if (lpDev->lpVtbl->EndScene(lpDev) != D3D_OK) return FALSE; Keywords : Direct3D Technology : kbDirectXSDK Version : WINDOWS:4.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |