MrHat

Hello,

I have the february 2007 sdk and I'm using the sampleframework.

Im making my first card game in Managed DirectX and I want to load some card textures on a table. The camera is looking straight down on the table (like in 2D), but I have to have it in 3D because I want to be able to move the camera to "zoom" in/out on the table.

My cards have some text one it, so ití»s important that the texture is as clear as possable.

I've been experimenting with several methods to load textures. The best one so far has been to load the texture by using a Sprite like is done in the sdk "Simple2D" sample.
The good: It gives me the best texture quality of the methods that I've tried.
The bad: I've been only able to use these sprites in 2D, not 3D.

Always when I try to load my texture in 3D (by using f.ex. Vertex Buffer) my Texture gets blurry. My texture is 250x349 in size. How would you recommend that I render my Texture

Thank you.


Re: Game Technologies: Graphics Texture looks good in 2D, but not 3D

Asesh

Sprites are 2D images so rotating sprites would just give an illusion of 3D textures/model but not exactly though. And for the second query, this might help you:
// Set the magnification and minification filters for the textures
m_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); // Magnification filter
m_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); // Minification filter

You need to refer to good books and I would recommend this book "Introduction to 3D game programming with DirectX 9.0c a shader approach" by Frank Luna. That's the best book out there.




Re: Game Technologies: Graphics Texture looks good in 2D, but not 3D

MrHat

This is the original image.

Original

This is how it looks like then I use a 2D Sprite.
2D Sprite

Now comes what I really want, to render the texture cristal clear in 3D.

This is the best way that Ií»ve been able to render it in 3D. As you can see, the text on the texture looks really blurry Sad
3D using a Vertex Buffer


For this last one, Im using the following settings. Since the original texture is 256x356 pixels in size, Im scaling it by 1.4. My game resolution is 1024x768 pixels.
---------------------------------------------------------------------------
OnResetDevice()
{
texture = TextureLoader.FromFile(e.Device, Utility.FindMediaFile("original.tga"));

e.Device.SamplerState[0].MinFilter = TextureFilter.None;
e.Device.SamplerState[0].MagFilter = TextureFilter.None;
e.Device.SamplerState[0].MipFilter = TextureFilter.None;

e.Device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, -7f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(.0f, .5f, 0.0f));

e.Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)desc.Width / (float)desc.Height,1.0f, 100.0f);


vb = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, e.Device, 0, CustomVertex.PositionTextured.Format, Pool.Default);

CustomVertex.PositionTextured[] verts = (CustomVertex.PositionTextured[])vb.Lock(0, 0);
verts[0].X = -1.0f;
verts[0].Y = -1.0f;
verts[0].Z = 0.0f;
verts[0].Tu = 0.0f;
verts[0].Tv = 0.0f;

verts[1].X = -1.0f;
verts[1].Y = 1.0f;
verts[1].Z = 0.0f;
verts[1].Tu = 1.0f;
verts[1].Tv = 0.0f;
verts[2].X = 1.0f;
verts[2].Y = -1.0f;
verts[2].Z = 0.0f;
verts[2].Tu = 0.0f;
verts[2].Tv = 1.0f;

verts[3].X = 1.0f;
verts[3].Y = 1.0f;
verts[3].Z = 0.0f;
verts[3].Tu = 1.0f;
verts[3].Tv = 1.0f;
vb.Unlock();
}


OnFrameRender()
{
MatrixStack matrixStack = new MatrixStack();
matrixStack.Push();

Matrix LocalMatrix1 = Matrix.Identity;
Matrix LocalMatrix2 = Matrix.Identity;

double degrees = -90;
double radians = (Math.PI / 180) * degrees;
LocalMatrix1.RotateZ( (float)radians );
LocalMatrix2.Scale(1.4f, 1.0f, 1.0f);

device.SetTexture(0, texture);
device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
device.VertexFormat = CustomVertex.PositionTextured.Format;
device.SetStreamSource(0, vb, 0);

matrixStack.MultiplyMatrixLocal(LocalMatrix1);
matrixStack.MultiplyMatrixLocal(LocalMatrix2);
device.Transform.World = matrixStack.Top;

device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
}




Re: Game Technologies: Graphics Texture looks good in 2D, but not 3D

MrHat

If I use OrthoLH, Im concerned about the space between the textures if I simply make them smaller instead of moving the camera away when zooming out. When I'm not zooming out, I want the textures to look as perfect as they do in 2D.

See Example




Re: Game Technologies: Graphics Texture looks good in 2D, but not 3D

Asesh

e.Device.SamplerState[0].MinFilter = TextureFilter.None;

You should set MinFilter and MagFilter to either linear or anisotropic for more better results