Summary of the invention
Problem to be solved by this invention is to overcome the deficiency that C Tech (being called for short C Tech down) software exists in 3-D display, realizes that the real tri-dimension that former software is not added modification shows.Core of the present invention is to utilize the ultimate principle of three-dimensional rendering, by color data and depth data in the interception video card result frame image, resolve the projective transformation matrix that generates the result frame image, the ultimate principle that applying three-dimensional is played up and the three-dimensional scenic of reconstructing grid, on this scene basis, use principle of stereoscopic vision, generate stereogram, based on different stereo display patterns, drive video card and carry out solid output.
The technical foundation that the present invention relies on is about the basic model of three-dimensional rendering in the computer graphics, be the basic model of the three-dimensional rendering of the 3D API that uses of the CTech groupware (current under Windows the C Tech groupware all use OpenGL), comprise the transformation pipeline, Z buffer zone algorithm on three-dimensional rendering streamline, summit etc.Realize that according to being OpenGL API and video card both all are based on this basic model and carry out work.The present invention makes this computer software realize the three-dimensional true 3-D display and the observation of binocular vision under the situation of not changing C Tech source code, binary code or computer hardware structure.
The ultimate principle that Computerized three-dimensional shows is with after three-dimensional scenic process geometric transformation and photo-irradiation treatment and the rasterizing, generates a width of cloth two-dimensional grid image and exports on output device.Comprise a series of three dimensional object in the three-dimensional scenic, three dimensional object is to be combined by the geometric graphic element (comprising some line and triangle) that a series of summits constitute.The summit is one and comprises three-dimensional space position and the corresponding coordinate points of playing up parameter thereof.At first vertex data is carried out perspective grid conversion and photo-irradiation treatment.In the coordinate transform stage, the summit of describing geometry of objects is transformed under the coordinate system that viewpoint is the center, carries out color and brightness that illumination calculation determines that each summit should have again.The basic display unit of computer graphics is a pixel, and these geometric objects are tiled into pixel, and it is medium to be shown that these pixels are sent to frame buffer at last, as shown in Figure 2.
In three-dimensional picture is played up, exist a series of coordinate transform, at last the coordinate transform of object itself is become the pixel coordinate on the two-dimensional screen.These coordinate transforms all with the previous step transformation results as output, constitute the streamline of an apex coordinate conversion, as shown in Figure 3.The coordinate of all three dimensional objects has all been arrived under the same coordinate system by unified, forms normalized coordinate through projection and cutting, forms image pixel by the rasterizing conversion.
Z buffer zone algorithm claims depth buffered algorithm again.Because the two dimensional surface coordinate can corresponding unlimited a plurality of three-dimensional coordinates under perspective projection.So what the geometric object of rasterizing had comprised each pixel correspondence is called the parameter of depth value to viewpoint, if the depth value of rasterizing geometric object pixel is less than original pixel, just replace the value of origin-location with the value of this pixel, this has just guaranteed that always nearest apart from viewpoint pixel is saved.
At above principle, realize that the technical scheme of the object of the invention is:
Towards the built-in real tri-dimension display packing of C Tech software, this method may further comprise the steps:
Data interception is monitored and played up to step (1) at the 3D API that C Tech uses;
Step (2) is utilized scene change matrix and projective transformation matrix reconstructing grid three-dimensional data;
Step (3) self-adaptation screen resolution and people's eye cardinal distance is set two different viewpoint positions and is generated stereogram;
Step (4) is carried out true three-dimensional observation at different stereoscopy equipment.
The concrete available the following step of method of the present invention realizes, the following step in no particular order:
A. the function of 3-D display environment is created in monitoring, in this function, add system's detection function function of calling 3D API, obtain system's stereo display characteristic, according to corresponding stereo display characteristic, stereo display pattern in the display environment of change original start, on the hardware of supporting stereo display, open real tri-dimension and show support, on the hardware of not supporting stereo display, sign is set so that carry out red green stereo display.
B. monitoring beginning one frame is drawn function, and the adding code obtains the viewport size when the pre-plot frame in this function, is that stereogram is created interim buffer zone according to the pixel format of playing up.
C. monitoring changes current drafting matrix function, in this function, add code to obtain of the change of three-dimensional applications software, by the projection type of matrix parameter identification scene rendering, when being perspective projection to current drafting matrix, write down this matrix, as the key parameter of three-dimensional scenic reconstruct;
D. monitor the function that frame buffer is outputed to display device, add code to obtain each color of pixel and depth data in the entire frame at the monitoring function, the projective transformation matrix information of obtaining based on step c, the three-dimensional coordinate of each pixel of inverse under eye coordinates system reconstructs the three-dimensional scenic based on the rasterizing of pixel; According to the stereoscopic vision model of eye, generation can be for the stereogram of stereo display.
In the described step (1) monitoring of 3D API with play up data interception and further comprise: utilize API interception technology, obtain the output of 3 D rendering correlation matrix and three-dimensional rendering data, extract the wide height of projection matrix, viewport of realizing the three-dimensional perspective conversion, as the key parameter of three-dimensional scenic reconstruct; Utilize the specific function of 3D API, the output of interception three-dimensional rendering is extracted color and depth data in the video card frame buffer, as the basis of three-dimensional scenic reconstruct.
3D API interception is meant and utilizes computer programming, the 3D api function that C Tech is used calls to be monitored, and the data of playing up that 3D API produces are tackled and insert self-defined code therein, reach the purpose that original API is monitored or realizes again.API tackles technology maturation and is widely used, as screen word-selecting software, anti-viral software, network firewall or the like.The 3D API of indication of the present invention plays up the some crucial 3D api function that interception is meant the interception specific function.
Also further comprise the concrete steps that realize the interception of 3D api function at it in the described step (1): at the 3D API (OpenGL) of C Tech use, inject or/and the Hook Function technology is write specific hook procedure by code, in the data load stage of three-dimensional visualization program, 3D API hook procedure is loaded in the process of three-dimensional visualization program, thus interception and monitoring 3D API Calls.The crucial function of the 3D API that indication of the present invention need be tackled is as follows:
(21) 3D API creates the function of 3-D display environment;
(22) 3D API begins the function of a frame scene rendering;
(23) 3D API changes the current function of playing up matrix;
(24) 3D API finishes the function of a frame scene rendering;
(25) 3D API will play up data and output to function on the current screen.
Described step (2) further comprises utilizes 3D API to output to color and depth data in the video card frame buffer, and the projective parameter that obtains in conjunction with interception 3D API Calls is resolved the three-dimensional spatial information that generates color image and depth data.Promptly, by generating the projection matrix and the wide height of viewport of three-dimensional rendering output, calculate the color and the depth data of the output of three-dimensional rendering key control parameter (viewpoint position, hither plane, far plane) and three-dimensional rendering, and then calculate the three-dimensional coordinate of each pixel in the visual space and corresponding color characteristics, the three-dimensional scenic data of rasterizing under the reconstruct visual space.It specifically can comprise following steps:
I. the identification of perspective projection transformation matrix.In the render process of a frame scene, three-dimensional applications software may repeatedly be changed projective transformation matrix, has only perspective transformation matrix just can produce the perspective three dimensional effect.Be without loss of generality, suppose that the perspective projection transformation matrix is consistent in the render process of a frame, perspective projection matrix is tackled, the eigenwert in the matrix as criterion, is judged whether the matrix of current interception is the perspective projection transformation matrix.
II. setting up viewpoint is the three dimensional space coordinate system (being called for short eye coordinates system) of true origin.The perspective projection transformation matrix of intercepting and capturing with step I is a parameter, foundation is the view coordinate system of true origin with the power pin: the Z axle passes the center of hither plane, the X-axis of the Y-axis of hither plane and X-direction and this coordinate system, the Y direction unanimity, hither plane is positioned on the scale of Z axle of hither plane value correspondence.The codomain of X is [width/2, width/2] on the hither plane, and the codomain of Y is [height/2, height/2].In this coordinate system, (Z) the coordinate figure P ' of the subpoint on hither plane (X ', Y ', Z ') can be tried to achieve by the perspective projection matrix conversion arbitrary coordinate point P for X, Y, and wherein Z ' is corresponding to the depth value in the frame depth buffer.Can get: X ' equals width/2*X/Z; Y ' equals height/2*Y/Z; Z ' equals (Z-zNear)/Z*zFar/ (zFar-zNear), and wherein Z ' is corresponding to the value in the depth buffer.
III. the reconstruct of rasterizing three-dimensional scenic data.If the width of viewport is width ', highly is height ' to be obtained by OpenGL API related function.By the proportionate relationship of viewport and the hither plane coordinate P of three-dimensional rendering two field picture pixel " ' (X " ' arbitrarily as can be known, Y " ') corresponding to the three-dimensional coordinate Pn on the hither plane (xn, yn, zn); xn=(X " '-width '/2) * width/2 wherein, yn=(Y " '-height '/2) * height/2.Value Z ' in the corresponding depth buffer, equal (Z-zNear)/Z*zFar/ (zFar-zNear) as can be known by Step II Z ', corresponding eye coordinates system is the Z value down, can get the coordinate P (X of pixel under eye coordinates system, Y, Z), wherein X equals xNear/zNear*Z, and Y equals yNear/zNear*Z.
By calling color buffer district function and the depth buffer function in the video card of reading of OpenGL API, utilize coordinate system and the above-mentioned relation set up in the Step II, can obtain the eye coordinates system three-dimensional coordinate of all pixels down.All three-dimensional coordinates are coupled together with triangle surface, just constituted a three-dimensional surface that can carry out three-dimensional rendering, is playing up under the visual angle arbitrarily by the three-dimensional flow waterline on this surface.
" setting two different viewpoint positions and generate stereogram " in the described step (3) is the three-dimensional scenic that utilizes step (2) reconstruct, generates two width of cloth images, forms stereogram.The present invention proposes the stereo display model based on the three-dimensional scenic of " voxel ", so-called voxel is meant the three-dimensional coordinate of each pixel of the three-dimensional scenic of step (2) reconstruct and its corresponding view space composition sequence [(X together, Y, Z), (R, G, B)], a voxel space of formation.At each pixel in this space,, calculate its location of pixels point in new viewpoint according to the perspective transform principle.
Generate stereogram and can adopt following two kinds of methods:
Method one. call 3D API, play up the contextual data that obtains in the step (2), original image as left visual point image situation under, generate right visual point image; Original image as right visual point image situation under, generate left visual point image; Do not preserving under the original image situation, generating left and right sides visual point image, thereby realizing that stereogram generates.
Method two. adopt rasterizing three-dimensional scenic data, make up the mapping relations of pixel under original visual space and the target visual space, the pixel under the original visual space is converted directly under the target visual space.Original image as left visual point image situation under, generate right visual point image; Original image as right visual point image situation under, generate left visual point image; Do not preserving under the original image situation, generating left and right sides visual point image, thereby realizing that stereogram generates fast.Wherein:
The viewpoint horizontal-shift is meant the change amount D of the new viewpoint original viewpoint of distance on X-direction
x
The viewpoint vertical shift is meant the change amount D of the new viewpoint original viewpoint of distance on Z-direction
z
Image pixel is offset, and is meant the additional offset D of the image pixel horizontal direction of generation
Pixel
Then under another eye coordinates system, (the coordinate X that pixel Z) is marked under the left viewpoint is Width ' * (X-Dx)/(Z-Dz)+D for X, Y to primitive frame image mid point P
Pixel, Y is Height ' * Y/ (Z-Dz).This pixel is under for right eye coordinates being, coordinate calculates according to the method described above, but Dx, Dz gets negative sign.
Each color of pixel is copied to the target location.Thereby two viewpoints are all used this method obtain stereogram.This method has without graphics pipeline, and program composition is simple, optimizes advantages such as easy.
" carry out true three-dimensional observation " in the described step (4) and be meant stereogram that step (3) is generated, by display device output and carry out stereoscopy at different stereoscopy equipment.The stereogram that the present invention generates is carried out true 3-D display in the following way:
X. the binocular solid of video card support shows.As supporting under the OpenGL API ring border of stereo display, creating the stereo display pattern that the equipment handle stage starts OpenGL API, about being transported to respectively, the stereogram that generates in two buffer zones, realizes stereo display.
Y. on the video card of not supporting stereo display, stereogram is synthesized a width of cloth red and green complementary color stereo-picture, and an image from the stereogram of the left and right sides extracts red channel, extracts green and blue channel in another image, the passage that extracts is merged, form the stereo-picture of a complementary colors.And send original image buffer back to and carry out stereo display and observation.
Z. stereo-picture or picture are supported on the stereoscopic display device being transported to other.
The present invention is intended to solve the problem that C Tech program can not be supported stereo display, relies on ripe code interception technical intercept to carry out layout again at C Tech for calling of 3D API.By the monitoring projection matrix, obtain the key parameter of inverse three-dimensional scenic, by color image and the depth image of drawing,, and pixel value is mapped on the position of correspondence by counter its three-dimensional coordinate of asking of pixel, form stereogram.Carry out stereo display by various display modes, the present invention also provides a feasible approach for the direct three-dimensional of existing a large amount of three-dimensional programs.The present invention has following characteristic:
(1) solved the problem that to carry out stereo display at C Tech, promoted mutual and user experience at C Tech.
(2) the algorithm novelty of Shi Xianing is redistributed the formation stereogram by color image data in the frame buffer zone and depth data process, and algorithm principle is simple, and programming realizes convenient.
(3) made full use of existing technical resource,, had good adaptability, do not had specific (special) requirements for video card owing to develop based on the OpenGL API of industrial standard.Support plurality of display modes, can realize stereo display under the display environment arbitrarily.
Embodiment
Below in conjunction with drawings and Examples the present invention is described in further details.
Embodiment 1
As shown in Figures 2 and 3 owing to all use OpenGL API as three-dimensional rendering API at modelling phase C Tech, so present embodiment based on OpenGL API as objective for implementation, operating system platform is implemented for Windows XP.
The interception of OpenGL API is developed based on Micorsoft Detours SDK with monitoring.Detours is the kit that a cover that Microsoft provides carries out the API Calls interception under the windows platform, supports all platforms of Win32.
As shown in Figure 1, towards the built-in real tri-dimension display packing of C Tech software, this method may further comprise the steps:
Data interception is monitored and played up to step (1) at the OpenGL API that C Tech uses;
Step (2) is utilized scene change matrix and projective transformation matrix reconstructing grid three-dimensional data;
Step (3) self-adaptation screen resolution and people's eye cardinal distance is set two different viewpoint positions and is generated stereogram;
Step (4) is carried out true three-dimensional observation at different stereoscopy equipment.
In the step (1) interception of OpenGL API with obtain the scene rendering data and further comprise: utilize 3D API interception technology, obtain 3 D rendering correlation matrix and three-dimensional rendering data, extract the wide height of projection matrix, viewport of realizing the three-dimensional perspective conversion, as the key parameter of three-dimensional scenic reconstruct; Utilize the specific function of 3D API, the output of interception three-dimensional rendering is extracted color and depth data in the video card frame buffer, as the basis of three-dimensional scenic reconstruct.
Step (2) further comprises utilizes OpenGL API to output to color and depth data in the video card frame buffer, and the projective parameter that obtains in conjunction with interception OpenGL API Calls is resolved the three-dimensional spatial information that generates color image and depth data.It further comprises following steps:
I. the identification of perspective projection transformation matrix.In the render process of a frame scene, three-dimensional applications software may repeatedly be changed projective transformation matrix, has only perspective transformation matrix just can produce the perspective three dimensional effect.Be without loss of generality, suppose that the perspective projection transformation matrix is consistent in the render process of a frame.Every controlled variable of perspective projection is seen shown in the accompanying drawing 4 with corresponding matrix relationship.Perspective projection matrix is tackled, the eigenwert in the matrix as criterion, is judged whether the matrix of current interception is the perspective projection transformation matrix.
II. setting up viewpoint is the three dimensional space coordinate system (being called for short eye coordinates system) of true origin.The perspective projection transformation matrix of intercepting and capturing with a is a parameter, foundation is the view coordinate system of true origin with the power pin: the Z axle passes the center of hither plane, the X-axis of the Y-axis of hither plane and X-direction and this coordinate system, the Y direction unanimity, hither plane is positioned on the scale of Z axle of hither plane value correspondence.The codomain of X is [width/2, width/2] on the hither plane, and the codomain of Y is [height/2, height/2].In this coordinate system, (Z) the coordinate figure P ' of the subpoint on hither plane (X ', Y ', Z ') can be tried to achieve by the perspective projection matrix conversion arbitrary coordinate point P for X, Y, and wherein Z ' is corresponding to the depth value in the frame depth buffer, as shown in Figure 5.Can get: X ' equals width/2*X/Z; Y ' equals height/2*Y/Z; Z ' equals (Z-zNear)/Z*zFar/ (zFar-zNear), and wherein Z ' is corresponding to the value in the depth buffer.
III. the reconstruct of rasterizing three-dimensional scenic data.If the width of viewport is width ', highly is height ' to be obtained by OpenGL API related function.By the proportionate relationship of viewport and the hither plane coordinate P of three-dimensional rendering two field picture pixel " ' (X " ' arbitrarily as can be known, Y " ') corresponding to the three-dimensional coordinate Pn on the hither plane (xn, yn, zn); xn=(X " '-width '/2) * width/2 wherein, yn=(Y " '-height '/2) * height/2.Value Z ' in the corresponding depth buffer, by Step II as can be known, corresponding eye coordinates system is the Z value down, and (Z), wherein X equals xNear/zNear*Z for X, Y, and Y equals yNear/zNear*Z can to get the coordinate P of pixel under eye coordinates system.
By calling color buffer district function and the depth buffer function in the video card of reading of OpenGL API, utilize coordinate system and the above-mentioned relation set up in the Step II, can obtain the eye coordinates system three-dimensional coordinate of all pixels down.All three-dimensional coordinates are coupled together with triangle surface, just constituted a three-dimensional surface that can carry out three-dimensional rendering, is playing up under the visual angle arbitrarily by the three-dimensional flow waterline on this surface.
Step (3) is utilized the three-dimensional scenic of step (2) reconstruct, generates two width of cloth images, forms stereogram.Generate stereogram and can adopt following two kinds of methods:
Method one. call 3D API, play up the contextual data that obtains in the step (2), original image as left visual point image situation under, generate right visual point image; Original image as right visual point image situation under, generate left visual point image; Do not preserving under the original image situation, generating left and right sides visual point image, thereby realizing that stereogram generates.
Method two. adopt rasterizing three-dimensional scenic data, make up the mapping relations of pixel under original visual space and the target visual space, the pixel under the original visual space is converted directly under the target visual space.Original image as left visual point image situation under, generate right visual point image; Original image as right visual point image situation under, generate left visual point image; Do not preserving under the original image situation, generating left and right sides visual point image, thereby realizing that stereogram generates fast.Wherein:
The viewpoint horizontal-shift is meant the change amount D of the new viewpoint original viewpoint of distance on X-direction
x
The viewpoint vertical shift is meant the change amount D of the new viewpoint original viewpoint of distance on Z-direction
z
Image pixel is offset, and is meant the additional offset D of the visual pixel level direction of generation
Pixel
Then under another eye coordinates system, (the coordinate X that pixel Z) is marked under the left viewpoint is Width ' * (X-Dx)/(Z-Dz)+D for X, Y to primitive frame image mid point P
Pixel, Y is Height ' * Y/ (Z-Dz).This pixel is under for right eye coordinates being, coordinate calculates according to the method described above, but Dx, Dz gets negative sign.
Each color of pixel is copied to the target location.Thereby two viewpoints are all used this method obtain stereogram.This method has without graphics pipeline, and program composition is simple, optimizes advantages such as easy.
The stereogram that step (4) generates step (3) is by display device output and carry out stereoscopy.The stereogram that the present invention generates is carried out true 3-D display in the following way:
X. the binocular solid of video card support shows.As supporting under the OpenGL environment of stereo display, creating the stereo display pattern that the equipment handle stage starts OpenGL, about being transported to respectively, the stereogram that generates in two buffer zones, realizes stereo display.Or
Y. on the video card of not supporting stereo display, stereogram is synthesized a width of cloth red and green complementary color stereo-picture, and an image from the stereogram of the left and right sides extracts red channel, extracts green and blue channel in another image, the passage that extracts is merged, form the stereo-picture of a complementary colors.And send original image buffer back to and carry out stereo display and observation.Or
Z. stereo-picture or picture are supported on the stereoscopic display device being transported to other.
Embodiment 2
A kind of built-in real tri-dimension display packing towards C Tech software comprises the interception with minor function:
A. create the function of 3-D display environment, monitor this function, in the monitoring function, add system's detection function function of calling 3D API, obtain system's stereo display characteristic, according to corresponding stereo display characteristic, the stereo display pattern in the display environment of change original start is opened real tri-dimension and is shown support on the hardware of supporting stereo display, on the hardware of not supporting stereo display, sign is set so that carry out red green stereo display.
B. begin a frame and draw function, monitor this function, the adding code obtains the viewport size when the pre-plot frame in the monitoring function, is that stereogram is created interim buffer zone according to the pixel format of playing up.
D. frame buffer is outputed to the function of display device, monitor this function, add code to obtain each color of pixel and depth data in the entire frame at the monitoring function, the projective transformation matrix information of obtaining based on c, the three-dimensional coordinate of each pixel of inverse under eye coordinates system reconstructs the three-dimensional scenic based on the rasterizing of pixel;
E. the projection matrix information of obtaining based on c, the parameters of perspective projection in the inverse 3 D rendering, according to these parameters, rebuild the three-dimensional scenic of rasterizing, according to the stereoscopic vision model of eye, generation can be for the stereogram of stereo display.
Following implementation process is the concrete software decoding process of said method.
1. based on Detours API, under Windows XP platform based on Visual Studio 2005 set up based on based on the Win32 DLL engineering StereoDriver_CTech_OpenGL of C Plus Plus as the interception code skeleton.
2. define a data structure OpenGL_Stereo in StereoDriver_CTech_OpenGL, this data structure comprises following content:
(1) Windows drawing context variable hDC, type HDC;
(2) OpenGL rendering context variable hGLRC, type HGLRC;
(3) whether the current hardware of record supports the variable IsStereoSupport of stereo display, type bool;
(4) the wide high variable width of record viewport, height, type int;
(5) the variable ColorBuffer of buffer memory color data, type GLbyte*;
(6) the variables D epthBuffer of buffer memory depth data, type GLfloat;
(7) the variable MatrixMode of the current transformation matrix pattern of record, type GLMatrixMode
(8) the variable Matrix of the current perspective projection matrix of record, type GLfloat[4] [4]
(9) the chained list gOpenGL_Stereos that creates an overall situation preserves the pointer of OpenGL_Stereo structure.
(10) the OpenGL_Stereo pointer ActiveOpenGL_Stereo of an overall situation of establishment is initialized as NULL.
3. realize monitoring based on Detours API as minor function:
1)wglCreateContext
WglCreateContext creates the rendering context of a corresponding OpenGL according to the setting of application program.Create monitoring function My_wglCreateContext, in wglCreateContext, be achieved as follows function:
Resolve the parameter of wglCreateContext, judge whether user program uses the PFD_STEREO mark to start the binary channels solid and play up support, plays up support if user program starts solid, illustrate that then user program support solid itself plays up.
If user program is not activated solid and plays up support, show that then user program do not support solid to play up, whether the inquiry user starts that implanted is three-dimensional to be supported.
If the user selects to enable and implants is three-dimensional the support, create the OpenGL_Stereo structure, and be kept in the global listings that comprises the OpenGLStereo structured fingers, and initialization.Use wglChoosePixelFormat function and PF_STEREO mark to inquire about current video card and whether support stereo display.If support stereo display then the IsStereoSupport of OpenGLStereo is set to true, otherwise be set to false.
Use original wglCreateContext to create HGLRC, and in OpenGLStereo, write down corresponding HDC and HGLRC, the OpenGLStereo structure is joined among the gOpenGL_Stereos.
2)wglMakeCurrent
WglMakeCurrent selects one as current active in some OpenGL rendering contexts, generally begin and finish the drafting of a frame after wglMakeCurrent.Create monitoring function My_wglMakeCurrent, in My_wglMakeCurrent, be achieved as follows function: when HDC parameter and HGLRC parameter during for NULL, the OpenGL_Stereo structure of from gOpenGL_Stereos, searching corresponding hDC and hGLRC with these two parameters, and assignment is given the ActiveOpenGL_Stereo variable.If two parameters are NULL, be NULL then with the ActiveOpenGL_Stereo assignment.
Call original wglMakeCurrent.
3)glViewport
GlViewport is set to assigned address and size with the viewport of the OpenGL rendering context of current active.Create monitoring function My_glViewport, in My_glViewport, be achieved as follows function:
If ActiveOpenGL_Stere is not empty, then judge the wide height of new viewport whether with ActiveOpenGL_Stereo in width, height equates.If original ColorBuffer and DepthBuffer internal memory among the unequal release OpenGL_Stereo; Wide high color buffer area ColorBuffer and the depth buffer district DepthBuffer of creating according to viewport; Write down new width and height.
Call original glViewport.
4)glMatrixMode
GlMatrixMode is provided with the active matrix model of current active OpenGL rendering context.Create monitoring function My_glMatrixMode, in My_glMatrixMode, be achieved as follows function:
If ActiveOpenGL_Stereo is not empty, then the MatrixMode of ActiveOpenGL_Stere is set to the parameter of glMatrixMode.
Call original glMatrixMode.
5)glLoadMatrixd,glLoadMatrixf
GlLoadMatrix is provided with matrix for movable OpenGL plays up current matrix pattern up and down.Create monitoring function My_glMLoadMatrix, in My_glLoadMatrix, be achieved as follows function:
If ActiveOpenGL_Stereo is not empty, and its variable MatrixMode equals GL_PROJECTION, and the m variable that then writes down this function is in the Matrix of ActiveOpenGL_Stere.
Call original glLoadMatrix function.
a.SwapBuffers
This function outputs to the frame that OpenGL plays up on the display device from video memory.Create monitoring function My_SwapBuffers, in this function, be achieved as follows function:
If ActiveOpenGL_Stereo is not empty, call the glReadPixels function, from the color buffer district, read the ColorBuffer variable of color with GL_RGB to ActiveOpenGL_Stereo; Call the glReadPixels function with the GL_DEPTH_COMPONENT parameter, read depth value in the DepthBuffer of ActiveOpenGL_Stereo.
From the Matrix variable of ActiveOpenGL_Stereo, obtain the width width of the hither plane of perspective projection, height height, and the zNear of hither plane and far plane zFar.
According to the width ViewPortWidth and the ViewPortHeight of the viewport that writes down among the ActiveOpenGL_Stereo, create interim color buffer district, ColorBufferLeft and ColorBufferRight.
From being provided with, the user obtains viewpoint skew D
x, depth shift D
zWith pixel-shift D
PixelSet up a circulation,, take out corresponding pixel coordinate iX, the depth value among the DepthBuffer of iY and color RGB and correspondence each ColorBuffer pixel.The method of utilizing the present invention to design, and the coordinate P in the eye coordinates system of pixel correspondence (X, Y, Z).To left eye with D
x, D
z, D
PixelBe parameter.The quick stereo picture that uses the present invention's design calculates the pixel coordinate P of P correspondence to generating algorithm
LeftTo right eye with-D
x,-D
z,-D
PixelBe parameter, the quick stereo picture that uses the present invention's design calculates the right pixel coordinate P of P correspondence to generating algorithm
RightThe color difference assignment of current pixel is given the P of ColorBufferLeft
LeftThe P of position and ColorBufferRight
RightThe position.
Whether the IsStereoSupport that judges ActiveOpenGL_Stere is true.If be true, call glDrawPixels and respectively the content among ColorBufferLeft and the ColorBufferRight is copied among GL_BACK_LEFT and the GL_BACK_RIGT.Otherwise with the G among the ColorBufferRight, B passage assignment is to the G of ColorBufferLeft respective pixel, and the B passage gets on, and forms a red green solid, and the content of ColorBufferLeft is copied among the GL_BACK.
Call original SwapBuffer.
4. compiling StereoDriver_CTech_OpenGL engineering generates the StereoDriver_CTech_OpenGL.DLL file
5. with the withdll.Exe order line startup corresponding program of StereoDriver_CTech_OpenGL.DLL file by detours SDK.