I have been learning and using Objective-C and cocos2d (iOS game-engine) for a couple of years now and so I decided to start with OpenGL ES for iOS devices. I have started reading a book that covers this topic, however with little background in this area I have to admit that I am a little lost. I am a really practical person and I only learn by doing things myself. The book does give some nice examples, but unfortunately mostly covers triangular shapes.
So, I have a couple of questions regarding OpenGL:
- Do vertices really need to be declared in a counter-clockwise order to prevent culling ?
- Does OpenGL really draw all shapes based on triangles ?
- If so, how would I draw a rectangle ?
I would really appreciate it if somebody could write a quick vertex array sample of how to achieve to draw a rect on the screen. No need for the buffers or anything, really just the vertices of the rectangle.
OpenGl ES 2.0 supports the following rendering types: GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, and GL_TRIANGLES.
If you ignore the ones for drawing points and lines you can choose between triangle strips, triangle fans and simple triangles. To draw a rectangle you can easily use two triangles.
To specify the ordering for face culling you can use glFrontFace. However its common practise (as far as i know) to use counter clockwise ordering.
If you have problems finding good opengl es 2.0 tutorials for ios you should maybe look for some tutorials on some plattforms. WebGL and Android are also using opengl es 2.0 and (except the syntax) the code will look nearly identical.