X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FOpenGl%2FOpenGl_Text.cxx;h=7d7de531ebb06dfdcdb144269919f174f3c7437a;hp=d4db2cec368066e4aa9f6a687b15b05ee3f59f1b;hb=c827ea3a68fdad4dda5575c9cbba79675387d0eb;hpb=00ea319b16d13f35bfc6f832ad5027d1a8283fdc diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index d4db2cec36..7d7de531eb 100755 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -32,12 +33,12 @@ namespace { - static const GLdouble THE_IDENTITY_MATRIX[4][4] = + static const GLdouble THE_IDENTITY_MATRIX[16] = { - {1.,0.,0.,0.}, - {0.,1.,0.,0.}, - {0.,0.,1.,0.}, - {0.,0.,0.,1.} + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 }; #ifdef HAVE_GL2PS @@ -455,27 +456,33 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, { // setup matrix #if !defined(GL_ES_VERSION_2_0) + + OpenGl_Mat4d aModViewMat; + if (myIs2d) { - glLoadIdentity(); - glTranslatef (myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.0f); - glScalef (1.0f, -1.0f, 1.0f); - glRotatef (theTextAspect.Angle(), 0.0, 0.0, 1.0); + OpenGl_Utils::Translate (aModViewMat, myPoint.x() + theDVec.x(), myPoint.y() + theDVec.y(), 0.f); + OpenGl_Utils::Scale (aModViewMat, 1.f, -1.f, 1.f); + OpenGl_Utils::Rotate (aModViewMat, theTextAspect.Angle(), 0.f, 0.f, 1.f); } else { // align coordinates to the nearest integer // to avoid extra interpolation issues GLdouble anObjX, anObjY, anObjZ; - gluUnProject (std::floor (myWinX + (GLdouble )theDVec.x()), - std::floor (myWinY + (GLdouble )theDVec.y()), - myWinZ + (GLdouble )theDVec.z(), - (GLdouble* )THE_IDENTITY_MATRIX, myProjMatrix, myViewport, - &anObjX, &anObjY, &anObjZ); - - glLoadIdentity(); - theCtx->core11->glTranslated (anObjX, anObjY, anObjZ); - theCtx->core11->glRotated (theTextAspect.Angle(), 0.0, 0.0, 1.0); + OpenGl_Utils::UnProject (std::floor (myWinX + theDVec.x()), + std::floor (myWinY + theDVec.y()), + myWinZ + theDVec.z(), + OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), + OpenGl_Mat4d::Map (myProjMatrix), + myViewport, + anObjX, + anObjY, + anObjZ); + + OpenGl_Utils::Translate (aModViewMat, anObjX, anObjY, anObjZ); + OpenGl_Utils::Rotate (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0); + if (!theTextAspect.IsZoomable()) { #ifdef _WIN32 @@ -489,12 +496,15 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, // text should be scaled in all directions with same // factor to save its proportions, so use height (y) scaling // as it is better for keeping text/3d graphics proportions - theCtx->core11->glScaled ((GLfloat )aTextScaley, (GLfloat )aTextScaley, (GLfloat )aTextScaley); + OpenGl_Utils::Scale (aModViewMat, aTextScaley, aTextScaley, aTextScaley); } #endif - theCtx->core11->glScaled (myScaleHeight, myScaleHeight, myScaleHeight); + OpenGl_Utils::Scale (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight); } } + + theCtx->WorldViewState.SetCurrent (aModViewMat); + theCtx->ApplyWorldViewMatrix(); #endif } @@ -660,30 +670,49 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, myExportHeight = 1.0f; myScaleHeight = 1.0f; + theCtx->WorldViewState.Push(); + #if !defined(GL_ES_VERSION_2_0) - glMatrixMode (GL_MODELVIEW); - glPushMatrix(); + myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current()); + if (!myIs2d) { - // retrieve active matrices for project/unproject calls - glGetDoublev (GL_MODELVIEW_MATRIX, myModelMatrix); - glGetDoublev (GL_PROJECTION_MATRIX, myProjMatrix); glGetIntegerv (GL_VIEWPORT, myViewport); - gluProject (myPoint.x(), myPoint.y(), myPoint.z(), - myModelMatrix, myProjMatrix, myViewport, - &myWinX, &myWinY, &myWinZ); + myProjMatrix.Convert (theCtx->ProjectionState.Current()); + + OpenGl_Utils::Project (myPoint.x(), + myPoint.y(), + myPoint.z(), + myModelMatrix, + myProjMatrix, + myViewport, + myWinX, + myWinY, + myWinZ); // compute scale factor for constant text height GLdouble x1, y1, z1; - gluUnProject (myWinX, myWinY, myWinZ, - (GLdouble* )THE_IDENTITY_MATRIX, myProjMatrix, myViewport, - &x1, &y1, &z1); + OpenGl_Utils::UnProject (myWinX, + myWinY, + myWinZ, + OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), + myProjMatrix, + myViewport, + x1, + y1, + z1); GLdouble x2, y2, z2; const GLdouble h = (GLdouble )myFont->FTFont()->PointSize(); - gluUnProject (myWinX, myWinY + h, myWinZ, - (GLdouble* )THE_IDENTITY_MATRIX, myProjMatrix, myViewport, - &x2, &y2, &z2); + OpenGl_Utils::UnProject (myWinX, + myWinY + h, + myWinZ, + OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), + myProjMatrix, + myViewport, + x2, + y2, + z2); myScaleHeight = (y2 - y1) / h; if (theTextAspect.IsZoomable()) @@ -708,7 +737,6 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, glDisable (GL_DEPTH_TEST); } - // setup alpha test GLint aTexEnvParam = GL_REPLACE; glGetTexEnviv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &aTexEnvParam); @@ -823,7 +851,10 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, // revert OpenGL state glPopAttrib(); // enable bit - glPopMatrix(); // model view matrix was modified + + // model view matrix was modified + theCtx->WorldViewState.Pop(); + theCtx->ApplyModelViewMatrix(); // revert custom OpenGL sampler if (!aSampler.IsNull() && aSampler->IsValid())