I have a circle drawn in an NSOpenGL view, but the OpenGL units and the frame units are very different.
Given a square size, how can I make a circle to fit the frame? It seems like a guessing game!
I am very new to OpenGL, as I started to figure some things out just yesterday, so go easy on me please
Almost forgot, here's the code:
Given a square size, how can I make a circle to fit the frame? It seems like a guessing game!
I am very new to OpenGL, as I started to figure some things out just yesterday, so go easy on me please
Almost forgot, here's the code:
Code:
void glCircle3i3d(GLint x, GLint y, GLint rad, GLdouble red, GLdouble green, GLdouble blue) {
float angle;
glPushMatrix();
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glLineWidth(1.0f);
glBegin(GL_POLYGON);
glColor3d(red, green, blue);
for(int i = 0; i < 100; i++) {
angle = i*2*M_PI/100;
glVertex2f(x + (cos(angle) * rad), y + (sin(angle) * rad));
}
glEnd();
glEnable(GL_TEXTURE_2D);
glPopMatrix();
}
- (void)drawRect:(NSRect)rect
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity(); // Reset the current modelview matrix
glCircle3i3d(0, 0, rect.size.width/2, myColor.red, myColor.green,
myColor.blue);
[[self openGLContext] flushBuffer];
}