void CCParticleSystemPoint::draw(RenderContext* ctx)
{
	CCParticleSystem::draw(ctx);

	if (m_uParticleIdx == 0) return;

	if (!activateBuffers(ctx)) return;

	// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
	// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY
	// Unneeded states: GL_TEXTURE_COORD_ARRAY
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glBindTexture(GL_TEXTURE_2D, m_pTexture->activate(ctx));

	glEnable(GL_POINT_SPRITE_OES);
	glTexEnvi( GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE );	

#define kPointSize sizeof(m_pVertices[0])

	glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuf->useHandle(ctx));
	glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(ccPointSprite)*m_uParticleCount, m_pVertices);

	glVertexPointer(2,GL_FLOAT,kPointSize,0);

	glColorPointer(4, GL_UNSIGNED_BYTE, kPointSize,(GLvoid*)offsetof(ccPointSprite,color) );

	glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
	glPointSizePointerOES(GL_FLOAT,kPointSize,(GLvoid*) offsetof(ccPointSprite,size) );

    bool newBlend = (m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST) ? true : false;
	if( newBlend ) 
	{
		glBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
	}

	glDrawArrays(GL_POINTS, 0, m_uParticleIdx);

	// restore blend state
	if( newBlend )
		glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST);

	// unbind VBO buffer
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
	glDisable(GL_POINT_SPRITE_OES);

	// restore GL default state
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
Exemple #2
0
void CIronBall::drawModel()
{
	setRenderProperties();
	activateBuffers();
	ID3D11Buffer *conbuf = mpColorShader.GetVConstantBuffer();
	sVConstantBuffer &bufvdat = mpColorShader.GetVConstantBufferData();

	for (auto ball : CModelSets::getInstance()->getBallVectors())
	{
		//DirectX::XMMATRIX translation =
		//	DirectX::XMMatrixTranslation(ball.second.posActual[0], ball.second.posActual[1], 0.0f);
		//bufvdat.model = DirectX::XMMatrixTranspose(translation);
		MathUtil::CMatrix translation =
			MathUtil::MatrixTranslation(ball.second.posActual[0], ball.second.posActual[1], 0.0f);
		bufvdat.model = MathUtil::MatrixTranspose(translation);
		mpContext->UpdateSubresource(conbuf, 0, nullptr, &bufvdat, 0, 0);
		mpContext->VSSetConstantBuffers(0, 1, &conbuf);

		mpContext->DrawIndexed(mIndexBufferSize, 0, 0);
	}
}