fixed circle

This commit is contained in:
Jenny White 2018-04-30 18:29:20 +03:00
parent 8772b9266d
commit 58b10ada51
3 changed files with 12 additions and 18 deletions

View File

@ -13,8 +13,6 @@
static const char *shader_vertex = R"END(
#version 150
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
in vec2 vertex;
in vec2 tex_coord;
@ -25,7 +23,7 @@ out vec4 frag_Color;
out vec2 frag_TexCoord;
void main()
{
gl_Position = projection*(view*(model*vec4(vertex,0.0,1.0)));
gl_Position = projection*vec4(vertex + vec2(0.0, -0.05),0.0,1.0);
frag_TexCoord = tex_coord;
frag_Color = color;
frag_DrawMode = drawmode;
@ -122,16 +120,9 @@ void init(int width, int height)
shader = link(compile(shader_vertex, GL_VERTEX_SHADER),
compile(shader_fragment, GL_FRAGMENT_SHADER));
mat4 model, view;
mat4_set_identity(&model);
mat4_set_identity(&view);
resize(width, height);
glUseProgram(shader);
glUniformMatrix4fv(glGetUniformLocation(shader, "model"), 1, 0, model.data);
glUniformMatrix4fv(glGetUniformLocation(shader, "view"), 1, 0, view.data);
glUniform1i(glGetUniformLocation(shader, "texture"), 0);
glUseProgram(0);
}

View File

@ -25,6 +25,7 @@ void begin()
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_STENCIL_TEST);
glDisable(GL_POLYGON_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

View File

@ -132,16 +132,18 @@ void line(int x, int y, int dx, int dy, rgba color, int thickness)
nx /= length;
ny /= length;
nx *= thickness * 0.5f;
ny *= thickness * 0.5f;
float th = thickness;
nx *= th * 0.5f;
ny *= th * 0.5f;
float px = ny;
float py = -nx;
vertices[0].position = { x - nx + px, y - ny + py };
vertices[1].position = { x + nx + px, y + ny + py };
vertices[2].position = { x + dx + nx - px, y + dy + ny - py };
vertices[3].position = { x + dx - nx - px, y + dy - ny - py };
vertices[2].position = { float(x) - nx + px, float(y) - ny + py };
vertices[1].position = { float(x) - nx - px, float(y) - ny - py };
vertices[3].position = { ex + nx + px, ey + ny + py };
vertices[0].position = { ex + nx - px, ey + ny - py };
ftgl::vertex_buffer_push_back(detail::program::buffer, vertices, 4,
indices::rectangle, 6);
@ -178,11 +180,11 @@ void circle(int x, int y, int radius, rgba color, int thickness, int steps)
{
float px = 0;
float py = 0;
for (int i = 0; i < steps; i++)
for (int i = 0; i <= steps; i++)
{
float ang = 2 * float(M_PI) * (float(i) / steps);
if (!i)
ang = 2 * float(M_PI) * (float(steps - 1) / float(steps));
ang = 2 * float(M_PI);
if (i)
line(px, py, x - px + radius * cos(ang), y - py + radius * sin(ang),
color, thickness);