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
This commit is contained in:
Mike Erwin 2016-10-20 14:33:32 -04:00
parent c6abbb40ad
commit 4ea6917468
2 changed files with 28 additions and 0 deletions

View File

@ -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
*

View File

@ -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),