Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi.

 

I'm converting my GDI+ isometric tile engine to managed Direct3D due to performance issues. This is my first programming expirience in Direct3D.

 

For every tile I use two triangle strips made of 4 vertices. The vertices are of Transformed.Textured Format:

 

 

 

int vertexCounter = 0;

for(int x = 0; x <= 13; x++)

{

for(int y = 0; y <= 13; y++)

{

int positionX = 390 - y * 30 + x * 30;

int positionY = y * 15 + x * 15;

customVertex[vertexCounter++] = new CustomVertex.TransformedTextured(positionX, positionY, 0.5F, 1, 1, -1);

customVertex[vertexCounter++] = new CustomVertex.TransformedTextured(positionX + 60, positionY, 0.5F, 1, 0, -1);

customVertex[vertexCounter++] = new CustomVertex.TransformedTextured(positionX, positionY + 29, 0.5F, 1, 1, 0);

customVertex[vertexCounter++] = new CustomVertex.TransformedTextured(positionX + 60, positionY + 29, 0.5F, 1, 0, 0);

}

}

 

 

 

I load the texture with the TextureLoader.FromFile method and attach a color key to it:

 

 

 

public void CreateOverlayTexture(string file)

{

Texture texture = TextureLoader.FromFile(device, file, 60, 29, 0, 0, 0, Pool.Default, Filter.None, Filter.None, Color.FromArgb(255,0,255).ToArgb());

arrayListTexture.Add(texture);

}

 

 

 

The problem is, that the textures aren't mapped properly as you can see in the attached GIF.

 

All the tiles should have 60x29 pixels. But they all have a different size.

 

What do I do wrong?

 

THX and C ya

gdp2000

Posted

Hi

 

Thanks for the fast reply, but this didn't help. I think it has something to do with the coordinates of the vertices. As you can see, I'm using transformed position for the vertices. Every tile which is painted has its own 4 vertices. When the first vertex would be on 0,0 then the second on 60,0, third on 0,29, and fourth on 60,29. When the texture would be mapped properly, every tile should look like in the attached picture...

 

C ya

gdp2000

test.gif.af5891c0f945efc856d2357e2176890a.gif

  • Administrators
Posted

Will try and look into it more over the weekend (no promises).

The Texture shouldn't be affected by the vertices though. Setting the texture's v co-ordinate to -1 will prevent it mapping across the tile correctly i think (0, -1) puts it at the top but one unit to the left of the square.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Maybe the problem is, that the textures doesn't have the same x and y dimmension? I mean that they are all 60x29 and not 60x60.

 

I even tried it with 60x20 and corrected the uv mapping coodinates as you said and it didn't help.

Posted

I don't know if this is what you should have, but if you already have it then it won't help

int vertexCounter = 0;
for(int x = 0; x <= 13; x++)
{
for(int y = 0; y <= 13; y++)
{
int positionX = 390 - y * 30 + x * 30;
int positionY = y * 15 + x * 15;
customVertex[vertexCounter++] = new CustomVertex.TransformedTextured(positionX, positionY, 0.5F, 1, 0, 0);
customVertex[vertexCounter++] = new CustomVertex.TransformedTextured(positionX + 60, positionY, 0.5F, 1, 1, 0);
customVertex[vertexCounter++] = new CustomVertex.TransformedTextured(positionX, positionY + 29, 0.5F, 1, 0, 1); 
customVertex[vertexCounter++] = new CustomVertex.TransformedTextured(positionX + 60, positionY + 29, 0.5F, 1, 1, 1);
}
}

public void CreateOverlayTexture(string file)
{
Texture texture = TextureLoader.FromFile(device, file, 64, 32, 0, 0, 0, Pool.Default, Filter.None, Filter.None, Color.FromArgb(255,0,255).ToArgb());
arrayListTexture.Add(texture);
}

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted

OK, finally i got it. :D

 

The vertex distance in transformed co-ordinates between the x vertices must be 63 and the y distance 31.

For example the co-ordinates of one TriangleStrip primitive are:

 

1. 0,0

2. 63,0

3. 0,31

4. 63,31

 

This is very interesting, because the image I'm loading with TextureLoader.FromFile has the dimensions of 60x29:

 

TextureLoader.FromFile(device, TextureFileName, 60, 29, 0, Usage.RenderTarget, 0, Pool.Default, Filter.None, Filter.None, Color.FromArgb(255,0,255).ToArgb());

 

Can someone please explain this???

 

I tried every sugestion from AndreRyan and PlausiblyDamp, but only this helped. Is this normal behavior or do I make something wrong?

  • *Experts*
Posted

Have you checked the size of the texture after you load it? I've never seen TextureLoad.FromFile load a non-power-of-2 texture properly. Meaning, if I load a 60x29 bitmap, it'll scale it to 128x32 or something similar. You can get the surface description after you load the bitmap to see the size to make sure it's what you passed to FromFile().

 

Also, I know that all vertices must be offset by 0.5 pixels when drawing. It took me the longest time to find it in the docs because *most* of the 2D sprites would draw fine, but some would be scaled off by 1 pixel.

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...