Hey everyone, needing a little hand...

i'm using the SDL on windows and all the right libraries are installed correctly, I know this because all my other functions that need these libraries worked and still do, but my

SDL_Surface* pFontSurface;

variable my print text method creates a compile error.

~The error states that i cant use a right hand operand to assign whether my font is shaded, solid, etc. As no such operator was found or there is no acceptable conversion.

The next 2 comments are in order my .h file and my .cpp file regarding this little problem...

Thanks for any help....!

The problem is in the printText() method

#ifndef __SDLCANVAS_H_
#define __SDLCANVAS_H_

#include "STDAFX.h"

extern enum textquality {solid, shaded, blended};
/** This object is used as an attempt to encapsulate the more common
* tasks or operations when working with graphics
*/
class SDLCanvas
{
protected:
  SDL_Surface* pSurface; /** our SDL_Surface for drawing */
  SDL_Surface* pFontSurface; // surface for fonts
  TTF_Font* pFont; //our true type font
  
public:
  /** constructor */
  SDLCanvas();

  /** destructor */
  ~SDLCanvas();

  /** This function just creates the video surface according to our
  * needs
  * @param int    - width of video surface
  * @param int    - heigh of video surface
  * @param int    - bits-per-pixel of surface
  * @param bool   - windowed or fullscreen?
  * @return bool - true if everything's ok
  */
  bool createCanvas( int width, int height, int depth, bool windowed = true );

  /** destroy our video surface */
  void destroyCanvas();

  //this function is used to load the specified TrueType font 
  //use by the SDL canvas object. For now it only supports 
  //one font at a time because thats all I need.... 
  bool createFont( char* strFontFace, int size );
  
  //this  method prints the desired text to the screen using 
  //the true type library  

 //Heres where the problem is...
  void printText( char fgR, char fgG, char fgB, char fgA, char bgR, char bgG, 
	             char bgB, char bgA, char* strText, textquality quality );




};




#endif

And heres my .cpp file....

#include "SDLCanvas.h"
 

SDLCanvas::SDLCanvas()
{
  pSurface = NULL;
}

SDLCanvas::~SDLCanvas()
{
  destroyCanvas();
}

bool SDLCanvas::createCanvas(int width, int height, int bpp, bool windowed)
{
      
     int flags = SDL_SWSURFACE;

	 pSurface = SDL_SetVideoMode(width, height, bpp, flags);
	 if(NULL == pSurface)
	   return false;

     return true;
}

void SDLCanvas::destroyCanvas()
{
     if(pSurface)
	{
		SDL_FreeSurface( pSurface );
	}
    
}
 
bool SDLCanvas::createFont( char* strFontFace, int size )
{

 if( TTF_Init() < 0 )
 {
   //error loading the library...
   return false;
 }

 pFont = TTF_OpenFont(strFontFace, size);
 if (pFont == NULL)
 {
   //error loading font...
   return false;
 }

 return true;
} 


void SDLCanvas::printText( char fgR, char fgG, char fgB, char fgA, 
			               char bgR, char bgG, char bgB, char bgA, 
				           char* strText, textquality quality ) 
{   

	SDL_Color fgColor = {fgR, fgG, fgB, fgA}; 
	SDL_Color bgColor = {bgR, bgG, bgB, bgA}; 

	if (quality == solid) 
	{ 
		*pFontSurface = TTF_RenderText_Solid( pFont, strText, 
			                                  fgColor ); 
	
	}else if (quality == shaded) 
	{ 
		*pFontSurface = TTF_RenderText_Shaded( pFont, strText, 
			                                   fgColor,
											   bgColor); 
	}else if (quality == blended) 
	{ 
		*pFontSurface = TTF_RenderText_Blended( pFont, strText, 
			                                    fgColor ); 
	} 
}

sorry about the formatting.... its not that weird in my compiler...

This article has been dead for over six months. Start a new discussion instead.