Example #1
0
//Constructor
Button::Button(Point placement, std::string textString, TTF_Font * theFont)
{
  // Probably should verify these before applying them
  point.x = placement.x;
  point.y = placement.y;

  state = B_STATE_NORMAL;  // Set the intial state to be normal

  SDL_Color textColor = {0,0,0};

  font = theFont;

  text = TTF_RenderText_Blended( font, textString.c_str(), textColor);

  // Everything initialized
}
Example #2
0
//load the text, if it doesnt load throw an error
SDL_Surface* ImageCache::loadText(TTF_Font* font, const std::string text) const
{
	SDL_Color textColor;
	textColor.r = 192;
	textColor.g = textColor.b = 0;
    SDL_Surface* surface = TTF_RenderText_Blended(font, text.c_str(), textColor);

    if(!surface)
    {
		throw(TTF_GetError());
	}
    else
    {
		return surface;
	}
}
Example #3
0
File: exp.c Project: bigml/emoon
SDL_Texture* create_texture_str(char *msg, SDL_Color color, int fontsize)
{
    TTF_Font *font = TTF_OpenFont("studyres/a.ttf", fontsize);
    if (!font) {
        mtc_err("create font error %s", TTF_GetError());
        return NULL;
    }

    SDL_Surface *sur = TTF_RenderText_Blended(font, msg, color);
    SDL_Texture *tex = SDL_CreateTextureFromSurface(m_render2, sur);

    SDL_FreeSurface(sur);
    TTF_CloseFont(font);

    return tex;
}
Example #4
0
Renderer::Renderer()
{
    SDL_Init(SDL_INIT_EVERYTHING);
    TTF_Init();
//    freopen( "CON", "w", stdout );
//freopen( "CON", "w", stderr );
    firstRender = true;
    Font = TTF_OpenFont("Pokemon_GB.ttf", 18);
    message = NULL;
    SDL_Color textColor = { 255, 180, 255 };
    sprite1 = SDL_LoadBMP("sprites_frame_1.bmp");
    sprite2 = SDL_LoadBMP("sprites_frame_2.bmp");

    message = TTF_RenderText_Blended( Font, "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG", textColor );

}
Example #5
0
void		draw_text(t_visu *visu, char *text, int coor[2])
{
    SDL_Surface	*texte;
    SDL_Color	couleurNoire;
    SDL_Rect	position;
    SDL_Surface	*base;

    texte = NULL;
    memset(&couleurNoire, 0, sizeof(couleurNoire));
    base = visu->info;
    position.x = coor[0];
    position.y = coor[1];
    texte = TTF_RenderText_Blended(visu->police, text, couleurNoire);
    SDL_BlitSurface(texte, NULL, base, &position);
    SDL_FreeSurface(texte);
}
Example #6
0
std::vector<SDL_Surface*> createRankSurfaces(TTF_Font* font){
	SDL_Color white = {255, 255, 255};
	std::vector<SDL_Surface*> rankSurfaces;
	for(int i=0; i<8; ++i){
    	SDL_Surface* newSurface = NULL;
    	rankSurfaces.push_back(newSurface);
    }
    rankSurfaces[0] = TTF_RenderText_Blended(font, "1er", white);
    rankSurfaces[1] = TTF_RenderText_Blended(font, "2ème", white);
    rankSurfaces[2] = TTF_RenderText_Blended(font, "3ème", white);
    rankSurfaces[3] = TTF_RenderText_Blended(font, "4ème", white);
    rankSurfaces[4] = TTF_RenderText_Blended(font, "5ème", white);
    rankSurfaces[5] = TTF_RenderText_Blended(font, "6ème", white);
    rankSurfaces[6] = TTF_RenderText_Blended(font, "7ème", white);
    rankSurfaces[7] = TTF_RenderText_Blended(font, "8ème", white);

    return rankSurfaces;
}
Example #7
0
void Menu::Draw( SGameEngine* game )
{
	SDL_Rect bgrect = { 28, 28, SCREENWIDTH - 28 * 2, SCREENHEIGHT - 28 * 2 };
    SDL_FillRect( game->screen, &bgrect, SDL_MapRGB( game->screen->format, bgColor.r, bgColor.g, bgColor.b ) );
    
    //draw menu title
	fontSurface = TTF_RenderText_Blended( theFont, title.c_str(), titleColor );
	SDL_Rect where = { SCREENWIDTH / 2 - fontSurface->w / 2, 75 };
	SDL_BlitSurface( fontSurface, NULL, game->screen, &where );

	//draw top line
	where.h = 3;
	where.w = fontSurface->w + 8;
	where.x -= 4;
	where.y -= 2;
	SDL_FillRect( game->screen, &where, SDL_MapRGB( game->screen->format, titleColor.r, titleColor.g, titleColor.b ) );

	//draw left line
	where.x -= 3;
	where.h = 6 + fontSurface->h;
	where.w = 3;
	SDL_FillRect( game->screen, &where, SDL_MapRGB( game->screen->format, titleColor.r, titleColor.g, titleColor.b ) );
	
	//draw right line
	where.x += 10 + fontSurface->w;
	SDL_FillRect( game->screen, &where, SDL_MapRGB( game->screen->format, titleColor.r, titleColor.g, titleColor.b ) );
	
	//draw bottom line
	where.x = SCREENWIDTH / 2 - fontSurface->w / 2 - 4;
	where.y += 3 + fontSurface->h;
	where.h = 3;
	where.w = fontSurface->w + 8;
	SDL_FillRect( game->screen, &where, SDL_MapRGB( game->screen->format, titleColor.r, titleColor.g, titleColor.b ) );    
	SDL_FreeSurface( fontSurface );
	
	
    
    int offset = SCREENHEIGHT / 2 - 50 * numOptions / 2 + 10;
    for( int i = 0; i < numOptions; i++ ) {
        if( options[i]->isSelectable() )
            drawSelectableOption( game, i, offset );
        else
            drawOption( game, i, offset );
        
        offset += 50;
    }        
}
Example #8
0
/***********************************************************************
 * draw:   Simply draws the Counter to the screen
 *
 * returns:   void.
***********************************************************************/
void Counter::draw(){
    
    stringstream message;
    message << fixed << setprecision(precision) << value;

    // Create the surface to copy to the renderer
    SDL_Surface *surf = TTF_RenderText_Blended(font, message.str().c_str(), color);
    if (surf == NULL){
		TTF_CloseFont(font);
		return;
	}

    GLuint Texture = 0;

    // Create the texture
    glGenTextures(1, &Texture);
    glBindTexture(GL_TEXTURE_2D, Texture);

    // Enable texture parameters
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    // Render the text to 2D by referencing its pixel data
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, GL_BGRA_EXT,
                    GL_UNSIGNED_BYTE, surf->pixels);

    // Enable 2D Texture and alpha blend
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    // Draw the text
    glBegin(GL_QUADS);
        glTexCoord2d(0, 1); glVertex3d(xPosition, yPosition + surf->h, 0);
        glTexCoord2d(1, 1); glVertex3d(xPosition + surf->w, yPosition + surf->h, 0);
        glTexCoord2d(1, 0); glVertex3d(xPosition + surf->w, yPosition, 0);
        glTexCoord2d(0, 0); glVertex3d(xPosition, yPosition, 0);        
    glEnd();

    // Clean up
    SDL_FreeSurface(surf);
    glDisable(GL_BLEND);
    glDisable(GL_TEXTURE_2D); 
    glDeleteTextures(1, &Texture);
}
Example #9
0
void		loop_name(SDL_Rect *position, t_sdl *cor, int i, t_champ *tmp)
{
  SDL_Color	color;

  color.r = 255;
  color.g = 255;
  color.b = 255;
  position->w = 15;
  position->h = 30;
  SDL_FillRect(cor->screen, position, tmp->color);
  position->x += 50;
  cor->name[i] = TTF_RenderText_Blended(cor->font,
					tmp->graphic_name, color);
  SDL_BlitSurface(cor->name[i], NULL, cor->screen, position);
  position->x -= 50;
  position->y += 35;
}
Example #10
0
SDL_Texture* loadTextTexture(char* string, TTF_Font* Font, SDL_Color textColor, SDL_Renderer* renderer){
    SDL_Surface* textSurface = TTF_RenderText_Blended(Font, string, textColor);
    SDL_Texture* texture = NULL;
    if (textSurface == NULL){
        prError("Unable to create texture from rendered text");
        return NULL;
    }
    else{
        texture = SDL_CreateTextureFromSurface(renderer, textSurface);
        if (texture == NULL){
            prError("Unable to create texture from rendered text");
            return NULL;
        }
        SDL_FreeSurface(textSurface);
    }
    return texture;
}
Example #11
0
SDL_Rect font_render(char* message, int x, int y, int centered, TTF_Font *font, SDL_Color color) {
    int w, h;
    SDL_Surface *surf = TTF_RenderText_Blended(font, message, color);
    SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surf);
    SDL_FreeSurface(surf);
    SDL_QueryTexture(texture, NULL, NULL, &w, &h);
    SDL_Rect dest;
    if (centered == 1) {
        x = 640 / 2 - w / 2;
    }
    dest.x = x;
    dest.y = y;
    dest.h = h;
    dest.w = w;
    SDL_RenderCopy(renderer, texture, NULL, &dest);
    return dest;
}
Example #12
0
void TextPainter::Text::Update()
{
    //content_.clear();
    std::string new_content;
    updater_(&new_content);
    if (content_ == new_content)
        return;
    content_.clear();
    content_ = new_content;
    auto local = TTF_RenderText_Blended(master_->GetFont(font_name_, size_), content_.c_str(), color_);
              
    delete content_image_;
    content_image_ = nullptr;

    if (local)
        content_image_ = new ApproxGLImage(local);
}
Example #13
0
SDL_Texture* Window::RenderText(const std::string &message, const std::string &fontFile, SDL_Color color, int fontSize)
{
    //Open the font
	TTF_Font *font = nullptr;
	font = TTF_OpenFont(fontFile.c_str(), fontSize);
	if (font == nullptr)
		throw std::runtime_error("Failed to load font: " + fontFile + TTF_GetError());

	//Render the message to an SDL_Surface, as that's what TTF_RenderText_X returns
	SDL_Surface *surf = TTF_RenderText_Blended(font, message.c_str(), color);
	SDL_Texture *texture = SDL_CreateTextureFromSurface(m_renderer, surf);
	//Clean up unneeded stuff
	SDL_FreeSurface(surf);
	TTF_CloseFont(font);

	return texture;
}
        void SDLTrueTypeFont::drawString(gcn::Graphics* graphics, const std::string& text, const int x, const int y)
        {
            if (text == "")
            {
                return;
            }
        
            SDLGraphics *sdlGraphics = dynamic_cast<SDLGraphics *>(graphics);

            if (sdlGraphics == NULL)
            {
                throw GCN_EXCEPTION("SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!");
                return;
            }
        
            // This is needed for drawing the Glyph in the middle if we have spacing
            int yoffset = getRowSpacing() / 2;
        
            Color col = sdlGraphics->getColor();

            SDL_Color sdlCol;
            sdlCol.b = col.b;
            sdlCol.r = col.r;
            sdlCol.g = col.g;

            SDL_Surface *textSurface;
            if (mAntiAlias)
            {
                textSurface = TTF_RenderText_Blended(mFont, text.c_str(), sdlCol);
            }
            else
            {
                textSurface = TTF_RenderText_Solid(mFont, text.c_str(), sdlCol);
            }
        
            SDL_Rect dst, src;
            dst.x = x;
            dst.y = y + yoffset;
            src.w = textSurface->w;
            src.h = textSurface->h;
            src.x = 0;
            src.y = 0;
        
            sdlGraphics->drawSDLSurface(textSurface, src, dst);
            SDL_FreeSurface(textSurface);        
        }
