I attempted to render a circle in opengl es 1.1 as a test before building a larger program, but it renders as an oval. Here is the code I use to generate and render my vertices:
static const int numVerts = 40;
static GLfloat myFirstCircle[82];
myFirstCircle[0] = 0.0f;
myFirstCircle[1] = 0.0f;
for (int i = 2; i < (numVerts+1)*2; i+=2) {
myFirstCircle[i] = .5 * cosf(i*2*3.14159/numVerts);
myFirstCircle[i+1] = .5 * sinf(i*2*3.14159/numVerts);
}
glVertexPointer(2, GL_FLOAT, 0, myFirstCircle);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLE_FAN, 0, 22);
I’m still somewhat new to this system, so I may have a silly error that I do not see, but it seems to me like this should generate 40 vertices on a circle of radius .5. When it renders, the shape on screen appears to be an oval, significantly taller than it is wide.
My question is thus: why is my circle rendering this way, and what could I do to fix it? This is the first question on stackoverflow, so I’m not sure how to share an image of my output.
You have to set up your projection matrix according to your screen’s proportions. As it is now, all the edges of your screen are at +-1.0, causing stretching in the long dimension. This little ditty sets the top and bottom edges to +-1.5.