Exemple #1
0
void Batch2D::Begin(){
	
	//bind the shader program
	shaderProgram.Bind();
	//bind the vao, automatically element buffer and attribute info
	glBindVertexArray(vao.get());
	//bind the vertex array, not automatically done by vao
	glBindBuffer(GL_ARRAY_BUFFER, vertexBuff.get());

	//enable alpha blending
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	//no texture has been assigned
	texture = nullptr;

	//allow buffer loading
	MapBuffers();

	//number of instances defaults to 0
	instanceCount = 0;

	//set 2d projection matrix to screen size
	GLint viewportInfo[4];
	glGetIntegerv(GL_VIEWPORT, viewportInfo);
	glm::mat4 projMat = glm::ortho(0.f, (float)viewportInfo[2], (float)viewportInfo[3], 0.f);
	glUniformMatrix4fv(0, 1, GL_FALSE, glm::value_ptr(projMat));

	glPointSize(40.0f);
}
Exemple #2
0
void CHUDMesh::Draw()
{
	// Grab Render Components //
	ID3D11DeviceContext* d3dContext = GRAPHICS->GetDeviceContext();

	// Set Shader Resource View //
	d3dContext->PSSetShaderResources(0, 1, &m_d3dDiffuse);

	if (m_bNormalMapped)
		d3dContext->PSSetShaderResources(1, 1, &m_d3dNormals);

	// Set Vertex + Index Buffers //
	unsigned int nOffset = 0;
	unsigned int nStrideSize = sizeof(TVertex2D);

	d3dContext->IASetIndexBuffer(m_d3dIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
	d3dContext->IASetVertexBuffers(0, 1, &m_d3dVertexBuffer, &nStrideSize, &nOffset);

	// Map Constant Buffers //
	MapBuffers();

	if (m_nInstances)
		d3dContext->DrawIndexedInstanced(m_nIndexArr.size(), m_nInstances, 0, 0, 0);
	else
		d3dContext->DrawIndexed(m_nIndexArr.size(), 0, 0);
}
Exemple #3
0
//draw sprites to framebuffer
void Batch2D::Flush(){
	UnmapBuffers();
	glDrawElements(GL_TRIANGLES, instanceCount * indexPerSprite, GL_UNSIGNED_SHORT, 0);
	instanceCount = 0;
	MapBuffers();
}