[SlimDX] Dynamically creating a Mesh and Textures, then drawing it?

Started by
4 comments, last by GameDev.net 13 years, 9 months ago
Hello,

I've tried SlimDX and it seems as a reasonable way to program games for C#, and so far I liked it.
But now I'm in the need of dynamically creating a Box, apply a texture to it, and then draw it.

How to create the box is easy, using Mesh.CreateBox. But somehow I could not find a straightforward tutorial or guide on the internet that aids me to apply a texture to it and position it in the 3D-scene.

Can someone give me some hints how to accomplish that? This is an essential feature for the game I'm creating, so I need that feature to be in.

Regards,
chris
Advertisement
The box doesn't have texture coordinates, you'll have to generate them yourself. This might help you with that.

About positioning the box, you can either use a matrix (basically this will be the world matrix for the box), or you can create the box directly in world space (so its world matrix will be the identity matrix).
Hi,

I thought that thing with the box, so thank you :) But how do I apply the texture after I have computed the texture coordinates? Something like "mesh.Texture = ..." would be handy, but I guess it is in fact not that easy?

I already got a World matrix, because - for the underlying Entity that utilizes the box/mesh - I got Position (Vector3) and Rotation (float) and Scale (float) values. Using the static Matrix methods I can create the World matrix pretty easy.

The thing is, how do I tell SlimDX to apply the matrix to just that one mesh? Do I have to tell the renderer (for each entity) to use the mesh using that one "Device.SetTransform(int, Matrix)" method?

Regards,
chris
Looks like you're using the fixed function pipeline, in which case you would use the SetTexture() method from the Device class.

To draw a mesh using a particular world matrix, you just set that matrix as the current world matrix using SetTransform(), and then draw the mesh.
Hello again,

so using these Methods basically means using the FFP?
I don't want to do that, I want to use Shaders.

Does that mean when I want to draw it with a Shader/Effect, all I have to do is to set the World, View, Projection matrices (which are parameters in the shader) and also set the Texture parameter in the shader, and the shader will do everything for me, what I otherwise had to do very inconvienient with the FFP methods SetTexture() and so on?

For some reason I'm a little confused right now :/

Thank You,
chris
Hello all,

thank you, the problem is solved. It worked like it should by using shaders and parameters (or _effect.SetValue<Matrix>("worldViewProjection", ...)).

Regards,
chris

This topic is closed to new replies.

Advertisement