Is this easy to do? I don't want to use texture images. I want to create a rectangle, probably of two polygons, and then set a color on this. A friend who claims to know OpenGL a little bit said that I must always use triangles for everything and that I must use textures for everything when I want it colored. Can't imagine that is true.
Asked
Active
Viewed 4,057 times
2 Answers
4
You can set per-vertex colors (which can all be the same) and draw quads. The tricky part about OpenGL ES is that they don't support immediate mode, so you have a much steeper initial learning curve compared to OpenGL.
This question covers the differences between OpenGL and ES:
OpenGL vs OpenGL ES 2.0 - Can an OpenGL Application Be Easily Ported?

Community
- 1
- 1

Ben Jackson
- 90,079
- 9
- 98
- 150
-
Thank you, Ben. What happens when I set different vertex colors for a quad? Would this produce a gradient? And no immediate mode means that it is not fast? – Proud Member Nov 18 '10 at 22:30
-
Actually immediate mode is *slow*, it's just easy to get started with. With the fixed-function pipeline, setting different vertex colors will produce a gradient. – Ben Jackson Nov 18 '10 at 22:37
-
Sounds good. Do you know of any code example out there that shows how this looks like? – Proud Member Nov 18 '10 at 22:44
-
I would strongly recommend you buy a copy of [The OpenGL SuperBible](http://www.starstonesoftware.com/OpenGL/) **5th Edition** (very important not the 4th). It's the best (only?) resource I know of for getting started without immediate mode and the fixed-function pipeline. – Ben Jackson Nov 18 '10 at 23:08
-
How about "OpenGL ES 2.0 Programming Guide" (golden rectangle top left, kind of fake iPod touch with a game on the cover)? That should also talk about how to not use immediate mode right? How is the other mode than called? Have it here... – Proud Member Nov 19 '10 at 12:32
1
With OpenGL ES 2.0, you do have to use a shader, which (among other things) normally sets the color. As long as you want one solid color for the whole thing, you can do it in the vertex shader.

Jerry Coffin
- 476,176
- 80
- 629
- 1,111
-
The vertex shader will affect the all the geometry in the scene? Or can I apply a color for this one rectangle only in the vertex shader? – Proud Member Nov 18 '10 at 22:28
-
-
@BugAlert: the easiest way to handle it is probably to switch from one shader to another as necessary. @Ben: oops, quite right. – Jerry Coffin Nov 18 '10 at 23:32