Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Reaper_Unreal

Texture sizes and backgrounds

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

I''m trying to make a 2D game using DirectX Graphics, and I''m having a small problem with textures. It seems that using the D3DXLoadTextureFromFile() function, if the function isn''t a direct power of 2 (2, 4, 8, 16, 32, 64...) it''ll resize it to the appropriate size. However, I don''t want it to resize to that. Right now I''m just setting the texture coordinates as per the following:
void gBackground::setTexture(IDirect3DTexture8 *pTex)
{
	if(loaded)
		SafeRelease(pTex);
	screenTex = pTex;
	if(screenTex == NULL)
		loaded = 0;
	else
	{
		loaded = 1;
		D3DSURFACE_DESC surfDesc;
		screenTex->GetLevelDesc(0, &surfDesc);
		width = surfDesc.Width;
		height = surfDesc.Height;
		verts[0].u = 0.0f;
		verts[0].v = MIN(screenH/height, 1.0f);
		verts[1].u = 0.0f;
		verts[1].v = 0.0f;
		verts[2].u = MIN(screenW/width, 1.0f);
		verts[2].v = verts[0].v;
		verts[3].u = verts[2].u;
		verts[3].v = 0.0f;
	}
}[/CODE]

and leaving the vertices themselves at the corner of the screen.

I''m wondering if there''s possibly a better way to do this. Possibly using a surface instead of a texture, but I''m not sure if a surface will resize the picture as well.

Help?   
She walked into my office like a centipede with 98 missing legs.

Share this post


Link to post
Share on other sites
Advertisement
Ahh your using 8.0 I take it. Not sure in 8.0 though sorry :-(

In 9.0 you can use D3DXCreateTextureFromFile so that you can specify the size of the texture. Managed 9.0 Has this too.

[edited by - 3dxd on June 10, 2004 12:41:04 AM]

Share this post


Link to post
Share on other sites
Yes, in 8.0 use the function (In VB, should be easy enough to understand though):

D3DX.CreateTextureFromFileEx(...)

Most of the parameters can just be set to default values, you may want to find a tutorials or something, it takes quite a few (13) parameters, some of which I don''t fully understand...

Share this post


Link to post
Share on other sites
If this is for use in a place where performance isn''t critical (like a splash screen, main menu, etc) you can load it into a surface and use CopyRects to copy it to the backbuffer. It''s a "slow" method though so I wouldn''t use it in-game.

For in-game you have 2 real choices:
1)cut up the background into multiple power-of-2 textures. This saves memory but is more hassle
2)Load the background into a paint program and resize the canvas to be a power-of-2. This way you have a non-pow2 image sitting in a pow2 texture with black surrounding it. Then set your tex coordinates to juse use the sub-rect you need. This takes up more memory, but it''s trivial to do.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
See I would do that last approach, but I''d rather not have to get the level designers (either me or a modder) to have to write a separate level description txt file which contains the real dimensions of the background. I think I''ll try the separating thing, but I dunno how well that''ll go. We''ll see... I might try some other approaches.

Share this post


Link to post
Share on other sites

  • 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!