• 9
• 13
• 9
• 18
• 19

# [.net] [DirectX] Very very basic project

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

## Recommended Posts

Hi everyone ! I feel now that I should make a little project to see if I understood well everything I just learned about C# DirectX. Do you guys have any idea of something really really basic to do that would help me see if I understood all the stuff taught here ? http://users.pandora.be/riemer/index.html. [Edited by - White Scorpion on January 3, 2005 7:40:28 PM]

##### Share on other sites
Well, the tutorial taught you to make a VB/ID'd heightmap, which I'm assuming that you did. :)

If you want a challenge to spice things up while still building off of your existing heightmap project, try one/some of these:

* Applying colours to each vertex based on the pixel colour on the image file (simple-ish)
* Applying textures to each vertex based on the pixel colour on the image file read (intermediate)
* Adding a variable-height 'water' plane over the terrain (simple-ish) and perhaps a scrolling texture across it (intermediate)
* Play with billboarding (see the SDK example) and get trees scattered around your heightmap (more challenging)
* To test your understanding, how about allowing the size (width/height) of the heightmap to be modified during runtime? (tricky :P)

Good luck, directxmonger. :)

##### Share on other sites
Do you have any good link on using textures ? And when you say "based on the pixel color", what file format are you talking about ? Because that tutorial used .raw files so it's only black&white. I managed to set the vertices to the proper color though. As for the other points well I think I'll have to read a little more on DX before I can do them :P

##### Share on other sites
Quote:
 Do you have any good link on using textures ?

Check out Tutorial 5 in the DXSDK samples.

Quote:
 And when you say "based on the pixel color", what file format are you talking about ? Because that tutorial used .raw files so it's only black&white.

Ah, I was assuming you were using an RGB(A) image format. It shouldn't be very hard to convert the RAW image to a BMP/PNG/JPG to load instead, though. :)

##### Share on other sites
I took a peek at the tutorial and initialized my texture and all but now I have to use the Tu and Tv members... I don't quite understand what they are each... I know you have to specify the top-left coordinate of the texture and bottom right... but how ? I already have this code... but now I must replace the color member by those Tu and Tv, how should I do this ? I made a 2 "textures"... one is a completely green bitmap ("grass") and the other one is completely brown ("mudd"). I wish the mudd to be the texture used when Z > 0 and grass when Z == 0 but I don't really know how to mess with the vertex buffer again...

Here's the code I've got so far:
/// <summary>/// Creates the VertexBuffer object/// Sets up each vertex with its corresponding position/color/// </summary>public void VertexBufferSetUp(){	VBuf = new VertexBuffer(typeof(CustomVertex.PositionTextured), WIDTH*HEIGHT, D3DDevice,		Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);	Vertices = new CustomVertex.PositionTextured[WIDTH*HEIGHT];	for(int x = 0; x < WIDTH; x++)	{		for(int y = 0; y < HEIGHT; y++)		{			Vertices[x+y*WIDTH].Position = new Vector3(x, y, HeightData[x,y]);			if(HeightData[x,y] == 0)			{				Vertices[x+y*WIDTH].Color = Color.Black.ToArgb();			}			if(HeightData[x,y] > 0)			{				Vertices[x+y*WIDTH].Color = Color.White.ToArgb();			}		}	}	VBuf.SetData(Vertices, 0, LockFlags.None);}
Should I do something like this ?
if(HeightData[x,y] == 0){    // Tell it to use the grass texture, but how ???!!}if(HeightData[x,y] > 0){    // Tell it to use the mudd texture, but how ???!!}Vertices[x+y*WIDTH].Tu = ((x%2) ? 1.0f : 0.0f);Vertices[x+y*WIDTH].Tv = ((y%2) ? 1.0f : 0.0f);
Am I at least near ?