Jump to content
  • Advertisement
phil67rpg

drawing triangle

Recommended Posts

well I am working on a direct x tutorial, I have  drawn a triangle with colors, I want to change  the colors of the  triangle. I am very new to direct x, go easy on me.

int x = 255, y = 255, z = 255;

// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{
	// create the vertices using the CUSTOMVERTEX struct
	CUSTOMVERTEX vertices[] =
	{
		{ 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(x--, 0,  0), },
		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, y--), },
		{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, z--, 0), },
	};

 

Share this post


Link to post
Share on other sites
Advertisement

The colors are defined by the D3DCOLOR_XRGB macros. The three parameters are R, G and B part of the color.

I'd get a different tutorial. This code names the R, G, B parts with x, y, z (which is highly confusing).

 

 

Share this post


Link to post
Share on other sites

we could ignore that and consider it perhaps an inkling towards the swizzle concept. Hi Phil :) 

If you do it on the path you are on, you will have to update your buffer per an interval or per frame. DirectX9 is fine, There are some cool things that lived in that space, I'm thinking the .fx format which I thought was neat (when I had it working), umm...the era of the .x file format. That thing I thought would live forever. Funny how that goes. There's a nice long trek ahead on this path...

When I go to pull the documentation on this I get [ docs.ms/d3d9/acessing the contents of a vertex buffer ] 

And the relevant [ docs.ms/d3d9/creating a vertex buffer ]

The other option is through the programmable shader pipeline. Which will be quite some setup if you're not there already. The decrement thing in the array initialization is weird. 

Share this post


Link to post
Share on other sites
12 hours ago, GoliathForge said:

you will have to update your buffer per an interval or per frame.

can you explain this further

Share this post


Link to post
Share on other sites

That tutorial is not the best at explaining what they are doing and is a little 'old school messy'. In that tutorial:

 

struct CUSTOMVERTEX
{
    FLOAT x, y, z, rhw;    // from the D3DFVF_XYZRHW flag
    DWORD color;    // from the D3DFVF_DIFFUSE flag
}

This is the vertex format. The DWORD color part is the color. DWORD is 32 bits, or probably ARGB but its up to the shader how it uses the info. Because this tutorial isn't using shaders, you need to follow the defined color format.

This line:

  d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;

Confirms the target will accept colours as 4 bytes in XRGB. Note the X means it doesn't care about the first byte of the DWORD (the first byte that could have been alpha in an ARGB format).

D3DCOLOR_XRGB

This is a macro that converts the 3 values (red, green, blue as integers between 0 and 255) into the DWORD color.

You could replace the macro with 0xFFFFFF to mean white, 0xFF0000 to mean red, or 0x000000 to mean black etc.

 

The x, y and z in the D3DCOLOR_XRGB macro example  are used just to give some color variation. Doing the 'x--' decrements in the macro is confusing though.

 

 

Share this post


Link to post
Share on other sites
2 hours ago, phil67rpg said:

is there any good dx9  tutorials out there?

All written in Pascal unfortunately.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!