Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / CreateTexture DX9 not working right? No clue? Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
terence tan

May 26, 2005, 01:52 AM

I am trying to load data straight into a newly created texture. But it doesn't seem to be working out right. I am not sure if the addressing is being done correctly because even when I set the RGB value to 255,0, comes out red partially on the model, some area done even get textured. BTW..its supposed to be converting a PCX file into a texture for my md2 loader.

  2.         // Create a texture and copy Image into surface
  3.         hResult = D3DXCreateTexture(g_pDirect3DDevice,wWidth+1,wHeight+1,
  4. 3DX_DEFAULT,0,
  5. D3DFMT_A8R8G8B8,
  6. D3DPOOL_MANAGED,&pTexture);
  8.         if (FAILED(hResult))
  9.         {
  10.                 fclose(fp);
  11.                 return -1;
  12.         }
  14.         pTexture->GetSurfaceLevel(0,&texSurface);
  16.         texSurface->LockRect(&texRect,NULL,0);
  18.         pData = (DWORD*)texRect.pBits;
  20.         for (y=0; y<=wHeight; y++)
  21.                 for (x=0;x<=wWidth;x++)
  22.                 {      
  23.                         //pData[ y * (texRect.Pitch/4) + x] = D3DCOLOR_ARGB(0,255,0,0);
  25.                         pData[ y * (texRect.Pitch/4) + x] = D3DCOLOR_ARGB(0,
  26.                         palette[ indexdata[x+y*(wWidth+1)]],                            // R                   
  27.                         palette[ indexdata[x+y*(wWidth+1)]] + 1,                // G
  28.                         palette[ indexdata[x+y*(wWidth+1)]] + 2);               // B
  29.                 }
  31.         texSurface->UnlockRect();

Erik Faye-Lund

May 26, 2005, 06:08 AM

try something like:

palette[ indexdata[x+y*(wWidth+1)] + 1]

instead of:

palette[ indexdata[x+y*(wWidth+1)]] + 1

you see, you're just adding one to the red component, not looking up the green component like you should.

oh, and also take the surface-pitch into account.

terence tan

May 26, 2005, 08:11 AM

Yeah that was a typo, but it didn't fix anything.

The texture are still off.

When I set the texture all red(I commented that code part out), the red comes out but part of it is missing(the back part of the texture).
is what it looks like

I loaded a tga image via CreateTextureFromFile and it looks ok(i converted the texture from pcx to tga).

I am using the pitch correctly I think since pData is a dword..i should calculate the position =(y * Pitch/4)+x

Erik Faye-Lund

May 26, 2005, 02:37 PM

> I am using the pitch correctly I think since pData is a dword..i should calculate the position =(y * Pitch/4)+x

ah, yes. for some silly reason i misread your post, sorry 'bout that ;)

is there a good reason why you're not using D3DXLoadSurfaceFromMemory() ?


May 28, 2005, 12:47 AM

Probably stupid question, but did you actually decompress the pcx before copying the data?

terence tan

May 28, 2005, 12:15 PM


I did. It's RLE encoded. I should write a better PCX routine..but for now it should do.

My 'biggest' problem is there is something wrong with the texture. I know I should just create a few vertexes and slap the texture on it to see..but the model seems to be textured wrong already...

When I set the texture piece to all red..and the model get's textured it should come out all red? But the model when textured leaves a big black part on the back part..see previous pictures...


May 29, 2005, 12:33 AM

Er.. is the pcx sized with a power of 2 or similar?
D3DXCreateTexture will actually give you a bigger surface than you asked for if the card doesn't support the true size of the image.

I'm not sure about the default behaviour, if it stretches the image data or just fills the right and bottom with black.
You should try to display a simple quad with the texture to see how it really looks like.

terence tan

May 29, 2005, 04:39 AM


That was it. It was changing the size of the surface. Another 'AHA'.

As a side not it returned a texture size of 512 x 256...aren't textures usually square 512 x 512? or is it hardware specific or am I just making things up as I go along.

DirectX so far fills it the blank part with black if you wanted to know.


May 30, 2005, 01:21 AM

In the beginning of 3d acceleration textured had to be square on most (all?) cards. Some cards are allowing non-square but still power-of-2 sized textures. Some now allow any size, but usually power of 2 is the best for speed.

The caps of the card tell you if it can do square only or power of 2 or any size. Just don't rely on any of those features.

Up till now i still put everything on 256x256 textures and never run into any trouble regarding texture size.

terence tan

May 30, 2005, 09:49 AM


I am probably better off using D3DXLoadSurfaceFromMemory...been thinking ...if CreateTexture resizes the texture won't the uv coordinates be off? Cause the uv coordinates expect to use the entire texture.

Lets say my pcx file was 320x200 and I copied that into a 512x256 texture...there would be a blank spot right and bottom..

This thread contains 10 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.