Jump to content
  • Advertisement
Sign in to follow this  
Sandra-24

Rendered a quad, but the texture is grainy and mirrored

This topic is 4707 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

They say a picture is worth a thousand words. The image on the right is drawn with directx. Image Hosted by ImageShack.us I managed to get my textured quad to display, but the image is reversed and very poor quality. How can I fix that? I setup an OrthoLH projection and 4 vertices that are rendered as a traingle strip. The region that I'm drawing to is a 512x512 panel, and I'm using a 512x512 bitmap that I loaded into a texture like: texture = new Texture(device, new Bitmap(Image.FromFile(@"M:\Images\5.jpg")), Usage.Dynamic, Pool.Default); Here's my relevant code for the camera and the vertices. Thanks, -Sandra
[source code=C#]
private void SetupCamera()
{
	device.Transform.Projection = Matrix.OrthoLH(2, 2, 0.0f, 1.0f);
        // **If I comment this line out, the image is no longer reversed**
	device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 1.0f), new Vector3(), new Vector3(0, 1, 0));
}

private void SetupVertices()
{
	vertices = new VertexBuffer(typeof(CustomVertex.PositionTextured),
		4, device, 0, CustomVertex.PositionTextured.Format, Pool.Default);

	CustomVertex.PositionTextured [] quad = (CustomVertex.PositionTextured[]) vertices.Lock(0, 0);

	// Bottom Left
	quad[0] = new CustomVertex.PositionTextured(-1, -1, 0.0f, 0,1);
	// Top Left
	quad[1] = new CustomVertex.PositionTextured(-1, 1, 0.0f, 0,0);
	// Bottom Right
	quad[2] = new CustomVertex.PositionTextured(1, -1, 0.0f, 1,1);
	// Top Right
	quad[3] = new CustomVertex.PositionTextured(1, 1, 0.0f, 1,0);

	vertices.Unlock();
}



[Edited by - Sandra-24 on August 29, 2005 5:16:37 PM]

Share this post


Link to post
Share on other sites
Advertisement
I posted the code right there. I assume they are correct. 0,0 being the top left, and 1,1 being the bottom right. If I take out the View = Matrix.LookAtLH() line then the image is no longer reversed. I'm less worried about why it is reversed than about why it is so blurry.

-Sandra

Share this post


Link to post
Share on other sites
I have no filtering / mipmaping or anything enabled, unless such things are enabled by default, in which case how do I turn them off?

-Sandra

Share this post


Link to post
Share on other sites
The blurring just looks like a resolution problem. And chance you're somehow creating the surface with a different resolution?

As for the flipping of the texture, it's probably a LH vs RH thing. Flip the order of your vertices.

Share this post


Link to post
Share on other sites
I had the same problem recently (never solved it). I was trying to make a skybox and my high res texture (512x512) looked awful like your screen shot. I don't know what the problem was because it was based on some old code I had written that worked perfectly. There's gotta be some filtering or mip mapping happening to cause that. I'll be monitoring this thread for the resolution. :)

Perhaps if you showed the code where you load and render the textures, it might shed some more light.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike Bossy
The blurring just looks like a resolution problem. And chance you're somehow creating the surface with a different resolution?

As for the flipping of the texture, it's probably a LH vs RH thing. Flip the order of your vertices.


Either what he said, or you have a backbuffer smaller than the destination rect in the form.
Texture filtering is disabled by default, but if you want to change it it must be something like device.SetSamplerState.. (I don't know C#).

Would you mind to show us your D3D presentation parameters that you're using to create the device?

Share this post


Link to post
Share on other sites
Ok, two things:

1) To make life easier, when you make the projection matrix use coordinates that correspond to pixels. That way positions of vertices line up with pixel positions on screen.

2) Once you do that, you need to correctly map texels to pixels. That means you need to translate all of the vertices by exactly (-.5, -.5). You can read more about this here. The basic idea is that mapping texels to pixels is a little unintuitive because of the way texels are referenced, and this leads to texels overlapping 4 pixels each and blurring the entire image.

Share this post


Link to post
Share on other sites
Thanks to everyone for all the input I really appreciate the help.

Quote:
Either what he said, or you have a backbuffer smaller than the destination rect in the form.


Bang on. I added:

presentParams.BackBufferHeight = 512;
presentParams.BackBufferWidth = 512;

To the code in Initialize() and it looks just like the image on the left (except reversed.) Thanks a bundle!

Here's what it looks like now:
Free Image Hosting at www.ImageShack.us

Quote:
As for the flipping of the texture, it's probably a LH vs RH thing. Flip the order of your vertices.


Reversing the order of the vertices had no effect at all. Changing the projection to RH and the z palne to -1.0 - 0 had no effect with either vertex order.

Quote:
To make life easier, when you make the projection matrix use coordinates that correspond to pixels. That way positions of vertices line up with pixel positions on screen.


This I would love. But how?

Quote:
Once you do that, you need to correctly map texels to pixels...


I think I understand how to do this, but I would need to solve 1) first.

Quote:
Would you mind to show us your D3D presentation parameters that you're using to create the device?


[source land=C#]
private void Initialize()
{
presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.DeviceWindow = this;
presentParams.BackBufferHeight = 512;
presentParams.BackBufferWidth = 512;
presentParams.PresentationInterval = PresentInterval.One;
presentParams.SwapEffect = SwapEffect.Discard;

// store our default adapter
int adapterOrdinal = Manager.Adapters.Default.Adapter;
// get our device capabilities so we can check
Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware);
CreateFlags createFlags;

if(caps.DeviceCaps.SupportsHardwareTransformAndLight)
createFlags = CreateFlags.HardwareVertexProcessing;
else
createFlags = CreateFlags.SoftwareVertexProcessing;

if(caps.DeviceCaps.SupportsPureDevice)
createFlags |= CreateFlags.PureDevice;

// create our device
device = new Device(adapterOrdinal, DeviceType.Hardware, this.Handle, createFlags, presentParams);

SetupDevice();
SetupCamera();
SetupVertices();
}


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!