Example #1
0
void DebugRenderer::DrawSolidCircle (const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color)
{
#ifndef NO_DEBUG_RENDERER
	const float32 k_segments = 16.0f;
	const int vertexCount = 16;
	const float32 k_increment = 2.0f * b2_pi / k_segments;
	float32 theta = 0.0f;

	GLfloat glVertices[vertexCount * 2];
	for (int i = 0; i < k_segments; ++i) {
		const b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
		glVertices[i * 2] = v.x;
		glVertices[i * 2 + 1] = v.y;
		theta += k_increment;
	}

	setColorPointer(color, 0.5f, vertexCount);
	glVertexPointer(2, GL_FLOAT, 0, glVertices);
	glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
	setColorPointer(color, 1.0f, vertexCount);
	glDrawArrays(GL_LINE_LOOP, 0, vertexCount);
	GL_checkError();

	// Draw the axis line
	DrawSegment(center, center + radius * axis, color);
#endif
}
Example #2
0
void DebugRenderer::DrawSolidPolygon (const b2Vec2* vertices, int vertexCount, const b2Color& color)
{
#ifndef NO_DEBUG_RENDERER
	glVertexPointer(2, GL_FLOAT, 0, vertices);

	setColorPointer(color, 0.5f, vertexCount);
	glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);

	setColorPointer(color, 1.0f, vertexCount);
	glDrawArrays(GL_LINE_LOOP, 0, vertexCount);
	GL_checkError();
#endif
}
Example #3
0
void DebugRenderer::DrawSegmentWithAlpha (const b2Vec2& p1, const b2Vec2& p2, const b2Color& color, float alpha)
{
#ifndef NO_DEBUG_RENDERER
	setColorPointer(color, alpha, 2);
	const GLfloat glVertices[] = { p1.x, p1.y, p2.x, p2.y };
	glVertexPointer(2, GL_FLOAT, 0, glVertices);
	glDrawArrays(GL_LINES, 0, 2);
	GL_checkError();
#endif
}
Example #4
0
void DebugRenderer::DrawPoint (const b2Vec2& p, float32 size, const b2Color& color)
{
#ifndef NO_DEBUG_RENDERER
	setColorPointer(color, 1.0f, 4);
	const float minx = p.x - size / 2.0f;
	const float maxx = p.x + size / 2.0f;
	const float miny = p.y - size / 2.0f;
	const float maxy = p.y + size / 2.0f;
	const float vertices[] = { minx, miny, maxx, miny, minx, maxy, maxx, maxy };
	glVertexPointer(2, GL_FLOAT, 0, vertices);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	GL_checkError();
#endif
}
Example #5
0
GLuint Color3DShader::createVertexArrayObject(GLuint vboId, GLsizei stride, const GLvoid* positionOffset, const GLvoid* colorOffset) {
	GLuint vaoId;
	glGenVertexArrays(1, &vaoId);
	glBindVertexArray(vaoId);

	glBindBuffer(GL_ARRAY_BUFFER, vboId);
	enablePositionPointer();
	setPositionPointer(stride, positionOffset);
	enableColorPointer();
	setColorPointer(stride, colorOffset);

	glBindVertexArray(0);

	return vaoId;
}