[mmap] partial revert of 8cef8db4 to disable using mmap file reader
[videoplayer.git] / GLvideo_osd.cpp
blob1843e834c6fb87e9accd4653f0640618c36e36b4
1 #include "GLvideo_osd.h"
2 #include "GLvideo_params.h"
3 #include "videoData.h"
4 #include "stats.h"
6 #define DEBUG 0
8 GLvideo_osd::~GLvideo_osd()
10 if(font)
11 delete font;
14 void GLvideo_osd::render(VideoData *videoData, GLvideo_params &params)
16 if (!params.osd_valid) {
17 if (DEBUG)
18 printf("Changing font\n");
19 if (font)
20 delete font;
21 font = new FTGLPolygonFont(params.font_file.toLatin1().constData());
22 if (!font->Error()) {
23 font->FaceSize(72);
24 font->CharMap(ft_encoding_unicode);
26 else {
27 delete font;
28 font = NULL;
31 params.osd_valid = true;
34 if(font) {
36 if(params.osd_bot != OSD_NONE)
37 renderOSD(videoData, params);
39 if(params.osd_perf)
40 renderStats(videoData);
44 void GLvideo_osd::renderOSD(VideoData *videoData, GLvideo_params &params)
46 //bounding box of text
47 float cx1, cy1, cz1, cx2, cy2, cz2;
49 //text string
50 char str[255];
51 switch (params.osd_bot) {
52 case OSD_FRAMENUM:
53 sprintf(str, "%06ld", videoData->frameNum);
54 font->BBox("000000", cx1, cy1, cz1, cx2, cy2, cz2);
55 break;
57 case OSD_CAPTION:
58 sprintf(str, "%s", params.caption.toLatin1().constData());
59 font->BBox(str, cx1, cy1, cz1, cx2, cy2, cz2);
60 break;
62 default:
63 str[0] = '\0';
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);
73 tx/=2;
76 //black box that text is rendered onto, larger than the text by 'border'
77 float border = 10;
78 float bx1, by1, bx2, by2;
79 bx1 = cx1 - border;
80 by1 = cy1 - border;
81 bx2 = cx2 + border;
82 by2 = cy2 + border;
84 //box beind text
85 glPushMatrix();
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);
90 glEnable(GL_BLEND);
91 glColor4f(0.0, 0.0, 0.0, params.osd_back_alpha);
93 glBegin(GL_QUADS);
94 glVertex2f(bx1, by1);
95 glVertex2f(bx1, by2);
96 glVertex2f(bx2, by2);
97 glVertex2f(bx2, by1);
98 glEnd();
100 //text
101 glColor4f(1.0, 1.0, 1.0, params.osd_text_alpha);
102 glEnable(GL_POLYGON_SMOOTH);
103 glEnable(GL_BLEND);
104 font->Render(str);
105 glDisable(GL_POLYGON_SMOOTH);
106 glDisable(GL_BLEND);
107 glPopMatrix();
110 void GLvideo_osd::drawText(const char *str)
112 glPushMatrix();
113 font->Render(str);
114 glPopMatrix();
117 void GLvideo_osd::draw2Text(const char *str1, const char *str2, float h_spacing)
119 glPushMatrix();
121 glPushMatrix();
122 font->Render(str1);
123 glPopMatrix();
125 glTranslatef(h_spacing, 0, 0);
127 glPushMatrix();
128 font->Render(str2);
129 glPopMatrix();
131 glPopMatrix();
134 void GLvideo_osd::drawPerfTimer(const char *str, int num, const char *units, float h_spacing)
136 char str2[255];
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'
156 float border = 10;
157 float bx1, by1, bx2, by2;
158 static int n_lines; //remember how many lines of stats there were last time
159 bx1 = -border;
160 by1 = spacing;
161 bx2 = width * 25;
162 by2 = (spacing * n_lines * -1) - border*2;
164 glPushMatrix();
165 glTranslated(tx, ty, 0); //near the top left corner
166 glScalef(0.25, 0.25, 0); //reduced in size compared to OSD
168 //box beind text
169 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
170 glEnable(GL_BLEND);
171 glEnable(GL_POLYGON_SMOOTH);
172 glColor4f(0.0, 0.0, 0.0, 0.7);
174 glBegin(GL_QUADS);
175 glVertex2f(bx1, by1);
176 glVertex2f(bx1, by2);
177 glVertex2f(bx2, by2);
178 glVertex2f(bx2, by1);
179 glEnd();
181 //render the stats text
182 Stats &s = Stats::getInstance();
183 Stats::section_t::const_iterator it = s.get_section_begin();
184 n_lines = 0;
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);
191 n_lines++;
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);
199 n_lines++;
200 it2++;
203 it++;
206 glDisable(GL_BLEND);
207 glDisable(GL_POLYGON_SMOOTH);
208 glPopMatrix();