Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sprite Overlay Fitting Problems

Started by HeavyStorm Oct 13, 2005 at 9:10 AM 4 replies 1.1k views
Original Post
HeavyStorm
HeavyStorm
Guys, I'm having a strange problem with my background texture in a 3D game. To make matters simple, I have this "sprite", a 800x600 png; It has tree "holes" in it (using alpha blending), so that I can use as an overlay and still have the "background" desired effect. I use a simple loader class to read the sprite (or texture) into the program, then I try to clip it with the following code:


if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{		
	g_pBGSprite->Begin( D3DXSPRITE_ALPHABLEND );
	g_pBGSprite->Draw( g_pBGTexture, NULL, NULL, NULL, D3DCOLOR_ARGB(255, 255, 255, 255) );

	g_pBGSprite->End();
	V( pd3dDevice->EndScene() );
}
As you can see, the code is very simple. I display it as a solid figure (255,255,255,255), and the actual coloring and transparency - alpha blending (creating the hole effect) works fine. The only problem is that I'm unable to display the whole sprite. My window is 800x600, as is the sprite. But the sprite is clipped to about 75% of its actual size. If I resize the window a few times, it reaches the desired size... But I can't say exactly why. So, is there a way to correct this? Why isn't it displaying correctly? I have to specify the rect for it to display right? Help! :)
Supernat02
Supernat02
A couple of issues come to mind, but you'll have to look into them to decide if they are affecting it.

First, since 800x600 isn't a power of 2 texture, your video card may not support it "out of the box". The D3DXCreateTextureFromFile functions will then create a power of 2 texture (unless you specify otherwise, see the SDK) and I'm pretty sure it will leave the extra space black. Hence, you'll see 800x600 texture and a 112x212 black border (30% horiz black, 35% vert black). My guess is this is the issue. One way to find out is to check the D3D Caps structure or use the handy utility included with the DX SDK that will provide the capabilities of your video card (you should see a tree list item for POWER_OF_TWO or something like that).

The other thing I can think of is the perspective. Be sure the perspective (whether you're using pre-transformed or orthogonal) is correct. Be sure your width/height values in the presentation parameters are correct also.
Chris ByersMicrosoft DirectX MVP - 2005
jthirst
jthirst
If this is in a window, it might be because when you tell Windows to create a 800x600 window, that size is including the border (so the actual client area is less then 800x600). Check out the AdjustWindowRect function, it can help you determine what size you really need to create the window with.
HeavyStorm
HeavyStorm
Accordingly to DX Caps Viewer, both D3DPTEXTURECAPS_POW2 and D3DPTEXTURECAPS_NONPOW2CONDITIONAL are true, which means that indeed my video card (which is a Radeon 9600PRO) is capable of loading irregular textures.

Also, my client are is right (I've double checked it trough a image editor) since I use the DX framework to set it up.

It's a really annoying problem; I thought it was related to the client size too, before I even posted this. And when I saw the POW2 problem, I was also led to believe that was the cause. Back when I used OGL these were great problems for us. But now, I don't know the cause of it.

So, if anyone still have patience to look into it, any clues might help. Thanks a lot to those who replied already.
HeavyStorm
HeavyStorm
Looking a little further into this, I can see that maybe the problem is related to the g_pBGSprite size. A Sprite has, as I can see, some transform matrices; So, should I set those matrices before drawing to the client? Remember that I loosing a little bit of the image, like if there is a zoom into the sprite.

Thanks again.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.