PDA

View Full Version : Need to translate from OpenGL 2.1 code to at least OpenGL 3.3



rxantos
10-17-2016, 03:31 AM
I have some (a lot) of old win32 C code that is OpenGL 2.1 compliant. The code still work on today's computers, but is in great need of support for shaders. Thus I need to translate it to at least OpenGL 3.3. So in interest of spending 1 month that I have instead of 1 year that I do not have doing the conversion. I have this questions.

Is there any library that would emulate the missing functionality of OpenGL 2.1 under OpenGL 3.3? Specially lines with patterns.

Is there a way to automatize the process of translating from 2.1 to 3.3?

Is there a way to at least identify the parts that are incompatible at compile time?

Silence
10-17-2016, 04:16 AM
First point: there might be one. But to my opinion, you shouldn't.

Second point: There is no since this is the essence of it: this is no more fixed, but flexible, programmable. So which way to go ? It all depends on what you want to achieve.

Third point: Yes. Use a header that provides only the version you are targetting. I guess this (https://www.google.fr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&sqi=2&ved=0ahUKEwjh6abCzeHPAhUkBsAKHfWkCLAQFggjMAE&url=https%3A%2F%2Fwww.opengl.org%2Fregistry%2Fapi% 2FGL%2Fglcorearb.h&usg=AFQjCNEtl7VAnnYR-J0hU7nOASohMOKhfg&bvm=bv.135974163,d.bGs&cad=rja) might help you.

GClements
10-17-2016, 05:32 AM
I have some (a lot) of old win32 C code that is OpenGL 2.1 compliant. The code still work on today's computers, but is in great need of support for shaders. Thus I need to translate it to at least OpenGL 3.3.

Why? OpenGL 2.1 supports shaders, and much of the fixed-function pipeline's state (matrices, material parameters, lighting parameters, pre-defined vertex attributes) is available to the shaders.

The main features which were added between 2.1 and 3.3 are framebuffer objects (FBOs), vertex array objects (VAOs) and instanced rendering.

Also, your existing code should work with a 3.3 compatibility profile, so you don't necessarily need to re-write it to use more modern features, unless you need to support Macs (which don't support the compatibility profile) or OpenGL ES (which is somewhat compatible with modern desktop OpenGL, but not legacy OpenGL).

Re-writing it to use modern OpenGL would be ideal, but IMHO using the compatibility profile would be preferable to an automated conversion or some kind of emulation layer (these are sometimes used to port legacy code to OpenGL ES, which doesn't support e.g. glBegin/glEnd, but they tend to be tailored to the specific code being ported).

mhagain
10-17-2016, 07:00 AM
Just so the OP is 100% clear, the following is a non-exhaustive list of "modern" rendering features that are fully implemented under OpenGL 2.1; depending on where one looks online, one may get the impression that these are somehow bleeding-edge features; they're not; they're old, they're robust and they're well-supported.



3D textures
Multitexture
Cube maps
Additional blend modes
Depth textures
Basic multi-draw
LOD bias
Vertex buffer objects
Occlusion queries
Generic vertex attributes
Vertex shaders via GLSL
Fragment shaders via GLSL
Basic multiple render targets
Non-power-of-two textures
Pixel buffer objects


Your GL 2.1 program is able to use these features right now, and in some cases you can incrementally add them to performance-critical or higher-quality code paths.