Attempted to render a circle in opengl es 1.1, renders as oval

Posted by eipxen on Stack Overflow See other posts from Stack Overflow or by eipxen
Published on 2010-03-26T06:33:16Z Indexed on 2010/03/26 6:43 UTC
Read the original article Hit count: 267

Filed under:
|
|
|

Hi all,

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.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone