Jump to content
  • Advertisement
Sign in to follow this  
vidalsasoon

textured quad ain't working!

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

I'm setting up my quad to cover half my screen. I just want to put a texture on it to then use it as a rendertarget... but, I can't even get the regular texture to work. What happens is that half the screen has the general color of the texture but the color is uniform... maybe my texture coords are wrong? Init Code

			this.D3DDevice.RenderState.ZBufferEnable = true;

			this.D3DDevice.RenderState.Lighting = false;
			this.D3DDevice.RenderState.CullMode = Cull.None;

			Global.Projection = Matrix.PerspectiveFovLH(
				(float) Math.PI/4,
				this.ClientSize.Width/(float)this.ClientSize.Height,
				0.1f, 1000.0f);

			this.D3DDevice.Transform.Projection = Global.Projection;

			#region renderTarget quad

			
			vertBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColoredTextured), 4 , this.D3DDevice, 0, CustomVertex.TransformedColoredTextured.Format, Pool.Managed);
			
			verts = (CustomVertex.TransformedColoredTextured[])vertBuffer.Lock(0, typeof(CustomVertex.TransformedColoredTextured), LockFlags.None, 4);

			vertFormat = VertexFormats.Transformed | Microsoft.DirectX.Direct3D.VertexFormats.Texture0; 

			verts[0].Position = new Vector4( 0.0f,this.ClientSize.Height, 1.0f, 1);
			verts[0].Color = Color.Red.ToArgb();
			verts[0].Tu = 0f;
			verts[0].Tv = 1f;

			verts[1].Position = new Vector4( 0.0f, 0.0f, 1.0f, 1 );
			verts[1].Color = Color.Green.ToArgb();
			verts[1].Tu = 0f;
			verts[1].Tv = 0f;

			verts[2].Position = new Vector4( this.ClientSize.Width/2, 0.0f, 1.0f, 1 );
			verts[2].Color = Color.Blue.ToArgb();
			verts[2].Tu = 1f;
			verts[2].Tv = 0f;

			verts[3].Position = new Vector4( this.ClientSize.Width/2, this.ClientSize.Height, 1.0f, 1 );
			verts[3].Color = Color.Cyan.ToArgb();
			verts[3].Tu = 1f;
			verts[3].Tv = 1f;

			vertBuffer.Unlock();

			renderTexture = TextureLoader.FromFile(this.D3DDevice, Global.settings.InstallPath + @"resources\" + "simmons.jpg");

Render() loop
			this.D3DDevice.SetTexture(0,renderTexture);
			this.D3DDevice.TextureState[0].ColorOperation = TextureOperation.Modulate;
			this.D3DDevice.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
			this.D3DDevice.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
			this.D3DDevice.TextureState[0].AlphaOperation = TextureOperation.Disable;

			this.D3DDevice.SetStreamSource(0, vertBuffer, 0);
			this.D3DDevice.VertexFormat = vertFormat;
			this.D3DDevice.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); //half number in array + y axis. (1 line has 2 points)
			

Share this post


Link to post
Share on other sites
Advertisement
I'm not a MDX programmer usually, but one thing I spotted that looks a little suspect (everything else seems okay to me):

You create the vertex buffer using the correct FVF:

vertBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColoredTextured), 4 ...

But then you assign the wrong FVF to a local (?) variable:

vertFormat = VertexFormats.Transformed | Microsoft.DirectX.Direct3D.VertexFormats.Texture0;

And then you then seem to use this to set to your device:

this.D3DDevice.VertexFormat = vertFormat;

Which, to me, looks like your vertex formats won't match correctly. Thus it's possible that D3D is reading your vertex data incorrectly and interpretting the wrong values - which could lead to the odd graphical results that you're seeing.

Usually running through with the debug runtime (link in my signiture) will scream and shout about mismatched FVF's...

hth
Jack

P.S. Try using [ source ] tags in future, it's a lot more readable!

Share this post


Link to post
Share on other sites
well, I had changed this to:

vertFormat = VertexFormats.Transformed | VertexFormats.Texture1;

and I did end up seeing my texture. However, it's all stretched out. I've trying to figure out if this is a problem with my Tu and Tv values.



What should show up...

Share this post


Link to post
Share on other sites
Quote:
Original post by vidalsasoon
FIXED!

you were right jolly.

Yay! [grin]

Getting the data mappings correct (or incorrect as the case may be) is an easy source of bugs. Luckily the debug runtimes usually churn out a lot of messages about mismatched streams/fvf/declarations.

Jack

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!