How to draw anti-aliased circle with iPhone OpenGL ES
-
There are three main ways I know of to draw a simple circle in OpenGL ES, as provided by the iPhone. They are all based on a simple algorithm (the VBO version is below). void circleBufferData(GLenum target, float radius, GLsizei count, GLenum usage) { const int segments = count - 2; const float coefficient = 2.0f * (float) M_PI / segments; float *vertices = new float[2 * (segments + 2)]; vertices[0] = 0; vertices[1] = 0; for (int i = 0; i <= segments; ++i) { float radians = i * coefficient; float j = radius * cosf(radians); float k = radius * sinf(radians); vertices[(i + 1) * 2] = j; vertices[(i + 1) * 2 + 1] = k; } glBufferData(target, sizeof(float) * 2 * (segments + 2), vertices, usage); glVertexPointer(2, GL_FLOAT, 0, 0); delete[] vertices; } The three ways that I know of to draw a simple circle are by using glDrawArray from an array of vertices held by the application; using glDrawArray from a vertex buffer; and by drawing to a texture on initialization and drawing the texture when rendering is requested. The first two methods I know fairly well (though I have not been able to get anti-aliasing to work). What code is involved for the last option (I am very new to OpenGL as a whole, so a detailed explanation would be very helpful)? Which is most efficient?
-
Answer:
Antialiasing in the iOS OpenGL ES impelmentation is severely limited. You won't be able to draw antialiased circles using traditional methods. However, if the circles you're drawing aren't that large, and are filled, you could take a look at using GL_POINT_SMOOTH. It's what I used for my game, Pizarro, which involves a lot of circles. Here's a detailed writeup of my experience with drawing antialiased circles on the iOS: http://sveinbjorn.org/drawing_antialiased_circles_opengl_iphone
ScootyPuff at Stack Overflow Visit the source
Related Q & A:
- How To Draw Save Electricity?Best solution by Yahoo! Answers
- How To Download Anti Virus In Galaxy Young?Best solution by app4smart.com
- How to add background image from OpenGL ES to iPhone?Best solution by stackoverflow.com
- How to draw a circle on a map?Best solution by Stack Overflow
- How to draw text clearly in OpenGL ES (Android?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.