Пример #1
0
bool Setup()
{
	Device->CreateVertexBuffer(
		3 * sizeof(ColorVertex),
		D3DUSAGE_WRITEONLY,
		ColorVertex::FVF,
		D3DPOOL_MANAGED,
		&Triangle,
		0);

	ColorVertex* v;
	Triangle->Lock(0, 0, reinterpret_cast<void**>(&v), 0);

	v[0] = ColorVertex(-1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(255, 0, 0));
	v[1] = ColorVertex(0.0f, 1.0f, 2.0f, D3DCOLOR_XRGB(0,255, 0));
	v[2] = ColorVertex(1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(0, 0, 255));

	Triangle->Unlock();

	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
		&proj,
		D3DX_PI*0.5f,
		static_cast<float>(Width) / static_cast<float>(Height),
		1.0f,
		1000.0f);

	Device->SetTransform(D3DTS_PROJECTION, &proj);

	Device->SetRenderState(D3DRS_LIGHTING, false);

	return true;
}
bool Setup()
{
	//Create the Vertex Buffer
	Device->CreateVertexBuffer(
		3 * sizeof(ColorVertex),
		D3DUSAGE_WRITEONLY, // usage
		ColorVertex::FVF,        // Vertex format
		D3DPOOL_MANAGED,    // managed memory pool
		&Triangle,          // return create vertex buffer
		0);

	//fill the vertex buffer
	ColorVertex* v;
	Triangle->Lock(0, 0, (void**)&v, 0);

	v[0] = ColorVertex(-1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(255,   0,   0));
	v[1] = ColorVertex( 0.0f, 1.0f, 2.0f, D3DCOLOR_XRGB(  0, 255,   0));
	v[2] = ColorVertex( 1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(  0,   0, 255));

	Triangle->Unlock();

	//投影矩阵
	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
		&proj,
		D3DX_PI * 0.5f,
		(float)Width / (float)Height,
		1.0f,
		1000.0f);
	Device->SetTransform(D3DTS_PROJECTION, &proj);
	Device->SetRenderState(D3DRS_LIGHTING, false); //普通的填充模式
	
	return true;
}
Пример #3
0
	virtual bool Setup(HINSTANCE hInstance, int width, int height, bool windowed, D3DDEVTYPE deviceType)
	{
		if (!D3DBase::Setup(hInstance, width, height, windowed, deviceType))
		{
			return false;
		}

		pDevice_->CreateVertexBuffer(3 * sizeof(ColorVertex),
			D3DUSAGE_WRITEONLY, FVF, D3DPOOL_MANAGED,
			&pTriangle, 0);
		// FIll the buffer with the triangle data

		ColorVertex *v;
		pTriangle->Lock(0, 0, (void **)&v, 0);
		v[0] = ColorVertex(-1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(255, 0, 0));
		v[1] = ColorVertex(0.0f, 1.0f, 2.0f, D3DCOLOR_XRGB(0, 255, 0));
		v[2] = ColorVertex(1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(0, 0, 255));

		pTriangle->Unlock();

		// set the projection matrix
		D3DXMATRIX proj;
		D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI * 0.5f,
			Width / Height, 1.0f, 1000.0f);
		pDevice_->SetTransform(D3DTS_PROJECTION, &proj);
		// turn off lighting

		pDevice_->SetRenderState(D3DRS_LIGHTING, false);
		return true;
	}
Пример #4
0
void Simulation::create_random_vertex(const int vertexIndex)
{
   const float centerX = random_float(-1.0f, 1.0f);
   const float centerY = random_float(-1.0f, 1.0f);
   const float Range = 0.15f;

   const unsigned char red = random_byte();
   const unsigned char green = random_byte();
   const unsigned char blue = random_byte();
   const unsigned char alpha = random_byte();

   currentVertices[vertexIndex + 0] = ColorVertex(centerX + random_float(-Range, Range), centerY + random_float(-Range, Range), red, green, blue, alpha);
   currentVertices[vertexIndex + 1] = ColorVertex(centerX + random_float(-Range, Range), centerY + random_float(-Range, Range), red, green, blue, alpha);
   currentVertices[vertexIndex + 2] = ColorVertex(centerX + random_float(-Range, Range), centerY + random_float(-Range, Range), red, green, blue, alpha);
   currentVertexCount += 3;
}