Jump to content
  • Advertisement
Sign in to follow this  
LandWarrior

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

This topic is 2995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!