Example #15
0
void textbox_set(Tbox t, char *s)
{
    SDL_Rect r;
    SDL_Surface *txt;
    SDL_Texture *text;

    t->s = s;
    r.x = t->x;
    r.y = t->y;

    txt = TTF_RenderText_Blended(t->font, s, font_fg);
    text = SDL_CreateTextureFromSurface(t->screen, txt);
    SDL_RenderCopy(t->screen, text, 0, &r);
    if (TEXT_UTIL_DEBUG > 1)
        fprintf(stderr, "%p Rendering textbox at %d/%d: `%s'\n",
            t->screen, r.x, r.y, s);
}
Example #16
0
File: text.c Project: nnesse/tbftss
static void drawTextNormal(int x, int y, int size, int align, SDL_Color c, char *text)
{
	SDL_Surface *surface;
	SDL_Texture *t;
	int w, h;
	long hash;
	
	if (size >= MAX_FONTS)
	{
		printf("ERROR: %d exceeds max font size index of %d\n", size, MAX_FONTS);
		exit(1);
	}
	
	if (!font[size])
	{
		loadFont(size);
	}

	hash = hashcode(text, size);

	t = getCachedText(hash);

	if (!t)
	{
		surface = TTF_RenderText_Blended(font[size], text, c);
		t = SDL_CreateTextureFromSurface(app.renderer, surface);
		SDL_FreeSurface(surface);
		
		cacheText(hash, t);
	}

	SDL_QueryTexture(t, NULL, NULL, &w, &h);

	if (align == TA_CENTER)
	{
		x -= (w / 2);
	}
	else if (align == TA_RIGHT)
	{
		x -= w;
	}
	
	SDL_SetTextureColorMod(t, c.r, c.g, c.b);

	blit(t, x, y, 0);
}
Example #17
0
void FWApplication::DrawText(const std::string & message, uint32_t offsetX, uint32_t offsetY)
{
	SDL_Color color = { mColor.r, mColor.g, mColor.b, mColor.a };
	//SDL_Color bgColor = { mTextBackgroundColor.r, mTextBackgroundColor.g, mTextBackgroundColor.b, mTextBackgroundColor.a };

	SDL_Surface * surface = TTF_RenderText_Blended(mFont, message.c_str(), color);
	if (surface)
	{
		SDL_Texture * texture = SDL_CreateTextureFromSurface(mRenderer, surface);
		if (texture)
		{
			DrawTexture(texture, offsetX, offsetY, surface->w, surface->h);
		}
		SDL_FreeSurface(surface);
		SDL_DestroyTexture(texture);
	}
}
Example #18
0
unsigned char conf_render_text ( TTF_Font *f, char *buffer, SDL_Rect *dest, unsigned int x, unsigned int y, unsigned char selected ) {
  unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
  unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
  unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
  unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );

  SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
  SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };

  SDL_Surface *rtext = TTF_RenderText_Blended ( f, buffer, selected ? selfontcolor : tmpfontcolor );
  dest -> x = x;
  dest -> y = y;
  SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
  SDL_FreeSurface ( rtext );

  return ( 1 );
}
Example #19
0
SDLFont* SDLFont::AppendText( std::string text )
{
	SDLObject::OnCleanup( );

	if ( font == NULL )
		return this;

	std::string out = "";
	std::vector<std::string> text_lines;
	std::string::iterator it;
	for ( it = text.begin(); it < text.end(); it++)
	{
		if ( *it == '\n' )
		{
			text_lines.push_back( out );
			out = "";
			continue;
		}
		out += *it;
	}
	if ( !out.empty() )
		text_lines.push_back( out );

	for( unsigned int i = 0; i < text_lines.size(); i++ )
	{
		SDL_Surface* render;
		render = TTF_RenderText_Blended( font, text_lines[i].c_str(), fnt_color );

		if ( render == NULL )
		{
			std::cerr<<"TTF_RenderText_Blended failed: "<<TTF_GetError()<<std::endl;
			return this;
		}

		SDLSurf::Transparent( render, GetSurfaceRGB( render, SDL_COLORKEY ) );

		rendered.push_back( render );
		if ( rendered.size( ) > max_lines )
		{
			SDL_FreeSurface( rendered.front( ) );
			rendered.pop_front( );
		}
	}

	return this;
}
Example #20
0
/*
 * Sets the text message
 */
