Background
I have a program for developing car control systems that uses a combination of TCL scripting language and OpenGL to additionally render the behaviour of the car driving on a road.
What I'm doing is implementing OculusRift support for it and so far have managed to solve the sesor part and by right-clicking the window where the car is driving I can send it to the oculus rift. So far it looks like this: Youtube-Video
The visual portion of the program has plenty of features already and includes options like adjusting FOV, fisheye lenses, camera orientation, inside car view, etc.
After looking around the software folder I found a TCL file with the following lines:
// ... cut here
gl pushmatrix
gl loadidentity
gl translate $x $y $z
gl rotate $xrot 1 0 0
gl rotate $yrot 0 1 0
gl rotate $zrot 0 0 1
gl translate $offx $offy $offz
lassign [lrange [OGL get modelviewmatrix] 12 14] tx ty tz
gl popmatrix
dict set ::View($view) CameraMode FixedToBodyA
dict set ::View($view) xrot $xrot
dict set ::View($view) yrot $yrot
dict set ::View($view) zrot [expr $zrot + $zrot_eyeAngle]
dict set ::View($view) dist $conf(dist)
dict set ::View($view) VPtOffset_x $tx
dict set ::View($view) VPtOffset_y $ty
dict set ::View($view) VPtOffset_z $tz
dict set ::View($view) FieldOfView $conf(fov)
dict set ::View($view) AspectRatio $conf(AspectRatio)
return;
}
I did not find any line that handles the rendering itself but "gl" -commands were enough to make me understand that this TCL file is being run directly attached to the rendering process. So I expanded the above with this:
// load a self written DLL that wraps OVR functionality (Github link bellow)
# now run tclovrGetData() from the loaded DLL to get sensor data
set data [tclovrGetData]
// data = x y z xrot yrot zrot
gl pushmatrix
gl loadidentity
gl translate $x $y $z
gl rotate $xrot 1 0 0
...
As you can see on the video, it looks good on the monitor but as we know the lenses of the Rift bring in distortion (which was just slight for me) and quite some chromatic aberration.
My Idea
What I want is grab that "image/texture/frame" on the screen in the video each 10-20ms (I'm still new to the terminologies) and do some color-filtering on it(I want to see if I can reduce chromatic aberration). Then perhaps (to make everthing independent) create a new window with the modified image and send that one to the Rift. Basically get the image in the required "format" to be able to perform computation on it.
My idea was (since we are attached to the rendering process) add some extra lines to the above TCL file that call additional functions inside my DLL that could do the following:
// Begin Oculus rendering loop
//1. get frame that is currently being rendered (in this process)
//2. copy this frame to memory
//3. perform some operations (color filtering) on this frame in memory
//4. send this frame to a new window
Now my question:
- Would something like this be possible?
- Could someone point me into the right direction? I.e. some gl functions I could use?
- Maybe Direct3D works aswell?
I did read This post on stackoverflow but failed to understand :/