Code for legacy openGL but still compatible with new openGL
Well, you could use OpenGL 3.x core context (or maybe OpenGL ES 2.0) while programming to avoid using legacy calls, use shaders with a low #version to allow easier conversion to the legacy version, use VBO, avoid doing fancy modern stuff, and everytime you add a call to a gl function you would need to check if it also exists in the legacy version (most likely 2.0 or 2.1, maybe 1.5 with some extensions) and only use it if thats true. Probably, you will find missing calls you need and then have to find a way around that, like creating a single VAO only when using the modern version. You would also need to regularly test with the legacy version.
That is, if you want to do all the extraneous work.
Thanks. I am also looking for a way to structure the data (polygons) so it can be more easily used in the two versions. What format could be handled by the two verions?
Thanks. I am also looking for a way to structure the data (polygons) so it can be more easily used in the two versions. What format could be handled by the two verions?
You might want to check the list of formats supported by glInterleavedArrays to see if any of those would suit you. Here is the manual page. If you want to go the structures of arrays route, I believe anything that GL1.1 gl[Vertex|Normal|Texcoord|Color]Pointer works with also works with shaders in the newer versions.
If you want a more specific answer, you may want to wait for someone more experienced to chime in.
Do you need to target OpenGL 2.0? 1.4? 1.0? What "era" of hardware? Are any particular extensions allowed? What operating systems need to be supported? Whose drivers do you need to remain compatible with? Are you even referring to actual OpenGL or is this legacy OpenGL|ES you're asking about?
The answers to those questions (and more I'm probably not remembering) will heavily modify the answer to your original question.
Opinion: If you need to support legacy systems and you aren't targeting some UNIX then just use DirectX 8 or 9; you'll spend less time wrestling with Khronos' API or implementations and be able to spend more time making a better application.
Thanks for the answers. I mean by "legacy" the glBegin style with no extensions. So, the very basic of triangles, vertex color, vertex normals, textures. light. Something that will look like a beginner did in end 90's
No openES but it will need to support *nixs (linux and macOS) and win.
One big game engine that I used did that -- it was built for D3D9/GCM/GX, but provided a GL1.x style API for immediate mode rendering.
You can write the whole thing in a modern GL version, and then write your own old skool Begin/Vertex/End functions on top.
Would you like to explain it better? What do you mean "on top" ? Will that mix the two somehow at same time? Thanks!
Thanks for the answers. I mean by "legacy" the glBegin style with no extensions. So, the very basic of triangles, vertex color, vertex normals, textures. light. Something that will look like a beginner did in end 90's
No openES but it will need to support *nixs (linux and macOS) and win.
Now I feel like we may be missing a critical piece of information. Will it be you who would use the glBegin etc. style programming, or will it be whoever it was who wished for this support?
You can write the whole thing in a modern GL version, and then write your own old skool Begin/Vertex/End functions on top.
Would you like to explain it better? What do you mean "on top" ? Will that mix the two somehow at same time? Thanks!
Hodgman means that you would write your own Begin function that sets up some lists or arrays to collect vertexes etc., Vertex functions that add to those, and an End function that actually draws those primitives using modern OpenGL. So it would be your very own implementation of "legacy OpenGL" using modern OpenGL.
Is the program actually required to run on machines with very old GPU and drivers that only support GL1.x, no shaders etc. or is it just that you want to supply a legacy OpenGL style API for users of the program?