| Poster | : AndyB | | Posts | : 14 | | Country | : Ireland | | City | : Dublin |
| | | | Posted by AndyB on 17/04/2008 at 16:45:49
| | Hi,
I have really been loving the tutorials.
Sorry for this being my third topic so fast. In the terrain basics.. This is now driving me mad. :(
All of the tutorials being xna 1.0 makes it hard for the beginner to convert over when reading.
My issue now is the line:
ib = new IndexBuffer(device, typeof(int), (WIDTH - 1) * (HEIGHT - 1) * 6, ResourceUsage.WriteOnly, ResourceManagementMode.Automatic);
ib.SetData(indices); |
Now, Due to XNA 2.0... This has been converted too:
ib = new IndexBuffer(device, typeof(int), (WIDTH - 1) * (HEIGHT - 1) * 6, BufferUsage.WriteOnly); |
But now i get a runtime error:
| This device does not support 32-bit indices. Use IndexElementSize.SixteenBits or a type that has a size of two bytes. |
For that line.. Please, could anyone help me please :(
Andy | |
|
|
| |
| |
| Poster | : riemer | | Posts | : 1392 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 18/04/2008 at 03:32:43
| | This one is related to your specific graphics card.
each time your encounter 'int' in the SetUpIndices method, change it to 'short' | |
|
|
| |
| |
| Poster | : AndyB | | Posts | : 14 | | Country | : Ireland | | City | : Dublin |
| | | | Posted by AndyB on 18/04/2008 at 05:49:40
| | Thank you i had noticed this.
The problem with that is:
When i change it, the index buffer instance is set ok.. But when i try
ib.SetIndices();
It says that the array is not large enough :(
I have tried multipling it but that just gives me the 32bit error again :(
Any idea? | |
|
|
| |
| |
| Poster | : riemer | | Posts | : 1392 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 18/04/2008 at 09:40:27
| | | Maybe it's easier if you post your whole method? | |
|
|
| |
| |
| Poster | : AndyB | | Posts | : 14 | | Country | : Ireland | | City | : Dublin |
| | | | Posted by AndyB on 18/04/2008 at 10:13:39
| | Thanks I really apriciate you taking the time to look at this for me.
The error is:
| The array is not the correct size for the amount of data requested. |
The Method:
private void SetUpIndices()
{
int[] indices = new int[(WIDTH - 1) * (HEIGHT - 1) * 6];
for (int x = 0; x < WIDTH - 1; x++)
{
for (int y = 0; y < HEIGHT - 1; y++)
{
indices[(x + y * (WIDTH - 1)) * 6] = (x + 1) + (y + 1) * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 1] = (x + 1) + y * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 2] = x + y * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 3] = (x + 1) + (y + 1) * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 4] = x + y * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 5] = x + (y + 1) * WIDTH;
}
}
ib = new IndexBuffer(device, typeof(short), (WIDTH - 1) * (HEIGHT - 1) * 6, BufferUsage.WriteOnly);
//ib = new IndexBuffer(device, typeof(int), (WIDTH - 1) * (HEIGHT - 1) * 6, BufferUsage.WriteOnly);
ib.SetData(indices);
} |
The full code can be found here:
http://pastebin.com/maf422ba
AndyB | |
|
|
| |
| |
| Poster | : riemer | | Posts | : 1392 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 18/04/2008 at 10:40:43
| | Make sure you are consistent in the type of data you're using. Look at these 2 lines:
int[] indices = new int[(WIDTH - 1) * (HEIGHT -
ib = new IndexBuffer(device, typeof(short), (WIDTH - 1) * (HEIGHT - 1) * 6, BufferUsage.WriteOnly);
|
First you're creating an array of ints, and in the end you're specifying you want to copy an array of shorts. So the last method expects to find (WIDTH - 1) * (HEIGHT - 1) * 6 * 16 bits (as a short takes up 16bits=2bytes), while the array stores (WIDTH - 1) * (HEIGHT - 1) * 6 * 32 bits (1int=32bits=4bytes).
So either you change the first line to shorts, or the last line to ints to solve your problem. | |
|
|
| |
| |
| Poster | : AndyB | | Posts | : 14 | | Country | : Ireland | | City | : Dublin |
| | | | Posted by AndyB on 18/04/2008 at 11:20:07
| | Hmm well i converted everything to ints.
And i just keep getting the error about 32 bit ints.
So i converted all to shorts.
Now i get the error:
Error 1 Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?) C:\Documents and Settings\Andrew Butler\My Documents\Visual Studio 2005\Projects\TerainOne\TerainOne\Engine.cs 145 58 TerrainOne
|
This is for every line of setting values in the arrays.
The updated method :
private void SetUpIndices()
{
short[] indices = new short[(WIDTH - 1) * (HEIGHT - 1) * 6];
for (short x = 0; x < WIDTH - 1; x++)
{
for (short y = 0; y < HEIGHT - 1; y++)
{
indices[(x + y * (WIDTH - 1)) * 6] = (x + 1) + (y + 1) * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 1] = (x + 1) + y * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 2] = x + y * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 3] = (x + 1) + (y + 1) * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 4] = x + y * WIDTH;
indices[(x + y * (WIDTH - 1)) * 6 + 5] = x + (y + 1) * WIDTH;
}
}
ib = new IndexBuffer(device, typeof(short), (WIDTH - 1) * (HEIGHT - 1) * 6, BufferUsage.WriteOnly);
//ib = new IndexBuffer(device, typeof(int), (WIDTH - 1) * (HEIGHT - 1) * 6, BufferUsage.WriteOnly);
ib.SetData(indices);
} |
Sorry to be annoying you :( | |
|
|
| |
| |
| Poster | : Nemo Krad | | Posts | : 61 | | Country | : England | | City | : Leicester |
| | | | Posted by Nemo Krad on 18/04/2008 at 13:40:29
| | You need to cast the resulting values.
So
indices[(x + y * (WIDTH - 1)) * 6] = (x + 1) + (y + 1) * WIDTH;
|
should look like this
indices[(x + y * (WIDTH - 1)) * 6] = (short)((x + 1) + (y + 1) * WIDTH);
|
| |
|
|
| |
| |
| Poster | : AndyB | | Posts | : 14 | | Country | : Ireland | | City | : Dublin |
| | | | Posted by AndyB on 20/04/2008 at 16:52:23
| | Hi, sorry for the late reply,
Have been away reciently,
I would like to thank you, the cast advice you gave me worked.
Thanks :) | |
|
|