Advertisement Jump to content
Sign in to follow this  

UserControl and MDX

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

Hi! I'm trying to create a user control in C# that uses MDX to render a terrain. So far I was able to set up a device and a vertex buffer, however when I try to draw the vertex buffer I can't see the triangle in the control. In the constructor of my UserControl I create the device and the vertex buffer:
// Initialize directx components
PresentParameters d3dpp = new PresentParameters();
d3dpp.Windowed	 = true;
d3dpp.SwapEffect = SwapEffect.Discard;
d3dpp.BackBufferCount = 1;
d3dpp.PresentationInterval = PresentInterval.Immediate;
d3dpp.AutoDepthStencilFormat = DepthFormat.D24X8;
d3dpp.EnableAutoDepthStencil = true;

m_d3dDevice = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, d3dpp);

// create the vertex buffer

// set matrices
m_d3dDevice.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f,
    (float)ClientRectangle.Width / (float)ClientRectangle.Height, 0.1f, 1000.0f);

// set renderstates
m_d3dDevice.RenderState.Lighting = false;
m_d3dDevice.RenderState.CullMode = Cull.None;

the Vertex Buffer creation:
CustomVertex.TransformedColored[] verts = 
	new CustomVertex.TransformedColored[3];

verts[0] = 
	new CustomVertex.TransformedColored(
	0, 1, 1, 1, 
verts[1] = 
	new CustomVertex.TransformedColored(
	-1, -1, 1, 1, 
verts[2] = 
	new CustomVertex.TransformedColored(
	1, -1, 1, 1, 

m_d3dVertBuf = 
	new VertexBuffer(
	Usage.WriteOnly | Usage.SoftwareProcessing, 

GraphicsStream stm = m_d3dVertBuf.Lock(0, 0, 0);

And finally the rendering code:
protected override void OnPaint(PaintEventArgs e)
	if(m_d3dDevice != null)
		m_d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Navy, 1.0f, 0);

		m_d3dDevice.SetStreamSource(0, m_d3dVertBuf, 0);
		m_d3dDevice.VertexFormat = CustomVertex.TransformedColored.Format;
		m_d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);      



All I can see is the navy-blue of my empty control - no triangle - nothing. I already compared my code with several tutorials on the net but I couldn't find any errors or differences ... Thanks for any help!

Share this post

Link to post
Share on other sites
Hi there BRooksWackerman,
How are you doing?

The Problem
You are using Transformed coordinates

The Solution
Difference between Transformed and UnTransformed Coordinates.
The vertices that you specify here will be in screen space already and no transformations will take place. These coordinates are sometimes distinguishable by their large numbers (on some occasions, not always).

The vertices that you specify here will be in object space. What does this mean?
This just means that the vertices will need to undergo transformations (metamorphisis? ehehhe) to get to screen space. Such as
Object Space : Vertices are defined here
World Space : Vertices are located in the world (we go here from object space using a world transformation matrix)
View Space : The camera is located in the world and objects relocated around the camera (a view frustum is formed) we go here from world space using a view transformation matrix.
Clip Space : The view frustum is transformed to a cube to give us the impression of perspective. We go here from view space using a projection transformation matrix.

You have 2 options. Rectify the vertices in the following manner

verts[0] = new CustomVertex.TransformedColored(0.0f, 150.0f, 0.0f, 1.0f, Color.Blue.ToArgb()); //bottom left
verts[1] = new CustomVertex.TransformedColored(0.0f, 0.0f, 0.0f, 1.0f, Color.Green.ToArgb()); //top left
verts[2] = new CustomVertex.TransformedColored(150.0f, 150.0f, 0.0f, 1.0f, Color.Red.ToArgb()); //bottom right

or you could just set the CustomVertex.TransformedColored to CustomVertex.PositionColored.

I hope this helps a bit.

[Edited by - Armadon on September 9, 2005 2:34:56 PM]

Share this post

Link to post
Share on other sites
Hey Armadon!

Doing fine thx!
Thanks for your help bud - I should definitely get more sleep!! ;)
See you in #graphicsdev!

Cheers, Martin

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!