Can't Load Textures

Started by
11 comments, last by dawoodr 9 years, 4 months ago

Hello!

Well as the title states, I am failing to load textures. I am following this guide http://www.braynzarsoft.net/index.php?p=D3D11TEXTURES. However I am on windows 8 so I am not using the "D3DX11CreateShaderResourceViewFromFile()" function instead I download the DirectXTK from here http://directxtk.codeplex.com/ and now I am trying to use the following function "CreateWICTextureFromFile()" which is described here http://directxtk.codeplex.com/wikipage?title=WICTextureLoader&referringTitle=Home

However when I run the program nothing is being drawn on my windows, it's only white, and I am getting no errors whatsoever. I am assuming that I am writing the following function wrongly "CreateWICTextureFromFile()". However I don't know what's wrong. You can find my entire project here http://pastebin.com/QrukNBUi

Any help is greatly appreciated!

Regards!

Advertisement

I doubt anyone is going to dig into your whole project and debug the issue for you. Generally speaking, when you are asking for help you should let us know what you have already checked. Is there return codes for the function you are using? Did you step through the function call and see what is going on inside? Have you used the graphics debugger to see what is happening from the API point of view? These are all things you can try for yourself, and then if you still can't find an answer you can post here and tell us what you see.

I don't mean to come off as harsh - but honestly I hope you try to solve the issue on your own before posting. You will learn much faster, and will need to post questions less frequently. If you really do get stuck, the forums are always here to help you out...

I solved a part of it, now my cubes are atleast being drawn but they are black, so like I said before I think I am writing this particular line wrongly "hResult = CreateWICTextureFromFile(device, L"C:\\Users\\Dawood\\Documents\\Visual Studio 2013\\Projects\\D3\\melones.jpg", NULL,&cubesTexture, NULL);"

but I don't know what is wrong, so if you could look at the following link http://directxtk.codeplex.com/wikipage?title=WICTextureLoader&referringTitle=Home and tell me what I am writing wrong it would be of help.

Use single slashes: C:\\Users/Path/to/image.jpg

Edit: Correction.

I don't think that is the issue since I am loading my shader that way and it is working fine, hwoever I tried it anyway and it didn't work.


I think I am writing this particular line wrongly "hResult = CreateWICTextureFromFile(device, L"C:\\Users\\Dawood\\Documents\\Visual Studio 2013\\Projects\\D3\\melones.jpg", NULL,&cubesTexture, NULL);"

If that line compiles and links without error, (assuming cubesTexture is ID3D11ShaderResourceView*) and hResult returns S_OK, that should be fine.

EDIT: More tough love - as Jason Z suggests, you're much more likely to get the help you need if you do some debugging on your own. I.e., rather than asking what's wrong with your code, think about asking how to determine what's wrong with your code. Those are two very different questions, and a change in the purpose of posting. In that regard, you may want to look into following the data as a method to finding areas of code that are causing the problems you see.

N.B., that debugging method will require you to know what your code is supposed to, and how it's supposed to do it, every step along the way. If you take that leap in your programming attempts, you will spend less time debugging, and more time enjoying satisfactory results.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I don't think that is the issue since I am loading my shader that way and it is working fine, hwoever I tried it anyway and it didn't work.

Sorry, I thought this could be a problem, but Windows seems to understand double backslashes. But you could use single ones or even slashes (/), it would save some seconds of your life...

Most common problem is that the image doesn't have a supported format.

I would recommend to use the dds texture loader. It is faster (and it works), I use it too. You can create dds textures with a (free) GIMP plugin. Choose RGBA8 (this should be the right format, but I'm not sure) when exporting the dds file. Plugin link: https://code.google.com/p/gimp-dds/

I don't think that is the issue since I am loading my shader that way and it is working fine, hwoever I tried it anyway and it didn't work.

Sorry, I thought this could be a problem, but Windows seems to understand double backslashes. But you could use single ones or even slashes (/), it would save some seconds of your life...

I don't know how Windows reacts to double backslashes, but I can imagine it will simply strip them as if they were a single backslash.

However, that is not important here, because the double backslashes have entirely different meanings in this context: a backslash in C and C++ strings literals, as well as in many other languages, is an escape character to insert special characters into a string. For example, the sequence "\n" compiles to a line break character, not a backslash followed by the letter 'n'. Likewise, "\t" is replaced by a tab character and not a backslash and a 't'.

Consequently, to insert a backslash into a string, you have to insert the escape sequence "\\” that will be compiled into a single backslash character in the final string. Your paths need double backslashes in the source code, so that your strings contain single backslashes.

Or, better yet, use forward slashes exclusively as you rightfully suggested.

Hi. Check you light all black the light may be behide or under the object.
*facepalm* Sorry, I forgot that you have to use \\ in a string to insert a backslash. Why am I so stupid?

However, use slashes (/) and relative instead of absolute paths for compatibility with other computers and other operation systems. I don't know if linux understands \, but it will understand /.

Have you set the texture as shader resource? Use ID3D11DeviceContext::PSSetShaderResources() for that.

Check if CreateWICTextureFromFile returns 0 (S_OK).

Try sampDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; instead of never.

This topic is closed to new replies.

Advertisement