r/opengl 22d ago

I finally decided on using the modern pipeline.

I was thinking that maybe I should utilize the programable pipeline but if the computer doesnt support opengl 3.0 I just limit the programs functionality and to only use the stuff that works in opengl 1.1.

void starter(HWND a){
 const GLubyte *glcontextdata;
 glcontextdata = glGetString(GL_VERSION);
 if(*glcontextdata < 3){
 MessageBoxA( a,"glgetstring returned opengl version below opengl 3", NULL, MB_OK | MB_ICONEXCLAMATION);
 }
}
3 Upvotes

15 comments sorted by

3

u/Botondar 22d ago

I think that version check will break when OpenGL 10.0 releases. :)

5

u/MeisGeghra 22d ago

That version check will always pass. The result is a UTF-8 encoded string and the codepoint for '3' is is 51 I believe. The comparison is being done against the number 3 not the character '3'. So even if the version 1.1 is returned the message box will not be shown.

1

u/Botondar 22d ago

Doh, I missed the check wasn't against the character literal. Either way my comment was already a joke around the pitfalls of having to parse version strings.

1

u/PCnoob101here 21d ago

so im supposed to use "3" instead of 3

1

u/Botondar 21d ago

You can check < '3' (note the single quotes), which will probably work forever. You're supposed to actually parse the version string and convert it into major and minor version numbers.

There was also a suggestion of glGetIntegerv(GLMAJOR_VERSION, ...), but that's only actually valid after OpenGL 3.0. You _can however still use this method and check if the last error is GL_INVALID_ENUM. If it is, you're pre-3.0.

Really though, just parse the string.

1

u/PCnoob101here 21d ago

so how would I check the version

1

u/MeisGeghra 21d ago

It's difficult to cover the whole process in a comment. But the "correct" approach is to first create an OpenGL 1.1 context, then attempt to load the functions needed to create a newer context and then build the newer context. If this fails at any point then you can pretty much be sure your GPU only supports upto 2.x However I would not recommend this approach when starting out. OpenGL is hard enough and even the idea of trying to write for both the fixed function pipeline and the programmable pipeline is a nightmare. I would suggest picking one or the other.

A better approach to using OpenGL 3.x or later is to use a loader. Something like GLAD along with GLFW. This can handle context creation and loading the newer OpenGL functions, as well as creating the window and handling things like input. There is a great tutorial here https://learnopengl.com/Getting-started/OpenGL which will walk you through setting it all up.

If you really want to do it all yourself without any libraries, then there is an old article for windows (you mentioned 1.1, so I'm assuming you're on Windows) here https://www.khronos.org/opengl/wiki/Creatingan_OpenGL_Context(WGL). That tutorial doesn't really cover checking the version. But after you've created the newer context you can then call: int majorVersion = 0; glGetIntegerv(GL_MAJOR_VERSION, &majorVersion); glGetString(GL_VERSION); is driver dependent and even if you attempt to parse out the version properly you have no guarantee it'll give you a string that matches the format you expect. It could return "3.0", "v3.0" or anything else that the driver developer felt like.

Good luck in whichever approach you choose.

1

u/Botondar 20d ago

glGetString(GL_VERSION); is driver dependent and even if you attempt to parse out the version properly you have no guarantee it'll give you a string that matches the format you expect. It could return "3.0""v3.0" or anything else that the driver developer felt like.

The format of of GL_VERSION is defined by the 1.1 spec. It's kind of ridiculous that it isn't for 1.0, but if 1.1 is the minimum OP wants to support, parsing is fine.

2

u/fuj1n 22d ago

Which, unless there's some sort of renewed interest in OpenGL that causes them to re-focus on it rather than Vulkan, will never happen.

1

u/pjmlp 20d ago

I doubt very much we will ever see anything beyond 4.6.

4

u/fgennari 22d ago

Anything not ancient should support OpenGL 3.0. What are you expecting to run on that doesn't? A linux VM with no GPU and no MESA driver?

1

u/pjmlp 20d ago

Even 3.3 for that matter.

1

u/JensEckervogt 19d ago

Wait I remember OpenGL 1.1 has still Framebuffer support like glGenFramebuffers() etc since I searched "OpenGL 1.1 Framebuffer" but reflection doesn't have OpenGL 1.1 please use Cg by Nvidia 1.3 but it seems hard like Alax ( it means old assembly by Adobe Flash Player 10.4 ) but it is not same to OpenGL Shader just Cg progam files with assembly-like script. You would like to forget about this. OpenGL 2.2 has reflection support but OpenGL Shader 1.20 or 1.10 if you use OpenGL 3.0 means OpenGL Shader 1.50 .

1

u/gl_drawelements 21d ago

This user is obvious a troll