3_DirectX_Color颜色

本文主要介绍了在DirectX中如何处理颜色,通过d3dUtility.h、d3dUtility.cpp和ColorTriangle.cpp三个文件的学习,展示了如何创建并显示具有不同颜色的三角形,从而理解颜色在3D图形中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

好了好了,

现在开始进行第四章,关于颜色的一个学习,

Ok、

话不多少,老规矩,上第一个d3dUtility.h


#ifndef __d3dUtilityH__
#define __d3dUtilityH__

#include <d3dx9.h>
#include <string>

namespace d3d
{
	//函数的声明:
	bool InitD3D(
		HINSTANCE hInstance,
		int width, int height,
		bool windowed,
		D3DDEVTYPE deviceType,
		IDirect3DDevice9** device);

	int EnterMsgLoop(
		bool (*ptr_display)(float timeDelta));

	LRESULT CALLBACK WndProc(
		HWND hwnd,
		UINT msg,
		WPARAM wParam,
		LPARAM lParam);

	//模板函数,通过起到清除内存空间的作用
	template<class T>void Release(T t)
	{
		if(t)
		{
			t->Release();
			t = 0;
		}
	}

	template<class T>void Delete(T t)
	{
		if(t)
		{
			delete t;
			t = 0;
		}
	}

	//好!现在就到了本章的重点,创建一个D3DXCOLOR,——定义相应的颜色的值

	const D3DXCOLOR WHITE( D3DCOLOR_XRGB(255,255,255));
	const D3DXCOLOR BLACK( D3DCOLOR_XRGB(  0,  0,  0));
	const D3DXCOLOR   RED( D3DCOLOR_XRGB(255,  0,  0));
	const D3DXCOLOR GREEN( D3DCOLOR_XRGB(  0,255,  0));
	const D3DXCOLOR  BLUE( D3DCOLOR_XRGB(  0,  0,  0));
	const D3DXCOLOR     YELLOW( D3DCOLOR_XRGB(255, 255,   0) );
	const D3DXCOLOR       CYAN( D3DCOLOR_XRGB(  0, 255, 255) );
	const D3DXCOLOR    MAGENTA( D3DCOLOR_XRGB(255,   0, 255) );


}





#endif 



接着是d3dUtility.cpp


#include "d3dUtility.h"

bool d3d::InitD3D(
	HINSTANCE hInstance,
	int width, int height,
	bool windowed,
	D3DDEVTYPE deviceType,
	IDirect3DDevice9** device)
{
	WNDCLASS wc;

	wc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值