ADTF Display Toolbox
Loading...
Searching...
No Matches
glcanvas.h
Go to the documentation of this file.
1
8#pragma once
9
10#ifndef PI
11 #define PI 3.1415926535897932384626433832795
12#endif
13
14#include <adtf_base.h>
15
16#ifdef WIN32
17 #include <windows.h>
18 #include <gl/GLU.h>
19 #include <gl/GL.h>
20#else
21 #include <GL/gl.h>
22 #include <GL/glu.h>
23 #include <fontconfig/fontconfig.h>
24#endif
25
26#ifdef GetObject
27 #undef GetObject
28#endif
29
35
36#include <cmath>
37
38#ifndef GL_BGR
39 // #define GL_BGR GL_BGR_EXT
40 #define GL_BGR GL_BGRA_EXT
41#endif
42
43namespace adtf
44{
45
46namespace disptb
47{
48
49namespace graphicslib
50{
51
52namespace dengar
53{
54
60
61class cGLCanvas : public ucom::catwo::object<ICanvas>
62{
63 friend class cGLFont;
64
65protected:
66 struct sFlags
67 {
68 tBool bTextOppsedYAxis;
69 tBool bTextScales;
70 tBool bTextRotate;
71 tBool bTextBaselineOnTop;
72 };
73
74protected:
75 IFont* m_pCurrentFont;
76 tBool m_bUseMapping;
77 tFloat64 m_fFontAngle;
78 GLUquadricObj* m_pGLUQuadric;
79 tUInt32 m_nMode;
80 tInt m_nBitsPerPixel;
81 tInt m_nHeight;
82 tInt m_nWidth;
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;
92
93public:
94 cGLCanvas():
95 m_pCurrentFont(nullptr),
96 m_bUseMapping(tFalse),
97 m_fFontAngle(0.0),
98 m_pGLUQuadric(nullptr),
99 m_nMode(COORDS_SCREEN)
100 {
101 ResetFlags();
102 }
103
107 virtual ~cGLCanvas() final
108 {
109 Release();
110 }
111
118 tResult Create(tInt nWidth, tInt nHeight, tInt nBitsPerPixel) override
119 {
120 m_bUseMapping = tFalse;
121
122 glShadeModel(GL_SMOOTH);
123 glDisable(GL_LIGHTING);
124 glDisable(GL_ALPHA_TEST);
125 glDisable(GL_BLEND);
126 glDisable(GL_DEPTH_TEST);
127 glEnable(GL_CULL_FACE);
128 glCullFace(GL_BACK);
129 glClearDepth(1.0f);
130 glDepthFunc(GL_LESS);
131 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
132
133 BgColor(0.0, 0.0, 0.0, 0.0);
134
135 m_nWidth = nWidth;
136 m_nHeight = nHeight;
137 m_nBitsPerPixel = nBitsPerPixel;
138 m_pGLUQuadric = gluNewQuadric();
139
140 SwitchToScreenCoords();
141
142 glDepthMask(GL_TRUE);
143 glDisable(GL_DEPTH_TEST);
144 glDisable(GL_CULL_FACE);
145 glDisable(GL_LIGHTING);
146
147 m_nMode = COORDS_SCREEN;
148
149 RETURN_NOERROR;
150 }
151
157 tResult Resize(tInt nWidth, tInt nHeight)
158 {
159 m_nWidth = nWidth;
160 m_nHeight = nHeight;
161 SwitchToScreenCoords();
162
163 RETURN_NOERROR;
164 }
165
169 tResult Release()
170 {
171 if (m_pGLUQuadric != NULL)
172 {
173 gluDeleteQuadric(m_pGLUQuadric);
174 m_pGLUQuadric = NULL;
175 }
176
177 m_pCurrentFont = NULL;
178
179 m_oCaptureBuffer.Release();
180 RETURN_NOERROR;
181 }
182
186 tUInt32 GetMode()
187 {
188 if (m_bUseMapping)
189 {
190 return COORDS_LOGICAL;
191 }
192
193 return m_nMode;
194 }
195
196 template<typename T>
197 static tVoid Sort(T& a, T& b)
198 {
199 T vTmp;
200
201 if (a > b)
202 {
203 vTmp = a;
204 a = b;
205 b = vTmp;
206 }
207 }
208
218 tVoid NormalizeRect(tInt& x1, tInt& y1, tInt& x2, tInt& y2) const
219 {
220 Sort<tInt>(x1, x2);
221 Sort<tInt>(y1, y2);
222 }
223
233 tVoid NormalizeRect(tFloat32& x1, tFloat32& y1, tFloat32& x2, tFloat32& y2) const
234 {
235 Sort<tFloat32>(x1, x2);
236 Sort<tFloat32>(y1, y2);
237 }
238
246
247 tVoid Coord(tFloat32* pXCoords, tFloat32* pYCoords, tInt nCount)
248 {
249 for (tInt l_nIdx = 0; l_nIdx < nCount; l_nIdx++)
250 {
251 glVertex2f(*(pXCoords++), *(pYCoords++));
252 }
253 }
254
255 virtual tVoid FlipTextHorizontally(tBool bOpposedYAxis)
256 {
257 m_oCurrentFlags.bTextOppsedYAxis = bOpposedYAxis;
258 };
259
260 virtual tVoid TextScaleWithZoom(tBool bScaleWithZoom)
261 {
262 m_oCurrentFlags.bTextScales = bScaleWithZoom;
263 }
264
265public: // implements IGraphicsMode
266 tBool IsSupported(tFeature nFeatureId) const override
267 {
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)
272 {
273 return tTrue;
274 }
275
276 return tFalse;
277 }
278
279 tVoid EnableAlpha(tBool bAdditiveMode = tFalse) const override
280 {
281 glEnable(GL_BLEND);
282 if (bAdditiveMode)
283 {
284 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
285 }
286 else
287 {
288 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
289 }
290 glDisable(GL_ALPHA_TEST);
291 }
292
293 tVoid DisableAlpha() const override
294 {
295 glDisable(GL_BLEND);
296 }
297
298 tVoid EnableAntialiasing() const override
299 {
300 glEnable(GL_LINE_SMOOTH);
301 glEnable(GL_POINT_SMOOTH);
302 glEnable(GL_POLYGON_SMOOTH);
303 }
304
305 tVoid DisableAntialiasing() const override
306 {
307 glDisable(GL_LINE_SMOOTH);
308 glDisable(GL_POINT_SMOOTH);
309 glDisable(GL_POLYGON_SMOOTH);
310 }
311
312 tVoid EnableLighting() const override
313 {
314 glEnable(GL_LIGHTING);
315 glEnable(GL_LIGHT0);
316
317 glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0f);
318
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);
325
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);
332
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);
339
340 glEnable(GL_COLOR_MATERIAL);
341 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
342
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);
347
348 glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 180.0);
349 glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 0.0);
350
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);
354 }
355
356 tVoid DisableLighting() const override
357 {
358 glDisable(GL_LIGHTING);
359 glDisable(GL_LIGHT0);
360 glDisable(GL_COLOR_MATERIAL);
361 }
362
363 tVoid EnableDepthBuffer() const override
364 {
365 glEnable(GL_DEPTH_TEST);
366 glDepthMask(GL_TRUE);
367 }
368
369 tVoid DisableDepthBuffer() const override
370 {
371 glDisable(GL_DEPTH_TEST);
372 glDepthMask(GL_FALSE);
373 }
374
375 tVoid EnableBackFaceCulling() const override
376 {
377 glEnable(GL_CULL_FACE);
378 }
379
380 tVoid DisableBackFaceCulling() const override
381 {
382 glDisable(GL_CULL_FACE);
383 }
384
385 tVoid LineWidth(tFloat64 fWidth) override
386 {
387 glLineWidth((GLfloat) fWidth);
388 glPointSize((GLfloat) fWidth);
389 }
390
391 tVoid LinePattern(tUInt16 ui16Pattern, tInt nFactor = 1) override
392 {
393 if (ui16Pattern != 0xFFFF)
394 {
395 glEnable(GL_LINE_STIPPLE);
396 }
397 else
398 {
399 glDisable(GL_LINE_STIPPLE);
400 }
401
402 glLineStipple(nFactor, ui16Pattern);
403 }
404
405 tVoid Color(const IColor* col) override
406 {
407 glColor4ub(col->GetRed(), col->GetGreen(), col->GetBlue(), col->GetAlpha());
408 }
409
410 tVoid Color(tInt nRed, tInt nGreen, tInt nBlue, tInt nAlpha = 255) override
411 {
412 glColor4ub((tUInt8) nRed, (tUInt8) nGreen, (tUInt8) nBlue, (tUInt8) nAlpha);
413 }
414
415 tVoid Color(tUInt8 nRed, tUInt8 nGreen, tUInt8 nBlue, tUInt8 nAlpha = 255) override
416 {
417 glColor4ub(nRed, nGreen, nBlue, nAlpha);
418 }
419
420 tVoid Color(tFloat64 fRed, tFloat64 fGreen, tFloat64 fBlue, tFloat64 fAlpha = 1.0) override
421 {
422 glColor4d(fRed, fGreen, fBlue, fAlpha);
423 }
424
425 tVoid BgColor(const IColor* col) override
426 {
427 BgColor(col->GetRed() / 255.0, col->GetGreen() / 255.0, col->GetBlue() / 255.0, col->GetAlpha() / 255.0);
428 }
429
430 tVoid BgColor(tInt nRed, tInt nGreen, tInt nBlue, tInt nAlpha = 255) override
431 {
432 BgColor(nRed / 255.0, nGreen / 255.0, nBlue / 255.0, nAlpha / 255.0);
433 }
434
435 tVoid BgColor(tUInt8 nRed, tUInt8 nGreen, tUInt8 nBlue, tUInt8 nAlpha = 255) override
436 {
437 BgColor(nRed / 255.0, nGreen / 255.0, nBlue / 255.0, nAlpha / 255.0);
438 }
439
440 tVoid BgColor(tFloat64 fRed, tFloat64 fGreen, tFloat64 fBlue, tFloat64 fAlpha = 0.0) override
441 {
442 glClearColor((GLclampf) fRed, (GLclampf) fGreen, (GLclampf) fBlue, (GLclampf) fAlpha);
443 }
444
445 tVoid Begin(tMode eMode) override
446 {
447 GLenum l_eGLMode = 0;
448
449 switch (eMode)
450 {
451 case MODE_DrawPoints:
452 {
453 l_eGLMode = GL_POINTS;
454 break;
455 }
456 case MODE_DrawLines:
457 {
458 l_eGLMode = GL_LINES;
459 break;
460 }
461 case MODE_DrawLineStrip:
462 {
463 l_eGLMode = GL_LINE_STRIP;
464 break;
465 }
466 case MODE_DrawLineLoop:
467 {
468 l_eGLMode = GL_LINE_LOOP;
469 break;
470 }
471 case MODE_DrawTriangles:
472 {
473 l_eGLMode = GL_TRIANGLES;
474 break;
475 }
476 case MODE_DrawTriangleStrip:
477 {
478 l_eGLMode = GL_TRIANGLE_STRIP;
479 break;
480 }
481 case MODE_DrawTriangleFan:
482 {
483 l_eGLMode = GL_TRIANGLE_FAN;
484 break;
485 }
486 case MODE_DrawQuads:
487 {
488 l_eGLMode = GL_QUADS;
489 break;
490 }
491 case MODE_DrawQuadStrip:
492 {
493 l_eGLMode = GL_QUAD_STRIP;
494 break;
495 }
496 case MODE_DrawPolygon:
497 {
498 l_eGLMode = GL_POLYGON;
499 break;
500 }
501 default:
502 {
503 return;
504 }
505 }
506
507 glBegin(l_eGLMode);
508 }
509
510 tVoid Coord(tInt x, tInt y) override
511 {
512 glVertex2i(x, y);
513 }
514
515 tVoid Coord(tFloat32 x, tFloat32 y) override
516 {
517 glVertex2f(x, y);
518 }
519
520 tVoid Coord(IPoint* pt) override
521 {
522 glVertex2i(pt->GetX(), pt->GetY());
523 }
524
525 tVoid Coord(IPoint** ppPoints, tInt nCount) override
526 {
527 for (tInt l_nIdx = 0; l_nIdx < nCount; l_nIdx++)
528 {
529 glVertex2i(ppPoints[l_nIdx]->GetX(), ppPoints[l_nIdx]->GetY());
530 }
531 }
532
533 tVoid CoordTexture(tFloat32 u, tFloat32 v) override
534 {
535 glTexCoord2f(u, v);
536 }
537
538 tVoid End() override
539 {
540 glEnd();
541 }
542
543public: // implements ICanvas
544 tInt GetWidth() const override
545 {
546 return m_nWidth;
547 }
548
549 tInt GetHeight() const override
550 {
551 return m_nHeight;
552 }
553
554 tInt GetBitsPerPixel() const override
555 {
556 return m_nBitsPerPixel;
557 }
558
559 tVoid SetMapping(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) override
560 {
561 m_f32MappingX1 = x1;
562 m_f32MappingY1 = y1;
563 m_f32MappingX2 = x2;
564 m_f32MappingY2 = y2;
565 m_f32MappingWidth = x2 - x1;
566 m_f32MappingHeight = y2 - y1;
567 m_bUseMapping = tTrue;
568
569 SwitchToScreenCoords();
570 }
571
572 tVoid ClearMapping() override
573 {
574 m_bUseMapping = tFalse;
575 SwitchToScreenCoords();
576 }
577
578 tInt MapPixelX(tFloat32 x) override
579 {
580 if (m_bUseMapping)
581 {
582 return (tInt) ((x - m_f32MappingX1) * (tFloat32) m_nWidth / m_f32MappingWidth);
583 }
584
585 return (tInt) x;
586 }
587
588 tInt MapPixelY(tFloat32 y) override
589 {
590 if (m_bUseMapping)
591 {
592 return (tInt) ((y - m_f32MappingY1) * (tFloat32) m_nHeight / m_f32MappingHeight);
593 }
594
595 return (tInt) y;
596 }
597
598 tInt MapPixelX(tInt x) override
599 {
600 if (m_bUseMapping)
601 {
602 return (tInt) (((tFloat32) x - m_f32MappingX1) * (tFloat32) m_nWidth / m_f32MappingWidth);
603 }
604
605 return (tInt) x;
606 }
607
608 tInt MapPixelY(tInt y) override
609 {
610 if (m_bUseMapping)
611 {
612 return (tInt) (((tFloat32) y - m_f32MappingY1) * (tFloat32) m_nHeight / m_f32MappingHeight);
613 }
614
615 return (tInt) y;
616 }
617
618 tFloat32 UnmapPixelX(tInt x) override
619 {
620 if (m_bUseMapping)
621 {
622 return m_f32MappingX1 + ((tFloat32) x * m_f32MappingWidth) / (tFloat32) m_nWidth;
623 }
624
625 return (tFloat32) x;
626 }
627
628 tFloat32 UnmapPixelY(tInt y) override
629 {
630 if (m_bUseMapping)
631 {
632 return m_f32MappingY1 + ((tFloat32) y * m_f32MappingHeight) / (tFloat32) m_nHeight;
633 }
634
635 return (tFloat32) y;
636 }
637
638 tVoid Clear() override
639 {
640 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
641 }
642
643 tResult CreateTexture(IImage* pImage, ITexture*& pTexture) override
644 {
645 RETURN_IF_POINTER_NULL(pImage);
646
647 if (pTexture != nullptr)
648 {
649 pTexture->Release();
650 pTexture = nullptr;
651 }
652
653 pTexture = CreateTexture(pImage->GetFormat(), ITexture::MODE_BilinearFiltered);
654 RETURN_IF_POINTER_NULL(pTexture);
655 pTexture->Copy(pImage);
656 RETURN_NOERROR;
657 }
658
659 tVoid DrawTexture(ITexture* pTexture, tFloat32 vPoints[8]) override
660 {
661 if (!pTexture)
662 {
663 return; // Nothing todo.
664 }
665 Color(255, 255, 255);
666
667 pTexture->MakeCurrent();
668
669 tFloat32 u = (tFloat32) pTexture->GetWidth() / pTexture->GetPhysicalWidth();
670 tFloat32 v = (tFloat32) pTexture->GetHeight() / pTexture->GetPhysicalHeight();
671
672 glBegin(GL_QUADS);
673 glTexCoord2d(u, v);
674 glVertex2f(vPoints[0], vPoints[1]);
675
676 glTexCoord2d(u, 0);
677 glVertex2f(vPoints[2], vPoints[3]);
678
679 glTexCoord2d(0, 0);
680 glVertex2f(vPoints[4], vPoints[5]);
681
682 glTexCoord2d(0, v);
683 glVertex2f(vPoints[6], vPoints[7]);
684 glEnd();
685
686 glDisable(GL_TEXTURE_2D);
687 glDisable(GL_BLEND);
688 }
689
690 tVoid DrawPixel(tInt x, tInt y) override
691 {
692 glBegin(GL_POINTS);
693 Coord(x, y);
694 glEnd();
695 }
696
697 tVoid DrawPixel(tFloat32 x, tFloat32 y) override
698 {
699 glBegin(GL_POINTS);
700 Coord(x, y);
701 glEnd();
702 }
703
704 tVoid DrawPixel(IPoint* pt) override
705 {
706 DrawPixel(pt->GetX(), pt->GetY());
707 }
708
709 tVoid DrawLine(tInt x1, tInt y1, tInt x2, tInt y2) override
710 {
711 glBegin(GL_LINES);
712 CoordLine(x1, y1, x2, y2);
713 glEnd();
714 }
715
716 tVoid DrawLine(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) override
717 {
718 glBegin(GL_LINES);
719 CoordLine(x1, y1, x2, y2);
720 glEnd();
721 }
722
723 tVoid DrawLine(IPoint* ptStart, IPoint* ptEnd) override
724 {
725 DrawLine(ptStart->GetX(), ptStart->GetY(), ptEnd->GetX(), ptEnd->GetY());
726 }
727
728 tVoid DrawRect(tInt x1, tInt y1, tInt x2, tInt y2) override
729 {
730 glBegin(GL_LINE_LOOP);
731 CoordRect(x1, y1, x2, y2);
732 glEnd();
733 }
734
735 tVoid DrawRect(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) override
736 {
737 glBegin(GL_LINE_LOOP);
738 CoordRect(x1, y1, x2, y2);
739 glEnd();
740 }
741
742 tVoid DrawRect(IRect* rect) override
743 {
744 DrawRect(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom());
745 }
746
747 tVoid DrawCircle(tInt x1, tInt y1, tInt x2, tInt y2) override
748 {
749 glBegin(GL_LINE_LOOP);
750 CoordCircle(x1, y1, x2, y2);
751 glEnd();
752 }
753
754 tVoid DrawCircle(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) override
755 {
756 glBegin(GL_LINE_LOOP);
757 CoordCircle(x1, y1, x2, y2);
758 glEnd();
759 }
760
761 tVoid DrawCircle(IRect* rect) override
762 {
763 glBegin(GL_LINE_LOOP);
764 CoordCircle(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom());
765 glEnd();
766 }
767
768 tVoid DrawCircleSegment(tInt x1,
769 tInt y1,
770 tInt x2,
771 tInt y2,
772 tFloat64 fDegreeStart,
773 tFloat64 fDegreeEnd,
774 tBool bNormalizeRect = tFalse) override
775 {
776 if (bNormalizeRect)
777 {
778 NormalizeRect(x1, y1, x2, y2);
779 }
780
781 glBegin(GL_LINE_LOOP);
782 Coord((x1 + x2) / 2, (y1 + y2) / 2);
783 CoordCircleSegment(x1, y1, x2, y2, fDegreeStart, fDegreeEnd);
784 glEnd();
785 }
786
787 tVoid DrawCircleSegment(tFloat32 x1,
788 tFloat32 y1,
789 tFloat32 x2,
790 tFloat32 y2,
791 tFloat64 fDegreeStart,
792 tFloat64 fDegreeEnd,
793 tBool bNormalizeRect = tFalse) override
794 {
795 if (bNormalizeRect)
796 {
797 NormalizeRect(x1, y1, x2, y2);
798 }
799
800 glBegin(GL_LINE_LOOP);
801 Coord((x1 + x2) / 2.0f, (y1 + y2) / 2.0f);
802 CoordCircleSegment(x1, y1, x2, y2, fDegreeStart, fDegreeEnd);
803 glEnd();
804 }
805
806 tVoid DrawCircleSegment(IRect* rect, tFloat64 fDegreeStart, tFloat64 fDegreeEnd) override
807 {
808 DrawCircleSegment(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom(), fDegreeStart,
809 fDegreeEnd);
810 }
811
812 tVoid DrawPolygon(IPoint** ppPoints, tInt nCount) override
813 {
814 glBegin(GL_LINE_LOOP);
815 Coord(ppPoints, nCount);
816 glEnd();
817 }
818
819 tVoid FillRect(tInt x1, tInt y1, tInt x2, tInt y2) override
820 {
821 glBegin(GL_QUADS);
822 glNormal3f(0.0, 0.0, -1.0f);
823 CoordRect(x1, y1, x2, y2);
824 glEnd();
825 }
826
827 tVoid FillRect(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) override
828 {
829 glBegin(GL_QUADS);
830 glNormal3f(0.0, 0.0, -1.0f);
831 CoordRect(x1, y1, x2, y2);
832 glEnd();
833 }
834
835 tVoid FillRect(IRect* rect) override
836 {
837 FillRect(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom());
838 }
839
840 tVoid FillCircle(tInt x1, tInt y1, tInt x2, tInt y2) override
841 {
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);
846 glEnd();
847 }
848
849 tVoid FillCircle(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) override
850 {
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);
855 glEnd();
856 }
857
858 tVoid FillCircle(IRect* rect) override
859 {
860 return FillCircle(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom());
861 }
862
863 tVoid FillCircleSegment(tInt x1,
864 tInt y1,
865 tInt x2,
866 tInt y2,
867 tFloat64 fDegreeStart,
868 tFloat64 fDegreeEnd,
869 tBool bNormalizeRect = tFalse) override
870 {
871 if (bNormalizeRect)
872 {
873 NormalizeRect(x1, y1, x2, y2);
874 }
875
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);
880 glEnd();
881 }
882
883 tVoid FillCircleSegment(tFloat32 x1,
884 tFloat32 y1,
885 tFloat32 x2,
886 tFloat32 y2,
887 tFloat64 fDegreeStart,
888 tFloat64 fDegreeEnd,
889 tBool bNormalizeRect = tFalse) override
890 {
891 if (bNormalizeRect)
892 {
893 NormalizeRect(x1, y1, x2, y2);
894 }
895
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);
900 glEnd();
901 }
902
903 tVoid FillCircleSegment(IRect* rect, tFloat64 fDegreeStart, tFloat64 fDegreeEnd) override
904 {
905 return FillCircleSegment(rect->GetLeft(), rect->GetTop(), rect->GetRight(), rect->GetBottom(), fDegreeStart,
906 fDegreeEnd);
907 }
908
909 tVoid FillPolygon(IPoint** ppPoints, tInt nCount) override
910 {
911 glBegin(GL_POLYGON);
912 glNormal3f(0.0, 0.0, -1.0f);
913 Coord(ppPoints, nCount);
914 glEnd();
915 }
916
917 IFont* CreateFont(const char* strName, tInt nHeight, IFont::tStyle eFontStyle = IFont::STYLE_Default)
918 {
919 cGLFont* l_pFont = new cGLFont();
920 if (l_pFont == NULL)
921 {
922 return NULL;
923 }
924
925 if (IS_FAILED(l_pFont->Create(this, strName, nHeight, eFontStyle)))
926 {
927 delete l_pFont;
928 return NULL;
929 }
930
931 return static_cast<IFont*>(l_pFont);
932 }
933
934 tVoid SetFontAngle(tFloat64 fAngle)
935 {
936 m_fFontAngle = fAngle;
937 }
938
939 tFloat64 GetFontAngle()
940 {
941 return m_fFontAngle;
942 }
943
944 tVoid Font(IFont* pFont)
945 {
946 m_pCurrentFont = pFont;
947 }
948
949 tVoid OutputText(tInt x, tInt y, const char* strFormat, ...)
950 {
951 if (m_pCurrentFont == NULL)
952 {
953 return;
954 }
955
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);
960
961 va_list ap;
962 va_start(ap, strFormat);
963
964 if (m_bUseMapping)
965 {
966 tInt x_mapped = MapPixelX(x);
967 tInt y_mapped = MapPixelY(y);
968
969 // m_bUseMapping = tFalse; // disable mapping to atVoid stretching the text
970 // SwitchToScreenCoords();
971
972 ClearMapping();
973
974 ((cGLFont*) m_pCurrentFont)->Print(x_mapped, y_mapped, m_fFontAngle, strFormat, ap);
975
976 SetMapping(m_f32MappingX1, m_f32MappingY1, m_f32MappingX2, m_f32MappingY2);
977 }
978 else
979 {
980 ((cGLFont*) m_pCurrentFont)->Print(x, y, m_fFontAngle, strFormat, ap);
981 }
982
983 va_end(ap);
984 }
985
986 tVoid OutputText(tFloat32 x, tFloat32 y, const char* strFormat, ...)
987 {
988 if (m_pCurrentFont == NULL)
989 {
990 return;
991 }
992
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);
997
998 va_list ap;
999 va_start(ap, strFormat);
1000
1001 if (m_bUseMapping)
1002 {
1003 tInt x_mapped = MapPixelX(x);
1004 tInt y_mapped = MapPixelY(y);
1005
1006 // m_bUseMapping = tFalse; // disable mapping to atVoid stretching the text
1007 // SwitchToScreenCoords();
1008 ClearMapping();
1009
1010 ((cGLFont*) m_pCurrentFont)->Print(x_mapped, y_mapped, m_fFontAngle, strFormat, ap);
1011
1012 /*m_bUseMapping = tTrue;
1013 SwitchToScreenCoords();*/
1014 SetMapping(m_f32MappingX1, m_f32MappingY1, m_f32MappingX2, m_f32MappingY2);
1015 }
1016 else
1017 {
1018 ((cGLFont*) m_pCurrentFont)->Print(x, y, m_fFontAngle, strFormat, ap);
1019 }
1020
1021 va_end(ap);
1022 }
1023
1024 ITexture* CreateTexture(const tBitmapFormat* psFormat, tInt nMode = 0) override
1025 {
1026 cGLTexture* l_pTexture = new cGLTexture();
1027 if (l_pTexture == NULL)
1028 {
1029 return NULL;
1030 }
1031
1032 if (IS_FAILED(l_pTexture->Create(psFormat, nMode)))
1033 {
1034 delete l_pTexture;
1035 return NULL;
1036 }
1037
1038 return static_cast<ITexture*>(l_pTexture);
1039 }
1040
1041 tVoid Texture(ITexture* pTexture) override
1042 {
1043 if (pTexture == NULL)
1044 {
1045 // just turn off texturing
1046 glDisable(GL_TEXTURE_2D);
1047 return;
1048 }
1049
1050 ((cGLTexture*) pTexture)->MakeCurrent();
1051 }
1052
1053 tVoid Blit(ITexture* pTexture, tInt x, tInt y, tInt nWidth, tInt nHeight) override
1054 {
1055 if (pTexture == NULL)
1056 {
1057 return;
1058 }
1059
1060 ((cGLTexture*) pTexture)->Blit(x, y, nWidth, nHeight);
1061 }
1062
1063 tVoid Blit(IImage* pImage, tInt x, tInt y, tInt nWidth, tInt nHeight) override
1064 {
1065 if (pImage == NULL)
1066 {
1067 return;
1068 }
1069
1070 tVoid* pBitmap = pImage->GetBitmap();
1071 if (pBitmap == NULL)
1072 {
1073 return;
1074 }
1075
1076 tBool bBGR = tFalse;
1077
1078 switch (pImage->GetPixelFormat())
1079 {
1080 case cImage::PF_RGB_888:
1081 case cImage::PF_RGBA_8888:
1082 {
1083 bBGR = tTrue;
1084 }
1085 break;
1086
1087 case cImage::PF_BGR_888:
1088 case cImage::PF_BGRA_8888:
1089 {
1090 bBGR = tFalse;
1091 }
1092 break;
1093
1094 default:
1095 {
1096 cImage oImage;
1097 tBitmapFormat sFormat = *(pImage->GetFormat());
1098 sFormat.nBytesPerLine = 0;
1099 sFormat.nSize = 0;
1100
1101 oImage.Create(sFormat.nWidth, sFormat.nHeight, sFormat.nBitsPerPixel, sFormat.nBytesPerLine,
1102 pImage->GetBitmap(), sFormat.nPixelFormat);
1103
1104 switch (pImage->GetBitsPerPixel())
1105 {
1106 case 32:
1107 {
1108 sFormat.nPixelFormat = cImage::PF_RGBA_8888;
1109 sFormat.nBitsPerPixel = 32;
1110 }
1111 break;
1112
1113 case 24:
1114 default:
1115 {
1116 sFormat.nPixelFormat = cImage::PF_RGB_888;
1117 sFormat.nBitsPerPixel = 24;
1118 }
1119 break;
1120 }
1121
1122 if (IS_FAILED(oImage.Convert(&sFormat)))
1123 {
1124 LOG_ERROR("Cannot convert image!");
1125 return;
1126 }
1127 Blit(&oImage, x, y, nWidth, nHeight);
1128 }
1129 return;
1130 }
1131
1132 GLenum l_nFormat = 0;
1133
1134 switch (pImage->GetBitsPerPixel())
1135 {
1136 case 32:
1137 {
1138 l_nFormat = (bBGR ? GL_BGRA_EXT : GL_RGBA);
1139 break;
1140 }
1141 case 24:
1142 {
1143 l_nFormat = (bBGR ? GL_BGR_EXT : GL_RGB);
1144 break;
1145 }
1146 case 8:
1147 {
1148 l_nFormat = GL_LUMINANCE;
1149 break;
1150 }
1151 default:
1152 {
1153 return;
1154 }
1155 }
1156
1157 glPixelStorei(GL_PACK_ROW_LENGTH, pImage->GetWidth());
1158 glPixelStorei(GL_PACK_ALIGNMENT, 4);
1159
1160 // check whether clipping is needed or not
1161 if ((x >= 0) && (y >= 0) && ((x + nWidth) <= GetWidth()) && ((y + nHeight) <= GetHeight()))
1162 {
1163 // completely inside => no clipping needed
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);
1168 }
1169 else
1170 {
1171 if ((x >= GetWidth()) || (y >= GetHeight()) || (x + nWidth < 0) || (y + nHeight < 0))
1172 {
1173 // src rect is completely outside => nothing to do
1174 return;
1175 }
1176 else
1177 {
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;
1182
1183 tInt xs = (x < 0) ? -x : 0;
1184 tInt ys = (y < 0) ? -y : 0;
1185
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++)
1189 {
1190 glRasterPos2i(x1, y1 + i);
1191 glDrawPixels(x2, 1, l_nFormat, GL_UNSIGNED_BYTE, pData);
1192 pData += pImage->GetBytesPerLine();
1193 }
1194 glPixelZoom(1.0, 1.0);
1195 // glDrawPixels(pImage->GetWidth()-1, pImage->GetHeight()-1, l_nFormat, GL_UNSIGNED_BYTE,
1196 // (tUInt8*)pBitmap + 3 + 64*3);
1197 }
1198 }
1199 }
1200
1201 tVoid Capture(IImage** ppImage, tInt x, tInt y, tInt nWidth, tInt nHeight) override
1202 {
1203 if (nWidth <= 0)
1204 {
1205 nWidth = m_nWidth;
1206 }
1207
1208 if (nHeight <= 0)
1209 {
1210 nHeight = m_nHeight;
1211 }
1212
1213 if (m_oCaptureBuffer.GetWidth() != nWidth || m_oCaptureBuffer.GetHeight() != nHeight)
1214 {
1215 m_oCaptureBuffer.Create(nWidth, nHeight, 32, 0, NULL, IImage::PF_RGBA_8888);
1216 }
1217
1218 glFlush();
1219 glFinish();
1220 glPixelStorei(GL_PACK_ROW_LENGTH, nWidth);
1221 glPixelStorei(GL_PACK_ALIGNMENT, 4);
1222 glReadBuffer(GL_BACK);
1223
1224 glReadPixels(x, y, nWidth, nHeight, GL_BGR, GL_UNSIGNED_BYTE, m_oCaptureBuffer.GetBitmap());
1225
1226 m_oCaptureBuffer.Flip();
1227
1228 *ppImage = (IImage*) &m_oCaptureBuffer;
1229 }
1230
1231 IScene* BeginScene() override
1232 {
1233 glDepthMask(GL_FALSE);
1234 glEnable(GL_DEPTH_TEST);
1235 glEnable(GL_CULL_FACE);
1236
1237 m_nMode = COORDS_LOGICAL;
1238
1239 return NULL;
1240 }
1241
1242 tVoid EndScene() override
1243 {
1244 SwitchToScreenCoords();
1245
1246 glDepthMask(GL_TRUE);
1247 glDisable(GL_DEPTH_TEST);
1248 glDisable(GL_CULL_FACE);
1249 glDisable(GL_LIGHTING);
1250
1251 m_nMode = COORDS_SCREEN;
1252 }
1253
1254 tVoid SetFlag(tUInt32 nFlag, tInt32 nValue)
1255 {
1256 switch (nFlag)
1257 {
1259 {
1260 m_oCurrentFlags.bTextOppsedYAxis = nValue != 0;
1261 }
1262 break;
1264 {
1265 m_oCurrentFlags.bTextScales = nValue != 0;
1266 }
1267 break;
1269 {
1270 m_oCurrentFlags.bTextRotate = nValue != 0;
1271 }
1272 break;
1274 {
1275 m_oCurrentFlags.bTextBaselineOnTop = nValue != 0;
1276 }
1277 break;
1278 default:
1279 {
1280 }
1281 }
1282 }
1283
1284 tInt32 GetFlag(tUInt32 nFlag)
1285 {
1286 switch (nFlag)
1287 {
1289 {
1290 return m_oCurrentFlags.bTextOppsedYAxis ? 1 : 0;
1291 }
1292 break;
1294 {
1295 return m_oCurrentFlags.bTextScales ? 1 : 0;
1296 }
1297 break;
1299 {
1300 return m_oCurrentFlags.bTextRotate ? 1 : 0;
1301 }
1302 break;
1304 {
1305 return m_oCurrentFlags.bTextBaselineOnTop ? 1 : 0;
1306 }
1307 break;
1308 default:
1309 {
1310 }
1311 }
1312 return 0;
1313 }
1314
1315 tResult PushFlags()
1316 {
1317 if (m_oFlags.size() > 20)
1318 {
1319 RETURN_ERROR(ERR_OUT_OF_RANGE);
1320 }
1321
1322 m_oFlags.push(m_oCurrentFlags);
1323
1324 RETURN_NOERROR;
1325 };
1326
1327 tResult PopFlags()
1328 {
1329 if (m_oFlags.size() == 0)
1330 {
1331 RETURN_ERROR(ERR_OUT_OF_RANGE);
1332 }
1333
1334 m_oCurrentFlags = m_oFlags.top();
1335 m_oFlags.pop();
1336
1337 RETURN_NOERROR;
1338 };
1339
1340 tVoid ResetFlags()
1341 {
1342 m_oCurrentFlags.bTextRotate = tFalse;
1343 m_oCurrentFlags.bTextOppsedYAxis = tTrue;
1344 m_oCurrentFlags.bTextScales = tFalse;
1345 m_oCurrentFlags.bTextBaselineOnTop = tFalse;
1346 };
1347
1348 tVoid DrawEllipse(tInt iOriginX, tInt iOriginY, tInt iWidth, tInt iHeight, tInt iAngle)
1349 {
1350 DrawEllipse((tFloat32) iOriginX, (tFloat32) iOriginY, (tFloat32) iWidth, (tFloat32) iHeight, (tFloat32) iAngle);
1351 }
1352
1353 tVoid
1354 DrawEllipse(tFloat32 f32OriginX, tFloat32 f32OriginY, tFloat32 f32Width, tFloat32 f32Height, tFloat32 f32Angle)
1355 {
1356 tFloat32 x1 = -f32Width / 2;
1357 tFloat32 x2 = f32Width / 2;
1358 tFloat32 y1 = -f32Height / 2;
1359 tFloat32 y2 = f32Height / 2;
1360
1361 glPushMatrix();
1362
1363 glTranslatef(f32OriginX, f32OriginY, 0.0f);
1364 glRotatef(-f32Angle, 0.0f, 0.0f, 1.0f);
1365
1366 DrawCircle(x1, y1, x2, y2);
1367
1368 glPopMatrix();
1369 }
1370
1371 tVoid FillEllipse(tInt iOriginX, tInt iOriginY, tInt iWidth, tInt iHeight, tInt iAngle)
1372 {
1373 FillEllipse((tFloat32) iOriginX, (tFloat32) iOriginY, (tFloat32) iWidth, (tFloat32) iHeight, (tFloat32) iAngle);
1374 }
1375
1376 tVoid
1377 FillEllipse(tFloat32 f32OriginX, tFloat32 f32OriginY, tFloat32 f32Width, tFloat32 f32Height, tFloat32 f32Angle)
1378 {
1379 tFloat32 x1 = -f32Width / 2;
1380 tFloat32 x2 = f32Width / 2;
1381 tFloat32 y1 = -f32Height / 2;
1382 tFloat32 y2 = f32Height / 2;
1383
1384 glPushMatrix();
1385
1386 glTranslatef(f32OriginX, f32OriginY, 0.0f);
1387 glRotatef(-f32Angle, 0.0f, 0.0f, 1.0f);
1388
1389 FillCircle(x1, y1, x2, y2);
1390
1391 glPopMatrix();
1392 }
1393
1394 tVoid PushMatrix()
1395 {
1396 glPushMatrix();
1397 }
1398
1399 tVoid PopMatrix()
1400 {
1401 glPopMatrix();
1402 }
1403
1404 tVoid Translate(tFloat fx, tFloat fy, tFloat fz)
1405 {
1406 glTranslated(fx, fy, fz);
1407 }
1408
1409 tVoid Scale(tFloat fx, tFloat fy, tFloat fz)
1410 {
1411 glScaled(fx, fy, fz);
1412 }
1413
1414 tVoid Rotate(tFloat fangle, tFloat fx, tFloat fy, tFloat fz)
1415 {
1416 glRotated(fangle, fx, fy, fz);
1417 }
1418
1419protected:
1427 tVoid CoordLine(tInt x1, tInt y1, tInt x2, tInt y2) const
1428 {
1429 glVertex2i(x1, y1);
1430 glVertex2i(x2, y2);
1431 }
1432
1440 tVoid CoordRect(tInt x1, tInt y1, tInt x2, tInt y2) const
1441 {
1442 glVertex2i(x1, y1);
1443 glVertex2i(x2, y1);
1444 glVertex2i(x2, y2);
1445 glVertex2i(x1, y2);
1446 }
1447
1455 tVoid CoordCircle(tInt x1, tInt y1, tInt x2, tInt y2) const
1456 {
1457 CoordCircle((tFloat32) x1, (tFloat32) y1, (tFloat32) x2, (tFloat32) y2);
1458 }
1459
1469 tVoid CoordCircleSegment(tInt x1, tInt y1, tInt x2, tInt y2, tFloat64 fDegreeStart, tFloat64 fDegreeEnd) const
1470 {
1471 CoordCircleSegment((tFloat32) x1, (tFloat32) y1, (tFloat32) x2, (tFloat32) y2, fDegreeStart, fDegreeEnd);
1472 }
1473
1481 tVoid CoordLine(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) const
1482 {
1483 glVertex2f(x1, y1);
1484 glVertex2f(x2, y2);
1485 }
1486
1494 tVoid CoordRect(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) const
1495 {
1496 glVertex2f(x1, y1);
1497 glVertex2f(x2, y1);
1498 glVertex2f(x2, y2);
1499 glVertex2f(x1, y2);
1500 }
1501
1509 tVoid CoordCircle(tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2) const
1510 {
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;
1515
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);
1519 if (l_nStep < 1)
1520 {
1521 l_nStep = 1;
1522 }
1523
1524 const tFloat64 fDeg2Rad = PI / 180.0;
1525
1526 for (tInt w = 0; w < 360 + l_nStep; w += l_nStep)
1527 {
1528 glVertex2f(nCenterX + (tFloat32) (fRadX * sin(w * fDeg2Rad)),
1529 nCenterY + (tFloat32) (fRadY * cos(w * fDeg2Rad)));
1530 }
1531 }
1532
1542 tVoid CoordCircleSegment(
1543 tFloat32 x1, tFloat32 y1, tFloat32 x2, tFloat32 y2, tFloat64 fDegreeStart, tFloat64 fDegreeEnd) const
1544 {
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;
1549
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);
1553 if (l_nStep < 1)
1554 {
1555 l_nStep = 1;
1556 }
1557
1558 tInt nDegreeStart = (tInt) (fDegreeStart + 0.9999) % 360;
1559 tInt nDegreeEnd = (tInt) (fDegreeEnd);
1560 if (nDegreeEnd < nDegreeStart)
1561 {
1562 nDegreeEnd = nDegreeStart + 360;
1563 }
1564
1565 const tFloat64 fDeg2Rad = PI / 180.0;
1566
1567 glVertex2f(GLfloat(fCenterX + (tFloat32) (fRadX * sin(fDegreeStart * fDeg2Rad))),
1568 GLfloat(fCenterY + (tFloat32) (fRadY * cos(fDegreeStart * fDeg2Rad))));
1569
1570 for (tInt w = nDegreeStart; w < nDegreeEnd; w += l_nStep)
1571 {
1572 glVertex2f(GLfloat(fCenterX + static_cast<tFloat32>(fRadX * sin(w * fDeg2Rad))),
1573 GLfloat(fCenterY + static_cast<tFloat32>(fRadY * cos(w * fDeg2Rad))));
1574 }
1575
1576 glVertex2f(GLfloat(fCenterX + (tFloat32) (fRadX * sin(fDegreeEnd * fDeg2Rad))),
1577 GLfloat(fCenterY + (tFloat32) (fRadY * cos(fDegreeEnd * fDeg2Rad))));
1578 }
1579
1583 tVoid SwitchToScreenCoords()
1584 {
1585 glMatrixMode(GL_PROJECTION);
1586 glLoadIdentity();
1587
1588 GLdouble const zNear = -1.0;
1589 GLdouble const zFar = 1.0;
1590
1591 if (m_bUseMapping)
1592 {
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);
1598 }
1599 else
1600 {
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);
1606 }
1607
1608 glMatrixMode(GL_MODELVIEW);
1609 glLoadIdentity();
1610 }
1611};
1612
1613} // namespace dengar
1614
1615using dengar::cGLCanvas;
1616
1617} // namespace graphicslib
1618
1619} // namespace disptb
1620
1621} // namespace adtf
1622
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.
Main namespace.
Copyright © Audi Electronics Venture GmbH.
tInt32 nWidth
Specifies the width (in pixels) of the image.
tInt16 nBitsPerPixel
Specifies the number of bits used to represent the color of a single pixel.
tInt32 nSize
Size of bitmap in bytes (nBytesPerLine * nHeight)
tInt32 nHeight
Specifies the width (in pixels) of the image.
tInt16 nPixelFormat
Pixel format specified in tPixelFormat. More information ca be found at.
tInt32 nBytesPerLine
Specifies the number of bytes used per line (nWidth * nBitsPerPixel / 8 + n PaddingBytes) normally th...