 me1212 join:2008-11-20 Pleasant Hill, MO | OpenGL ellipses with GL_TRIANGLE_FAN? Anyone know about them Yeah, so basically I'm bored and trying to draw an ellipse and a circle(already done) both filled in in openGL. I got the circle done but I'm not sure how I would modify it for an ellipse, does anyone have any advice for a beginner?
Also here be the code I'm using for the circle, like I said I thankfully have this working I'm just not sure what to change to make it an ellipse.
void drawFilledCircle(GLfloat x, GLfloat y, GLfloat radius){ int i; int triangleAmount = 20; //# of triangles used to draw circle
//GLfloat radius = 0.8f; //radius GLfloat twicePi = 2.0f * PI;
glBegin(GL_TRIANGLE_FAN); glVertex2f(x, y); // center of circle for(i = 0; i = triangleAmount;i++) { glVertex2f( x + (radius * cos(i * twicePi / triangleAmount)), y + (radius * sin(i * twicePi / triangleAmount)) ); } glEnd(); glutSwapBuffers(); }
void myDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT);
drawFilledCircle(320,240,100);
glFlush(); } |
|
 BachI'll Be BachPremium join:2002-02-16 Flint, MI | Use a different value for "radius" in the calculation of the x and y coordinate, e.g. "1.5f * radius" for the x value and leave the y as is. |
|
 me1212 join:2008-11-20 Pleasant Hill, MO 1 edit | Thank you so much, that worked! I have one more thing I've been wondering though, how would I go about placing the circle inside of the ellipse? I tried having it draw the ellipse then circle right after each other, called the drawEllipse function the immediately after that was done I called the drawCircle function, but that just made HAL9000 show up on my screen. I used black for the ellipse and red for the circle. |
|
 BachI'll Be BachPremium join:2002-02-16 Flint, MI Reviews:
·Comcast
| Since you are drawing in 2D, all objects have the same Z value. OpenGL still does depth checking even though everything is at the same depth. Consequently the larger ellipse has already drawn in the affected area and the circle gets ignored.
A couple ways to get around this:
1. Draw the smaller object (circle) first, then the ellipse.
or 2. Call glDepthFunc(GL_LEQUAL); once before you start any drawing. This will allow pixels at the same depth to be overwritten. |
|
 me1212 join:2008-11-20 Pleasant Hill, MO 1 edit | Never mind, I'm a derp who accidentally called swapbuffers after each function and that made it not work right. |
|
|
|
 BachI'll Be BachPremium join:2002-02-16 Flint, MI Reviews:
·Comcast
| Yeah, I'm a derp as well in the mis-advice I gave on the Z buffer. 
My test program had GL_DEPTH_TEST enabled, which is probably not the case in your program since it defaults to off. |
|
 me1212 join:2008-11-20 Pleasant Hill, MO | Its all good man, having the glDepthFunc(GL_LEQUAL); still in my program doesn't seem to be making a difference, plus now I know how to use it. I'm sure it will come in handy down the road. |
|