Ejemplo n.º 1
0
void Buttons::draw() {
    if(!is_visible) {
        return;
    }

    // update projection matrix when viewport size changes.
    GLint vp[4];
    glGetIntegerv(GL_VIEWPORT, vp);
    if(vp[2] != win_w || vp[3] != win_h) {
        win_w = vp[2];
        win_h = vp[3];
        createOrtho(win_w, win_h);
    }

    // we draw in 2D so no depth test and cull fase.
    bool cull_enabled = false;
    if(glIsEnabled(GL_CULL_FACE)) {
        glDisable(GL_CULL_FACE);
        cull_enabled = true;
    }

    bool depth_enabled = false;
    if(glIsEnabled(GL_DEPTH_TEST)) {
        glDisable(GL_DEPTH_TEST);
        depth_enabled = true;
    }

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    gui_shader.enable();
    glBindVertexArray(vao);
    //vao.bind();

    gui_shader.uniformMat4fv("projection_matrix", &ortho[0]);

    for(int i = 0; i < vd.draw_arrays.size(); ++i) {
        ButtonDrawArray& bda = vd.draw_arrays[i];
        glDrawArrays(bda.mode, bda.start, bda.count);
    }
    //    glBindVertexArray(0); // @todo we might remove this

    static_text->draw();
    dynamic_text->draw();

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindTexture(GL_TEXTURE_2D, 0);
    //    glBindVertexArray(0);
    glUseProgram(0);

    // Allow custom drawing.
    if(cull_enabled) {
        glEnable(GL_CULL_FACE);
    }

    if(depth_enabled) {
        glEnable(GL_DEPTH_TEST);
    }

}
Ejemplo n.º 2
0
void Font::draw() {
    // Create projection matrix
    GLint vp[4];
    glGetIntegerv(GL_VIEWPORT, vp);
    if(vp[2] != win_w || vp[3] != win_h) {
        win_w = vp[2];
        win_h = vp[3];
        createOrtho(win_w, win_h);
    }

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glBindVertexArray(vao);
    //vao.bind();
    shader.enable();

    shader.uniformMat4fv("u_projection_matrix", pm);

    // set texture
    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D, tex);
    shader.uniform1i("u_font_texture", 3);

    // draw
    //glPointSize(5.0f);
    size_t dx = 0;
    for(std::vector<FontEntry>::iterator it = entries.begin(); it != entries.end(); ++it) {
        FontEntry& e = *it;
        mm[12] = e.pos[0];
        mm[13] = e.pos[1];
        mm[14] = -0.5f;
        shader.uniformMat4fv("u_model_matrix", mm);
        glDrawArrays(GL_TRIANGLES, dx, vertices.size()); // e.num_vertices);
        dx += e.num_vertices;
    }
    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D, 0);
    // vao.unbind();
}
Ejemplo n.º 3
0
Buttons::Buttons(const string& title, int w)
    :is_mouse_down(false)
    ,first_run(true)
    ,x(0)
    ,y(0)
    ,w(w)
    ,h(0)
    ,win_w(0)
    ,win_h(0)
    ,header_h(20) // header height (draggable area)
    ,border(1)
    ,state(BSTATE_NONE)
    ,is_changed(false)
    ,is_mouse_inside_header(false)
    ,is_mouse_inside_panel(false)
    ,triggered_drag(false)
    ,mdx(0)
    ,mdy(0)
    ,pmx(0)
    ,pmy(0)
    ,title(title)
    ,title_dx(0)
    ,num_panel_vertices(0)
    ,is_locked(false)
    ,static_text(NULL)
    ,dynamic_text(NULL)
    ,allocated_bytes(0)
    ,is_open(true)
    ,is_visible(true)
    ,name(title)
    ,col_hue(0.0f)
    ,col_sat(0.0f)
    ,col_bright(0.0f)
    ,col_alpha(0.0f)
    ,vao(0)
{

    if(!shaders_initialized) {
        bmf = new BitmapFont();

        gui_shader.create(BUTTONS_VS, BUTTONS_FS);
        glBindAttribLocation(gui_shader.prog_id, 0, "pos");
        glBindAttribLocation(gui_shader.prog_id, 1, "col");
        gui_shader.link();

        gui_shader.enable();
        gui_shader.addUniform("projection_matrix");
        gui_shader.addAttribute("pos");
        gui_shader.addAttribute("col");
        shaders_initialized = true;
    }

    static_text = new Text(*bmf);
    dynamic_text = new Text(*bmf);
    glBindVertexArray(vao);
    glGenBuffers(1, &vbo);
    eglGetError();

    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    eglGetError();
    glEnableVertexAttribArray(0);
    eglGetError();
    glEnableVertexAttribArray(1);
    eglGetError();
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(ButtonVertex), (GLvoid*)0);
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(ButtonVertex), (GLvoid*)8);
    glBindVertexArray(0);

    createOrtho(768, 1024);

    // top draggable handle
    BSET_COLOR(header_color_top, 0.07,0.07,0.07,1.0);
    BSET_COLOR(header_color_bottom, 0.1,0.1,0.1,0.8);
    BSET_COLOR(shadow_color, 0.1, 0.1, 0.1, 0.1);

    title_dx = static_text->add(x+5, y+2, title);
    name = createCleanName(title);

    ++num_created;
    id = num_created;
}
Ejemplo n.º 4
0
void Buttons::onResize(int nw, int nh) {
    createOrtho(nw,nh);
}