Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Tutorial 3 for Windows Phone 7
  Posted by: Anonymous
  When: 20/05/2013 at 02:30:13

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22

 XNA 4.0
  Posted by: Anonymous
  When: 15/03/2013 at 19:43:57

 Error when I try to run.
  Posted by: Anonymous
  When: 15/03/2013 at 19:21:06

 Error With the Effect File
  Posted by: Anonymous
  When: 15/03/2013 at 18:21:01

 Can only get shadowmap
  Posted by: Anonymous
  When: 15/03/2013 at 15:48:52

 Vertex and Pixel Shader Versions?
  Posted by: Anonymous
  When: 15/03/2013 at 15:07:16

 Unsupported properties
  Posted by: Anonymous
  When: 15/03/2013 at 14:23:00

 Problem Loading Skybox
  Posted by: Rana
  When: 15/03/2013 at 10:34:45

 Black Screen Of Death - Help!
  Posted by: Anonymous
  When: 15/03/2013 at 03:43:43

 2.0 anyone?
  Posted by: Anonymous
  When: 15/03/2013 at 02:19:48

 Defitinition of tha rotation axis
  Posted by: Anonymous
  When: 15/03/2013 at 00:55:14




Topic: IndexBuffer typeof(int) not excepted



  
Goto parent category
  
Create a new user account


   IndexBuffer typeof(int) not excepted
 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 :)

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)