Beispiel #1
0
Texture *load_text(const char *text, TTF_Font *font) {
	Texture *tex = malloc(sizeof(Texture));
	SDL_Color clr = {255,255,255};
	SDL_Surface *surf = TTF_RenderText_Blended(font, text, clr);
	assert(surf != NULL);	
	
	load_sdl_surf(surf, tex);
	SDL_FreeSurface(surf);
	
	return tex;
}
Beispiel #2
0
Texture *load_texture(const char *filename) {	
	SDL_Surface *surface = load_png(filename);
	
	if(surface == NULL)
		errx(-1,"load_texture():\n!- cannot load '%s'", filename);
	
	Texture *texture = create_element((void **)&resources.textures, sizeof(Texture));
	load_sdl_surf(surface, texture);	
	free(surface->pixels);
	SDL_FreeSurface(surface);
	
	char *beg = strstr(filename, "gfx/") + 4;
	char *end = strrchr(filename, '.');
	
	texture->name = malloc(end - beg + 1);
	memset(texture->name, 0, end-beg + 1);
	strncpy(texture->name, beg, end-beg);
	
	printf("-- loaded '%s' as '%s'\n", filename, texture->name);
	
	return texture;
}