void S2D_SetText(Text *txt, const char *msg) {
  if(!txt) {
      return;
  }

  txt->msg = msg;
  
  TTF_SizeText(txt->font, txt->msg, &txt->w, &txt->h);
  
  SDL_Surface *surface;
  SDL_Color color = { 255, 255, 255 };
  surface = TTF_RenderText_Blended(txt->font, txt->msg, color);
  
  S2D_GL_SetUpTexture(&txt->texture_id, GL_RGBA, txt->w, txt->h, surface->pixels, GL_NEAREST);
  
  SDL_FreeSurface(surface);
}
/*** setText ***/
int TextManager::setText(const char text[]){
	// Se crea la imagen
	if ((image = TTF_RenderText_Blended(font,text,fgcolor/*,bgcolor*/)) == NULL){	// Si no se puede cargar
		return -1;																// sale y devuelve -1
	}else{																		
		imageRect.w = image->w;													// se guardan los atributos
		imageRect.h = image->h;					// de la imagen cargada

		// Se crea la superfie auxiliar
		auxiliar = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_SRCCOLORKEY|SDL_SRCALPHA,
			imageRect.w,imageRect.h,32,0,0,0,0);

		// Se copia la imagen original en la superficie auxiliar
		SDL_BlitSurface(image,NULL,auxiliar,&imageRect);
		return 0;								// Si todo va bien devuelve 0
	}
}
Example #22
0
GLuint	loadTextureFromFont(const string& fontFilename, int	pointSize, const string& text)
{
    TTF_Font	*	font = TTF_OpenFont(fontFilename.c_str(), pointSize);
    if (!font)
    {
        cout << "Unable	to load font	" << fontFilename << "	" << TTF_GetError();
        return	0;
    }
    SDL_Surface	*textSurface = TTF_RenderText_Blended(font, text.c_str(), { 255, 255, 255 });

    GLuint textureID = convertSDLSurfaceToTexture(textSurface);
    SDL_FreeSurface(textSurface);

    TTF_CloseFont(font);

    return textureID;
}
Example #23
0
void display_text_box (Display* display, GLuint* id, 
		TTF_Font *font, const char* text,
		float x, float y, float w, float h,
		float r, float g, float b, float a)
{
	if(text == NULL || text[0] == '\0')
		return;

	if(*id == 0) {
		glGenTextures(1, id);
		glBindTexture(GL_TEXTURE_2D, *id);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	} else {
		glBindTexture(GL_TEXTURE_2D, *id);
	}

	SDL_Color color = {0xff,0xff,0xff,0xff};
	SDL_Surface* label = TTF_RenderText_Blended(font, text, color);
	if(label == NULL)
		return;

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);

	// FIXME dont rebuild the texture when it didnt changed
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, label->w, label->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, label->pixels);

	SDL_FreeSurface(label);

	glPushMatrix();
		glColor4f(r,g,b,a);
		glTranslatef(0,0,-2.65); // XXX magic number
		glBegin(GL_QUAD_STRIP);
			glTexCoord2f(0,1);  glVertex3f(1-x*2+w,1-y*2-h,0);
			glTexCoord2f(0,0);  glVertex3f(1-x*2+w,1-y*2+h,0);

			glTexCoord2f(1,1);  glVertex3f(1-x*2-w,1-y*2-h,0);
			glTexCoord2f(1,0);  glVertex3f(1-x*2-w,1-y*2+h,0);
		glEnd();
	glPopMatrix();
}
Example #24
0
	// 5.1 Affiche du texte avec
	// Le texte est passé dans l'argument "a_ecrire" 
	// la police est celle définie par la constante POLICE_NAME 
	//           dans graphics.c
	// la taille est passée en argument
	// l'argument p de type POINT est le point en haut à gauche
	// à partir duquel le texte s'affiche
	// la COULEUR C passée en argument est la couleur d'affichage
	// Nécessite l'installation  de SDL_ttf.h
