Пример #1
0
static int graphicsrender_drawCropped_GL(
        struct graphicstexture *gt, int x, int y, float alpha,
        unsigned int sourcex, unsigned int sourcey,
        unsigned int sourcewidth, unsigned int sourceheight,
        unsigned int drawwidth, unsigned int drawheight,
        int rotationcenterx, int rotationcentery, double rotationangle,
        int horiflipped,
        double red, double green, double blue, int textureFiltering) {
    // source UV coords:
    assert(gt->width >= 0);
    assert(gt->height >= 0);
    double sx = ((double)sourcex) / (double)gt->width;
    double sy = ((double)sourcey) / (double)gt->height;
    double sw = ((double)sourcewidth) / (double)gt->width;
    double sh = ((double)sourceheight) / (double)gt->height;
    assert(sw >= 0);
    assert(sh >= 0);

    GLenum err;
    if ((err = glGetError()) != GL_NO_ERROR) {
        printwarning("graphicsrender_drawCropped_GL: "
            "lingering error before render: %s",
            glGetErrorString(err));
    }

    glEnable(GL_TEXTURE_2D);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 
    glPushMatrix();
    // apply sprite rotation:
    glTranslatef((x + drawwidth * 0.5), (y + drawheight * 0.5), 0);
    glRotated(rotationangle, 0, 0, 1);
    glTranslatef(-(x + drawwidth * 0.5), -(y + drawheight * 0.5),
        -(0));
    // draw sprite:
    if (graphicstexture_bindGl(gt, renderts)) {
        glBegin(GL_QUADS);

        glTexCoord2f(sx, sy + sh); 
        glVertex2d(x, y + drawheight);
        glTexCoord2f(sx + sw, sy + sh);
        glVertex2d(x + drawwidth, y + drawheight);
        glTexCoord2f(sx + sw, sy);
        glVertex2d(x + drawwidth, y);
        glTexCoord2f(sx, sy);
        glVertex2d(x, y);

        glEnd();
    }
    glPopMatrix();
    glDisable(GL_BLEND);
    if ((err = glGetError()) != GL_NO_ERROR) {
        printwarning("graphicsrender_drawCropped_GL: "
            "error after render: %s",
            glGetErrorString(err));
    }
    return 1;
}
Пример #2
0
static int graphicsrender_drawCropped_GL(
        struct graphicstexture *gt, int x, int y, float alpha,
        unsigned int sourcex, unsigned int sourcey,
        unsigned int sourcewidth, unsigned int sourceheight,
        unsigned int drawwidth, unsigned int drawheight,
        int rotationcenterx, int rotationcentery, double rotationangle,
        int horiflipped,
        double red, double green, double blue, int textureFiltering) {
    // source UV coords:
    double sx = sourcex / (double)gt->width;
    double sy = sourcey / (double)gt->height;
    double sw = sourcewidth / (double)gt->width;
    double sh = sourceheight / (double)gt->height;

    glEnable(GL_TEXTURE_2D);
    glPushMatrix();
    glRotated((rotationangle / M_PI) * 180, x + drawwidth / 2,
        0, y + drawwidth / 2);
    glActiveTexture(GL_TEXTURE0);
    if (graphicstexture_bindGl(gt, renderts)) {
        glBegin(GL_QUADS);
        glVertex2d(x, y);
        glVertex2d(x, y + drawheight);
        glVertex2d(x + drawwidth, y + drawheight);
        glVertex2d(x + drawwidth, y);       
        glEnd();
    }
    glPopMatrix();
    GLenum err;
    if ((err = glGetError()) != GL_NO_ERROR) {
        printwarning("graphicsrender_drawCropped_GL: "
            "error after render: %s",
            gluErrorString(err));
    }
    return 1;
}