Jump to content
  • Advertisement
Sign in to follow this  
tariq9112003

Cant use CreateTextureFromFile() function

This topic is 3060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys , small problem...i use visual 2010 ..i get an error in my CreateTextureFromFile() function call where you write the image file name ...this error is thrown



1 IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR"

this is my function call
D3DXCreateTextureFromFile(d3ddev, "dx5_logo.bmp", &Tex);

My Solution Explorer has no folder for images also.i am so lost

Share this post


Link to post
Share on other sites
Advertisement
That error you're getting is because of the fact that VS 2010 uses Unicode. That is, it uses wide strings, while you are using regular ones.
You won't get any errors if you put an L in front of "dx5_logo.bmp". Like so:

D3DXCreateTextureFromFile(d3ddev, L"dx5_logo.bmp", &Tex);

Or, if you don't want to use Unicode you can disable it by going to your project properties and set the character set to No Character Set or Multibyte.

Share this post


Link to post
Share on other sites
In addition, you might want to read this article, specifically the section on wchar_t*.

While L"dx5_logo.bmp" works in the above hard coded example, it will help to understand the difference between chars and wchars. What if you want to store your texture file names in a class? Well, you'll have something like


// In your header.
...
private:
std::string m_TexFilename;
...




// In your source.
HRESULT foo()
{
...
// Your compiler will generate that same error or one that is extremely similar.
hr = D3DXCreateTextureFromFile(d3ddev, m_TexFilename.c_str(), &Tex);
...
}



This is when a more complete understanding of windows' characters will come in handy as you will have to convert between different types.

Share this post


Link to post
Share on other sites
Thanks guys..that helped..but when i compile the image never shows up i know i haven't included the image properly in the project..how do i add an image to the project(in xna i could just drag my image to the images folder of solution explorer here in d3d i cant)

Share this post


Link to post
Share on other sites
Firstly, I advice you to write the full image path (just for testing):

D3DXCreateTextureFromFileA(d3ddev, "C:\\Folder1\\dx5_logo.bmp", &Tex);

If you see the texture in your game, that's because there is a problem of import
If you don't see the texture, it's because there is an other problem

it's important that you take the HRESULT :

HRESULT res = D3DXCreateTextureFromFileA(d3ddev, "C:\\Folder1\\dx5_logo.bmp", &Tex);

res contains a lot of informations : http://msdn.microsoft.com/en-us/library/bb401631.aspx

Share this post


Link to post
Share on other sites
You're creating the texture every frame and never releasing it, you're probably running out of memory, causing D3DXCreateTextureFromFile() to fail.

Either Release() the texture at the end of your render loop, or - preferably - create it once at startup, and Release() it at cleanup time.

Share this post


Link to post
Share on other sites
Take one thing at a time. "still doesn't work" is too little to help you with.

After you create your device, create a texture from file. Get that working before you do anything else to your code.

#include "dxerr.h"
#pragma comment(lib,"dxerr.lib")
//... after device created...
HRESULT hr;
hr = D3DXCreateTextureFromFile(d3ddev, "c:\\folder1\\dx5_logo.bmp", &Tex); // whatever your full path to the file is
if( FAILED(hr) )
{
MessageBox(NULL,DXGetErrorDescription(hr),"Failed to load texture",MB_OK);
}
else
{
MessageBox(NULL,"Texture loaded successfully","Load Success!",MB_OK);
}

At least get some information to work with. When you get that working, we'll go from there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!