locked
Direct3D Tutorial (SDK Sampels) Texture Load Question

    Question

  • Hi --

    The SDK samples has a sample Direct3D Tutorial. When I build and run Tutorial 4 it works fine. If I then change (Main.cpp line 324) to use a .dds file instead of the tutorial's texturedata.bin the texture is shifted on the cube by about 15% (and wraps around to the next face). Do you know what should be changed in the tutorial to make .dds work. I see it works in tutorial 5 but I want to understand tutorial 4 and why this bug happens.

    What I did:
    -copy the texture from tutorial 5 to tutorial 4 (reftexture.dds) (also try some dds I made myself).
    -change the load: auto textureData = reader->ReadData("reftexture.dds");

    The texture renders but it is shifted on the cube so that it wraps around the cube.

    Thank you!


    • Edited by mcngraphics Thursday, August 2, 2012 9:32 PM
    Thursday, August 2, 2012 9:31 PM

Answers

  • I see what you did now...

    The .BIN file is the 'naked' pixels without any header information. The code in Tutorial 4 is hard-coded to know exaxctly what the format, pitch, size, and layout of the pixel data is inside the .BIN.

    A .DDS file is more complicated and contains a header, can have multiple surfaces, and lots of other options. Your change to Tutorial 4 just loaded the .DDS file bits directly and assumed it was raw texture data that was 1024 bytes in pitch, DXGI_FORMAT_R8G8B8A8_UNORM format, and 256 x 256 in size.

    Now, if you actually change the code to skip the header bytes (.DDS files have 4 bytes of 'magic' value, 124 bytes of header, and then optionally another 20 bytes of extended header and this particular DDS doesn't contain the extended header), it works but only for this specific file in this speicfic case!

    textureSubresourceData.pSysMem = textureData->Data + 128;
    

    You should make use of the DDSTextureLoader.cpp/.h code to actually load arbitrary .DDS files. That's why Tutorial 5 is calling:

    loader->LoadTexture( L"reftexture.dds", &m_texture, &m_textureSRV );
    

    Using a little 'header dump' tool I have for DDS files, the REFTEXTURE.DDS header contains the following information:

    DDS ..\..\media\reftexture.dds
    Flags 00021007: CAPS HEIGHT WIDTH PIXELFORMAT MIPMAPCOUNT
    256 x 256
    Pitch: 0
    Mipmap count: 9
    Surface flags: 0040100a: COMPLEX TEXTURE MIPMAP ALPHA
    PIXELFORMAT: 00000041: ALPHAPIXELS RGB
    bitCount 32
    R: 00ff0000 G: 0000ff00 B: 000000ff A: ff000000

    For more information on DDS files, see MSDN and http://blogs.msdn.com/b/chuckw/archive/tags/dds/

    Thursday, August 23, 2012 12:16 AM

All replies

  • What error message did you get?

    NEU_ShieldEdge

    Tuesday, August 7, 2012 8:05 AM
  • Hi -- there is no error message and the code runs fine. The problem I see is that the .dds texture is shifted about 10% on the cube so it does not lay correctly on the cube. So for example I run Tutorial4 with the it's texturedata.bin texture and it works fine. Then I replace texturedata.bin with a dds (I just got reftexture.dds from tutorial 5 folder) and it shifts (as does any .dds I try). So I wonder what is it about the code in Tutorial 4 that causes this shifting of .dds textures?


    • Edited by mcngraphics Tuesday, August 7, 2012 3:20 PM
    Tuesday, August 7, 2012 3:18 PM
  • Check the texture coordinates and the sampler modes.
    Tuesday, August 14, 2012 9:41 PM
  • Hi --

    I checked the texcoord and sampler...

    • I replaced the sampler in tutorial 4 with that of tutorial 5
    • The textcoords are the same for both tutorials


    I still can't determine why the problem is there.

    Recap of the behavior:
    Using tutorial 4... if I replace the .bin texture with a .dds texture (reftexture.dds from tutorial 5 or any other 256x256 .dds texture) the texture is shifted on the cube.

    What I did:

    • copy the texture from tutorial 5 to tutorial 4 (reftexture.dds) (also try some dds I made myself)
    • change the load: auto textureData = reader->ReadData("reftexture.dds");

    Attached is an image showing the problem...
    Notice the texture maps correctly in one direction but not the other.



    • Edited by mcngraphics Wednesday, August 22, 2012 9:07 PM
    Tuesday, August 21, 2012 3:36 AM
  • I see what you did now...

    The .BIN file is the 'naked' pixels without any header information. The code in Tutorial 4 is hard-coded to know exaxctly what the format, pitch, size, and layout of the pixel data is inside the .BIN.

    A .DDS file is more complicated and contains a header, can have multiple surfaces, and lots of other options. Your change to Tutorial 4 just loaded the .DDS file bits directly and assumed it was raw texture data that was 1024 bytes in pitch, DXGI_FORMAT_R8G8B8A8_UNORM format, and 256 x 256 in size.

    Now, if you actually change the code to skip the header bytes (.DDS files have 4 bytes of 'magic' value, 124 bytes of header, and then optionally another 20 bytes of extended header and this particular DDS doesn't contain the extended header), it works but only for this specific file in this speicfic case!

    textureSubresourceData.pSysMem = textureData->Data + 128;
    

    You should make use of the DDSTextureLoader.cpp/.h code to actually load arbitrary .DDS files. That's why Tutorial 5 is calling:

    loader->LoadTexture( L"reftexture.dds", &m_texture, &m_textureSRV );
    

    Using a little 'header dump' tool I have for DDS files, the REFTEXTURE.DDS header contains the following information:

    DDS ..\..\media\reftexture.dds
    Flags 00021007: CAPS HEIGHT WIDTH PIXELFORMAT MIPMAPCOUNT
    256 x 256
    Pitch: 0
    Mipmap count: 9
    Surface flags: 0040100a: COMPLEX TEXTURE MIPMAP ALPHA
    PIXELFORMAT: 00000041: ALPHAPIXELS RGB
    bitCount 32
    R: 00ff0000 G: 0000ff00 B: 000000ff A: ff000000

    For more information on DDS files, see MSDN and http://blogs.msdn.com/b/chuckw/archive/tags/dds/

    Thursday, August 23, 2012 12:16 AM
  • Hi --

    Ahhhh I am so glad to now understand what is happening -- I really appreciate the time you took to explore this and to explain it!!!

    Thank you!

    Thursday, August 23, 2012 2:46 PM