Jump to content
  • Advertisement
Sign in to follow this  
Dhaos

[FIXED!] Using over 8 textures in direct 3d

This topic is 4577 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

problem solved, thanks again everybody =3 [Edited by - Dhaos on May 6, 2006 10:30:35 PM]

Share this post


Link to post
Share on other sites
Advertisement
I'm pretty sure that the "8 texture limit" is for multi-texturing. You can easily load and use more than 8 textures per scene.

Are you doing it like this?

SetTexture( 0, SomeTexture );
DrawStuff();
SetTexture( 1, SomeOtherTexture );
DrawMoreStuff();

You don't have to do that. This will work as well:

SetTexture( 0, SomeTexture );
DrawStuff();
SetTexture( 0, SomeOtherTexture );
DrawMoreStuff();

Infact if you're not using multi-texturing then just stick to level 0.

Share this post


Link to post
Share on other sites
actually this is what I"m doing (when I try using more than 8 of these, they last one won't load)

D3DXCreateTextureFromFileEx(g_pd3ddevi, "sprite_bird_front.png", 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT ,0xFF8D8686, NULL, NULL, &g_texture_enemy_01);


if(FAILED(D3DXCreateSprite(g_pd3ddevi,&g_sprite_enemy_01)))
{
MessageBox(0,"D3DXCreateSprite() - Failed","error",0);
//return 0;
}

g_pd3ddevi->SetTexture(0, g_texture_enemy_01);

D3DXCreateTextureFromFileEx(g_pd3ddevi, "sprite_lizard_front.png", 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT ,0xFF8D8686, NULL, NULL, &g_texture_player_01);


if(FAILED(D3DXCreateSprite(g_pd3ddevi,&g_sprite_player_01)))
{
MessageBox(0,"D3DXCreateSprite() - Failed","error",0);
//return 0;
}
g_pd3ddevi->SetTexture(0, g_texture_player_01);


////TEXT//////////////////////////////////////////////////////////////////////////////////////////
D3DXCreateTextureFromFileEx(g_pd3ddevi, "interface_font.png", 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT ,0xFF8D8686, NULL, NULL, &g_texture_text_00);

if(FAILED(D3DXCreateSprite(g_pd3ddevi,&g_sprite_text_00)))
{
MessageBox(0,"D3DXCreateSprite() - Failed","error",0);
//return 0;
}

g_pd3ddevi->SetTexture(0, g_texture_text_00);
////BAR//////////////////////////////////////////////////////////////////////////////////////////
D3DXCreateTextureFromFileEx(g_pd3ddevi, "interface_bars.png", 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT ,0xFF8D8686, NULL, NULL, &g_texture_bar);

if(FAILED(D3DXCreateSprite(g_pd3ddevi,&g_sprite_bar)))
{
MessageBox(0,"D3DXCreateSprite() - Failed","error",0);
//return 0;
}

g_pd3ddevi->SetTexture(0, g_texture_bar);
////MISC//////////////////////////////////////////////////////////////////////////////////////////
D3DXCreateTextureFromFileEx(g_pd3ddevi, "interface_misc.png", 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT ,0xFF8D8686, NULL, NULL, &g_texture_misc);

if(FAILED(D3DXCreateSprite(g_pd3ddevi,&g_sprite)))
{
MessageBox(0,"D3DXCreateSprite() - Failed","error",0);
//return 0;
}

g_pd3ddevi->SetTexture(0, g_texture_misc);


////ICONS_SKILLS//////////////////////////////////////////////////////////////////////////////////
D3DXCreateTextureFromFileEx(g_pd3ddevi, "icons_skills.png", 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT ,0xFF8D8686, NULL, NULL, &g_texture_icons_skills);

if(FAILED(D3DXCreateSprite(g_pd3ddevi,&g_sprite)))
{
MessageBox(0,"D3DXCreateSprite() - Failed","error",0);
//return 0;
}

g_pd3ddevi->SetTexture(0, g_texture_icons_skills);

////PARTICLE//////////////////////////////////////////////////////////////////////////////////
D3DXCreateTextureFromFileEx(g_pd3ddevi, "particle.png", 0, 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT ,0xFF8D8686, NULL, NULL, &g_texture_particle);

if(FAILED(D3DXCreateSprite(g_pd3ddevi,&g_sprite)))
{
MessageBox(0,"D3DXCreateSprite() - Failed","error",0);
//return 0;
}

g_pd3ddevi->SetTexture(0, g_texture_particle);


Share this post


Link to post
Share on other sites
I am taking a guess that you are misunderstanding. Those are texture-stage states, all of which will be applied in some way to every polygon while they are set.

It is intended as a way to avoid rendering multiple passes on the same object when that object requires more than one texture applied to the same place. Example: A brick wall with a lightmap applied. In this case, both textures are set to the appropriate stages, the proper blending factors are set and the wall is then rendered in a single pass. If you want to render several different objects with several different textures, you will be required to set the appropriate texture for each object before it is rendered. For instance: a brick wall and a street sidewalk. You will need to set the brick texture and render the wall, then set the sidewalk texture and render the sidewalk.

If I am mistaken and you are simply trying to render more than eight textures in a single pass, then you may want to look into multiple rendering passes with additive blending.

Share this post


Link to post
Share on other sites
All I'm trying to do is load up more textures to display my sprites on screen. I think my sprite function might be malfunctioning... or I"m just missing some incredibly basic concept *again*... thanks for the replies *does some testing*

Share this post


Link to post
Share on other sites
Is that code per frame or is it cut up some how? Anyway you only really need one sprite object. You can use more of course if you want.

Also you created g_sprite 3 times and g_sprite_enemy_01 twice.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dhaos
or I"m just missing some incredibly basic concept *again*


Yes, that's what you're doing.

There are four things you do with textures, in general:


  • Load the texture from disk into an IDirect3DTexture9 object. This is saying to Direct3D, "I am going to want to use this texture at some point."
  • Bind the texture to a texture stage, by calling IDirect3DDevice9::SetTexture(). This is saying to Direct3D, "I want to use this texture during the next DrawPrimitive call I make."
  • Unbind the texture from a texture stage, by calling IDirect3DDevice9::SetTexture() with a different texture (or NULL). This is saying to Direct3D, "I'm done using this texture for now, but keep it around, because I'll want to use it again."
  • Unload the texture from memory. This is saying to Direct3D, "I'm done using this texture for the foreseeable future."


It's very, very common for a game to have many tens of textures loaded in to memory; it just won't be using more than 8 for a single DrawPrimitive call.

D3DXSprite actually calls SetTexture for you internally; so all you need to do is load and unload textures, and pass them to D3DXSprite.

Edit: Also, Scet is right about the sprites - you only need one D3DXSprite object. It shouldn't really be called D3DXSprite - a better name would be D3DXSpriteRenderer. Use one D3DXSprite object for all your sprites.

Share this post


Link to post
Share on other sites
OK fixed x_______x I have no clue why either, I just started deleting code and reordering things and then...wahm it worked. Thanks everybody for helping, my code now runs a wii bit faster ^_^

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!