void aff_pol(char *a_ecrire, int taille, POINT p, COULEUR C)
	{
	#ifdef SDL_TTF_OK
	    int i;
	    SDL_Color color;
	    SDL_Surface *texte = NULL;
	    SDL_Rect position;
	    static int premiere_fois = 1;
	    static TTF_Font *police[256];
//	    TTF_Font *pol;
		int style;
	    
	    // Initialisation de la police (n'est fait qu'une seule fois pour les tailles < 256)
	    if (premiere_fois)  { TTF_Init(); for (i=0;i<256;i++) police[i] = NULL; premiere_fois = 0; ___pol = NULL;}
	    if (___pol) style = TTF_GetFontStyle(___pol); else style = NORMAL;
	    if (taille>=256) ___pol = TTF_OpenFont(POLICE_NAME, taille);
		    else {
			 if (police[taille]==NULL) police[taille] = TTF_OpenFont(POLICE_NAME, taille);
		         ___pol = police[taille];
			 }
	    SDL_GetRGB(C,SDL_screen->format,&(color.r),&(color.g),&(color.b));
		TTF_SetFontStyle(___pol,style);

//		___pol = pol;
	    /* Ecriture du texte dans la SDL_Surface "texte" en mode Blended (optimal) */
	    if (___pol) texte = TTF_RenderText_Blended(___pol, a_ecrire, color); else texte = NULL;
	    if (texte)  {
		    	position.x = p.x;
		    	position.y = HEIGHT - p.y;
		    	SDL_BlitSurface(texte, NULL, SDL_screen, &position); /* Blit du texte par-dessus */
	            	if (SDL_AFFICHE_AUTO) affiche_all();
			SDL_FreeSurface(texte);
		    	}
		    else printf("%s\n",a_ecrire);
/*	
	    if (SDL_AFFICHE_AUTO) affiche_all();
	    if (police) TTF_CloseFont(police);
	    TTF_Quit();
	    if (texte) SDL_FreeSurface(texte);
*/
	#else 
		taille = 0; p.x = p.y = 0; C = 0;
		printf("%s\n",a_ecrire);
	#endif
	}
