コード例 #1
0
void AnimatedParticle::render(IDirect3DDevice9* device)
{
	IDirect3DTexture9** texArray = NULL;
	device->SetTransform(D3DTS_WORLD, &transform);

	if (typeOfAnim == ANIM_EXPLOSION)
	{
		texArray = explosionTexArray;
		device->SetRenderState(D3DRS_POINTSIZE, FtoDw(10));
	}
	else
	{
		texArray = smokeTexArray;
		device->SetRenderState(D3DRS_POINTSIZE, FtoDw(12));
	}


	ParticlePoint* point;

	particleBuffer->Lock(0, sizeof(ParticlePoint), (void**) &point, D3DLOCK_DISCARD);

	point[0].pos = D3DXVECTOR3(0,0,0);
	point[0].color = D3DCOLOR_ARGB(alpha,255,255,255);

	particleBuffer->Unlock();

	device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
	device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	device->SetRenderState(D3DRS_LIGHTING, FALSE);

	device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
	device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
	device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

	device->SetRenderState(D3DRS_ALPHAREF, (unsigned long) 50);
	device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);

	device->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);

	device->SetTexture(0, texArray[currentFrame]);

	device->SetStreamSource(0, particleBuffer, 0, sizeof(ParticlePoint));
	device->DrawPrimitive(D3DPT_POINTLIST, 0, 1);

	device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
	device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
}
コード例 #2
0
void ComParticle::Render()
{
	pDevice9->SetRenderState(D3DRS_ZWRITEENABLE, false);
	pDevice9->SetRenderState(D3DRS_LIGHTING, false);
	pDevice9->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
	pDevice9->SetRenderState(D3DRS_POINTSCALEENABLE, true);

	pDevice9->SetRenderState(D3DRS_POINTSIZE, FtoDw(0.6f));
	pDevice9->SetRenderState(D3DRS_POINTSIZE_MIN, FtoDw(0.0f));

	pDevice9->SetRenderState(D3DRS_POINTSCALE_A, FtoDw(0.0f));
	pDevice9->SetRenderState(D3DRS_POINTSCALE_B, FtoDw(0.0f));
	pDevice9->SetRenderState(D3DRS_POINTSCALE_C, FtoDw(1.0f));

	//pDevice9->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
	//pDevice9->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
	//pDevice9->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
	//pDevice9->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

	// 알파 블랜딩
	pDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	pDevice9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	//pDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	pDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

	// 렌더링
	pDevice9->SetTransform(D3DTS_WORLD, &gameObject->transform->GetWorldMatrix());
	pDevice9->SetTexture(0, texture);
	pDevice9->SetFVF(Particle::FVF);
	pDevice9->SetStreamSource(0, m_VB, 0, sizeof(Particle));

	// POINTLIST로 그려줌, 빌보딩이 자동적으로 되고 있음
	pDevice9->DrawPrimitive(D3DPT_POINTLIST, 0, m_vecParticles.size());

	// post
	pDevice9->SetRenderState(D3DRS_ZWRITEENABLE, true);
	pDevice9->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
	pDevice9->SetRenderState(D3DRS_POINTSCALEENABLE, false);
	pDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, false);

	// restore
	pDevice9->SetRenderState(D3DRS_LIGHTING, true);
	pDevice9->SetTexture(0, NULL);
}
コード例 #3
0
void cMainGame::Setup()
{
// 	m_pMap = new cHeightMap;
// 	m_pMap->Setup("HeightMapData", "HeightMap.raw", "terrain.jpg");

	
	m_vecVertex.resize(1000);
	for (int i = 0; i < m_vecVertex.size(); ++i)
	{
		m_vecVertex[i].p = D3DXVECTOR3(
			(rand() % 1000 - 500) / 10.0f,
			(rand() % 1000 - 500) / 10.0f,
			(rand() % 1000 - 500) / 10.0f);
		m_vecVertex[i].c = D3DCOLOR_ARGB(255, 180, 70, 20);
	}

	// 포인트를 확대 축소 할 수 있게 해줌
	g_pD3DDevice->SetRenderState(D3DRS_POINTSCALEENABLE, true); 

	// 포인트 사이즈 설정
	g_pD3DDevice->SetRenderState(D3DRS_POINTSIZE, FtoDw(10.0f));

	// 포인트 스케일링 Factor값 설정
	g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_A, FtoDw(0.0f));
	g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_B, FtoDw(0.0f));
	g_pD3DDevice->SetRenderState(D3DRS_POINTSCALE_C, FtoDw(1.0f));

	// 포인트 최소 크기
	g_pD3DDevice->SetRenderState(D3DRS_POINTSIZE_MIN, FtoDw(0.0f));

	// 포인트 최대 크기
	g_pD3DDevice->SetRenderState(D3DRS_POINTSIZE_MAX, FtoDw(100.0f));

	// 포인트에 텍스쳐를 입힐 수 있게 해줌
	g_pD3DDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, true);

	// 알파블랜딩 방식 결정.
	g_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	g_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

	// 텍스쳐 알파 옵션 설정
	g_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );  
	g_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );  
	g_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );  


	cSkinnedMesh* pSkinnedMesh = new cSkinnedMesh("Zealot/", "zealot.X");
	pSkinnedMesh->SetAnimationIndex(3);

	m_pCharacter = pSkinnedMesh;

	m_pGrid = new cGrid;
	m_pGrid->Setup();

	m_pCamera = new cCamera;
	m_pCamera->Setup();
	m_pCamera->SetTarget(&m_pCharacter->GetPosition());
	SetLight();
}
コード例 #4
0
bool Renderer::initialize(int width, int height, HWND hwnd, float zNear, float zFar, int numToDraw, char* msg)
{
	numDrawables = numToDraw;
	useTwoSidedStencils = false;

	drawables = new Drawable*[numToDraw];
	dynamicDrawables = new std::vector<Drawable*>();
	dynamicDrawables->clear();
	dynamicDrawables->reserve(100);
	
	hud = new HUD(width, height);
	menuHandler = new MenuHandler(width, height);

	d3dObject = Direct3DCreate9(D3D_SDK_VERSION);
	
	D3DCAPS9 caps;
	d3dObject->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);

	if (!(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT))
	{
		LPCTSTR descr = "This program requires a video card that supports hardware vertex processing!";
		strcpy_s((char*) msg, 128, descr);
		
		return false;
	}


	useTwoSidedStencils = ((caps.StencilCaps & D3DSTENCILCAPS_TWOSIDED) != 0);


	D3DPRESENT_PARAMETERS params;

	ZeroMemory(&params,sizeof(D3DPRESENT_PARAMETERS));

	params.Windowed = TRUE;
	params.BackBufferCount= 1;
	params.BackBufferFormat = D3DFMT_X8R8G8B8;
	
	params.BackBufferWidth = width;
	params.BackBufferHeight = height;
	params.SwapEffect = D3DSWAPEFFECT_DISCARD;
	params.hDeviceWindow = hwnd;
	params.EnableAutoDepthStencil = TRUE;
	params.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;

	// VSYNC. Change to INTERVAL_IMMEDIATE to turn off VSYNC, change to INTERVAL_ONE to turn on VSYNC
	params.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

	// Now need to set up the depth stencil format.
	D3DFORMAT formats[] = { D3DFMT_D24S8, D3DFMT_D24X4S4, D3DFMT_D24FS8 };
	
	D3DFORMAT format = (D3DFORMAT) 0;
	
	for (int i = 0; i < 3; i++)
	{
		HRESULT result = d3dObject->CheckDeviceFormat(D3DADAPTER_DEFAULT,
			D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL,
			D3DRTYPE_SURFACE, formats[i]);

		if (result == D3D_OK)
		{
			result = d3dObject->CheckDepthStencilMatch(D3DADAPTER_DEFAULT,
				D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, formats[i]);

			if (result == D3D_OK)
			{
				format = formats[i];
				break;
			}
		}
	}
	
	if (format == (D3DFORMAT) 0)
	{
		LPCTSTR descr = "Couldn't find a suitable depth format!";
		strcpy_s((char*) msg, 128, descr);
		
		return false;
	}
	
	params.AutoDepthStencilFormat = format;

	HRESULT result = d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, &device);

	if (FAILED(result))
	{
		LPCTSTR descr = DXGetErrorDescription(result);
		strcpy_s((char*) msg, 128, descr);
		
		return false;
	}

	device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
	device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);

	D3DVIEWPORT9 viewport;
	viewport.Width = width;
	viewport.Height = height;
	viewport.MinZ = 0.0f;
	viewport.MaxZ = 1.0f;
	viewport.X = 0;
	viewport.Y = 0;

	device->SetViewport(&viewport);

	float fieldOfView, screenAspect;

	// Setup the projection matrix.
	fieldOfView = (float)D3DX_PI / 2.5f;
	screenAspect = (float)width / (float)height;

	// Create the projection matrix for 3D rendering.
	D3DXMatrixPerspectiveFovLH(&projectionMatrix, fieldOfView, screenAspect, zNear, zFar);

	D3DXMatrixIdentity(&worldMatrix);
	
	camera = new Camera;
	
	device->SetRenderState(D3DRS_LIGHTING, TRUE);
	device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100));
	device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
	device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
	
	
	D3DLIGHT9 light;    // create the light struct
	D3DMATERIAL9 material;    // create the material struct
	
	ZeroMemory(&light, sizeof(light));    // clear out the light struct for use
	light.Type = D3DLIGHT_DIRECTIONAL;    // make the light type 'directional light'
	light.Diffuse = D3DXCOLOR(0.6f, 0.6f, 0.7f, 1.0f);    // set the light's color
	light.Ambient = D3DXCOLOR(0.1f, 0.1f, 0.1f, 1.0f);

	D3DXVec3Normalize(&lightDir, &lightDir);
	light.Direction = lightDir;
	
    device->SetLight(0, &light);    // send the light struct properties to light #0
	device->LightEnable(0, TRUE);    // turn on light #0

	ZeroMemory(&material, sizeof(D3DMATERIAL9));
	material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	material.Ambient = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f);

	device->SetMaterial(&material);    // set the globably-used material to &material

	// Set up font stuff
	D3DXCreateFont(device, 0, 10, FW_BOLD, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DRAFT_QUALITY,
		DEFAULT_PITCH | FF_DONTCARE, "Terminal", &font);

	device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTOP_SELECTARG1);
	device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);	// Just to be safe (ignored)
	device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);

	// Stuff for particle effects
	device->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
	device->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
	device->SetRenderState(D3DRS_POINTSCALE_A, FtoDw(0.0f));
	device->SetRenderState(D3DRS_POINTSCALE_B, FtoDw(0.0f));
	device->SetRenderState(D3DRS_POINTSCALE_C, FtoDw(1.0f));
	device->SetRenderState(D3DRS_POINTSIZE_MIN, FtoDw(0.1f));
	device->SetRenderState(D3DRS_POINTSIZE_MAX, FtoDw(1280.0f));
	
	// Set fog
	float startFog = 1.0f;
	float endFog = 500.0f;
	device->SetRenderState(D3DRS_FOGCOLOR, D3DCOLOR_ARGB(200,120,120,140));
	device->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
	device->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&startFog));
    device->SetRenderState(D3DRS_FOGEND, *(DWORD *)(&endFog));

	// Set up HUD
	hud->initialize(device);

	// Set up menu handler
	menuHandler->initialize(device);

	// Set up Skybox
	skybox = new Skybox(device);

	ShadowPoint* points;

	// Set up shadow texture
	device->CreateVertexBuffer(sizeof(ShadowPoint) * 4, D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW | D3DFVF_DIFFUSE,
		D3DPOOL_MANAGED, &shadowQuadVertexBuffer, NULL);

	shadowQuadVertexBuffer->Lock(0, sizeof(ShadowPoint) * 4, (void**) &points, NULL);

	points[0].position = D3DXVECTOR4(0, (FLOAT) height, 0, 1);
	points[1].position = D3DXVECTOR4(0, 0, 0, 1);
	points[2].position = D3DXVECTOR4((FLOAT) width, (FLOAT) height, 0, 1);
	points[3].position = D3DXVECTOR4((FLOAT) width, 0, 0, 1);
	points[0].color = D3DCOLOR_ARGB(180,0,0,0);
	points[1].color = D3DCOLOR_ARGB(180,0,0,0);
	points[2].color = D3DCOLOR_ARGB(180,0,0,0);
	points[3].color = D3DCOLOR_ARGB(180,0,0,0);

	shadowQuadVertexBuffer->Unlock();

	smokeSystem = new SmokeSystem();
	laserSystem = new LaserSystem();

	return true;
}