Archived

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

Paladin__

Texel/Pixel conversion?

Recommended Posts

I am making breakout, and I have my paddle, ball and block textures on a 256 x 256 bmp texture and. The image is 120 pixels wide and 20 pixels long, so since the U and V coords have to be between 0.0 and 1.0, I use a triangle strip and calculate my four coords and my texture for the paddle is in the top left corner of the 256x256 texture, so my array is as follows: coord1: x = 290 y = 570 u = 0.0f v = (20.0f / 256.0f ) coord2: x = 290 y = 550 u = 0.0f v = 0.0f coord3: x = 390 y = 570 u = 100.0f / 256.0f v = 20.0f / 256.0f coord4: x = 390 y = 550 u = 100.0f / 256.0f v = 0.0f The U and V calculations are the 100 wide by 20 tall texture segment in the 256 x 256 texture, but for some reason, the paddle doesn't come out quite right. Any ideas on what I'm doing wrong? Is there a better way to do coordinates on a texture? Much greatness is achieved thru perseverance and faith. [edited by - Paladin__ on November 4, 2002 4:09:06 PM]

Share this post


Link to post
Share on other sites
Do I lose graphic quality when the app goes fullscreen? Could this cause the distortion?

I tried bilinear filtering, and it looked better, but blurry.

Any other advice on texel/pixel conversions?

Much greatness is achieved thru perseverance and faith.

[edited by - Paladin__ on November 4, 2002 4:09:57 PM]

Share this post


Link to post
Share on other sites
Sorry, I''ve been studying Direct3D for so long that I want to start 2D with Direct3D, so that I can make 3D games as well as 2D games and be well versed in the Direct3D area of study.

I have nothing against DirectDraw, but I don''t care to learn it when I can accomplish the same with Direct3D and have the avenue open to do 3D if I''d like.

Much greatness is achieved thru perseverance and faith.

Share this post


Link to post
Share on other sites
Hey Paladin,

I've struggled much with this problem in the past. Other GameDev'ers helped me out with mine, so I'll pass along what I learned from them.

(1) Turn off all filtering before rendering your textures. So:

    
g_pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_NONE );
g_pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_NONE );
g_pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_NONE );


(2) Offset the x and y coordinates of your triangles' vertices by -0.5 so that the rasterizer has an easier time of translating texture pixels ('texels') to screen pixels.

So, using your example, coord1 should become:
x = 289.5
y = 569.5

I didn't go over your uv values with a fined-tooth comb, but you appear to be using the right calculations for those values.

Finally, you are using transformed vertices, not untransformed vertices, right?

Without seeing an actual image of the results you're getting, I can't offer much more than that. Good luck!

--Hoozit.

----------------------
Check out my game demo and resume at
www.fivestory.com/projects/game.

[edited by - HoozitWhatzit on November 5, 2002 1:54:47 AM]

Share this post


Link to post
Share on other sites
Thanks HoozitWhatzit, I''ll give that a shot after work. I AM using transformed vertices, so hopefully this is all I''ll need.

I did read about subtracting 0.5 finally, and my problems are down to one row of pixels on the first row turning on and off based on the position of my paddle.

I will try the filter thing when I get home and see if that helps.

How does this affect when my ball moves? Since the left screen is at 0.0, won''t I have issues when my ball tries to bounce off of that? (Guess I''ll either bounce 0.5 inside the border, or 0.5 outside).

Much greatness is achieved thru perseverance and faith.

Share this post


Link to post
Share on other sites
quote:

How does this affect when my ball moves? Since the left screen is at 0.0, won''t I have issues when my ball tries to bounce off of that? (Guess I''ll either bounce 0.5 inside the border, or 0.5 outside).



That would probably be the solution; although, if the ball is moving fast enough, no one will notice if you don''t align it!

--Neil.

----------------------
Check out my game demo and resume at
www.fivestory.com/projects/game.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If it looks okay in Windowed mode, and not in fullscreen. try checking what colors your using in Fullscreen.
For example, if your using 32 bit on your desktop, your program will use 32 bit if your running windowed. But fullscreen might only use 16 bit, that can be your problems.

Share this post


Link to post
Share on other sites
I''m running the D3DFMT_A8R8G8B8 in fullscreen mode, and I''m running 32 bit on the desktop. That''s correct isnt it?

Another question pertaining to this:

I think I''m confusing myself here, but say I have 3 images that I want to texture out to a mesh, two of them are 100 wide and 20 tall, and one is 20 wide by 20 tall on a 256 x 256 texture. The images on my texture are side by side.

would my texture coordinates on a square mesh using a D3DPT_TRIANGLESTRIP be:

square mesh 1
lower left coord x: 0.0f
lower left coord y: 20.0f / 256.0f

top left coord x: 0.0f
top left coord y: 0.0f

lower right coord x: 100.0f / 256.0f
lower right coord y: 20.0f / 256.0f

top right coord x: 100.0f / 256.0f
top right coord y: 0.0f

square mesh 2
lower left coord x: 101.0f / 256.0f
lower left coord y: 20.0f / 256.0f

top left coord x: 101.0f / 256.0f
top left coord y: 0.0f

lower right coord x: 201.0f / 256.0f
lower right coord y: 20.0f / 256.0f

top right coord x: 201.0f / 256.0f
top right coord y: 0.0f

square mesh 3
lower left coord x: 202.0f / 256.0f
lower left coord y: 20.0f / 256.0f

top left coord x: 202.0f / 256.0f
top left coord y: 0.0f

lower right coord x: 222.0f / 256.0f
lower right coord y: 20.0f / 256.0f

top right coord x: 222.0f / 256.0f
top right coord y: 0.0f

Is this correct?

Much greatness is achieved thru perseverance and faith.

Share this post


Link to post
Share on other sites