Example #1
0
void CircleSweep(float x, float y, float radius, float start, float end, size_t count, rImmediateBuffer& geometry, float zValue, CircleIndexFunc indexFunc){
	unsigned short centerIndex = geometry.VertexCount();
	unsigned short currentIndex = centerIndex;
	rVector3 center(x,y, zValue);

	geometry.PushVertex(center);

	float deg = start;
	float step = (end - start) / (float)count;
	rVector3 vertex;

	for (uint16_t i = 0; i <= count; i++){
		float rad = rMath::DegreeToRad(deg);

		vertex.Set(std::cos(rad), std::sin(rad), 0.0);
		vertex.x *= radius;
		vertex.y *= -radius;
		vertex = center + vertex;

		geometry.PushVertex(vertex);
		currentIndex += 1;

		indexFunc(centerIndex, i, currentIndex);
		
		deg += step;

		if (deg > end)
			deg = end;
	}
}
Example #2
0
void AppendRectVerticies(const rRect& rect, rImmediateBuffer& geometry, float zValue){
	unsigned short offset = geometry.VertexCount();

	CreateRectVerticies(rect, geometry, zValue);

	for (size_t i = 0; i < 6; i ++)
		geometry.PushIndex(offset + rectIndicies[i]);

}
Example #3
0
bool rGeometryUtil::CreateWireRectVerticies(const rRect& rect, rImmediateBuffer& geometry, float zValue){
	if (geometry.GeometryType() != rGeometryType::Lines) return false;

	uint16_t baseIndex = (uint16_t)geometry.VertexCount();
	for (uint16_t i = 0; i < 8; i++){
		geometry.PushIndex(wireRectIndicies[i] + baseIndex);
	}

	CreateRectVerticies(rect, geometry, zValue);

	return true;
}
Example #4
0
bool rGeometryUtil::CreateRectVerticies(const rRect& rect, rImmediateBuffer& geometry, bool texCoords, float zValue){
	if (geometry.GeometryType() != rGeometryType::Triangles) return false;
	if (texCoords && !geometry.HasTexCoords()) return false;

	uint16_t baseIndex = (uint16_t)geometry.VertexCount();
	for (uint16_t i = 0; i < 6; i++){
		geometry.PushIndex(rectIndicies[i] + baseIndex);
	}
	
	if (texCoords){
		CreateRectVerticiesWithTexCoords(rect, geometry, zValue);
	}
	else{
		CreateRectVerticies(rect, geometry, zValue);
	}

	return true;
}
Example #5
0
bool rGeometryUtil::CreateRoundedWireRectVerticies(const rRect& rect, float radius, size_t detail, rImmediateBuffer& geometry, float zValue){
	if (geometry.GeometryType() != rGeometryType::Lines) return false;

	CircleIndexFunc indexFunc = [&](uint16_t centerIndex, uint16_t vertexNum, uint16_t currentIndex){
		if (vertexNum)
			geometry.PushIndex(currentIndex - 1, currentIndex);
	};

	size_t offset = geometry.VertexCount();

	GenerateRoundedBorders(rect, radius, detail, geometry, zValue, indexFunc);
	
	geometry.PushIndex(offset + detail + 1, offset + detail + 3);
	geometry.PushIndex(offset + (2 * detail) + 3, offset + (2 * detail) + 5);
	geometry.PushIndex(offset + (3 * detail) + 5, offset + (3 * detail) + 7);
	geometry.PushIndex(offset + (4 * detail) + 7, offset + 1);

	return true;
}
void rOpenGLGraphicsDevice::RenderImmediate(const rImmediateBuffer& geometry, const rMatrix4& transform, rMaterial* material){
	if (material && geometry.VertexCount() > 0){
		size_t vertexElementSize = geometry.VertexSize();
		bool texCoords = geometry.HasTexCoords();

		GLsizei vertexStride = texCoords ? (vertexElementSize + 2) * sizeof (GLfloat) : 0;

		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

		SetActiveMaterial(material);

		GLint programId = material->Shader()->ProgramId();
		GLuint gPositionLoc = glGetAttribLocation ( programId, "recPosition" );
		GLuint gMatrixLoc = glGetUniformLocation ( programId, "recMVPMatrix" );
		GLuint gTexCoordLoc = 0;
		
		glUniformMatrix4fv(gMatrixLoc, 1, GL_FALSE, transform.m);

		glVertexAttribPointer ( gPositionLoc, vertexElementSize, GL_FLOAT, GL_FALSE, vertexStride, geometry.VertexData() );
		glEnableVertexAttribArray ( gPositionLoc );

		if (texCoords){
			gTexCoordLoc = glGetAttribLocation ( programId, "recTexCoord" );
			glVertexAttribPointer ( gTexCoordLoc, 2, GL_FLOAT, GL_FALSE, vertexStride, geometry.VertexData() + (vertexElementSize * sizeof (GLfloat)));
			glEnableVertexAttribArray ( gTexCoordLoc );
		}
		glDrawElements ( GLGeometryType(geometry.GeometryType()), geometry.IndexCount(), GL_UNSIGNED_SHORT, geometry.IndexData() );

		glDisableVertexAttribArray ( gPositionLoc );

		if (texCoords)
			glDisableVertexAttribArray ( gTexCoordLoc );

	}
}