Search code examples
c#xnamonogameprimitive

How to draw a textured sphere in XNA


I would like an example on how to draw a sphere, with texture on it (e.g. checkered), in modern XNA (as per MonoGame). Everything should happen programmatically (model and texture are generated, not loaded from files). Brief and tractable is a plus.

The end result would look like

http://www.publicdomainpictures.net/pictures/170000/t2/3d-sphere-with-mapped-checkerboard-1461656185N5D.jpg

except for the shadow and the fact that I don't care how exactly texture deforms towards the edges.

Indicating prior research: I've tried SpherePrimitive but could never put texture on it. If you can, consider it is already present. I have also tried this example from the web, it didn't compile agains MonoGame, when it did the end result did not look like a sphere.

A bit of context: I'm using XNA because it looks like the only cross-platform way to do 3D in C#, but I'm doing a simple visualization so I only ever need spheres so far.


Solution

  • It turns out that XNA/MonoGame is a particularly poor fit for that task. Contrary to my expectations it is not a 3D game builder, but 3D game engine builder. APIs provided are too low-level to tackle the described task in one go.

    I have tried Unity 3D but it makes development Unity-centric, which is a nuisance given that I already have code base and tooling selected.

    I am currently settling for using OpenTK for the job. It is still fairly low-level, but:

    • It is a no-frills solution. Create window when needed, dispose when done. It doesn't force a certain mindset, tooling or entry point, being a library.
    • It is basically OpenGL, for which there's a huge amount of code already written and available for review.
    • It's one small and stable dependency. Smaller number of layers of indirection.
    • I have already found a working textured sphere-drawing example