From 4ea6917468ec82c966a2f67db0b0b6f375d8d9d4 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 20 Oct 2016 14:33:32 -0400 Subject: [PATCH] OpenGL: box & circle outline functions that work with 3D position (z=0) New immediate mode API is strict about attribute formats. These new functions make existing code easier to port. Supports T49043 --- source/blender/editors/include/BIF_glutil.h | 6 ++++++ source/blender/editors/screen/glutil.c | 22 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index 30718ccd18d..7045340d070 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -92,6 +92,9 @@ void glutil_draw_filled_arc(float start, float angle, float radius, int nsegment */ void imm_draw_lined_circle(unsigned pos, float x, float y, float radius, int nsegments); +/* use this version when VertexFormat has a vec3 position */ +void imm_draw_lined_circle_3D(unsigned pos, float x, float y, float radius, int nsegments); + /** * Draw a filled circle with the given \a radius. * The circle is centered at \a x, \a y and drawn in the XY plane. @@ -115,6 +118,9 @@ void imm_draw_filled_circle(unsigned pos, float x, float y, float radius, int ns */ void imm_draw_line_box(unsigned pos, float x1, float y1, float x2, float y2); +/* use this version when VertexFormat has a vec3 position */ +void imm_draw_line_box_3D(unsigned pos, float x1, float y1, float x2, float y2); + /** * Pack color into 3 bytes * diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index a7e8c210335..b64152b111b 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -203,6 +203,17 @@ void imm_draw_filled_circle(unsigned pos, float x, float y, float rad, int nsegm imm_draw_circle(GL_TRIANGLE_FAN, pos, x, y, rad, nsegments); } +void imm_draw_lined_circle_3D(unsigned pos, float x, float y, float rad, int nsegments) +{ + immBegin(GL_LINE_LOOP, nsegments); + for (int i = 0; i < nsegments; ++i) { + float angle = 2 * M_PI * ((float)i / (float)nsegments); + immVertex3f(pos, x + rad * cosf(angle), + y + rad * sinf(angle), 0.0f); + } + immEnd(); +} + void imm_draw_line_box(unsigned pos, float x1, float y1, float x2, float y2) { immBegin(GL_LINE_LOOP, 4); @@ -213,6 +224,17 @@ void imm_draw_line_box(unsigned pos, float x1, float y1, float x2, float y2) immEnd(); } +void imm_draw_line_box_3D(unsigned pos, float x1, float y1, float x2, float y2) +{ + /* use this version when VertexFormat has a vec3 position */ + immBegin(GL_LINE_LOOP, 4); + immVertex3f(pos, x1, y1, 0.0f); + immVertex3f(pos, x1, y2, 0.0f); + immVertex3f(pos, x2, y2, 0.0f); + immVertex3f(pos, x2, y1, 0.0f); + immEnd(); +} + void imm_cpack(unsigned int x) { immUniformColor3ub(((x)& 0xFF),