Advertisement

more directx9 tutorial

Started by March 18, 2021 09:42 PM
10 comments, last by pbivens67 3ย years, 8ย months ago

I am still working on the exercises in a direct x9 tutorial. I am trying to get a triangle to fade the colors at the vertices. sorry for all the handholding but I am very new at dx9, I am still reading my tutorial. here is the code I am using.

void initD3D(HWND hWnd)
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

	D3DPRESENT_PARAMETERS d3dpp;

	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = hWnd;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferWidth = SCREEN_WIDTH;
	d3dpp.BackBufferHeight = SCREEN_HEIGHT;

	// create a device class using this information and the info from the d3dpp stuct
	d3d->CreateDevice(D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp,
		&d3ddev);

	for (int i = 0; i < 256; i++)
	{
	init_graphics();    // call the function to initialize the triangle
	}
}

int x = 0, count = 0;

// this is the function used to render a single frame
void render_frame(void)
{
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	d3ddev->BeginScene();

	// select which vertex format we are using
	d3ddev->SetFVF(CUSTOMFVF);

	// select the vertex buffer to display
	d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));

	// copy the vertex buffer to the back buffer
	d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	d3ddev->EndScene();

	d3ddev->Present(NULL, NULL, NULL, NULL);
}


// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
	v_buffer->Release();    // close and release the vertex buffer
	d3ddev->Release();    // close and release the 3D device
	d3d->Release();    // close and release Direct3D
}

// 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, x++), },
			{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, x++, 0), },
		};
	// create a vertex buffer interface called v_buffer
	d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX),
		0,
		CUSTOMFVF,
		D3DPOOL_MANAGED,
		&v_buffer,
		NULL);

	VOID* pVoid;    // a void pointer

	// lock v_buffer and load the vertices into it
	v_buffer->Lock(0, 0, (void**)&pVoid, 0);
	memcpy(pVoid, vertices, sizeof(vertices));
	v_buffer->Unlock();
}

What happens when you run the code? Do the colors fade at the vertices or not?

-- Tom Sloper -- sloperama.com

Advertisement

when I run my code it only draws the triangle but the colors are static

See, it helps if you tell people what your problem is, and what you need help with.

-- Tom Sloper -- sloperama.com

@pbivens67 You can't run from them foreverโ€ฆ

I just googled for this, the internet is awesome.

๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚<โ†The tone posse, ready for action.

@fleabay , your hint (if that's what it is) is rather cryptic.

-- Tom Sloper -- sloperama.com

Advertisement

before I get into shaders I think I should learn the basics of direct x9 first. tom are you good at directx9?

@pbivens67 no, I am not a programmer. I'm a designer/producer. Don't ask me programming questions. I'm just moderating here.

-- Tom Sloper -- sloperama.com

@fleabay are you good at directx9?

@pbivens67 I use OpenGL. I'm slowly learning Direct3D 11.

๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚<โ†The tone posse, ready for action.

This topic is closed to new replies.

Advertisement