[.net] C# skybox

Started by
4 comments, last by MikeyO 19 years, 5 months ago
I'v tried searching, I've tried filling vertex buffers every which way, and I'm about ready to kick myself...I am trying to learn to use DirectX in C# without much luck...I figure a simple experiment to try first is a skybox...but I can't seem to find a proper way to fill in the data. I created an array of vertices (using my own simple 'vertex' with x,y,z,u,v), but have been unable to successfully find a way to fill a vertexbuffer...the directx FAQ states I need to specify the size of each vertex in my array for instance...but you can't use sizeof() in safe code? Has anyone seen a simple example of a skybox out there? I'm floundering, and the help provided by microsoft seems to be entirely devoid of decent examples.
David Clifton
Advertisement
this might help a little:
there is a helper method in directx (Microsoft.DirectX.DXHelp.GetTypeSize) that should run in a safe context. You can also just figure out the size yourself by adding up all the sizes of the types in your vert. You can even use the StructLayout attributes to explicitly control the size if you need to.

Are you using FVF or Declarations for your custom vertex? If you use decleartions, the size passed to the buffer can be greater than the actual size of your vert.

If you are just starting you don't need to use a VertexBuffer, take a look at Device.DrawUserPrimitive/DrawIndexedUserPrimitive. It is slower, but it might get you going.
For each custom vertex type, there is a size stored inside it called stridesize
ie; CustomVertex.PositionColored.StrideSize

Why not just load a mesh for a skybox?
Was using FVF...I'd be all about loading a mesh for the skybox if I could quite figure out how to do one...I figured the vertexbuffer would be simpler to start with. I'll take a look at the mesh stuff and see if something jumps out at me :)
David Clifton

I'm going to put further questions on this in the DirectX forum, as I feel my problem is my understanding of using DirectX, not C#, at this point.

[Edited by - Direct on December 6, 2004 8:42:24 AM]
David Clifton
//Loading files (in initialization)
Mesh m = Mesh.FromFile(/*insert parameters here*/);
Texture texName = TextureLoader.FromFile(/*insert params here*/);

//Drawing
device.SetTexture(0, texName);
m.DrawSubset(0);

This topic is closed to new replies.

Advertisement