1 #include "GLvideo_osd.h"
2 #include "GLvideo_params.h"
8 GLvideo_osd::~GLvideo_osd()
14 void GLvideo_osd::render(VideoData
*videoData
, GLvideo_params
¶ms
)
16 if (!params
.osd_valid
) {
18 printf("Changing font\n");
21 font
= new FTGLPolygonFont(params
.font_file
.toLatin1().constData());
24 font
->CharMap(ft_encoding_unicode
);
31 params
.osd_valid
= true;
36 if(params
.osd_bot
!= OSD_NONE
)
37 renderOSD(videoData
, params
);
40 renderStats(videoData
);
44 void GLvideo_osd::renderOSD(VideoData
*videoData
, GLvideo_params
¶ms
)
46 //bounding box of text
47 float cx1
, cy1
, cz1
, cx2
, cy2
, cz2
;
51 switch (params
.osd_bot
) {
53 sprintf(str
, "%06ld", videoData
->frameNum
);
54 font
->BBox("000000", cx1
, cy1
, cz1
, cx2
, cy2
, cz2
);
58 sprintf(str
, "%s", params
.caption
.toLatin1().constData());
59 font
->BBox(str
, cx1
, cy1
, cz1
, cx2
, cy2
, cz2
);
66 //text box location, defaults to bottom left
67 float tx
=0.05 * videoData
->Ywidth
;
68 float ty
=0.05 * videoData
->Yheight
;
70 if (params
.osd_bot
==OSD_CAPTION
) {
71 //put the caption in the middle of the screen
72 tx
= videoData
->Ywidth
- ((cx2
- cx1
) * params
.osd_scale
);
76 //black box that text is rendered onto, larger than the text by 'border'
78 float bx1
, by1
, bx2
, by2
;
86 glTranslated(tx
, ty
, 0);
87 glScalef(params
.osd_scale
, params
.osd_scale
, 0); //scale the on screen display
89 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
91 glColor4f(0.0, 0.0, 0.0, params
.osd_back_alpha
);
101 glColor4f(1.0, 1.0, 1.0, params
.osd_text_alpha
);
102 glEnable(GL_POLYGON_SMOOTH
);
105 glDisable(GL_POLYGON_SMOOTH
);
110 void GLvideo_osd::drawText(const char *str
)
117 void GLvideo_osd::draw2Text(const char *str1
, const char *str2
, float h_spacing
)
125 glTranslatef(h_spacing
, 0, 0);
134 void GLvideo_osd::drawPerfTimer(const char *str
, int num
, const char *units
, float h_spacing
)
137 sprintf(str2
, "%d%s", num
, units
);
138 draw2Text(str
, str2
, h_spacing
);
141 void GLvideo_osd::renderStats(VideoData
*videoData
)
143 //position of the stats relative to the video
144 float tx
= 0.05 * videoData
->Ywidth
;
145 float ty
= 0.95 * videoData
->Yheight
;
147 //determine approx character size
148 float cx1
, cy1
, cz1
, cx2
, cy2
, cz2
;
150 font
->BBox("0", cx1
, cy1
, cz1
, cx2
, cy2
, cz2
);
151 float spacing
= (cy2
-cy1
) * 1.5;
152 float width
= cx2
- cx1
;
153 float gap
= width
* 17;
155 //black box that text is rendered onto, larger than the text by 'border'
157 float bx1
, by1
, bx2
, by2
;
158 static int n_lines
; //remember how many lines of stats there were last time
162 by2
= (spacing
* n_lines
* -1) - border
*2;
165 glTranslated(tx
, ty
, 0); //near the top left corner
166 glScalef(0.25, 0.25, 0); //reduced in size compared to OSD
169 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
171 glEnable(GL_POLYGON_SMOOTH
);
172 glColor4f(0.0, 0.0, 0.0, 0.7);
175 glVertex2f(bx1
, by1
);
176 glVertex2f(bx1
, by2
);
177 glVertex2f(bx2
, by2
);
178 glVertex2f(bx2
, by1
);
181 //render the stats text
182 Stats
&s
= Stats::getInstance();
183 Stats::section_t::const_iterator it
= s
.get_section_begin();
185 while(it
!= s
.get_section_end())
187 glColor4f(0.0, 1.0, 0.0, 0.5);
188 drawText((*it
).first
.c_str());
189 glTranslated(0, -spacing
, 0);
190 glColor4f(1.0, 1.0, 1.0, 0.5);
193 Stats::inner_t::const_iterator it2
= (*it
).second
->begin();
195 while(it2
!= (*it
).second
->end()) {
197 draw2Text((*it2
).first
.c_str(), (*it2
).second
.c_str(), gap
);
198 glTranslated(0, -spacing
, 0);
207 glDisable(GL_POLYGON_SMOOTH
);