drawing triangle

Started by
21 comments, last by jbadams 4 years, 10 months ago

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), },
	};

 

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).

 

 

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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. 

12 hours ago, GoliathForge said:

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

can you explain this further

sure directxtutorial.com lesson 4 in direct x 9 menu

I'm so sorry...I thought we wanted to animate the colors through the formatted vertices. @Endurion ninja'd. Why don't you just give valid values. You appear to know it's between 0 and 255 for each. What is stopping you from changing the colors? Here is a decent online color wheel https://www.rapidtables.com/web/color/RGB_Color.html 

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.

 

 

Hi Phil...Did the color wheel help with visualizing how colors are represented by a set of integer ranged values? Or is it something else that is holding you down. 

is there any good dx9  tutorials out there?

This topic is closed to new replies.

Advertisement