Example #25
0
int affListeInventaire(int tabObjet[10], int deplaList, int listType,SDL_Surface *fenetreListe,SDL_Surface *ecran,SDL_Surface *texte,SDL_Rect positionFenetreListe, SDL_Rect postexte,sMESS_ITEMS *items_data,TTF_Font *police,SDL_Color noire)
{

    //affichage liste

SDL_BlitSurface(fenetreListe,NULL,ecran,&positionFenetreListe);
SDL_Flip(ecran);

int listeActive=10;
int affichageinventaire=0,pos=0,anaItems=0,numObjets=0;

for (affichageinventaire=listeActive-10;affichageinventaire<listeActive;affichageinventaire++)
    {
        postexte.x=123;
        postexte.y=195+pos;

    if (items_data->data[affichageinventaire].categorie==listType && items_data->data[affichageinventaire].possede==1)
        {
            if (anaItems>=deplaList)
                {
                    texte = TTF_RenderText_Blended(police ,items_data->data[affichageinventaire].name,noire);
                    SDL_BlitSurface(texte,NULL,ecran,&postexte);
                    pos=pos+67;
                    tabObjet[numObjets]=affichageinventaire;
                    numObjets++;
                }
            else
                {
                    affichageinventaire++;
                    listeActive++;
                    anaItems++;
                }
        }
    else if (affichageinventaire>100)
        {
            affichageinventaire = listeActive;
        }
    else
        {
            listeActive++;
        }

    }
return tabObjet[10];
}
Example #26
0
Texture Texture_createText(const char* s, int p, SDL_Color c, int wl)
{
	SDL_Surface* swap = NULL;

	Texture texture;
	texture.raw = NULL;
	texture.type = TEXTURE_UNFINISHED;

	if(wl <= 0)
		swap = TTF_RenderText_Blended(GAME_FONT, s, c);

	if(wl > 0)
		swap = TTF_RenderText_Blended_Wrapped(GAME_FONT, s, c, wl);

	if(swap == NULL)
	{
		throw_warning("Failed to render text! Returning empty texture.");
		return texture;
	}

	texture.raw = SDL_CreateTextureFromSurface(RENDERER, swap);

	if(texture.raw == NULL)
	{
		throw_warning("Failed to create texture! Returning empty texture.");
		SDL_FreeSurface(swap);
		return texture;
	}

	texture.cropX = 0;
	texture.cropY = 0;
	texture.cropW = 0;
	texture.cropH = 0;

	texture.positionX = 0;
	texture.positionY = 0;
	texture.sizeX = (float)strlen(s) * p;
	texture.sizeY = (float)p;

	SDL_FreeSurface(swap);

	texture.type = TEXTURE_TEXT;

	return texture;
}
Example #27
0
int vultures_put_text (int font_id, const char *str, SDL_Surface *dest, int x, int y, Uint32 color)
{
    SDL_Surface * textsurface;
    SDL_Color fontcolor;
    SDL_Rect dstrect;
    char * cleaned_str;
    int len, i;

    if (font_id >= VULTURES_MAX_FONTS || (!vultures_fonts[font_id].fontptr) || !str)
        return FALSE;

    /* sanitize the input string of unprintable characters */
    len = strlen(str);
    cleaned_str = (char *)malloc(len+1);
    strcpy(cleaned_str, str);
    for (i = 0; i < len; i++)
        if (!isprint(cleaned_str[i]))
            cleaned_str[i] = ' ';


    /* extract components from the 32-bit color value */
    fontcolor.r = (color & dest->format->Rmask) >> dest->format->Rshift;
    fontcolor.g = (color & dest->format->Gmask) >> dest->format->Gshift;
    fontcolor.b = (color & dest->format->Bmask) >> dest->format->Bshift;
    fontcolor.unused = 0;

    textsurface = TTF_RenderText_Blended(vultures_fonts[font_id].fontptr, cleaned_str, fontcolor);
    if (!textsurface)
    {
        free(cleaned_str);
        return FALSE;
    }

    free(cleaned_str);

    dstrect.x = x;
    dstrect.y = y - 1;
    dstrect.w = textsurface->w;
    dstrect.h = textsurface->h;

    SDL_BlitSurface(textsurface, NULL, dest, &dstrect);
    SDL_FreeSurface(textsurface);
    
    return TRUE;
}
Example #28
0
File: menu.c Project: graue/spray
void displaytext(const char *text)
{
	TTF_Font *font = NULL;
	SDL_Color textcolor;
	SDL_Surface *textsurface;
	SDL_Rect dest;
	int textwidth, textheight;

	/* happy orange */
	textcolor.r = 255;
	textcolor.g = 192;
	textcolor.b = 0;

	if (TTF_Init() < 0)
		error("Font error: %s", TTF_GetError());

	font = TTF_OpenFont("font.ttf", 48);

	if (font == NULL)
		error("Font error: %s", TTF_GetError());

	if (TTF_SizeText(font, text, &textwidth, &textheight) < 0)
		error("Font error: %s", TTF_GetError());

	if (textwidth >= WIDTH || textheight >= HEIGHT)
		error("Font is too big (%dx%d)", textwidth, textheight);

	dest.x = WIDTH/2  - textwidth/2;
	dest.y = HEIGHT/2 - textheight/2;
	dest.w = textwidth;
	dest.h = textheight;

	textsurface = TTF_RenderText_Blended(font, text, textcolor);

	if (!textsurface)
		error("Font error: %s", TTF_GetError());

	SDL_BlitSurface(textsurface, NULL, getscreen(), &dest);
	SDL_FreeSurface(textsurface);
	SDL_UpdateRect(getscreen(), 0, 0, 0, 0);

	TTF_CloseFont(font);
	font = NULL;
	TTF_Quit();
}
GLuint* afficheVagues(GLuint *textureId, int vague){

    char valeur[25] = "Vague : ";
    sprintf(valeur+8, "%d", vague);

    TTF_Font *police = NULL;
    SDL_Surface *texte = NULL;
    SDL_Color couleurBlanche = {255, 255, 255};
    /* Chargement de la police */
    police = TTF_OpenFont("images/hoog0656.ttf", 20);

    // Bind the texture object
    glEnable(GL_TEXTURE_2D);
    glBindTexture( GL_TEXTURE_2D, textureId[10]);
    // Set the texture's stretching properties
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glLoadIdentity();
    glTranslatef(350,680,1);
    //////////////
    /////VAGUE////
    //////////////
    /* Écriture du texte dans la SDL_Surface texte en mode Blended (optimal) */
    texte = TTF_RenderText_Blended(police, valeur, couleurBlanche);
    // Edit the texture object's image data using the information SDL_Surface gives us
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, texte->w, texte->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texte->pixels );
    glBegin(GL_QUADS);
    glColor3ub(255,255,255);
    glTexCoord2f(1, 0);
    glVertex2f(0+texte->w, 80+texte->h);
    glTexCoord2f(0, 0);
    glVertex2f(0, 80+texte->h);
    glTexCoord2f(0, 1);
    glVertex2f(0,80);
    glTexCoord2f(1, 1);
    glVertex2f(0+texte->w, 80);
    glEnd();

    glBindTexture( GL_TEXTURE_2D, 0 );
    glDisable(GL_TEXTURE_2D);
    TTF_CloseFont(police);
    SDL_FreeSurface(texte);

    return textureId;
}
void Controller::GameWindowController::LoadNoMoreMoves(const char* str, int w, int h, int x, int y)
{
	TTF_Font* textFont = gameWindowModel->GetTextFont();

	SDL_Color textColor = gameWindowModel->GetTextColor();

	SDL_Surface* textSurface = TTF_RenderText_Blended(textFont, str, textColor);

	SDL_Rect rect;
	rect.h = h;
	rect.w = w;
	rect.x = x;
	rect.y = y;

	gameWindowModel->SetNoMoreMovesRect(&rect);

	gameWindowModel->SetNoMoreMovesStr(&textSurface);
}