7

I know nothing about OpenGL, but it turns out it might be needed for something that I'm working on (figured this out simply because I want some visual effects that need fast drawing - hardware accelerated).

So I'm very much troubled about which version of OpenGL to start coding for as of the current date? (September 2014 for future readers).

As of now, I have read OpenGL 3.x is the most available (read as: supported) version, even on very old hardware (i.e. designed for Windows XP). But, what if I develop for OpenGL 4.x, will my application be backward-compatible with 3.x supported hardware? Or does it just break there and only run on 4.x (and future?) supported hardware?

My use of OpenGL is not for a videogame or anything similar so I might never need advanced functionality (as of now I can't name any to give you an example of what I may never use, I hope experienced OpenGL people will understand my point). However, I don't think this is going to lower in any way the driver support required, am I right?

Please note that I might have used the wrong terminology and I want to start learning OpenGL which puts me in a position not so good to understand whether I might need this or that feature and/or possible requirements - I am in the need of real advice to get started and figure my way out.

genpfault
  • 51,148
  • 11
  • 85
  • 139
T3STY
  • 103
  • 7
  • 2
    My recommendation for widest support: Request a OpenGL-2.1 context, use the GL_ARB_framebuffer_object extension to get framebuffers (they're the only thing that went into core as late as OpenGL-3) and do everything in the "modern" style, i.e. no use of the fixed function pipeline, in the shaders no use of the built-in variables. That way you're making your code future proof but can also run on older systems. – datenwolf Sep 24 '14 at 10:49
  • There are also Vertex Array Objects that went core in 3.0 and those are necessary for the "modern" style. At least binding one at the start of the application is ;) – Andon M. Coleman Sep 24 '14 at 17:55
  • What do you mean with "modern style"? – T3STY Sep 24 '14 at 21:43

1 Answers1

5

I'm sure this answer skips many many details and exceptions (so take with salt and if you disagree or have something to add, leave a comment :P), but... Each OpenGL version mostly just adds features, so if you start using a new features it might limit the hardware you can run your app on (and so the question attracted a downvote, when instead it should have attracted an explanation).

Basic drawing pretty much remains a constant, with one very big exception: all the stuff that was deprecated in version 3 and removed in 3.1.

Old, < GL 3:

We used to be able to do things like:

glEnable(GL_LIGHTING); //fixed-pipeline lighting. replaced with shaders
glEnable(GL_TEXTURE_2D); //fixed texturing
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(...); //builtin matrices
glBegin(GL_TRIANGLES); glVertex3f(...) ...; glEnd(); //immediate mode with per-vertex calls
glVertexPointer(..., myArray); glDrawArrays(...); //immediate mode with client side array

But even then we still had GLSL shaders and VBOs. There's a fair amount of overlap and the GL3 deprecation didn't instantly replace everything:

glBufferData(...); //buffer mesh data to bound VBO
...
glVertexAttribPointer(...); //attach data to myCustomVar (either VBO or immediate mode local array)
...
attribute vec3 myCustomVar;
varying vec3 myVarying;
...
gl_Position = gl_ProjectionMatrix * gl_ModelviewMatrix * gl_Vertex;
...
gl_FragColor = vec4(1, 0, 0, 1);

New, >= GL 3:

The new way of drawing removes immediate mode and a lot of these in-built features so you do a lot from scratch, adds a few features and syntax changes. You have to use VBOs and shaders:

glBufferData(...); //buffer mesh data
...
glVertexAttribPointer(...); //attach VBOs, but have to set your own position etc too
...
#version 150 //set GLSL version number
out vec3 myVarying; //replaces "varying"
gl_Position = myProjection * myModelview * myPosition;
...
in vec3 myVarying;
out vec4 fragColour; //have to define your own fragment shader output
...
fragColour = vec4(1, 0, 0, 1);

To answer your question, and this is completely my opinion, I'd start learning GLES2.0 (afaik pretty much a subset of GL3) because it's so well supported right now. GL2/immediate mode certainly doesn't hurt as a learning step, and there's still quite a lot that isn't deprecated. You can always just use GL 4 features if you find you need them, but as said the basics really only changed between the above versions. Even if you use deprecated features you have to go out of your way to get a pure GL3.2 (for example) context that disallows certain calls/features. I'm not advocating it but it's entirely possible to mix very old with very new and most drivers seem to allow it.

TLDR: 1. use VBOs, 2. use shaders. Just for learning, don't bother with an explicit version context.

See Also:

Community
  • 1
  • 1
jozxyqk
  • 16,424
  • 12
  • 91
  • 180
  • For those who downvoted my post I think they either don't want to help or they know the answer and think people should read their mind right before posting. I really don't care anyway becuase your answer, jozxyqk, is the kind of answer I was expecting. As of now I would go about GLES2 because my application is going to be only 2D and lots of features added to OpenGL, as I could read, are intended for making 3D development better - not my case. I will check out GLES2 and OGL3 to see if I should go more about OGL3. Simple last question: can I use multiple contexts (2 + 3) in an application? thx – T3STY Sep 24 '14 at 21:39
  • @BlindedInChains GL is always going to give you a 3D context either way but using for 2D is just fine. My experience with GLES2 explicit contexts is limited to webgl (easy) and a little android (not sure). In desktop GL definitely. You might not need to [\[1\]](http://stackoverflow.com/questions/1377359/why-use-multiple-opengl-context) [\[2\]](http://stackoverflow.com/a/21650703/1888983) though. – jozxyqk Sep 25 '14 at 03:20
  • 1
    What's so special about GL 3.3? Isn't it GL 3.2 that introduced the compatible and core context? – Invalid Sep 25 '14 at 18:58
  • @Invalid yes, got this wrong and have updated. thanks for the comment!! – jozxyqk Sep 26 '14 at 03:13