DirectX 8.0A and Textures

DirectX 8.0A and Textures

Post by Pete Goodwi » Wed, 07 Nov 2001 20:37:59



I'm still struggling with textures in DirectX 8.0A

I've taken sample code from the SDK, yet nothing seems to work.

I've boiled it down to the simplest example - a box created with
D3DXCreateBox, then I create a texture with
D3DXCreateTextureFromResource which doesn't throw any errors.

However, when I try to use the texture, the object appears shaded in
gray. If I dump the texture and just use material, I can see shading on
the object according to the colour in the material.

The biggest difference I can see is that the samples use objects
created from .X files - I'm using objects created with D3DXCreateBox or
with meshes.

This is what I'm doing to draw the box:

  d3dDevice->SetMaterial(shapeMaterial);

  d3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
  d3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
  d3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESS );
  d3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 0 );
  d3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,  0 );

  d3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
  d3dDevice->SetRenderState( D3DRS_NORMALIZENORMALS, 1 );
  d3dDevice->SetRenderState( D3DRS_DITHERENABLE, 1 );

  if (bTexture)
  {
    d3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER,
    D3DTEXF_LINEAR ); d3dDevice->SetTextureStageState( 0,
    D3DTSS_MINFILTER, D3DTEXF_LINEAR ); d3dDevice-
    >SetTextureStageState( 0, D3DTSS_ADDRESSU,  D3DTADDRESS_WRAP );
    >d3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV,  
    >D3DTADDRESS_WRAP );

    d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,  
    D3DTOP_MODULATE ); d3dDevice->SetTextureStageState( 0,
    D3DTSS_COLORARG1, D3DTA_TEXTURE ); d3dDevice->SetTextureStageState(
    0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); d3dDevice-
    >SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
  }

  if (bTexture)
    d3dDevice->SetTexture(0, shapeTexture);

  shapeMesh->DrawSubset(0);

--
Pete Goodwin
---
(My opinions are my own)

 
 
 

DirectX 8.0A and Textures

Post by Philip Taylor [MS » Thu, 08 Nov 2001 02:11:15


I believe the d3dx object creation routines do not create objects with
texture coords.

retrieve the vertex buffer, several of the samples show how to get the vb
from a mesh, and then you can add whatever vertex elements you require.

--
Phil Taylor
PM : DirectX SDK, Managed DirectX, Windows XP Inbox 3D screensavers, and a
few more bits and bobs.
http://msdn.microsoft.com/directx
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.

Quote:> I'm still struggling with textures in DirectX 8.0A

> I've taken sample code from the SDK, yet nothing seems to work.

> I've boiled it down to the simplest example - a box created with
> D3DXCreateBox, then I create a texture with
> D3DXCreateTextureFromResource which doesn't throw any errors.

> However, when I try to use the texture, the object appears shaded in
> gray. If I dump the texture and just use material, I can see shading on
> the object according to the colour in the material.

> The biggest difference I can see is that the samples use objects
> created from .X files - I'm using objects created with D3DXCreateBox or
> with meshes.

> This is what I'm doing to draw the box:

>   d3dDevice->SetMaterial(shapeMaterial);

>   d3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
>   d3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
>   d3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESS );
>   d3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 0 );
>   d3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,  0 );

>   d3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
>   d3dDevice->SetRenderState( D3DRS_NORMALIZENORMALS, 1 );
>   d3dDevice->SetRenderState( D3DRS_DITHERENABLE, 1 );

>   if (bTexture)
>   {
>     d3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER,
>     D3DTEXF_LINEAR ); d3dDevice->SetTextureStageState( 0,
>     D3DTSS_MINFILTER, D3DTEXF_LINEAR ); d3dDevice-
>     >SetTextureStageState( 0, D3DTSS_ADDRESSU,  D3DTADDRESS_WRAP );
>     >d3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV,
>     >D3DTADDRESS_WRAP );

>     d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,
>     D3DTOP_MODULATE ); d3dDevice->SetTextureStageState( 0,
>     D3DTSS_COLORARG1, D3DTA_TEXTURE );

Device->SetTextureStageState(

- Show quoted text -

Quote:>     0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); d3dDevice-
>     >SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
>   }

>   if (bTexture)
>     d3dDevice->SetTexture(0, shapeTexture);

>   shapeMesh->DrawSubset(0);

> --
> Pete Goodwin
> ---
> (My opinions are my own)


 
 
 

DirectX 8.0A and Textures

Post by Pete Goodwi » Thu, 08 Nov 2001 02:03:40


Answered my own question - why don't textures work?

Answer: because my objects are created as meshes (not loaded .X files)
and don't have texture UV coordinates.

Once I added texture UV coordinates, then the texture would appear.

Now all I need is to figure out how to convert 3DS MAX UVW coordinates
to DX8 UV coordinates.

--
Pete Goodwin
---
(My opinions are my own)

 
 
 

DirectX 8.0A and Textures

Post by Pete Goodwi » Thu, 08 Nov 2001 17:45:36



> I believe the d3dx object creation routines do not create objects with
> texture coords.

> retrieve the vertex buffer, several of the samples show how to get
> the vb from a mesh, and then you can add whatever vertex elements you
> require.

This is very well described in http://www.mvps.
org/directx/articles/spheremap.htm

--
Pete Goodwin
---
(My opinions are my own)