src/render/opengles2/SDL_render_gles2.c
changeset 12156 e5a666405750
parent 12034 b3ae0dc577fd
child 12159 f7398cb0e3bf
     1.1 --- a/src/render/opengles2/SDL_render_gles2.c	Mon Aug 27 11:51:05 2018 -0700
     1.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Tue Aug 28 12:57:51 2018 -0700
     1.3 @@ -1534,7 +1534,7 @@
     1.4      GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
     1.5  
     1.6  #if !SDL_GLES2_USE_VBOS
     1.7 -    data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, vertexData);
     1.8 +    data->glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, vertexData);
     1.9  #else
    1.10      if (!data->vertex_buffers[attr]) {
    1.11          data->glGenBuffers(1, &data->vertex_buffers[attr]);
    1.12 @@ -1549,7 +1549,7 @@
    1.13          data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData);
    1.14      }
    1.15  
    1.16 -    data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, 0);
    1.17 +    data->glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, 0);
    1.18  #endif
    1.19  
    1.20      return 0;
    1.21 @@ -1857,6 +1857,8 @@
    1.22      return GL_CheckError("", renderer);
    1.23  }
    1.24  
    1.25 +#define PI 3.14159265f
    1.26 +
    1.27  static int
    1.28  GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
    1.29                   const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
    1.30 @@ -1865,8 +1867,9 @@
    1.31      GLfloat vertices[8];
    1.32      GLfloat texCoords[8];
    1.33      GLfloat translate[8];
    1.34 -    GLfloat fAngle[4];
    1.35 +    GLfloat fAngle[8];
    1.36      GLfloat tmp;
    1.37 +    float radian_angle;
    1.38  
    1.39      GLES2_ActivateRenderer(renderer);
    1.40  
    1.41 @@ -1876,7 +1879,11 @@
    1.42  
    1.43      data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_CENTER);
    1.44      data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE);
    1.45 -    fAngle[0] = fAngle[1] = fAngle[2] = fAngle[3] = (GLfloat)(360.0f - angle);
    1.46 +
    1.47 +    radian_angle = PI * (360.0f - angle) / 180.f;
    1.48 +    fAngle[0] = fAngle[2] = fAngle[4] = fAngle[6] = (GLfloat)sin(radian_angle);
    1.49 +    /* render expects cos value - 1 (see GLES2_VertexSrc_Default_) */
    1.50 +    fAngle[1] = fAngle[3] = fAngle[5] = fAngle[7] = (GLfloat)cos(radian_angle) - 1.0f;
    1.51      /* Calculate the center of rotation */
    1.52      translate[0] = translate[2] = translate[4] = translate[6] = (center->x + dstrect->x);
    1.53      translate[1] = translate[3] = translate[5] = translate[7] = (center->y + dstrect->y);
    1.54 @@ -1905,7 +1912,7 @@
    1.55      data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate);
    1.56      data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
    1.57  
    1.58 -    GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 4 * sizeof(GLfloat));
    1.59 +    GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 8 * sizeof(GLfloat));
    1.60      GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat));
    1.61      GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
    1.62