mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-13 14:27:08 +03:00
0022819: Redesign of OpenGl driver
This commit is contained in:
213
src/OpenGl/OpenGl_Text.cxx
Normal file
213
src/OpenGl/OpenGl_Text.cxx
Normal file
@@ -0,0 +1,213 @@
|
||||
// File: OpenGl_Text.cxx
|
||||
// Created: 13 July 2011
|
||||
// Author: Sergey ZERCHANINOV
|
||||
// Copyright: OPEN CASCADE 2011
|
||||
|
||||
#include <OpenGl_Text.hxx>
|
||||
|
||||
#if (!defined(_WIN32) && !defined(__WIN32__))
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
#include <OpenGl_tgl_all.hxx>
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include <OpenGl_Memory.hxx>
|
||||
|
||||
#include <OpenGl_AspectText.hxx>
|
||||
#include <OpenGl_Structure.hxx>
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
OpenGl_Text::OpenGl_Text (const TCollection_ExtendedString& AText,
|
||||
const Graphic3d_Vertex& APoint,
|
||||
const Standard_Real AHeight,
|
||||
const Graphic3d_HorizontalTextAlignment AHta,
|
||||
const Graphic3d_VerticalTextAlignment AVta)
|
||||
: myString(NULL)
|
||||
{
|
||||
const Techar *str = (const Techar *) AText.ToExtString();
|
||||
|
||||
//szv: instead of strlen + 1
|
||||
int i = 0; while (str[i++]);
|
||||
|
||||
wchar_t *wstr = new wchar_t[i];
|
||||
|
||||
//szv: instead of memcpy
|
||||
i = 0; while (wstr[i++] = (wchar_t)(*str++));
|
||||
if (myString) delete[] myString;
|
||||
myString = wstr;
|
||||
|
||||
Standard_Real X, Y, Z;
|
||||
APoint.Coord(X, Y, Z);
|
||||
myAttachPnt.xyz[0] = float (X);
|
||||
myAttachPnt.xyz[1] = float (Y);
|
||||
myAttachPnt.xyz[2] = float (Z);
|
||||
|
||||
myParam.Height = int (AHeight);
|
||||
|
||||
myParam.HAlign = AHta;
|
||||
myParam.VAlign = AVta;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
OpenGl_Text::~OpenGl_Text ()
|
||||
{
|
||||
if (myString)
|
||||
delete[] myString;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
void OpenGl_Text::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
|
||||
{
|
||||
if ( AWorkspace->DegenerateModel > 0 && AWorkspace->SkipRatio >= 1.f )
|
||||
return;
|
||||
|
||||
const OpenGl_AspectText *aspect_text = AWorkspace->AspectText( Standard_True );
|
||||
|
||||
const TEL_COLOUR *tcolor, *scolor;
|
||||
|
||||
// Use highlight colours
|
||||
if( AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT )
|
||||
{
|
||||
tcolor = scolor = AWorkspace->HighlightColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
tcolor = &aspect_text->Color();
|
||||
scolor = &aspect_text->SubtitleColor();
|
||||
}
|
||||
|
||||
// Handle annotation style
|
||||
GLboolean flag_zbuffer = GL_FALSE;
|
||||
if (aspect_text->StyleType() == Aspect_TOST_ANNOTATION)
|
||||
{
|
||||
flag_zbuffer = glIsEnabled(GL_DEPTH_TEST);
|
||||
if (flag_zbuffer) glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
AWorkspace->SetTextParam(&myParam);
|
||||
|
||||
GLboolean blend_state = GL_FALSE;
|
||||
GLdouble modelMatrix[16], projMatrix[16];
|
||||
GLint viewport[4];
|
||||
GLdouble objrefX, objrefY, objrefZ;
|
||||
GLdouble objX, objY, objZ;
|
||||
GLdouble obj1X, obj1Y, obj1Z;
|
||||
GLdouble obj2X, obj2Y, obj2Z;
|
||||
GLdouble obj3X, obj3Y, obj3Z;
|
||||
GLdouble winx1, winy1, winz1;
|
||||
GLdouble winx, winy, winz;
|
||||
GLint status;
|
||||
|
||||
/* display type of text */
|
||||
if (aspect_text->DisplayType() != Aspect_TODT_NORMAL)
|
||||
{
|
||||
/* Optimisation: il faudrait ne faire le Get qu'une fois par Redraw */
|
||||
glGetIntegerv (GL_VIEWPORT, viewport);
|
||||
glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
|
||||
glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
|
||||
|
||||
switch (aspect_text->DisplayType())
|
||||
{
|
||||
case Aspect_TODT_BLEND:
|
||||
blend_state = glIsEnabled(GL_BLEND);
|
||||
if (!blend_state) glEnable(GL_BLEND);
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
glLogicOp(GL_XOR);
|
||||
break;
|
||||
case Aspect_TODT_SUBTITLE:
|
||||
{
|
||||
int sWidth, sAscent, sDescent;
|
||||
AWorkspace->StringSize(myString, sWidth, sAscent, sDescent);
|
||||
|
||||
objrefX = (float)myAttachPnt.xyz[0];
|
||||
objrefY = (float)myAttachPnt.xyz[1];
|
||||
objrefZ = (float)myAttachPnt.xyz[2];
|
||||
status = gluProject (objrefX, objrefY, objrefZ, modelMatrix, projMatrix, viewport,
|
||||
&winx1, &winy1, &winz1);
|
||||
|
||||
winx = winx1;
|
||||
winy = winy1-sDescent;
|
||||
winz = winz1+0.00001;
|
||||
status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
|
||||
&objX, &objY, &objZ);
|
||||
|
||||
winx = winx1 + sWidth;
|
||||
winy = winy1-sDescent;
|
||||
winz = winz1+0.00001; /* il vaut mieux F+B / 1000000 ? */
|
||||
status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
|
||||
&obj1X, &obj1Y, &obj1Z);
|
||||
|
||||
winx = winx1 + sWidth;
|
||||
winy = winy1 + sAscent;
|
||||
winz = winz1+0.00001;
|
||||
status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
|
||||
&obj2X, &obj2Y, &obj2Z);
|
||||
|
||||
winx = winx1;
|
||||
winy = winy1+ sAscent;
|
||||
winz = winz1+0.00001;
|
||||
status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
|
||||
&obj3X, &obj3Y, &obj3Z);
|
||||
|
||||
glColor3fv( scolor->rgb );
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3d(objX, objY, objZ);
|
||||
glVertex3d(obj1X, obj1Y, obj1Z);
|
||||
glVertex3d(obj2X, obj2Y, obj2Z);
|
||||
glVertex3d(obj3X, obj3Y, obj3Z);
|
||||
glEnd();
|
||||
break;
|
||||
}
|
||||
|
||||
case Aspect_TODT_DEKALE:
|
||||
objrefX = (float)myAttachPnt.xyz[0];
|
||||
objrefY = (float)myAttachPnt.xyz[1];
|
||||
objrefZ = (float)myAttachPnt.xyz[2];
|
||||
status = gluProject (objrefX, objrefY, objrefZ, modelMatrix, projMatrix, viewport,
|
||||
&winx1, &winy1, &winz1);
|
||||
|
||||
winx = winx1+1;
|
||||
winy = winy1+1;
|
||||
winz = winz1+0.00001;
|
||||
status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
|
||||
&objX, &objY, &objZ);
|
||||
|
||||
glColor3fv( scolor->rgb );
|
||||
AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ );
|
||||
winx = winx1-1;
|
||||
winy = winy1-1;
|
||||
status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
|
||||
&objX, &objY, &objZ);
|
||||
|
||||
AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ );
|
||||
winx = winx1-1;
|
||||
winy = winy1+1;
|
||||
status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
|
||||
&objX, &objY, &objZ);
|
||||
|
||||
AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ );
|
||||
winx = winx1+1;
|
||||
winy = winy1-1;
|
||||
status = gluUnProject (winx, winy, winz, modelMatrix, projMatrix, viewport,
|
||||
&objX, &objY, &objZ);
|
||||
AWorkspace->RenderText( myString, 0, (float)objX, (float)objY,(float)objZ );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
glColor3fv( tcolor->rgb );
|
||||
AWorkspace->RenderText( myString, 0, (float)myAttachPnt.xyz[0], (float)myAttachPnt.xyz[1],(float)myAttachPnt.xyz[2] );
|
||||
/* maj attributs */
|
||||
if (flag_zbuffer) glEnable(GL_DEPTH_TEST);
|
||||
if (aspect_text->DisplayType() == Aspect_TODT_BLEND)
|
||||
{
|
||||
if (!blend_state) glDisable(GL_BLEND);
|
||||
glDisable(GL_COLOR_LOGIC_OP);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
Reference in New Issue
Block a user