30 #define BUFFER_OFFSET(x) ((const void*) (x)) 41 float v = (h - ps.
y) / h;
44 b2Vec2 extents(ratio * 25.0
f, 25.0f);
51 pw.
x = (1.0f - u) * lower.
x + u * upper.
x;
52 pw.
y = (1.0f - v) * lower.
y + v * upper.
y;
62 b2Vec2 extents(ratio * 25.0
f, 25.0f);
68 float u = (pw.
x - lower.
x) / (upper.
x - lower.
x);
69 float v = (pw.
y - lower.
y) / (upper.
y - lower.
y);
73 ps.
y = (1.0f - v) * h;
84 b2Vec2 extents(ratio * 25.0
f, 25.0f);
90 m[0] = 2.0f / (upper.
x - lower.
x);
96 m[5] = 2.0f / (upper.
y - lower.
y);
105 m[12] = -(upper.
x + lower.
x) / (upper.
x - lower.
x);
106 m[13] = -(upper.
y + lower.
y) / (upper.
y - lower.
y);
117 fprintf(stderr,
"OpenGL error = %d\n", errCode);
125 GLint log_length = 0;
132 fprintf(stderr,
"printlog: Not a shader or a program\n");
136 char*
log = (
char*)malloc(log_length);
143 fprintf(stderr,
"%s", log);
152 const char* sources[] = { source };
159 fprintf(stderr,
"Error compiling shader of type %d!\n", type);
173 assert(vsId != 0 && fsId != 0);
198 "uniform mat4 projectionMatrix;\n" 199 "layout(location = 0) in vec2 v_position;\n" 200 "layout(location = 1) in vec4 v_color;\n" 201 "layout(location = 2) in float v_size;\n" 202 "out vec4 f_color;\n" 205 " f_color = v_color;\n" 206 " gl_Position = projectionMatrix * vec4(v_position, 0.0f, 1.0f);\n" 207 " gl_PointSize = v_size;\n" 216 " color = f_color;\n" 221 m_vertexAttribute = 0;
222 m_colorAttribute = 1;
274 if (m_count == e_maxVertices)
277 m_vertices[m_count] = v;
278 m_colors[m_count] = c;
279 m_sizes[m_count] = size;
290 float proj[16] = { 0.0f };
319 enum { e_maxVertices = 512 };
322 float m_sizes[e_maxVertices];
342 "uniform mat4 projectionMatrix;\n" 343 "layout(location = 0) in vec2 v_position;\n" 344 "layout(location = 1) in vec4 v_color;\n" 345 "out vec4 f_color;\n" 348 " f_color = v_color;\n" 349 " gl_Position = projectionMatrix * vec4(v_position, 0.0f, 1.0f);\n" 358 " color = f_color;\n" 363 m_vertexAttribute = 0;
364 m_colorAttribute = 1;
410 if (m_count == e_maxVertices)
413 m_vertices[m_count] = v;
414 m_colors[m_count] = c;
425 float proj[16] = { 0.0f };
449 enum { e_maxVertices = 2 * 512 };
470 "uniform mat4 projectionMatrix;\n" 471 "layout(location = 0) in vec2 v_position;\n" 472 "layout(location = 1) in vec4 v_color;\n" 473 "out vec4 f_color;\n" 476 " f_color = v_color;\n" 477 " gl_Position = projectionMatrix * vec4(v_position, 0.0f, 1.0f);\n" 486 " color = f_color;\n" 491 m_vertexAttribute = 0;
492 m_colorAttribute = 1;
538 if (m_count == e_maxVertices)
541 m_vertices[m_count] = v;
542 m_colors[m_count] = c;
553 float proj[16] = { 0.0f };
580 enum { e_maxVertices = 3 * 512 };
633 m_triangles->Destroy();
641 b2Vec2 p1 = vertices[vertexCount - 1];
642 for (
int32 i = 0; i < vertexCount; ++i)
645 m_lines->Vertex(p1, color);
646 m_lines->Vertex(p2, color);
654 b2Color fillColor(0.5
f * color.
r, 0.5f * color.
g, 0.5f * color.
b, 0.5f);
656 for (
int32 i = 1; i < vertexCount - 1; ++i)
658 m_triangles->Vertex(vertices[0], fillColor);
659 m_triangles->Vertex(vertices[i], fillColor);
660 m_triangles->Vertex(vertices[i + 1], fillColor);
663 b2Vec2 p1 = vertices[vertexCount - 1];
664 for (
int32 i = 0; i < vertexCount; ++i)
667 m_lines->Vertex(p1, color);
668 m_lines->Vertex(p2, color);
676 const float k_segments = 16.0f;
677 const float k_increment = 2.0f *
b2_pi / k_segments;
678 float sinInc = sinf(k_increment);
679 float cosInc = cosf(k_increment);
681 b2Vec2 v1 = center + radius * r1;
682 for (
int32 i = 0; i < k_segments; ++i)
686 r2.
x = cosInc * r1.x - sinInc * r1.y;
687 r2.
y = sinInc * r1.x + cosInc * r1.y;
688 b2Vec2 v2 = center + radius * r2;
689 m_lines->Vertex(v1, color);
690 m_lines->Vertex(v2, color);
699 const float k_segments = 16.0f;
700 const float k_increment = 2.0f *
b2_pi / k_segments;
701 float sinInc = sinf(k_increment);
702 float cosInc = cosf(k_increment);
704 b2Vec2 r1(cosInc, sinInc);
705 b2Vec2 v1 = center + radius * r1;
706 b2Color fillColor(0.5
f * color.
r, 0.5f * color.
g, 0.5f * color.
b, 0.5f);
707 for (
int32 i = 0; i < k_segments; ++i)
711 r2.
x = cosInc * r1.x - sinInc * r1.y;
712 r2.
y = sinInc * r1.x + cosInc * r1.y;
713 b2Vec2 v2 = center + radius * r2;
714 m_triangles->Vertex(v0, fillColor);
715 m_triangles->Vertex(v1, fillColor);
716 m_triangles->Vertex(v2, fillColor);
722 v1 = center + radius * r1;
723 for (
int32 i = 0; i < k_segments; ++i)
726 r2.
x = cosInc * r1.x - sinInc * r1.y;
727 r2.
y = sinInc * r1.x + cosInc * r1.y;
728 b2Vec2 v2 = center + radius * r2;
729 m_lines->Vertex(v1, color);
730 m_lines->Vertex(v2, color);
736 b2Vec2 p = center + radius * axis;
737 m_lines->Vertex(center, color);
738 m_lines->Vertex(p, color);
744 m_lines->Vertex(p1, color);
745 m_lines->Vertex(p2, color);
751 const float k_axisScale = 0.4f;
756 m_lines->Vertex(p1, red);
758 m_lines->Vertex(p2, red);
760 m_lines->Vertex(p1, green);
762 m_lines->Vertex(p2, green);
768 m_points->Vertex(p, color, size);
774 if (m_showUI ==
false)
780 va_start(arg,
string);
794 va_start(arg,
string);
810 m_lines->Vertex(p1, c);
811 m_lines->Vertex(p2, c);
813 m_lines->Vertex(p2, c);
814 m_lines->Vertex(p3, c);
816 m_lines->Vertex(p3, c);
817 m_lines->Vertex(p4, c);
819 m_lines->Vertex(p4, c);
820 m_lines->Vertex(p1, c);
826 m_triangles->Flush();
IMGUI_API void TextColoredV(const ImVec4 &col, const char *fmt, va_list args) IM_FMTLIST(2)
GLint m_projectionUniform
b2Vec2 ConvertScreenToWorld(const b2Vec2 &screenPoint)
b2Vec2 lowerBound
the lower vertex
IMGUI_API void SetCursorPos(const ImVec2 &local_pos)
void DrawPoint(const b2Vec2 &p, float size, const b2Color &color) override
Draw a point.
static void sPrintLog(GLuint object)
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
#define glUniformMatrix4fv
#define glBindFragDataLocation
void Vertex(const b2Vec2 &v, const b2Color &c)
b2Vec2 GetXAxis() const
Get the x-axis.
#define GL_PROGRAM_POINT_SIZE
void DrawPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color &color) override
Draw a closed polygon provided in CCW order.
void DrawTransform(const b2Transform &xf) override
Color for debug drawing. Each value has the range [0,1].
#define GL_FRAGMENT_SHADER
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
void DrawCircle(const b2Vec2 ¢er, float radius, const b2Color &color) override
Draw a circle.
static GLuint sCreateShaderFromString(const char *source, GLenum type)
void DrawSolidCircle(const b2Vec2 ¢er, float radius, const b2Vec2 &axis, const b2Color &color) override
Draw a solid circle.
#define glGetUniformLocation
#define glVertexAttribPointer
void Set(float x_, float y_)
Set this vector to some specified coordinates.
void Vertex(const b2Vec2 &v, const b2Color &c, float size)
static void sCheckGLError()
#define GL_INFO_LOG_LENGTH
b2Vec2 GetYAxis() const
Get the u-axis.
void BuildProjectionMatrix(float *m, float zBias)
#define glGenVertexArrays
An axis aligned bounding box.
#define glBindVertexArray
#define glDeleteVertexArrays
GLint m_projectionUniform
#define glEnableVertexAttribArray
b2Vec2 ConvertWorldToScreen(const b2Vec2 &worldPoint)
#define glGetProgramInfoLog
void DrawString(int x, int y, const char *string,...)
#define GL_ONE_MINUS_SRC_ALPHA
GLint m_projectionUniform
void DrawAABB(b2AABB *aabb, const b2Color &color)
void Vertex(const b2Vec2 &v, const b2Color &c)
#define GL_COMPILE_STATUS
void DrawSegment(const b2Vec2 &p1, const b2Vec2 &p2, const b2Color &color) override
Draw a line segment.
void DrawSolidPolygon(const b2Vec2 *vertices, int32 vertexCount, const b2Color &color) override
Draw a solid closed polygon provided in CCW order.
static GLuint sCreateShaderProgram(const char *vs, const char *fs)
b2Vec2 upperBound
the upper vertex
#define glGetShaderInfoLog