Im using Box2D physics with SFML 2.0. Im using Box2D's opengl debug draw callbacks. Before I switched to SFML 2.0 from 1.6 the callbacks worked properly. After my switch to SFML 2.0 all the debug draw shapes show up as black in color. Whats even stranger is when I spawn new objects to be drawn, the debug draw changes from black to whatever color the image of the new object is. Has anyone else experience anything like this?
Here is the debug draw code:
void DebugDraw::DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{
glColor3f(color.r, color.g, color.b);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < vertexCount; ++i)
{
glVertex2f(vertices[i].x * PTM_RATIO, vertices[i].y * PTM_RATIO);
}
glEnd();
}
void DebugDraw::DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.5f);
glBegin(GL_TRIANGLE_FAN);
for (int32 i = 0; i < vertexCount; ++i)
{
glVertex2f(vertices[i].x * PTM_RATIO, vertices[i].y * PTM_RATIO);
}
glEnd();
glDisable(GL_BLEND);
glColor4f(color.r, color.g, color.b, 1.0f);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < vertexCount; ++i)
{
glVertex2f(vertices[i].x * PTM_RATIO, vertices[i].y * PTM_RATIO);
}
glEnd();
}
void DebugDraw::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color)
{
const float32 k_segments = 16.0f;
const float32 k_increment = 2.0f * b2_pi / k_segments;
float32 theta = 0.0f;
glColor3f(color.r, color.g, color.b);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < k_segments; ++i)
{
b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
glVertex2f(v.x * PTM_RATIO, v.y * PTM_RATIO);
theta += k_increment;
}
glEnd();
}
void DebugDraw::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color)
{
const float32 k_segments = 16.0f;
const float32 k_increment = 2.0f * b2_pi / k_segments;
float32 theta = 0.0f;
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.5f);
glBegin(GL_TRIANGLE_FAN);
for (int32 i = 0; i < k_segments; ++i)
{
b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
glVertex2f(v.x * PTM_RATIO, v.y * PTM_RATIO);
theta += k_increment;
}
glEnd();
glDisable(GL_BLEND);
theta = 0.0f;
glColor4f(color.r, color.g, color.b, 1.0f);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < k_segments; ++i)
{
b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
glVertex2f(v.x * PTM_RATIO, v.y * PTM_RATIO);
theta += k_increment;
}
glEnd();
b2Vec2 p = center + radius * axis;
glBegin(GL_LINES);
glVertex2f(center.x * PTM_RATIO, center.y * PTM_RATIO);
glVertex2f(p.x * PTM_RATIO, p.y * PTM_RATIO);
glEnd();
}
void DebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
{
glColor3f(color.r, color.g, color.b);
glBegin(GL_LINES);
glVertex2f(p1.x * PTM_RATIO, p1.y * PTM_RATIO);
glVertex2f(p2.x * PTM_RATIO, p2.y * PTM_RATIO);
glEnd();
}
void DebugDraw::DrawTransform(const b2Transform& xf)
{
b2Vec2 p1 = xf.position, p2;
const float32 k_axisScale = 0.4f;
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(p1.x * PTM_RATIO, p1.y * PTM_RATIO);
p2 = p1 + k_axisScale * xf.R.col1;
glVertex2f(p2.x * PTM_RATIO, p2.y * PTM_RATIO);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(p1.x * PTM_RATIO, p1.y * PTM_RATIO);
p2 = p1 + k_axisScale * xf.R.col2;
glVertex2f(p2.x * PTM_RATIO, p2.y * PTM_RATIO);
glEnd();
}
void DebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color)
{
glPointSize(size);
glBegin(GL_POINTS);
glColor3f(color.r, color.g, color.b);
glVertex2f(p.x * PTM_RATIO, p.y * PTM_RATIO);
glEnd();
glPointSize(1.0f);
}
void DebugDraw::DrawString(int x, int y, const char *string, ...)
{
//char buffer[128];
//
// va_list arg;
// va_start(arg, string);
// vsprintf(buffer, string, arg);
// va_end(arg);
//
// glMatrixMode(GL_PROJECTION);
// glPushMatrix();
// glLoadIdentity();
// int w = glutGet(GLUT_WINDOW_WIDTH);
// int h = glutGet(GLUT_WINDOW_HEIGHT);
// gluOrtho2D(0, w, h, 0);
// glMatrixMode(GL_MODELVIEW);
// glPushMatrix();
// glLoadIdentity();
//
// glColor3f(0.9f, 0.6f, 0.6f);
// glRasterPos2i(x, y);
// int32 length = (int32)strlen(buffer);
// for (int32 i = 0; i < length; ++i)
// {
// glutBitmapCharacter(GLUT_BITMAP_8_BY_13, buffer[i]);
// }
//
// glPopMatrix();
// glMatrixMode(GL_PROJECTION);
// glPopMatrix();
// glMatrixMode(GL_MODELVIEW);
}
void DebugDraw::DrawAABB(b2AABB* aabb, const b2Color& c)
{
glColor3f(c.r, c.g, c.b);
glBegin(GL_LINE_LOOP);
glVertex2f(aabb->lowerBound.x * PTM_RATIO, aabb->lowerBound.y * PTM_RATIO);
glVertex2f(aabb->upperBound.x * PTM_RATIO, aabb->lowerBound.y * PTM_RATIO);
glVertex2f(aabb->upperBound.x * PTM_RATIO, aabb->upperBound.y * PTM_RATIO);
glVertex2f(aabb->lowerBound.x * PTM_RATIO, aabb->upperBound.y * PTM_RATIO);
glEnd();
}