C++: Drawing a 2D disk in OpenGL -
i've tried write proper function drawing 2d disk on screen opengl few days now, , can't seem right :(
this current code:
void disk( float x, float y, float r, const color& vcolor ) { glbegin( gl_triangle_fan ); glvertex2f( x, y ); for( float = 0; <= 2 * pi + 0.1; += 0.1 ) { glvertex2f( x + sin( ) * r, y + cos( ) * r ); } glend(); }
when zooming in, resulting disk shows spikes, not in edges spikes pointing out.
also function doesn't draw 1 disk only, bit more 1 - means if alpha enabled, results wrong.
- what need change in function draws disk?
void circle(float x, float y, float r, int segments) { glbegin( gl_triangle_fan ); glvertex2f(x, y); for( int n = 0; n <= segments; ++n ) { float const t = 2 * m_pi * (float)n / (float)segments; glvertex2f(x + sin(t) * r, y + cos(t) * r); } glend(); }
that should rid of overdraw. spikes... picture tell thousand words.
Comments
Post a Comment