Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int __render_gl(int id, SDL_Surface* surface, int srcX, int srcY, int dstX,
- int dstY, int width, int height)
- {
- GLuint texture;
- GLenum texture_format;
- /* Get the texture format.
- */
- if (surface->format->BytesPerPixel == 4) {
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- if (surface->format->Rmask == 0xff000000)
- #else
- if (surface->format->Rmask == 0x000000ff)
- #endif
- texture_format = GL_RGBA;
- else
- texture_format = GL_BGRA;
- } else if (surface->format->BytesPerPixel == 3) {
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- if (surface->format->Rmask == 0xff000000)
- #else
- if (surface->format->Rmask == 0x000000ff)
- #endif
- texture_format = GL_RGB;
- else
- texture_format = GL_BGR;
- } else {
- sgeSetError("%s: Surface %d has unknown/invalid format", __func__,
- id);
- return -1;
- }
- /* Generate & set up the texture object.
- */
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, width,
- height, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels);
- /* Draw the texture.
- */
- glBindTexture(GL_TEXTURE_2D, texture);
- glBegin(GL_QUADS);
- /* Bottem-left vertex. */
- glTexCoord2i(0, 0);
- glVertex3f(dstX, dstY, 0.f);
- /* Bottom-right vertex. */
- glTexCoord2i(1, 0);
- glVertex3f(dstX + width, dstY, 0.f);
- /* Top-right vertex. */
- glTexCoord2i(1, 1);
- glVertex3f(dstX + width, dstY + height, 0.f);
- /* Top-left vertex. */
- glTexCoord2i(0, 1);
- glVertex3f(dstX, dstY + height, 0.f);
- glEnd();
- glDeleteTextures(1, &texture);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment