I want to create Audi logo circles:
However, the result of my code:
#define PI 3.14159265358979323846
#ifdef __APPLE_CC__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <cstdlib>
#include <iostream>
float zoom = 1.0f;
void init() {
// Set the background color to white
glClearColor(1.0, 1.0, 1.0, 1.0);
// Set up the viewport
glViewport(0, 0, 500, 500);
// Initialize the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Initial zoom setup, centering at the origin
float range = 5.0 * zoom;
gluOrtho2D(-range, range, -range, range);
// Initialize the modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void drawCircle(GLfloat x, GLfloat y, GLfloat radius, GLint numberOfSides, GLfloat r, GLfloat g, GLfloat b, GLfloat alpha) {
glColor4f(r, g, b, alpha);
glBegin(GL_POLYGON);
for (int i = 0; i < numberOfSides; i++) {
GLfloat angle = 2.0f * PI * i / numberOfSides;
glVertex2f(x + cos(angle) * radius, y + sin(angle) * radius);
}
glEnd();
}
void display() {
// Clear the color buffer
glClear(GL_COLOR_BUFFER_BIT);
// Draw circles with specified fills
drawCircle(3.0, 0.0, 2.0, 100, 0.3921f, 0.4313f, 0.4470f, 1.0f); // outer circle 1
drawCircle(3.0, 0.0, 1.5, 100, 1.0f, 1.0f, 1.0f, 1.0f); // innermost circle 1
drawCircle(1.0, 0.0, 2.0, 100, 0.3921f, 0.4313f, 0.4470f, 1.0f); // outer circle 2
drawCircle(1.0, 0.0, 1.5, 100, 1.0f, 1.0f, 1.0f, 1.0f); // innermost circle 2
drawCircle(-1.0, 0.0, 2.0, 100, 0.3921f, 0.4313f, 0.4470f, 1.0f); // outer circle 2
drawCircle(-1.0, 0.0, 1.5, 100, 1.0f, 1.0f, 1.0f, 1.0f); // innermost circle 2
drawCircle(-3.0, 0.0, 2.0, 100, 0.3921f, 0.4313f, 0.4470f, 1.0f); // outer circle 2
drawCircle(-3.0, 0.0, 1.5, 100, 1.0f, 1.0f, 1.0f, 1.0f); // innermost circle 2
// Draw the star
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800, 800);
glutInitWindowPosition(100, 100);
glutCreateWindow("Mercedes Logo with Circle");
init();
// Register display callback function
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
…is not what I expected:
The second circle hides a part of first circle.
4