11 #define PI 3.1415926535897932384626433832795
23 #include <fontconfig/fontconfig.h>
40 #define GL_BGR GL_BGRA_EXT
61class cGLCanvas :
public ucom::catwo::object<ICanvas>
68 tBool bTextOppsedYAxis;
71 tBool bTextBaselineOnTop;
75 IFont* m_pCurrentFont;
77 tFloat64 m_fFontAngle;
78 GLUquadricObj* m_pGLUQuadric;
83 tFloat32 m_f32MappingX1;
84 tFloat32 m_f32MappingY1;
85 tFloat32 m_f32MappingX2;
86 tFloat32 m_f32MappingY2;
87 tFloat32 m_f32MappingWidth;
88 tFloat32 m_f32MappingHeight;
89 std::stack<sFlags> m_oFlags;
90 sFlags m_oCurrentFlags;
91 cImage m_oCaptureBuffer;
95 m_pCurrentFont(nullptr),
96 m_bUseMapping(tFalse),
98 m_pGLUQuadric(nullptr),
107 virtual ~cGLCanvas() final
118 tResult Create(tInt nWidth, tInt nHeight, tInt nBitsPerPixel)
override
120 m_bUseMapping = tFalse;
122 glShadeModel(GL_SMOOTH);
123 glDisable(GL_LIGHTING);
124 glDisable(GL_ALPHA_TEST);
126 glDisable(GL_DEPTH_TEST);
127 glEnable(GL_CULL_FACE);
130 glDepthFunc(GL_LESS);
131 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
133 BgColor(0.0, 0.0, 0.0, 0.0);
137 m_nBitsPerPixel = nBitsPerPixel;
138 m_pGLUQuadric = gluNewQuadric();
140 SwitchToScreenCoords();
142 glDepthMask(GL_TRUE);
143 glDisable(GL_DEPTH_TEST);
144 glDisable(GL_CULL_FACE);
145 glDisable(GL_LIGHTING);
157 tResult Resize(tInt nWidth, tInt nHeight)
161 SwitchToScreenCoords();
171 if (m_pGLUQuadric != NULL)
173 gluDeleteQuadric(m_pGLUQuadric);
174 m_pGLUQuadric = NULL;
177 m_pCurrentFont = NULL;
179 m_oCaptureBuffer.Release();
197 static tVoid Sort(T& a, T& b)
218 tVoid NormalizeRect(tInt& x1, tInt& y1, tInt& x2, tInt& y2)
const
233 tVoid NormalizeRect(tFloat32& x1, tFloat32& y1, tFloat32& x2, tFloat32& y2)
const
235 Sort<tFloat32>(x1, x2);
236 Sort<tFloat32>(y1, y2);
247 tVoid Coord(tFloat32* pXCoords, tFloat32* pYCoords, tInt nCount)
249 for (tInt l_nIdx = 0; l_nIdx < nCount; l_nIdx++)
251 glVertex2f(*(pXCoords++), *(pYCoords++));
255 virtual tVoid FlipTextHorizontally(tBool bOpposedYAxis)
257 m_oCurrentFlags.bTextOppsedYAxis = bOpposedYAxis;
260 virtual tVoid TextScaleWithZoom(tBool bScaleWithZoom)
262 m_oCurrentFlags.bTextScales = bScaleWithZoom;
266 tBool IsSupported(tFeature nFeatureId)
const override
268 if (nFeatureId == FEATURE_AlphaBlending || nFeatureId == FEATURE_Antialiasing ||
269 nFeatureId == FEATURE_Lighting || nFeatureId == FEATURE_DepthBuffer ||
270 nFeatureId == FEATURE_BackFaceCulling || nFeatureId == FEATURE_CommandLists ||
271 nFeatureId == FEATURE_HardwareAcceleration)
279 tVoid EnableAlpha(tBool bAdditiveMode = tFalse)
const override
284 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
288 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
290 glDisable(GL_ALPHA_TEST);
293 tVoid DisableAlpha()
const override
298 tVoid EnableAntialiasing()
const override
300 glEnable(GL_LINE_SMOOTH);
301 glEnable(GL_POINT_SMOOTH);
302 glEnable(GL_POLYGON_SMOOTH);
305 tVoid DisableAntialiasing()
const override
307 glDisable(GL_LINE_SMOOTH);
308 glDisable(GL_POINT_SMOOTH);
309 glDisable(GL_POLYGON_SMOOTH);
312 tVoid EnableLighting()
const override
314 glEnable(GL_LIGHTING);
317 glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0f);
319 GLfloat ambient_light[4];
320 ambient_light[0] = 0.2f;
321 ambient_light[1] = 0.2f;
322 ambient_light[2] = 0.2f;
323 ambient_light[3] = 0.2f;
324 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_light);
326 GLfloat diffuse_light[4];
327 diffuse_light[0] = 0.8f;
328 diffuse_light[1] = 0.8f;
329 diffuse_light[2] = 0.8f;
330 diffuse_light[3] = 0.8f;
331 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
333 GLfloat specular_light[4];
334 specular_light[0] = 1.0f;
335 specular_light[1] = 1.0f;
336 specular_light[2] = 1.0f;
337 specular_light[3] = 1.0f;
338 glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light);
340 glEnable(GL_COLOR_MATERIAL);
341 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
343 GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
344 GLfloat mat_shininess[] = {80.0};
345 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
346 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
348 glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 180.0);
349 glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 0.0);
351 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f);
352 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f);
353 glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0f);
356 tVoid DisableLighting()
const override
358 glDisable(GL_LIGHTING);
359 glDisable(GL_LIGHT0);
360 glDisable(GL_COLOR_MATERIAL);
363 tVoid EnableDepthBuffer()
const override
365 glEnable(GL_DEPTH_TEST);
366 glDepthMask(GL_TRUE);
369 tVoid DisableDepthBuffer()
const override
371 glDisable(GL_DEPTH_TEST);
372 glDepthMask(GL_FALSE);
375 tVoid EnableBackFaceCulling()
const override
377 glEnable(GL_CULL_FACE);
380 tVoid DisableBackFaceCulling()
const override
382 glDisable(GL_CULL_FACE);
385 tVoid LineWidth(tFloat64 fWidth)
override
387 glLineWidth((GLfloat) fWidth);
388 glPointSize((GLfloat) fWidth);
391 tVoid LinePattern(tUInt16 ui16Pattern, tInt nFactor = 1)
override
393 if (ui16Pattern != 0xFFFF)
395 glEnable(GL_LINE_STIPPLE);
399 glDisable(GL_LINE_STIPPLE);
402 glLineStipple(nFactor, ui16Pattern);
405 tVoid Color(
const IColor* col)
override
407 glColor4ub(col->GetRed(), col->GetGreen(), col->GetBlue(), col->GetAlpha());
410 tVoid Color(tInt nRed, tInt nGreen, tInt nBlue, tInt nAlpha = 255)
override
412 glColor4ub((tUInt8) nRed, (tUInt8) nGreen, (tUInt8) nBlue, (tUInt8) nAlpha);
415 tVoid Color(tUInt8 nRed, tUInt8 nGreen, tUInt8 nBlue, tUInt8 nAlpha = 255)
override
417 glColor4ub(nRed, nGreen, nBlue, nAlpha);
420 tVoid Color(tFloat64 fRed, tFloat64 fGreen, tFloat64 fBlue, tFloat64 fAlpha = 1.0)
override
422 glColor4d(fRed, fGreen, fBlue, fAlpha);
425 tVoid BgColor(
const IColor* col)
override
427 BgColor(col->GetRed() / 255.0, col->GetGreen() / 255.0, col->GetBlue() / 255.0, col->GetAlpha() / 255.0);
430 tVoid BgColor(tInt nRed, tInt nGreen, tInt nBlue, tInt nAlpha = 255)
override
432 BgColor(nRed / 255.0, nGreen / 255.0, nBlue / 255.0, nAlpha / 255.0);
435 tVoid BgColor(tUInt8 nRed, tUInt8 nGreen, tUInt8 nBlue, tUInt8 nAlpha = 255)
override
437 BgColor(nRed / 255.0, nGreen / 255.0, nBlue / 255.0, nAlpha / 255.0);
440 tVoid BgColor(tFloat64 fRed, tFloat64 fGreen, tFloat64 fBlue, tFloat64 fAlpha = 0.0)
override
442 glClearColor((GLclampf) fRed, (GLclampf) fGreen, (GLclampf) fBlue, (GLclampf) fAlpha);
445 tVoid Begin(tMode eMode)
override
447 GLenum l_eGLMode = 0;
451 case MODE_DrawPoints:
453 l_eGLMode = GL_POINTS;
458 l_eGLMode = GL_LINES;
461 case MODE_DrawLineStrip:
463 l_eGLMode = GL_LINE_STRIP;
466 case MODE_DrawLineLoop:
468 l_eGLMode = GL_LINE_LOOP;
471 case MODE_DrawTriangles:
473 l_eGLMode = GL_TRIANGLES;
476 case MODE_DrawTriangleStrip:
478 l_eGLMode = GL_TRIANGLE_STRIP;
481 case MODE_DrawTriangleFan:
483 l_eGLMode = GL_TRIANGLE_FAN;
488 l_eGLMode = GL_QUADS;
491 case MODE_DrawQuadStrip:
493 l_eGLMode = GL_QUAD_STRIP;
496 case MODE_DrawPolygon:
498 l_eGLMode = GL_POLYGON;
510 tVoid Coord(tInt x, tInt y)
override
515 tVoid Coord(tFloat32 x, tFloat32 y)
override
520 tVoid Coord(IPoint* pt)
override
522 glVertex2i(pt->GetX(), pt->GetY());
525 tVoid Coord(IPoint** ppPoints, tInt nCount)
override
527 for (tInt l_nIdx = 0; l_nIdx < nCount; l_nIdx++)
529 glVertex2i(ppPoints[l_nIdx]->GetX(), ppPoints[l_nIdx]->GetY());
533 tVoid CoordTexture(tFloat32 u, tFloat32 v)
override
544 tInt GetWidth()
const override
549 tInt GetHeight()
const override
554 tInt GetBitsPerPixel()
const override
556 return m_nBitsPerPixel;
559 tVoid SetMapping(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
override
565 m_f32MappingWidth = x2 - x1;
566 m_f32MappingHeight = y2 - y1;
567 m_bUseMapping = tTrue;
569 SwitchToScreenCoords();
572 tVoid ClearMapping()
override
574 m_bUseMapping = tFalse;
575 SwitchToScreenCoords();
578 tInt MapPixelX(tFloat32 x)
override
582 return (tInt) ((x - m_f32MappingX1) * (tFloat32) m_nWidth / m_f32MappingWidth);
588 tInt MapPixelY(tFloat32 y)
override
592 return (tInt) ((y - m_f32MappingY1) * (tFloat32) m_nHeight / m_f32MappingHeight);
598 tInt MapPixelX(tInt x)
override
602 return (tInt) (((tFloat32) x - m_f32MappingX1) * (tFloat32) m_nWidth / m_f32MappingWidth);
608 tInt MapPixelY(tInt y)
override
612 return (tInt) (((tFloat32) y - m_f32MappingY1) * (tFloat32) m_nHeight / m_f32MappingHeight);
618 tFloat32 UnmapPixelX(tInt x)
override
622 return m_f32MappingX1 + ((tFloat32) x * m_f32MappingWidth) / (tFloat32) m_nWidth;
628 tFloat32 UnmapPixelY(tInt y)
override
632 return m_f32MappingY1 + ((tFloat32) y * m_f32MappingHeight) / (tFloat32) m_nHeight;
638 tVoid Clear()
override
640 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
643 tResult CreateTexture(IImage* pImage, ITexture*& pTexture)
override
645 RETURN_IF_POINTER_NULL(pImage);
647 if (pTexture !=
nullptr)
653 pTexture = CreateTexture(pImage->GetFormat(), ITexture::MODE_BilinearFiltered);
654 RETURN_IF_POINTER_NULL(pTexture);
655 pTexture->Copy(pImage);
659 tVoid DrawTexture(ITexture* pTexture, tFloat32 vPoints[8])
override
665 Color(255, 255, 255);
667 pTexture->MakeCurrent();
669 tFloat32 u = (tFloat32) pTexture->GetWidth() / pTexture->GetPhysicalWidth();
670 tFloat32 v = (tFloat32) pTexture->GetHeight() / pTexture->GetPhysicalHeight();
674 glVertex2f(vPoints[0], vPoints[1]);
677 glVertex2f(vPoints[2], vPoints[3]);
680 glVertex2f(vPoints[4], vPoints[5]);
683 glVertex2f(vPoints[6], vPoints[7]);
686 glDisable(GL_TEXTURE_2D);
690 tVoid DrawPixel(tInt x, tInt y)
override
697 tVoid DrawPixel(tFloat32 x, tFloat32 y)
override
704 tVoid DrawPixel(IPoint* pt)
override
706 DrawPixel(pt->GetX(), pt->GetY());
709 tVoid DrawLine(tInt x1, tInt y1, tInt x2, tInt y2)
override
712 CoordLine(x1, y1, x2, y2);
716 tVoid DrawLine(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
override
719 CoordLine(x1, y1, x2, y2);
723 tVoid DrawLine(IPoint* ptStart, IPoint* ptEnd)
override
725 DrawLine(ptStart->GetX(), ptStart->GetY(), ptEnd->GetX(), ptEnd->GetY());
728 tVoid DrawRect(tInt x1, tInt y1, tInt x2, tInt y2)
override
730 glBegin(GL_LINE_LOOP);
731 CoordRect(x1, y1, x2, y2);
735 tVoid DrawRect(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
override
737 glBegin(GL_LINE_LOOP);
738 CoordRect(x1, y1, x2, y2);
742 tVoid DrawRect(IRect* rect)
override
744 DrawRect(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom());
747 tVoid DrawCircle(tInt x1, tInt y1, tInt x2, tInt y2)
override
749 glBegin(GL_LINE_LOOP);
750 CoordCircle(x1, y1, x2, y2);
754 tVoid DrawCircle(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
override
756 glBegin(GL_LINE_LOOP);
757 CoordCircle(x1, y1, x2, y2);
761 tVoid DrawCircle(IRect* rect)
override
763 glBegin(GL_LINE_LOOP);
764 CoordCircle(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom());
768 tVoid DrawCircleSegment(tInt x1,
772 tFloat64 fDegreeStart,
774 tBool bNormalizeRect = tFalse)
override
778 NormalizeRect(x1, y1, x2, y2);
781 glBegin(GL_LINE_LOOP);
782 Coord((x1 + x2) / 2, (y1 + y2) / 2);
783 CoordCircleSegment(x1, y1, x2, y2, fDegreeStart, fDegreeEnd);
787 tVoid DrawCircleSegment(tFloat32 x1,
791 tFloat64 fDegreeStart,
793 tBool bNormalizeRect = tFalse)
override
797 NormalizeRect(x1, y1, x2, y2);
800 glBegin(GL_LINE_LOOP);
801 Coord((x1 + x2) / 2.0f, (y1 + y2) / 2.0f);
802 CoordCircleSegment(x1, y1, x2, y2, fDegreeStart, fDegreeEnd);
806 tVoid DrawCircleSegment(IRect* rect, tFloat64 fDegreeStart, tFloat64 fDegreeEnd)
override
808 DrawCircleSegment(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom(), fDegreeStart,
812 tVoid DrawPolygon(IPoint** ppPoints, tInt nCount)
override
814 glBegin(GL_LINE_LOOP);
815 Coord(ppPoints, nCount);
819 tVoid FillRect(tInt x1, tInt y1, tInt x2, tInt y2)
override
822 glNormal3f(0.0, 0.0, -1.0f);
823 CoordRect(x1, y1, x2, y2);
827 tVoid FillRect(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
override
830 glNormal3f(0.0, 0.0, -1.0f);
831 CoordRect(x1, y1, x2, y2);
835 tVoid FillRect(IRect* rect)
override
837 FillRect(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom());
840 tVoid FillCircle(tInt x1, tInt y1, tInt x2, tInt y2)
override
842 glBegin(GL_TRIANGLE_FAN);
843 glNormal3f(0.0f, 0.0f, -1.0f);
844 glVertex2i((x1 + x2) / 2, (y1 + y2) / 2);
845 CoordCircle(x1, y1, x2, y2);
849 tVoid FillCircle(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
override
851 glBegin(GL_TRIANGLE_FAN);
852 glNormal3f(0.0f, 0.0f, -1.0f);
853 glVertex2f((x1 + x2) / 2, (y1 + y2) / 2);
854 CoordCircle(x1, y1, x2, y2);
858 tVoid FillCircle(IRect* rect)
override
860 return FillCircle(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom());
863 tVoid FillCircleSegment(tInt x1,
867 tFloat64 fDegreeStart,
869 tBool bNormalizeRect = tFalse)
override
873 NormalizeRect(x1, y1, x2, y2);
876 glBegin(GL_TRIANGLE_FAN);
877 glNormal3f(0.0, 0.0, -1.0f);
878 glVertex2i((x1 + x2) / 2, (y1 + y2) / 2);
879 CoordCircleSegment(x1, y1, x2, y2, fDegreeStart, fDegreeEnd);
883 tVoid FillCircleSegment(tFloat32 x1,
887 tFloat64 fDegreeStart,
889 tBool bNormalizeRect = tFalse)
override
893 NormalizeRect(x1, y1, x2, y2);
896 glBegin(GL_TRIANGLE_FAN);
897 glNormal3f(0.0f, 0.0f, -1.0f);
898 glVertex2f((x1 + x2) / 2.0f, (y1 + y2) / 2.0f);
899 CoordCircleSegment(x1, y1, x2, y2, fDegreeStart, fDegreeEnd);
903 tVoid FillCircleSegment(IRect* rect, tFloat64 fDegreeStart, tFloat64 fDegreeEnd)
override
905 return FillCircleSegment(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom(), fDegreeStart,
909 tVoid FillPolygon(IPoint** ppPoints, tInt nCount)
override
912 glNormal3f(0.0, 0.0, -1.0f);
913 Coord(ppPoints, nCount);
917 IFont* CreateFont(
const char* strName, tInt nHeight, IFont::tStyle eFontStyle = IFont::STYLE_Default)
919 cGLFont* l_pFont =
new cGLFont();
925 if (IS_FAILED(l_pFont->Create(
this, strName, nHeight, eFontStyle)))
931 return static_cast<IFont*
>(l_pFont);
934 tVoid SetFontAngle(tFloat64 fAngle)
936 m_fFontAngle = fAngle;
939 tFloat64 GetFontAngle()
944 tVoid Font(IFont* pFont)
946 m_pCurrentFont = pFont;
949 tVoid OutputText(tInt x, tInt y,
const char* strFormat, ...)
951 if (m_pCurrentFont == NULL)
956 ((cGLFont*) m_pCurrentFont)->FlipTextHorizontally(m_oCurrentFlags.bTextOppsedYAxis);
957 ((cGLFont*) m_pCurrentFont)->TextScaleWithCoordinateSystem(m_oCurrentFlags.bTextScales);
958 ((cGLFont*) m_pCurrentFont)->TextRotateWithCoordinateSystem(m_oCurrentFlags.bTextRotate);
959 ((cGLFont*) m_pCurrentFont)->TextBaselineOnTop(m_oCurrentFlags.bTextBaselineOnTop);
962 va_start(ap, strFormat);
966 tInt x_mapped = MapPixelX(x);
967 tInt y_mapped = MapPixelY(y);
974 ((cGLFont*) m_pCurrentFont)->Print(x_mapped, y_mapped, m_fFontAngle, strFormat, ap);
976 SetMapping(m_f32MappingX1, m_f32MappingY1, m_f32MappingX2, m_f32MappingY2);
980 ((cGLFont*) m_pCurrentFont)->Print(x, y, m_fFontAngle, strFormat, ap);
986 tVoid OutputText(tFloat32 x, tFloat32 y,
const char* strFormat, ...)
988 if (m_pCurrentFont == NULL)
993 ((cGLFont*) m_pCurrentFont)->FlipTextHorizontally(m_oCurrentFlags.bTextOppsedYAxis);
994 ((cGLFont*) m_pCurrentFont)->TextScaleWithCoordinateSystem(m_oCurrentFlags.bTextScales);
995 ((cGLFont*) m_pCurrentFont)->TextRotateWithCoordinateSystem(m_oCurrentFlags.bTextRotate);
996 ((cGLFont*) m_pCurrentFont)->TextBaselineOnTop(m_oCurrentFlags.bTextBaselineOnTop);
999 va_start(ap, strFormat);
1003 tInt x_mapped = MapPixelX(x);
1004 tInt y_mapped = MapPixelY(y);
1010 ((cGLFont*) m_pCurrentFont)->Print(x_mapped, y_mapped, m_fFontAngle, strFormat, ap);
1014 SetMapping(m_f32MappingX1, m_f32MappingY1, m_f32MappingX2, m_f32MappingY2);
1018 ((cGLFont*) m_pCurrentFont)->Print(x, y, m_fFontAngle, strFormat, ap);
1024 ITexture* CreateTexture(
const tBitmapFormat* psFormat, tInt nMode = 0)
override
1026 cGLTexture* l_pTexture =
new cGLTexture();
1027 if (l_pTexture == NULL)
1032 if (IS_FAILED(l_pTexture->Create(psFormat, nMode)))
1038 return static_cast<ITexture*
>(l_pTexture);
1041 tVoid Texture(ITexture* pTexture)
override
1043 if (pTexture == NULL)
1046 glDisable(GL_TEXTURE_2D);
1050 ((cGLTexture*) pTexture)->MakeCurrent();
1053 tVoid Blit(ITexture* pTexture, tInt x, tInt y, tInt nWidth, tInt nHeight)
override
1055 if (pTexture == NULL)
1060 ((cGLTexture*) pTexture)->Blit(x, y, nWidth, nHeight);
1063 tVoid Blit(IImage* pImage, tInt x, tInt y, tInt nWidth, tInt nHeight)
override
1070 tVoid* pBitmap = pImage->GetBitmap();
1071 if (pBitmap == NULL)
1076 tBool bBGR = tFalse;
1078 switch (pImage->GetPixelFormat())
1080 case cImage::PF_RGB_888:
1081 case cImage::PF_RGBA_8888:
1087 case cImage::PF_BGR_888:
1088 case cImage::PF_BGRA_8888:
1097 tBitmapFormat sFormat = *(pImage->GetFormat());
1104 switch (pImage->GetBitsPerPixel())
1122 if (IS_FAILED(oImage.Convert(&sFormat)))
1124 LOG_ERROR(
"Cannot convert image!");
1127 Blit(&oImage, x, y, nWidth, nHeight);
1132 GLenum l_nFormat = 0;
1134 switch (pImage->GetBitsPerPixel())
1138 l_nFormat = (bBGR ? GL_BGRA_EXT : GL_RGBA);
1143 l_nFormat = (bBGR ? GL_BGR_EXT : GL_RGB);
1148 l_nFormat = GL_LUMINANCE;
1157 glPixelStorei(GL_PACK_ROW_LENGTH, pImage->GetWidth());
1158 glPixelStorei(GL_PACK_ALIGNMENT, 4);
1161 if ((x >= 0) && (y >= 0) && ((x + nWidth) <= GetWidth()) && ((y + nHeight) <= GetHeight()))
1164 glRasterPos2i(x, y);
1165 glPixelZoom((
float) (nWidth) / pImage->GetWidth(), -(
float) (nHeight) / pImage->GetHeight());
1166 glDrawPixels(pImage->GetWidth(), pImage->GetHeight(), l_nFormat, GL_UNSIGNED_BYTE, pBitmap);
1167 glPixelZoom(1.0f, 1.0f);
1171 if ((x >= GetWidth()) || (y >= GetHeight()) || (x + nWidth < 0) || (y + nHeight < 0))
1178 tInt x1 = (x < 0) ? 0 : x;
1179 tInt y1 = (y < 0) ? 0 : y;
1180 tInt x2 = (x < 0) ? nWidth + x : nWidth;
1181 tInt y2 = (y < 0) ? nHeight + y : nHeight;
1183 tInt xs = (x < 0) ? -x : 0;
1184 tInt ys = (y < 0) ? -y : 0;
1186 glPixelZoom(1.0, -1.0);
1187 tUInt8* pData = (tUInt8*) pBitmap + xs * pImage->GetBitsPerPixel() / 8 + ys * pImage->GetBytesPerLine();
1188 for (tInt i = 0; i < y2; i++)
1190 glRasterPos2i(x1, y1 + i);
1191 glDrawPixels(x2, 1, l_nFormat, GL_UNSIGNED_BYTE, pData);
1192 pData += pImage->GetBytesPerLine();
1194 glPixelZoom(1.0, 1.0);
1201 tVoid Capture(IImage** ppImage, tInt x, tInt y, tInt nWidth, tInt nHeight)
override
1210 nHeight = m_nHeight;
1213 if (m_oCaptureBuffer.GetWidth() != nWidth || m_oCaptureBuffer.GetHeight() != nHeight)
1215 m_oCaptureBuffer.Create(nWidth, nHeight, 32, 0, NULL, IImage::PF_RGBA_8888);
1220 glPixelStorei(GL_PACK_ROW_LENGTH, nWidth);
1221 glPixelStorei(GL_PACK_ALIGNMENT, 4);
1222 glReadBuffer(GL_BACK);
1224 glReadPixels(x, y, nWidth, nHeight, GL_BGR, GL_UNSIGNED_BYTE, m_oCaptureBuffer.GetBitmap());
1226 m_oCaptureBuffer.Flip();
1228 *ppImage = (IImage*) &m_oCaptureBuffer;
1231 IScene* BeginScene()
override
1233 glDepthMask(GL_FALSE);
1234 glEnable(GL_DEPTH_TEST);
1235 glEnable(GL_CULL_FACE);
1242 tVoid EndScene()
override
1244 SwitchToScreenCoords();
1246 glDepthMask(GL_TRUE);
1247 glDisable(GL_DEPTH_TEST);
1248 glDisable(GL_CULL_FACE);
1249 glDisable(GL_LIGHTING);
1254 tVoid SetFlag(tUInt32 nFlag, tInt32 nValue)
1260 m_oCurrentFlags.bTextOppsedYAxis = nValue != 0;
1265 m_oCurrentFlags.bTextScales = nValue != 0;
1270 m_oCurrentFlags.bTextRotate = nValue != 0;
1275 m_oCurrentFlags.bTextBaselineOnTop = nValue != 0;
1284 tInt32 GetFlag(tUInt32 nFlag)
1290 return m_oCurrentFlags.bTextOppsedYAxis ? 1 : 0;
1295 return m_oCurrentFlags.bTextScales ? 1 : 0;
1300 return m_oCurrentFlags.bTextRotate ? 1 : 0;
1305 return m_oCurrentFlags.bTextBaselineOnTop ? 1 : 0;
1317 if (m_oFlags.size() > 20)
1319 RETURN_ERROR(ERR_OUT_OF_RANGE);
1322 m_oFlags.push(m_oCurrentFlags);
1329 if (m_oFlags.size() == 0)
1331 RETURN_ERROR(ERR_OUT_OF_RANGE);
1334 m_oCurrentFlags = m_oFlags.top();
1342 m_oCurrentFlags.bTextRotate = tFalse;
1343 m_oCurrentFlags.bTextOppsedYAxis = tTrue;
1344 m_oCurrentFlags.bTextScales = tFalse;
1345 m_oCurrentFlags.bTextBaselineOnTop = tFalse;
1348 tVoid DrawEllipse(tInt iOriginX, tInt iOriginY, tInt iWidth, tInt iHeight, tInt iAngle)
1350 DrawEllipse((tFloat32) iOriginX, (tFloat32) iOriginY, (tFloat32) iWidth, (tFloat32) iHeight, (tFloat32) iAngle);
1354 DrawEllipse(tFloat32 f32OriginX, tFloat32 f32OriginY, tFloat32 f32Width, tFloat32 f32Height, tFloat32 f32Angle)
1356 tFloat32 x1 = -f32Width / 2;
1357 tFloat32 x2 = f32Width / 2;
1358 tFloat32 y1 = -f32Height / 2;
1359 tFloat32 y2 = f32Height / 2;
1363 glTranslatef(f32OriginX, f32OriginY, 0.0f);
1364 glRotatef(-f32Angle, 0.0f, 0.0f, 1.0f);
1366 DrawCircle(x1, y1, x2, y2);
1371 tVoid FillEllipse(tInt iOriginX, tInt iOriginY, tInt iWidth, tInt iHeight, tInt iAngle)
1373 FillEllipse((tFloat32) iOriginX, (tFloat32) iOriginY, (tFloat32) iWidth, (tFloat32) iHeight, (tFloat32) iAngle);
1377 FillEllipse(tFloat32 f32OriginX, tFloat32 f32OriginY, tFloat32 f32Width, tFloat32 f32Height, tFloat32 f32Angle)
1379 tFloat32 x1 = -f32Width / 2;
1380 tFloat32 x2 = f32Width / 2;
1381 tFloat32 y1 = -f32Height / 2;
1382 tFloat32 y2 = f32Height / 2;
1386 glTranslatef(f32OriginX, f32OriginY, 0.0f);
1387 glRotatef(-f32Angle, 0.0f, 0.0f, 1.0f);
1389 FillCircle(x1, y1, x2, y2);
1404 tVoid Translate(tFloat fx, tFloat fy, tFloat fz)
1406 glTranslated(fx, fy, fz);
1409 tVoid Scale(tFloat fx, tFloat fy, tFloat fz)
1411 glScaled(fx, fy, fz);
1414 tVoid Rotate(tFloat fangle, tFloat fx, tFloat fy, tFloat fz)
1416 glRotated(fangle, fx, fy, fz);
1427 tVoid CoordLine(tInt x1, tInt y1, tInt x2, tInt y2)
const
1440 tVoid CoordRect(tInt x1, tInt y1, tInt x2, tInt y2)
const
1455 tVoid CoordCircle(tInt x1, tInt y1, tInt x2, tInt y2)
const
1457 CoordCircle((tFloat32) x1, (tFloat32) y1, (tFloat32) x2, (tFloat32) y2);
1469 tVoid CoordCircleSegment(tInt x1, tInt y1, tInt x2, tInt y2, tFloat64 fDegreeStart, tFloat64 fDegreeEnd)
const
1471 CoordCircleSegment((tFloat32) x1, (tFloat32) y1, (tFloat32) x2, (tFloat32) y2, fDegreeStart, fDegreeEnd);
1481 tVoid CoordLine(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
const
1494 tVoid CoordRect(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
const
1509 tVoid CoordCircle(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2)
const
1511 tFloat64 fRadX = (tFloat64) (x2 - x1) / 2.0;
1512 tFloat64 fRadY = (tFloat64) - (y2 - y1) / 2.0;
1513 tFloat32 nCenterX = (x1 + x2) / 2.0f;
1514 tFloat32 nCenterY = (y1 + y2) / 2.0f;
1516 tFloat32 l_fRadDist = (tFloat32) (fRadX + fRadY) / 2.0f;
1517 tInt l_nSegments = 32 + tInt(l_fRadDist / 4.0f);
1518 tInt l_nStep = (tInt) (PI * 2.0 / l_nSegments);
1524 const tFloat64 fDeg2Rad = PI / 180.0;
1526 for (tInt w = 0; w < 360 + l_nStep; w += l_nStep)
1528 glVertex2f(nCenterX + (tFloat32) (fRadX * sin(w * fDeg2Rad)),
1529 nCenterY + (tFloat32) (fRadY * cos(w * fDeg2Rad)));
1542 tVoid CoordCircleSegment(
1543 tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2, tFloat64 fDegreeStart, tFloat64 fDegreeEnd)
const
1545 tFloat64 fRadX = (tFloat64) (x2 - x1) / 2.0;
1546 tFloat64 fRadY = (tFloat64) - (y2 - y1) / 2.0;
1547 tFloat64 fCenterX = (x1 + x2) / 2;
1548 tFloat64 fCenterY = (y1 + y2) / 2;
1550 tFloat64 l_fRadDist = (fRadX + fRadY / 2.0);
1551 tInt l_nSegments = 32 + tInt(l_fRadDist / 4.0);
1552 tInt l_nStep = (tInt) (PI * 2.0 / l_nSegments);
1558 tInt nDegreeStart = (tInt) (fDegreeStart + 0.9999) % 360;
1559 tInt nDegreeEnd = (tInt) (fDegreeEnd);
1560 if (nDegreeEnd < nDegreeStart)
1562 nDegreeEnd = nDegreeStart + 360;
1565 const tFloat64 fDeg2Rad = PI / 180.0;
1567 glVertex2f(GLfloat(fCenterX + (tFloat32) (fRadX * sin(fDegreeStart * fDeg2Rad))),
1568 GLfloat(fCenterY + (tFloat32) (fRadY * cos(fDegreeStart * fDeg2Rad))));
1570 for (tInt w = nDegreeStart; w < nDegreeEnd; w += l_nStep)
1572 glVertex2f(GLfloat(fCenterX +
static_cast<tFloat32
>(fRadX * sin(w * fDeg2Rad))),
1573 GLfloat(fCenterY +
static_cast<tFloat32
>(fRadY * cos(w * fDeg2Rad))));
1576 glVertex2f(GLfloat(fCenterX + (tFloat32) (fRadX * sin(fDegreeEnd * fDeg2Rad))),
1577 GLfloat(fCenterY + (tFloat32) (fRadY * cos(fDegreeEnd * fDeg2Rad))));
1583 tVoid SwitchToScreenCoords()
1585 glMatrixMode(GL_PROJECTION);
1588 GLdouble
const zNear = -1.0;
1589 GLdouble
const zFar = 1.0;
1593 GLdouble
const x1 = m_f32MappingX1;
1594 GLdouble
const y1 = m_f32MappingY1;
1595 GLdouble
const x2 = m_f32MappingX2;
1596 GLdouble
const y2 = m_f32MappingY2;
1597 glOrtho(x1, x2, y2, y1, zNear, zFar);
1601 GLdouble
const x1 = 0;
1602 GLdouble
const y1 = 0;
1603 GLdouble
const x2 = m_nWidth;
1604 GLdouble
const y2 = m_nHeight;
1605 glOrtho(x1, x2, y2, y1, zNear, zFar);
1608 glMatrixMode(GL_MODELVIEW);
1615using dengar::cGLCanvas;
Copyright © Audi Electronics Venture GmbH.
#define COORDS_LOGICAL
defines a constant for indicate coordinates as logical coordinates.
@ CANVAS_FLAG_TEXT_BASELINE_ON_TOP
Set the text baseline on top of the text (0: baseline is on button of a glyphe, 1: baseline is on top...
@ CANVAS_FLAG_TEXT_FLIP_HORIZONTALLY
Set the text direction with or opposed the x-axis direction (0: with the x-axis direction,...
@ CANVAS_FLAG_TEXT_ROTATE_WITH_COORDINATE_SYSTEM
Set the text to scale with the level of zoom.
@ CANVAS_FLAG_TEXT_SCALE_WITH_COORDINATE_SYSTEM
Set the text to scale with the coordinatesystem.
#define COORDS_SCREEN
defines a constant for indicate coordinates as screen coordinates.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Namespace for functionality provided by the Display Toolbox.
Copyright © Audi Electronics Venture GmbH.