Intercepting GL commands

Started by
3 comments, last by Leroy1891 20 years ago
Let''s say I have a class that loads a texture and displays it on the screen using opengl, but the class hides all of it''s data. How would I make another unrelated class intercept the gl commands it uses such as: glBindTexture(),glVertex,glTexCoord
Advertisement
Wrap the OpenGL interface with your own, which internally calls the regular GL functions. Never done this, but I suppose you''d create your own DLL, replacing all GL functions you want to override, then internally call the corresponding functions.

In techie lingo, you''re creating function stubs...

If you''ve never used DLLs before, well, you''d invoke the OpenGL.dll and get function pointers to the functions you want. Something like:

void glVertex3f(float x, float y, float z)
{
// do something...
true_gl_vertex3f->(x, y, z);
}

true_gl_vertex3f is a function pointer to the proper implementation of glVertex3f() that you''ve bound elsewhere.

Hope that helps.
g''luck.
People fear what they don''t understand, hate what they can''t conquer!
Just a dumb question but would wrapping OpenGL add a preformance hit? Well I''m sure it does, but is it noticable.
Thanks alot, I''ll try that
Performance: I think it would add overhead, but nothing extremely significant (I would think). One could always wrap in debug mode only, if that were a huge problem.

Overall, I think it would be useful for the programmer because you could add the ability to keep track of how many times your making certain calls (state changes, primitive draws, etc.)
People fear what they don''t understand, hate what they can''t conquer!

This topic is closed to new replies.

Advertisement