Tuesday, May 12, 2015

vbo - What OpenGL version(s) to learn and/or use?


So, I'm new to OpenGL... I have general knowledge of game programming but little practical experience.



I've been looking into various articles and books and trying to dive into OpenGL, but I've found the various versions and old vs new way of doing things confusing.


I guess my first questions is does anyone know some figures about percentages of gamers that can run each version of OpenGL. What's the market share like? 2.x, 3.x, 4.x...


I looked into the requirements for Half Life 2 since I know Valve updated it with OpenGL to run on Mac and I know they usually try to hit a very wide user-base, and they say a minimum of GeForce 8 Series. I looked at the 8800 GT on Nvidia's website and it listed support for OpenGL 2.1. Which, maybe I'm wrong, sounds ancient to me since there's already 4.x. I looked up a driver for 8800GT and it says it supports 4.2! A bit of a discrepancy there, lol.


I've also read things like XP only supports up to a certain version, or OS X only supports 3.2, or all kinds of other things. Overall, I'm just confused as to how much support there is for various versions and what version to learn/use.


I'm also looking for learning resources. My search results thus far have pointed me to the OpenGL SuperBible. The 4th edition has great reviews on Amazon, but it teaches 2.1. The 5th edition teaches 3.3 and there are a couple things in the reviews that mention the 4th edition is better and that the 5th edition doesn't properly teach the new features or something? Basically, even within learning material I'm seeing discrepancies and I just don't even know where to start.


From what I understand, 3.x started a whole new way of doing things and I've read from various articles and reviews that you want to "stay away from deprecated features like glBegin(), glEnd()" yet a lot of books and tutorials I've seen use that method. I've seen people saying that, basically, the new way of doing stuff is more complicated yet the old way is bad >.>


Just a side note, personally, I know I still have a lot to learn beforehand, but I'm interested in tessellation; so I guess that factors into it as well, because, as far as I understand that's only in 4.x?


[just btw, my desktop supports 4.2]



Answer



If you're wondering about OpenGL coverage, a good place to start is the Steam Hardware Survey.



http://store.steampowered.com/hwsurvey?platform=pc


Unfortunately, it seems to be broken right now and it doesn't display any stats for videocards. :\



I've also read things like XP only supports up to a certain version



DirectX 9 is comparable to OpenGL 2.1, DirectX 10 to OpenGL 3.0 and DirectX 11 to OpenGL 4.0. This is where the confusion stems from.


XP supports all versions of OpenGL, but it does not support DirectX 10 or up. This is how Microsoft wanted to force people to upgrade to Vista, but it didn't work out very well. OpenGL is an open standard, so as long as videocard manufacturers are willing to produce drivers for XP, it will support newer versions of OpenGL.



From what I understand, 3.x started a whole new way of doing things and I've read from various articles and reviews that you want to "stay away from deprecated features like glBegin(), glEnd()" yet a lot of books and tutorials I've seen use that method. I've seen people saying that, basically, the new way of doing stuff is more complicated yet the old way is bad >.>




This is a very big problem for OpenGL. Basically, in the olden days, you'd send stuff to the videocard by using "immediate mode". Start with glBegin, do some stuff, end with glEnd. However, video card drivers do not like this at all. How can they know how much stuff you're going to send? Is it going to be 4 vertices for a textured quad or 100,000 for a skinned model? This is why they introduced vertex buffer objects (VBO's). While immediate mode is a linked list, a VBO is a static array. The developer knows how big it is, the driver knows how big it is. Everybody's happy. So the OpenGL standards board (Khronos Group) decided to deprecate immediate mode for OpenGL 3.0 and up. However, this is problematic, as I'll show with a simple example.


Let's say you want to display a textured quad, starting from scratch.


In OpenGL 2.1:



  • Set up the projection matrix and put it in GL_PROJECTION.

  • Set up the modelview matrix and put it in GL_MODELVIEW.

  • Load an image and put it in a GL_TEXTURE_2D handle.

  • Define the positions, texture coordinates and colors for your vertices.

  • Bind the texture.

  • glBegin ... glVertex2f ... glTexCoord2f ... glEnd.



In OpenGL 3.0:



  • Build a matrix for projection and modelview.

  • Load an image and put it in a GL_TEXTURE_2D handle.

  • Define the positions, texture coordinates and colors for your vertices and put them in VBO's.

  • Create a vertex array object (VAO's) and attach your VBO's.

  • Write a shader to output a textured quad and put it in a shader program.

  • Attach the matrices to the shader program using uniforms.

  • Bind the texture.


  • Attach the texture to the shader program.

  • glDrawArrays.


So what could go wrong in the first version?



  • Your positions are incorrect.

  • Your vertex winding is the wrong way around.

  • Your texture doesn't load properly.

  • Your texture doesn't bind properly.

  • Your projection matrix is wrong.


  • Your modelview matrix is wrong.

  • You're not sending the right vertices.


And in the second version, you can have problems with the above and:



  • Your VBO's are wrong.

  • Your VAO is wrong.

  • Your shader is wrong.

  • Your texture binding to the shader is wrong.



Without proper debug tools, this becomes a serious problem. This is why people say you should stick to immediate mode. Luckily, we now have the free and excellent gDEBugger now, but it's not a magic bullet.


To answer your question: it depends on your game. If you want to reach a wide audience (for instance a casual game or a 2D platformer), you should target 2.1. If you're making an epic space game that isn't going to run on six-year old hardware anyway, target 3.3. And if you need the latest and greatest for future-compatibility, target 4.0.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...