Guest User

Untitled

a guest
May 10th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. static int __render_gl(int id, SDL_Surface* surface, int srcX, int srcY, int dstX,
  2.                         int dstY, int width, int height)
  3. {
  4.     GLuint texture;
  5.     GLenum texture_format;
  6.     /* Get the texture format.
  7.      */
  8.     if (surface->format->BytesPerPixel == 4) {
  9. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  10.         if (surface->format->Rmask == 0xff000000)
  11. #else
  12.         if (surface->format->Rmask == 0x000000ff)
  13. #endif
  14.             texture_format = GL_RGBA;
  15.         else
  16.             texture_format = GL_BGRA;
  17.     } else if (surface->format->BytesPerPixel == 3) {
  18. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  19.         if (surface->format->Rmask == 0xff000000)
  20. #else
  21.         if (surface->format->Rmask == 0x000000ff)
  22. #endif
  23.             texture_format = GL_RGB;
  24.         else
  25.             texture_format = GL_BGR;
  26.     } else {
  27.         sgeSetError("%s: Surface %d has unknown/invalid format", __func__,
  28.                                 id);
  29.         return -1;
  30.     }
  31.     /* Generate & set up the texture object.
  32.      */
  33.     glGenTextures(1, &texture);
  34.     glBindTexture(GL_TEXTURE_2D, texture);
  35.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  36.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  37.     glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, width,
  38.         height, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels);
  39.     /* Draw the texture.
  40.      */
  41.     glBindTexture(GL_TEXTURE_2D, texture);
  42.     glBegin(GL_QUADS);
  43.         /* Bottem-left vertex. */
  44.         glTexCoord2i(0, 0);
  45.         glVertex3f(dstX,         dstY, 0.f);
  46.         /* Bottom-right vertex. */
  47.         glTexCoord2i(1, 0);
  48.         glVertex3f(dstX + width, dstY, 0.f);
  49.         /* Top-right vertex. */
  50.         glTexCoord2i(1, 1);
  51.         glVertex3f(dstX + width, dstY + height, 0.f);
  52.         /* Top-left vertex. */
  53.         glTexCoord2i(0, 1);
  54.         glVertex3f(dstX,         dstY + height, 0.f);
  55.        
  56.     glEnd();
  57.     glDeleteTextures(1, &texture);
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment