PDA

View Full Version : Drawing 2D crescent



xEnOnn
09-01-2011, 07:19 AM
I'm trying to draw a 2D crescent(a moon) but I'm facing a lot of problem. Here's what I've been playing with so far, which have problems with the start and end vertices:

void drawCresent(float step, float radius, float cut) {
float angle=0.0f;
glBegin(GL_POLYGON);
glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex2f(cut*radius*sinf(-1.5f*PI),0);
while (angle<=PI) {
glVertex2f(radius*sinf(angle),radius*cosf(angle));
angle+=step;
}
while (angle<(2.0f*PI)) {
angle+=step;
}
glEnd();
} [/B]
[/B]

Unfortunately, because of the start and end points of the polygon are automatically joined, a straight line is being cut across the polygon and the colour filling of the area is incorrect. The inner curve of the crescent is lost because of the straight line.

I found this method really troublesome and not flexible because I have hardcoded the angles. I was thinking to use the intersection between 2 circles instead. Is it possible to remove an intersection area of a polygon in OpenGL? How can I do it? I've searched the web but have no answers to how I could remove intersected areas between polygons.

If removal of intersections is not possible or turns out to be more complicated, what else can I do to fix the problem in the above code?

Thanks for any help.

xiphos
09-02-2011, 01:13 AM
Check below link, hope this will help you...

http://stackoverflow.com/questions/7260963/drawing-a-crescent-shape-in-opengl

MaxH
09-02-2011, 10:22 AM
while (angle<(2.0f*PI)) {
angle += step;
}
}Do you realize that this block of 3 lines has no effect on what gets drawn?
Comment it out and run your code, you'll see what I mean.

Concerning your drawing issue, I think you have misdiagnosed the problem.
Change GL_POLYGON to GL_POINTS and run your code.
You'll see that nothing is being overdrawn.
The code (as posted) is not generating an inner curve of vertices.
I recommend working in point mode until you're sure the vertices of both
the inner and outer arc are being generated correctly.
Then, switch to POLY mode and worry about how to use the vertices to make polygons.