Archived

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

Ahh texture cords driving me crazy

Recommended Posts

Ratman    181
I've been playing around with Direct3D to do some 2D rendering and have hit a wall. I started with transformed vertices and drew a nice little tile map using triangle strips, and everything went fine. I was then going experiment with some positioned vertices in an Ortho projection. I've set everything and can render lines and triangles but I just cant for the life of me get the textures to appear properly. Here is the important code: Code to setup 4 vertices textured to a 64x64 bitmap:
int i=0;
int x = 0;
int y = 0;
int tileWidth = 64;
int tileHeight = 64;

verts[i].X = x;
verts[i].Y = y;
verts[i].Z = 0.5f;
verts[i].Tu = 0.0f;
verts[i].Tv = 1.0f;

verts[i+1].X = x+tileWidth;
verts[i+1].Y = y;
verts[i+1].Z = 0.5f;
verts[i+1].Tu = 1.0f;
verts[i+1].Tv = 1.0f;

verts[i+2].X = x;
verts[i+2].Y = y+tileHeight;
verts[i+2].Z = 0.5f;
verts[i+2].Tu = 0.0f;
verts[i+2].Tv = 0.0f;

verts[i+3].X = x+tileWidth;
verts[i+3].Y = y+tileHeight;
verts[i+3].Z = 0.5f;
verts[i+3].Tu = 1.0f;
verts[i+3].Tv = 0.0f;

My matrix code:

m_device.Transform.World = Matrix.Identity;
m_device.Transform.View = Matrix.Identity;
m_device.Transform.Projection = Matrix.OrthoOffCenterLH(0,ScreenWidth, ScreenHeight, 0, 0.0f, 1.0f);

This is C# BTW but I'm sure it'll make sense to any C++ guys. Anyways the specific problem I'm having is the very bottom row on my 64x64 texture is appearing in the 2nd row from the top.
------            ------
------     ->>>   ++++++
------            ------
++++++            ------

Is how he texture is being rendered (again: bottom row of pixels being displaced to 2nd row). I've taken a printScreen in windowed mode and looked at it pixel-by-pixel and it is rendering a 64x64 polygon (2 triangles), its just messing up the textures. Any ideas? Ive tried everything I can think of. Thanks for any help. Let me know if you want more source code or screenshots ro whatever. Thanks ratman [edited by - ratman on January 24, 2004 9:56:29 PM] [edited by - ratman on January 24, 2004 9:57:27 PM] [edited by - ratman on January 24, 2004 9:57:49 PM]

Share on other sites
VenDrake    131
Having a hard time seeing anything wrong. Try posting original texture and a screenshot so we can see them side by side. Vertex Declaration may help too. (Make sure you Tu & Tv are 2 bytes not 4 bytes)

-----------
VenDrake

"When you and a friend are being chased by a King Cheata, you have but one chance, trip your friend."

Share on other sites
Ratman    181
Heres the original texture:
http://www.ratfest.org/images/testGOOD.bmp

Heres how it is being rendered:

Note: dont use windows image viewer to look at them, open them up in MS Paint or another program that wont anti-alias or blend the images.

Here's the code to create my vertex buffer:
m_vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, m_device, 0,  CustomVertex.PositionTextured.Format, Pool.Default);

Heres' the code Im using the render it:

m_device.VertexFormat = CustomVertex.PositionTextured.Format;m_device.RenderState.Lighting=false;m_device.RenderState.CullMode = Cull.None;m_device.RenderState.ZBufferEnable=false; 		setupMatrices();    /matrix code in my first post m_device.SetStreamSource(0, m_vertexBuffer, 0); m_device.SetTexture(0,m_texture1);m_device.TextureState[0].ColorOperation = TextureOperation.Modulate;m_device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;m_device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;		m_device.TextureState[0].AlphaOperation = TextureOperation.Disable;			 m_device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

Thanks for the help

[edited by - ratman on January 24, 2004 10:51:15 PM]

[edited by - ratman on January 24, 2004 10:52:50 PM]

Share on other sites
VenDrake    131
Sorry man.

I don''t see anything that''s blatently wrong. Only thing I can think of is maybe somehow two tiles are slightly overlapped.

BTW: You''re second link hits the wrong file. I found the right one though.

-----------
VenDrake

"When you and a friend are being chased by a King Cheata, you have but one chance, trip your friend."

Share on other sites
Supernat02    604
I take it you''re working with transformed vertices? Maybe try:

verts[i].X = x;verts[i].Y = y;verts[i].Z = 0.5f;						verts[i].Tu = 0.0f;verts[i].Tv = 0.0f; verts[i+1].X = x+tileWidth;verts[i+1].Y = y;verts[i+1].Z = 0.5f;					verts[i+1].Tu = 1.0f;verts[i+1].Tv = 0.0f; verts[i+2].X = x;verts[i+2].Y = y+tileHeight;verts[i+2].Z = 0.5f;						verts[i+2].Tu = 0.0f;verts[i+2].Tv = 1.0f; verts[i+3].X = x+tileWidth;verts[i+3].Y = y+tileHeight;verts[i+3].Z = 0.5f;						verts[i+3].Tu = 1.0f;verts[i+3].Tv = 1.0f;

See if that helps...I just re-arranged the tex coords.

Chris