virtual Image* load(const std::string& filename,
                            bool convertToDisplayFormat = true)
        {
            SDL_Surface *loadedSurface = loadSDLSurface(filename);

            if (loadedSurface == NULL)
            {
                throw GCN_EXCEPTION(
                        std::string("Unable to load image file: ") + filename);
            }

            SDL_Surface *surface = convertToStandardFormat(loadedSurface);
            SDL_FreeSurface(loadedSurface);

            if (surface == NULL)
            {
                throw GCN_EXCEPTION(
                        std::string("Not enough memory to load: ") + filename);
            }

            OpenGLImage *image = new OpenGLImage((unsigned int*)surface->pixels,
                                                 surface->w,
                                                 surface->h,
                                                 convertToDisplayFormat);
            SDL_FreeSurface(surface);

            return image;
        }
gcn::Image* InfraellyImageLoader::load(unsigned char *buffer, long bufferLength, bool convertToDisplayFormat){
    //make rWop out of character buffer
    SDL_RWops *source_Rwop = SDL_RWFromMem(buffer, bufferLength);

    //load the rWop into a SDL Surface
    SDL_Surface *loadedSurface = IMG_Load_RW(source_Rwop, 1);

    if (loadedSurface == NULL)
    {
        throw GCN_EXCEPTION( std::string("Unable to load image file: ") );
    }

    SDL_Surface *surface = convertToStandardFormat(loadedSurface);
    SDL_FreeSurface(loadedSurface);

    if (surface == NULL)
    {
        throw GCN_EXCEPTION( std::string("Not enough memory to load: ") );
    }

    gcn::Image *image = new gcn::SDLImage(surface, true);

    if (convertToDisplayFormat)
    {
        image->convertToDisplayFormat();
    }

    return image;
}
gcn::Image* InfraellyImageLoader::load(SDL_RWops *source_Rwop, bool freeRWOP, bool convertToDisplayFormat){
    //load the rWop into a SDL Surface
    SDL_Surface *loadedSurface = IMG_Load_RW(source_Rwop, freeRWOP);

    if (loadedSurface == NULL)
    {
        throw GCN_EXCEPTION( std::string("Unable to load image file: ") );
    }

    SDL_Surface *surface = convertToStandardFormat(loadedSurface);
    SDL_FreeSurface(loadedSurface);

    if (surface == NULL)
    {
        throw GCN_EXCEPTION( std::string("Not enough memory to load: ") );
    }

    gcn::Image *image = new gcn::SDLImage(surface, true);

    if (convertToDisplayFormat)
    {
        image->convertToDisplayFormat();
    }

    return image;
}
Esempio n. 4
0
void make_dlist(TTF_Font *font, unsigned char ch, GLuint list_base, FonteChar *chars ) {
  char texto[5];

  SDL_Surface *text_surface;
  SDL_Color clrFg = {255,255,255,255};

  sprintf(texto,"%c",ch);

  text_surface=TTF_RenderText_Blended(font,texto, clrFg);

  if (!text_surface) return;
  SDL_Surface *Surface = convertToStandardFormat(text_surface);

	int width;
	int height;

	Uint32 *pixels = texturaPotencia2(Surface->pixels, Surface->w, Surface->h, &width, &height);

  glBindTexture( GL_TEXTURE_2D, chars->textura);

  glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);

  free(pixels);

  SDL_FreeSurface(text_surface);

  chars->width=Surface->w;

	glNewList(list_base+ch,GL_COMPILE);

	glBindTexture(GL_TEXTURE_2D,chars->textura);

  glPushMatrix();

	float	x=(float)Surface->w / (float)width,
			y=(float)Surface->h / (float)height;

	glBegin(GL_QUADS);
    glTexCoord2d(0,0); glVertex2f(0,0);
    glTexCoord2d(0,y); glVertex2f(0,Surface->h);
    glTexCoord2d(x,y); glVertex2f(Surface->w,Surface->h);
    glTexCoord2d(x,0); glVertex2f(Surface->w,0);
	glEnd();

	glPopMatrix();

	glTranslatef(chars->width ,0,0);

	glEndList();

	SDL_FreeSurface(Surface);
}
Esempio n. 5
0
Textura *carregar_img(enum TipoImagem tipo, char *text, ... ) {
  char imagem[256];

  va_list ap;

  if (text == NULL) return 0;

  va_start(ap, text);
  vsprintf(imagem, text, ap);
  va_end(ap);

  if (imagem[0] == '\0') return 0;

  SDL_Surface *loadedSurface = IMG_Load(imagem);

  if (loadedSurface == NULL) {
    logtemp=1;
    //logging(3,"Incapaz de carregar a imagem: %s", imagem);

    return NULL;
  }

  SDL_Surface *Surface = convertToStandardFormat(loadedSurface);

  SDL_FreeSurface(loadedSurface);

  if (tipo == IMG_FUNDOROSA) {
    int percorreX;
    int percorreY;

    Uint32 *pixels=(Uint32 *) Surface->pixels;

#ifdef __BIG_ENDIAN__
        const unsigned int magicPink = 0xff00ffff;
#else
        const unsigned int magicPink = 0xffff00ff;
#endif

		for (percorreY=0; percorreY < Surface->h ; percorreY++) {
			for (percorreX = 0; percorreX < Surface->w; percorreX++) {
        if (pixels[percorreX + percorreY * Surface->w] == magicPink)
          pixels[percorreX + percorreY * Surface->w] = 0x00000000;
			}
		}
  }

  Textura *retorno=carregar_memoria(Surface->pixels,Surface->w, Surface->h,(tipo != IMG_NORMAL));

  SDL_FreeSurface(Surface);

  return retorno;
}
Esempio n. 6
0
static gcn::Image* buildThemeGCNImageFrom(SDL_Surface* loadedSurface) {
  if (loadedSurface == NULL) {
    throw GCN_EXCEPTION(std::string("Unable to theme image"));
  }

  SDL_Surface *surface = convertToStandardFormat(loadedSurface);

  if (surface == NULL) {
    throw GCN_EXCEPTION(std::string("Not enough memory to load theme image"));
  }

  gcn::OpenGLImage *image = new gcn::OpenGLImage((unsigned int*)surface->pixels,
                                                 surface->w,
                                                 surface->h,
                                                 true);
  SDL_FreeSurface(surface);

  return image;
}