OpenGL Tutorial's Need to talk about glCheckError()

This is a problem that I have always encountered but at the moment it seems to be occurring so frequently that I feel justified in posting this.

The problem is that beginners (sometimes even those with a fair amount of experience) to OpenGL are not checking OpenGL for errors (sometimes they aren’t even aware that such a thing exists because they’re so used to Java exceptions), hence they find that a function “isn’t working” or that their whole screen goes black for “no reason.”

When I started learning OpenGL, I approached it from The Red Book and I’m 80% certain that one of the first things it taught you to do was call glGetError(), and then kept telling you, because this is the first thing I do in any OpenGL program I write. Now I think that all the new tutorials people are writing (which are good - don’t get me wrong) need to have this same insistence or at the very least a mention of this.

Now the discussion: Do people think that it would be appropriate to take some action on this front? Primarily I was thinking of an OpenGL specific please-read-before-posting thread in the Articles and Tutorials section. But what are other people’s opinions?

Why not write a tutorial about glGetError(), how to use it and why?

That’s true. I will modify mine to include this.

@SHC Thank you.

@Axeman Do you think that this deserves its own tutorial? As far as I can see there is nothing really to say on the topic other than “use it.” I don’t believe that people want to fish around for general tutorials, they want one that will take them through the process - like SHC’s series. Stopping half way through to read my tutorial on the off chance that in the future something will go wrong with their code is not something many people will do even given the unlikely chance that they are aware of my tutorial.

Despite my forthcomings, it something that I am perfectly happy to do if there’s any kind of general consensus here.

I advocate glCheckError()'s own tutorial. Possibly a tutorial on different ways to obtain/peek errors (log, status, etc.) with glCheckError in its own chapter/section.

Now that does sound like a good idea. I think most people would be happy to read a tutorial on how to debug their OpenGL applications.

This is one reason why I dislike the static nature of LWJGL, JOGLs approach is much better in this regard.
JOGL provides you with an GL object to call OpenGL functions on. You then can set a Debug mode so that after each OpenGL call glCheckError is called which then can throw an exception or log the error.

@Danny02

A) That has nothing to do with static / instance bindings. It is perfectly possible using a static context. In fact, recently whilst writing an abstract “backend” for OpenGL calls to Android’s OpenGL and LWJGL’s OpenGL, I considered doing just that using an static context. The only reason I didn’t was the overhead associated with error checking when it is only necessary in developing applications.

B) If I do write a tutorial, I will be sure to mention this (I’ve never used JOGL so I had no idea).

The thing is that you can’t inject a static context in Java. On the other hand you can of course inject an DebuglGL instance into something which needs a GL(interface) object. With this you can circumvent the overhead you are pointing at.

To go on with this a bit ;), providing interfaces for all the different OpenGL version and letting them inherit from each other;
i.e. GL3 -> GL2 -> GL
does help to make the API more easy to use.

For example in LWJGL I always have to guess in which OpenGL version a specific function or method was added, I know that something is included in 3, but dunno if it was added in 1.0 1.2 or 1.5.

And something like this makes your codebase more type-safe of course. You can i.e. code with this in a way so that you can’t use code which uses Shaders, when you only have a GL1 Context and not a GL2 one.

If you were to make GL classes inherit each other, it will make them have different OpenGL specifications mixed up, thus creating a mess on how to deprecate similar methods but entirely different functions.

I’d rather have all available constants from GL1.1 through GL4.4 in one place, while all methods are designated in their respective classes according to the specifications.

Also, method naming scheme probably can do a little upgrade:

glBegin() can be gl11Begin()
gl…() specific to GL3.0 can be gl30…()
glShader…() can be gl20Shader…(), or if it’s GL4.X specific, it would become gl40Shader…()

(I don’t know any GL functions, but at least my point is given.)

That way, you have your methods categorized.


import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
...

And then you can do this:


glBegin(GL_QUADS); //Just like in C!


cough … off topic … cough. We all have our preferences. What a boring world it would be where everyone did everything the same. Could we maybe try to stay on topic.

Edit: Yes I know I did a bit but I was talking about the topic as well.

Oh don’t worry, we’re just waiting for you to write a tutorial on many different ways to debugging OpenGL, and obscure debugging techniques.

Oh I see. So until I write the tutorial, my thread will descend further and further into chaos. No pressure then.