render_stats_opengl.cpp 5.21 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1 2 3 4 5 6 7 8
/*
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
9
**
Mathieu Faverge's avatar
Mathieu Faverge committed
10 11 12 13 14
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
15
**
Mathieu Faverge's avatar
Mathieu Faverge committed
16 17 18 19 20 21 22 23 24 25
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
26
**
Mathieu Faverge's avatar
Mathieu Faverge committed
27 28 29 30
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
31
** ViTE developers are (for version 0.* to 1.0):
Mathieu Faverge's avatar
Mathieu Faverge committed
32 33 34 35 36 37 38 39
**
**        - COULOMB Kevin
**        - FAVERGE Mathieu
**        - JAZEIX Johnny
**        - LAGRASSE Olivier
**        - MARCOUEILLE Jule
**        - NOISETTE Pascal
**        - REDONDY Arthur
40
**        - VUCHENER Clément
Mathieu Faverge's avatar
Mathieu Faverge committed
41 42
**
*/
43
/*!
44
 *\file render_stats_opengl.cpp
45
 */
46

47
#ifdef _WIN32
48
        #include <Windows.h>
49 50
#endif

51 52
#include <cstdio>
#include <string>
53
/* -- */
54 55
#include <GL/glu.h>
/* -- */
56
#include "common/common.hpp"
57
#include "common/Info.hpp"
58 59
/* -- */
#include "interface/resource.hpp"
60
#include "interface/Interface.hpp"
61 62 63 64
#include "core/Core.hpp"
/* -- */
#include "render/render_stats_opengl.hpp"
/* -- */
65 66
using namespace std;

67
Render_stats_opengl::Render_stats_opengl(QWidget *parent) : QGLWidget(parent), _stats_beginned_drawed(false) {
68 69
    _translated_y  = 0.;
    _translated_x  = 0.;
70
    _render_height = height();
71
    _render_width  = width();
72 73
    _rect_list = glGenLists(1);

74 75 76
}

Render_stats_opengl::~Render_stats_opengl(){
77 78
    _text_pos.clear();
    _text_value.clear();
79
    glDeleteLists(_rect_list, 1);
80 81 82 83 84 85 86 87 88
}

void Render_stats_opengl::initializeGL(){
    glEnable(GL_DEPTH_TEST);
}


void Render_stats_opengl::resizeGL(int width, int height){
    glViewport(0, 0, width, height);
89

90 91 92 93 94 95 96 97 98 99 100 101
    /* update informations about widget size */
    _screen_width = width;
    _screen_height = height;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glMatrixMode(GL_MODELVIEW);

}

void Render_stats_opengl::paintGL(){
102

103
    makeCurrent();
104 105 106
    glClearDepth(1.0);
    glClearColor(1.f, 1.f, 1.f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
107

108
    glLoadIdentity();
109

110 111 112
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0, _screen_width, 0, _screen_height);

113
    glTranslated(-_translated_x, _translated_y, 0);
114

115 116 117 118 119

    if(!_stats_beginned_drawed) {
        return;
    }

120 121
    list<Element_pos>::const_iterator it_pos;
    list<string>::const_iterator it_txt;
122 123
    Element_pos buf_x;
    Element_pos buf_y;
124
    string buf_txt;
125

126 127 128 129
    if (glIsList(_rect_list) == GL_FALSE)
        printf("ERROR LIST not exist for stats\n");
    else
        glCallList(_rect_list);
130

Olivier Lagrasse's avatar
Olivier Lagrasse committed
131
    glFlush();
132

133 134 135 136 137 138
    /* Check the errors */
    GLenum glerror;
    glerror = glGetError();
    if(glerror != GL_NO_ERROR) {
        fprintf(stderr, "Render stats openGL : the following OpengGL error occured: %s\n", gluErrorString(glerror));
    }
139

140 141
    const QFont &arial_font = QFont("Arial", 10);
    qglColor(QColor(0, 0, 0)); // We put the text in black
142
    for (it_txt=_text_value.begin(), it_pos=_text_pos.begin() ; it_txt!=_text_value.end() ; it_txt ++, it_pos ++) {
143

144
        buf_x = *it_pos - _translated_x;
145
        it_pos ++;
146

147
        buf_y =  *it_pos - _translated_y + height() - _size_for_one_container;
148 149 150

        buf_txt = *it_txt;

151 152
        //painter.drawText(buf_x, buf_y, buf_txt.c_str());
        renderText(buf_x, buf_y, buf_txt.c_str(), arial_font);
Olivier Lagrasse's avatar
Olivier Lagrasse committed
153
    }
154

155
//     painter.end();
156 157
}

158
void Render_stats_opengl::translate_y(int value) {
159 160 161 162 163 164
    if(value == 0) {
        _translated_y = 0;
    }
    else {
        _translated_y = (double)(value+1)/100.0*_render_height;
    }
165 166 167 168
    updateGL();
}

void Render_stats_opengl::translate_x(int value) {
169 170 171 172 173 174
    if(value == 0) {
        _translated_x = 0;
    }
    else {
        _translated_x = (double)(value+1)/100.0*_render_width;
    }
175 176 177
    //cout << "w :" << _render_width << endl;
    updateGL();
}
178 179 180 181

void Render_stats_opengl::set_total_height(Element_pos h) {
    _render_height = h;
}
182

183 184 185
void Render_stats_opengl::set_height_for_one_container(Element_pos h) {
    _size_for_one_container = h;
}
186

187 188 189 190 191 192 193 194 195 196
void Render_stats_opengl::set_total_width(Element_pos w) {
    _render_width = w;
}

void Render_stats_opengl::clear(){
    makeCurrent();
    _translated_y = 0;
    _translated_x = 0;
    _text_pos.clear();
    _text_value.clear();
197
}