Archived

This topic is now archived and is closed to further replies.

Telamon

Bitmap -> D3D Surf and Textured Spheres

Recommended Posts

Hello, I''m building a little proof-of-concept demo that shows realtime generation of Perlin Noise to create random textures for planets in a space game I want to make. I''ve made good progress so far, but I''m trying to learn C# and D3D at the same time and I''m stuck. I''ve written an app that allows users to tweak parameters and then generate Perlin Noise, which is put into a .NET Bitmap object (very handy thing). Now I want to take that texture and map it onto a sphere in another window, as a kind of preview feature. I cannibalized the DX9 tutorials and I have it rendering a cylinder in a separate window. But I''m having a hell of a time getting it to draw a my noise texture on a sphere! There are two problems. 1. I don''t know how to create a DX texture from a .NET Bitmap object (Can I use the TextureLoader.CreateFromStream function? How? There is no documentation). 2. I''m currently using the Mesh.Sphere() function to create my geometry, and that works fine. But I can''t texture anything onto it. I read elsewhere on this forum that the D3DX.CreateSphere function doesn''t generate texture coords. Is this the problem? How can I surmount this? Does anyone have a C# snippet that does this? I''ve used OpenGL for a while, enough to get an idea of what I was doing, but Direct3D forces the programmer to deal with a lot more low level details (vertex buffer? index buffer? Argh! I want to draw a sphere and some quads, not write a 3D engine). It''s giving me some trouble. If anyone can help out, I''d greatly appreciate it! Thanks

Share this post


Link to post
Share on other sites
I've not done any managed DX, but I'll give it a try:

quote:
Original post by Telamon
1. I don't know how to create a DX texture from a .NET Bitmap object (Can I use the TextureLoader.CreateFromStream function? How? There is no documentation).

Why not use the D3DX helper functions: D3DXCreateTextureFromFile and D3DXCreateTextureFromFileEx?
(I don't know in which namespace d3dx functions exist, but I suppose you know where to find these)

quote:
Original post by Telamon
2. I'm currently using the Mesh.Sphere() function to create my geometry, and that works fine. But I can't texture anything onto it. I read elsewhere on this forum that the D3DX.CreateSphere function doesn't generate texture coords. Is this the problem? How can I surmount this? Does anyone have a C# snippet that does this?

You should Clone the mesh (ID3DXMesh::CloneMeshFVF) into another mesh, and specific D3DFVF_TEX1 (i.e. indicating that it uses a texture, so that CloneMeshFVF uses vertices that have texture coordinates).

After cloning the mesh, lock it, loop through its vertices generating the texture coordinates. For a tutorial on sphere-mapping, see Robert Dunlop's X-Zone, you'll have to search around a bit to find the tutorial.

By the way, you'll have to find the equivalent of ID3DXMesh in managed DX (a search for the method CloneMeshFVF will do), and then you'll have to find the namespace for the FVF definitions.

quote:
Original post by Telamon
I've used OpenGL for a while, enough to get an idea of what I was doing, but Direct3D forces the programmer to deal with a lot more low level details (vertex buffer? index buffer? Argh! I want to draw a sphere and some quads, not write a 3D engine). It's giving me some trouble. If anyone can help out, I'd greatly appreciate it!

You can always use DrawPrimitiveUP in case you don't want to get involved with vertex and index buffers. It works well for light-weight stuff.
Unfortunately, Direct3D offers the functionality similar to OpenGL quadrics through the D3DX helper library, which forces you to use vertex and index buffers (as well as meshes )

Peace,
Muhammad Haggag

[edited by - Coder on July 27, 2003 2:02:06 AM]

Share this post


Link to post
Share on other sites