BBSysDyn
BBSysDyn

Reputation: 4601

FPS Game and OpenGL

I am trying to capture images coming from my game using LD_PRELOAD method, by supplying my own library so file that will intercept OpenGL calls. This method works great for simple demo OpenGL code (see this project's file demo.cpp, make.sh, load.sh), however does not work for FPS game UrbanTerror which I thought was using OpenGL. My own supplied function gettimeofday is called properly, however my glXSwapBuffers is not, for some reason. Do these games use OpenGL differently? If so, how? Any tips on how to hook into UrT, and/or another FPS game would be welcome. I am on Ubuntu 11.

Related Question 1

Related Question 2

Upvotes: 3

Views: 798

Answers (1)

datenwolf
datenwolf

Reputation: 162327

AFAIK the Quake3 engine (which is used for Urban Terror) implements a custom dynamic OpenGL loader system, i.e. the binary doesn't link against libGL.so directly, but uses dlopen to load libGL.so, then dlsym to retrieve all the OpenGL symbols. To avoid clashes with any directly linked code, all internal symbols are prefixed to "namespace" them.

The LD_PRELOAD environment variable however will have no effect then. To hook into dynamically loaded libraries you'll have to do some major trickery. There are several possibilities. I recommend also intercepting the dlopen and dlsym calls, and for functions you intend to hook into, return your trampoline (which will ultimately call the requested function) instead returning the function pointer directly.

BTW: It's good you asked this question now, as I'm about to write a similar preloading libGL.so as support for a window compositor I'm working on; and I'd probably fallen into the same pitfall.

Upvotes: 6

Related Questions