Archived

This topic is now archived and is closed to further replies.

Intercepting GL commands

This topic is 5004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Just a dumb question but would wrapping OpenGL add a preformance hit? Well I''m sure it does, but is it noticable.

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites