Advertisement

Creating Textures in Direct3D 7.0

Started by October 14, 1999 12:08 AM
0 comments, last by BriarLoDeran 25 years, 3 months ago
First off, let me say that I am new to Direct3D IM programming. Ok, I have successfully made a 2d square in 3d space, and would like to put a texture on it. This is where I have run into a problem. I have yet to be able to create a working texture map, much less attach it to my square.

I want to take an already created LPDIRECTDRAWSURFACE7 pointer and copy it's info to a texture map. Both the original surface and the new texture map are 64x64.

I define the texture surface as follows (I copied most of this from the DX7 help):

// previously defined
LPDIRECTDRAWSURFACE OriginalSurface;


LPDIRECTDRAWSURFACE7 TextureSurface;

DDSD ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize=sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_TEXTURESTAGE;

ddsd.dwWidth=64;
ddsd.dwHeight=64;
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;

ddsd.ddsCaps.dwCaps2=DDSCAPS2_TEXTUREMANAGE;

lpdd7->CreateSurface(&ddsd, &TextureSurface, NULL);

NOW, I have tried two techniques to put a bitmap on the new surface, both of which didn't work:

1) lpD3Ddevice->Load(TextureSurface, NULL,OriginalSurface, NULL, 0);
// I had the LPD3DDEVICE7 lpD3Ddevice already // defined

2) TextureSurface->Blt(NULL, OriginalSurface, NULL, DDBLT_KEYSRC|DDBLT_WAIT, NULL);

Then later in the main game loop, I try to Blt the TextureSurface to the BackBuffer, however, it doesn't work:

lpddsback->Blt(&DestRect, TextureSurface, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);

So, now that you all have this wonder information, does anyone see what is wrong?
Am I defining a texture surface wrong? Is there a specific way to Blt to a texture surface? Do I have no idea what I am doing?

Thanks in advance,
Briar LoDeran

I don't know if this would work, but you could try and use the Direct3DX function D3DXCreateTextureFromFile(...) to load the texture straight into your LPDIRECTDRAWSURFACE7 interface. I think that it would look something like this:

DWORD flags = 0;
DWORD width = 0;
DWORD height = 0;
DWORD numMips = 0;
D3DX_SURFACEFORMAT sf = D3DX_SF_UNKNOWN;

D3DXCreateTextureFromFile( lpD3DDevice, &flags, &width, &height, &sf, NULL, lpDDSurface, &numMips, "c:\\mytexture.bmp", D3D_FT_LINEAR );

using the flags param. you can set wether or not to create mipmaps, and setting the width and height to 0 causes the function to automatically size the LPDIRECTDRAWSURFACE7 parameter to the size of the texture, the sf parameter is the surface format and D3DX_SF_UNKNOWN tells the function to use the best format for the texture. The numMips parameter is used to tell you how many mipmaps were generated. The D3DX_FT_LINEAR is the filtering that is used on the mipmaps and can also be D3DX_FT_POINT.

By the way you need to include d3dx.h in your program if you are going to use this function, and also link to d3dx.lib.

I hope this helps.

[This message has been edited by Ranok (edited October 14, 1999).]

---Ranok---

This topic is closed to new replies.

Advertisement