/** * @brief Loads the already padded SDL_Surface to a glTexture. * * @param name Name to load with. * @param surface Surface to load. * @param flags Flags to use. * @param w Non-padded width. * @param h Non-padded height. * @param sx X sprites. * @param sy Y sprites. * @param freesur Whether or not to free the surface. * @return The glTexture for surface. */ glTexture* gl_loadImagePad( const char *name, SDL_Surface* surface, unsigned int flags, int w, int h, int sx, int sy, int freesur ) { glTexture *texture; int rw, rh; uint8_t *trans; /* Make sure doesn't already exist. */ if (name != NULL) { texture = gl_texExists( name ); if (texture != NULL) return texture; } /* set up the texture defaults */ texture = calloc( 1, sizeof(glTexture) ); /* Map transparency if needed .*/ if (flags & OPENGL_TEX_MAPTRANS) { SDL_LockSurface(surface); trans = SDL_MapTrans( surface, w, h ); SDL_UnlockSurface(surface); } else trans = NULL; texture->w = (double) w; texture->h = (double) h; texture->sx = (double) sx; texture->sy = (double) sy; texture->texture = gl_loadSurface( surface, &rw, &rh, flags, freesur ); texture->rw = (double) rw; texture->rh = (double) rh; texture->sw = texture->w / texture->sx; texture->sh = texture->h / texture->sy; texture->srw = texture->sw / texture->rw; texture->srh = texture->sh / texture->rh; texture->trans = trans; if (name != NULL) { texture->name = strdup(name); gl_texAdd( texture ); } else texture->name = NULL; return texture; }
/** * @brief Loads the already padded SDL_Surface to a glTexture. * * @param name Name to load with. * @param surface Surface to load. * @param flags Flags to use. * @param w Non-padded width. * @param h Non-padded height. * @param sx X sprites. * @param sy Y sprites. * @param freesur Whether or not to free the surface. * @return The glTexture for surface. */ glTexture* gl_loadImagePad( const char *name, SDL_Surface* surface, unsigned int flags, int w, int h, int sx, int sy, int freesur ) { glTexture *texture; int rw, rh; /* Make sure doesn't already exist. */ if (name != NULL) { texture = gl_texExists( name ); if (texture != NULL) return texture; } if (flags & OPENGL_TEX_MAPTRANS) return gl_loadImagePadTrans( name, surface, NULL, flags, w, h, sx, sy, freesur ); /* set up the texture defaults */ texture = calloc( 1, sizeof(glTexture) ); texture->w = (double) w; texture->h = (double) h; texture->sx = (double) sx; texture->sy = (double) sy; texture->texture = gl_loadSurface( surface, &rw, &rh, flags, freesur ); texture->rw = (double) rw; texture->rh = (double) rh; texture->sw = texture->w / texture->sx; texture->sh = texture->h / texture->sy; texture->srw = texture->sw / texture->rw; texture->srh = texture->sh / texture->rh; if (name != NULL) { texture->name = strdup(name); gl_texAdd( texture ); } else texture->name = NULL; return texture; }