src/render/opengl/SDL_render_gl.c
changeset 6320 6077a1310907
parent 6260 fd494c5f305b
child 6414 df50b0d6c1c3
     1.1 --- a/src/render/opengl/SDL_render_gl.c	Fri Jun 01 19:42:15 2012 -0300
     1.2 +++ b/src/render/opengl/SDL_render_gl.c	Fri Jun 01 19:51:08 2012 -0300
     1.3 @@ -65,6 +65,9 @@
     1.4                                const SDL_Rect * rects, int count);
     1.5  static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
     1.6                           const SDL_Rect * srcrect, const SDL_Rect * dstrect);
     1.7 +static int GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
     1.8 +                         const SDL_Rect * srcrect, const SDL_Rect * dstrect,
     1.9 +                         const double angle, const SDL_Point *center, const SDL_RendererFlip flip);
    1.10  static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    1.11                                 Uint32 pixel_format, void * pixels, int pitch);
    1.12  static void GL_RenderPresent(SDL_Renderer * renderer);
    1.13 @@ -314,6 +317,7 @@
    1.14      renderer->RenderDrawLines = GL_RenderDrawLines;
    1.15      renderer->RenderFillRects = GL_RenderFillRects;
    1.16      renderer->RenderCopy = GL_RenderCopy;
    1.17 +    renderer->RenderCopyEx = GL_RenderCopyEx;
    1.18      renderer->RenderReadPixels = GL_RenderReadPixels;
    1.19      renderer->RenderPresent = GL_RenderPresent;
    1.20      renderer->DestroyTexture = GL_DestroyTexture;
    1.21 @@ -1019,6 +1023,96 @@
    1.22  }
    1.23  
    1.24  static int
    1.25 +GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
    1.26 +              const SDL_Rect * srcrect, const SDL_Rect * dstrect,
    1.27 +              const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
    1.28 +{
    1.29 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
    1.30 +    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
    1.31 +    GLfloat minx, miny, maxx, maxy;
    1.32 +    GLfloat centerx, centery;
    1.33 +    GLfloat minu, maxu, minv, maxv;
    1.34 +    GL_ActivateRenderer(renderer);
    1.35 +
    1.36 +    data->glEnable(texturedata->type);
    1.37 +    if (texturedata->yuv) {
    1.38 +        data->glActiveTextureARB(GL_TEXTURE2_ARB);
    1.39 +        data->glBindTexture(texturedata->type, texturedata->vtexture);
    1.40 +
    1.41 +        data->glActiveTextureARB(GL_TEXTURE1_ARB);
    1.42 +        data->glBindTexture(texturedata->type, texturedata->utexture);
    1.43 +
    1.44 +        data->glActiveTextureARB(GL_TEXTURE0_ARB);
    1.45 +    }
    1.46 +    data->glBindTexture(texturedata->type, texturedata->texture);
    1.47 +
    1.48 +    if (texture->modMode) {
    1.49 +        GL_SetColor(data, texture->r, texture->g, texture->b, texture->a);
    1.50 +    } else {
    1.51 +        GL_SetColor(data, 255, 255, 255, 255);
    1.52 +    }
    1.53 +
    1.54 +    GL_SetBlendMode(data, texture->blendMode);
    1.55 +
    1.56 +    if (texturedata->yuv) {
    1.57 +        GL_SetShader(data, SHADER_YV12);
    1.58 +    } else {
    1.59 +        GL_SetShader(data, SHADER_RGB);
    1.60 +    }
    1.61 +
    1.62 +    centerx = (GLfloat)center->x;
    1.63 +    centery = (GLfloat)center->y;
    1.64 +
    1.65 +    if (flip & SDL_FLIP_HORIZONTAL) {
    1.66 +        minx = (GLfloat) dstrect->w - centerx;
    1.67 +        maxx = -centerx;
    1.68 +    }
    1.69 +    else {
    1.70 +        minx = -centerx;
    1.71 +        maxx = (GLfloat) dstrect->w - centerx;
    1.72 +    }
    1.73 +
    1.74 +    if (flip & SDL_FLIP_VERTICAL) {
    1.75 +        miny = (GLfloat) dstrect->h - centery;
    1.76 +        maxy = -centery;
    1.77 +    }
    1.78 +    else {
    1.79 +        miny = -centery;
    1.80 +        maxy = (GLfloat) dstrect->h - centery;
    1.81 +    }
    1.82 +
    1.83 +    minu = (GLfloat) srcrect->x / texture->w;
    1.84 +    minu *= texturedata->texw;
    1.85 +    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
    1.86 +    maxu *= texturedata->texw;
    1.87 +    minv = (GLfloat) srcrect->y / texture->h;
    1.88 +    minv *= texturedata->texh;
    1.89 +    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
    1.90 +    maxv *= texturedata->texh;
    1.91 +
    1.92 +    // Translate to flip, rotate, translate to position
    1.93 +    data->glPushMatrix();
    1.94 +    data->glTranslatef((GLfloat)dstrect->x + centerx, (GLfloat)dstrect->y + centery, (GLfloat)0.0);    
    1.95 +    data->glRotated(angle, (GLdouble)0.0, (GLdouble)0.0, (GLdouble)1.0);
    1.96 +    
    1.97 +    data->glBegin(GL_TRIANGLE_STRIP);
    1.98 +    data->glTexCoord2f(minu, minv);
    1.99 +    data->glVertex2f(minx, miny);
   1.100 +    data->glTexCoord2f(maxu, minv);
   1.101 +    data->glVertex2f(maxx, miny);
   1.102 +    data->glTexCoord2f(minu, maxv);
   1.103 +    data->glVertex2f(minx, maxy);
   1.104 +    data->glTexCoord2f(maxu, maxv);
   1.105 +    data->glVertex2f(maxx, maxy);
   1.106 +    data->glEnd();
   1.107 +    data->glPopMatrix();
   1.108 +    
   1.109 +    data->glDisable(texturedata->type);
   1.110 +
   1.111 +    return 0;
   1.112 +}
   1.113 +
   1.114 +static int
   1.115  GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   1.116                      Uint32 pixel_format, void * pixels, int pitch)
   1.117  {