D3DXCreateTextureFromFile problem!!!

Started by
7 comments, last by Corrosive 21 years, 7 months ago
Hey guys!! I´m having some problem with this function, I´m trying to load a TGA file and its not working properly... the code compiles everything ok but when i run the program it just enters and leave the program without the image... I need some example of how to use this function, the headers needed, the libs needed and everything that is necessary to declare before the call to this function!!! thank´s. Any help about the TGA problem will be helpful but since i dont explain much the problem i think it will be hard to answer a question like this cya! To code is to make things come to life
To code is to make things come to life ;)
Advertisement
maybe post some code???


"We call em ''natural disasters'' but ''he'' (or she?) calls them memory leaks!!"
Al
**MY HQ**
[size=2]aliak.net
More than likely if the program is exiting abnormally, it has nothing to do with loading the texture. Even If the texture failed to load during the call to D3DXCreateTextureFromFile, the call to set it and render with it would still work (since the texture object pointer would be set to NULL).

If the program works (it doesn''t exit abnormally) and you''re just not seeing the texture being drawn, than either the texture does not exist, you are not specifying the proper path/filename, or you have lighting enabled and no light/material set (other reasons may exist).

It is best if you post a little code, or compare your work to the DX texture tutorial located at Samples\Multimedia\Direct3D\Tutorials\Tut05_Textures\. Try compling that sample using your texture instead and see if it is displayed.





Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
How about some sanity checking, first?

This function requires a valid filename, and a valid device. Those are no-brainers. Trickier are the ''rules'' one has to follow when loading textures directly from file.

1-Is your texture smaller than the max texture width and max texture height that your card can handle?
2-Does your texture have a power of two width, and a power or two height? (Okay, so this shouldn''t prevent loading, it''s still something to worry about ;P)

As was said, check your filename, but also check your card''s caps. Then you may want to load a simple 256x256 bmp file rather than a tga one, until you get your code up to speed.

=^.^=
=^.^= Leaders and teachers should remember: It is best to offer others what they Need, not what they Want.
Here guys.. I will post some code:


  //Direct 3D inicialization...	G.d3dval = G.lpdd->QueryInterface( IID_IDirect3D7,                   (void **) &G.lpd3d);		if(FAILED( G.d3dval))		{			End();			erro("QueryInterface para D3D falhou!");		}	G.lpd3d->CreateDevice (IID_IDirect3DTnLHalDevice,                                     G.lpddBack, &G.lpdeviced3d);	}//My GameMain function to call the D3DXCreateTextureFromFile...        EraseBackground();	G.d3dval = D3DXInitialize();	if (G.d3dval != S_OK)		erro("Erro ao inicializar D3DX!");	G.d3dval = D3DXCreateTextureFromFile(G.lpdeviced3d, 		   NULL, 0, 0,                   (D3DX_SURFACEFORMAT *)D3DX_SF_UNKNOWN,                    G.lpddpal, &G.lpddBack,                   (unsigned long *)1, "c:/programa/legal.tga",                    D3DX_FT_DEFAULT);	if FAILED(G.d3dval)		erro("Não foi possível ler o arquivo TGA!");		Render();//My Render Function...void Render(){while(1) {         G.ddrval = G.lpddPrimary->Flip(NULL, 0);     if(G.ddrval == DD_OK)     {         break;     }     if(G.ddrval == DDERR_SURFACELOST)     {         G.ddrval = G.lpddPrimary->Restore();         if(G.ddrval != DD_OK)         {             break;         }     }     if(G.ddrval != DDERR_WASSTILLDRAWING)     {         break;     } }}  


and guys, i have a GeForce4 TI4600 MSI, i think there is no need to wory about vid caps, at least to test here, of course later i will make some optimization and compatibility mode

To code is to make things come to life


* edit - added source tags - Jim

[edited by - Jim Adams on September 3, 2002 6:18:23 PM]
To code is to make things come to life ;)
Hi, any clue of my problem?

To code is to make things come to life
To code is to make things come to life ;)
Forgive my simplicity, but perhaps you simply don''t have the file in your folder, or maybe you mistyped the file name in your code. I know it sounds dumb, but I''ve done it plenty of times, and when it tries to access the pointer for your texture when you set the texture before drawing, you get booted out.

Another problem, and this goes for a lot of debugging, is track the problem by eliminating parts of code. For example, take out the load texture, so that it stays null, and the set texture to null. If that works, then simply load the texture, and see what happens, then try to set texture to the texture you''ve loaded, and so on. see if you can pinpoint the problem like that.

Simple solutions, but I hope they help,

--Vic--
perhaps show the code where you actually render the texture to something? (when my textures refuse to show up on the screen the first thing i check is did i get my verts right... amazing how many times i forget something stupid (like making sure the camera is pointed at the object you want to render))

Brett Lynnes
cheez_keeper@hotmail.com
Brett Lynnescheez_keeper@hotmail.com
hehe, Maybe you guys will just laught at my face but im newbie with Direct3D and dont have any clue at how i can set a camera...

What i want is just to know how to use this function and what i need to do.. As you can see, the code i already posted is basically DirectDraw and a little Direct3D initializaion... What do i need to put a TGA texture from file in my screen!! I want it to work because i want to make a Map Editor and want TGA files on it!!!

Any help will be welcome.... thanks!

To code is to make things come to life
To code is to make things come to life ;)

This topic is closed to new replies.

Advertisement