1
我想通過使用glReadPixels和C++代碼來選擇兩個點(對角)來讀取像素的矩形。選擇Y軸值時出現問題。glReadPixels使用縮放移動座標
目前,我設法讓glReadPixels工作,直到縮放。當您縮放(放入或縮小)時,該工具從其他Y值讀取像素(X總是OK)
我在做什麼錯?
GLORTHO:
IZDA = mCameraPosition.x - ((double)(rectangleDim.x/SCRARatio)) * mZoomFactor/2;
DCHA = mCameraPosition.x + ((double)(rectangleDim.x/SCRARatio)) * mZoomFactor/2
ABAJO = mCameraPosition.y - ((double)rectangleDim.y) * mZoomFactor/2;
ARRIBA = mCameraPosition.y + ((double)rectangleDim.y) * mZoomFactor/2;
glOrtho(IZDA, DCHA, ABAJO, ARRIBA, -1.0f, 1.0f);
GETSCREENCOORDS
realDim.x = dimension.x * (dimension.x * mZoomFactor/2);
realDim.y = dimension.y * (dimension.y * mZoomFactor/2);
GSC.x = (dimension.x*(x-mCameraPosition.x))/realDim.x;
GSC.y = (dimension.y/realDim.y) * ((pow(dimension.y, 2)*mZoomFactor/2)+mCameraPosition.y + y - imgDim.y);
GETWORLDCOORDS
realDim.x = dimension.x * (dimension.x * mZoomFactor/2);
realDim.y = dimension.y * (dimension.y * mZoomFactor/2);
GWC.x =
((x * realDim.x)/dimension.x) + mCameraPosition.x;
GWC.y =
((y * realDim.y)/dimension.y)
-((dimension.y * (dimension.y * mZoomFactor/2)) + mCameraPosition.y)
+ imgDim.y;
CHECKFILLVALUE(使用glReadPixels)
ComplexData::Point a, b;
// Set points screen coordinates
getScreenCoords(FIP.x, FIP.y);
a.x = GSC.x;
a.y = GSC.y;
getScreenCoords(FEP.x, FEP.y);
b.x = GSC.x;
b.y = GSC.y;
// Set length and width to read (and write)
double RX_Length, RY_Length;
if (b.x < a.x) RX_Length = a.x - b.x;
else RX_Length = b.x - a.x;
if (b.y < a.y) RY_Length = a.y - b.y;
else RY_Length = b.y - a.y;
// Pixel data vector
float *tdata = new float[3*RX_Length*RY_Length];
double desp = (mZoomFactor*dvcamera)/dvzoom;
getScreenCoords(min(FIP.x, FEP.x), gHeight-FIP.y-2*(mCameraPosition.y-desp));
// Reading from the GET SCREEN COORDINATES global values (GSC)
glReadPixels(GSC.x, GSC.y, RX_Length, RY_Length, GL_RGB, GL_FLOAT, tdata); // <--- Works great until zooming
glRasterPos2d(min(FIP.x, FEP.x), gHeight-max(FIP.y, FEP.y));
glDrawPixels(RX_Length, RY_Length, GL_RGB, GL_FLOAT, tdata); // <--- Works great
delete[] tdata;
鼠標滾輪(縮放)
Drawing::Point pt = e->Location;
getWorldCoords(pt.X, pt.Y);
Initial_Zoom.X = rectangleDim.x - GWC.x;
Initial_Zoom.Y = GWC.y;
// ZOOM IN
if (e->Delta > 0){
if (mZoomFactor > float::Epsilon * 1000.0f){
mZoomFactor /= 1.15f;
}
}
// ZOOM OUT
else {
if (mZoomFactor < float::MaxValue/1000.0f){
mZoomFactor *= 1.15f;
}
}