void FontTTF::fontToGlyph(TTF_Font *font, unsigned char *texels) { SDL_Color white = { 255, 255, 255, 255 }; int r, g, b, a, xPos, yPos; int currentASCII = -1; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { currentASCII++; if (currentASCII == 0) { continue; } char letter[2] = {currentASCII, 0}; xPos = j * _cellWidth; yPos = i * _cellHeight; SDL_Surface *renderedLetter = TTF_RenderText_Blended(font, letter, white); for (int w = 0; w < renderedLetter->w; w++) { for (int h = 0; h < renderedLetter->h; h++) { SDL_GetPixel(renderedLetter, w, renderedLetter->h - 1 - h, r, g, b, a); texels[((yPos + h) * _texWidth) + (xPos + w)] = a; } } SDL_FreeSurface(renderedLetter); } } }
double Map::terrainHeight(int _x, int _y) { int x(_x),y(_y); if (x < 0) x=0; if (y < 0) y=0; if (x >= getSize().x) x = getSize().x-1; if (y >= getSize().y) y = getSize().y-1; Uint8 r,g,b; SDL_GetRGB( SDL_GetPixel(terrain,x,y), terrain->format, &r,&g,&b); return (double)(r)/255.0f*MAX_HEIGHT; }
bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y ) { if (x < 0 || y < 0 || x >= srf->w || y >= srf->h) return true; SDL_Color color; SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.unused); // color is considered transparent here if // a) image has aplha: less than 50% transparency // b) no alpha: color is cyan if (srf->format->Amask) return color.unused < 128; // almost transparent else return (color.r == 0 && color.g == 255 && color.b == 255); }