<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SDL Tutorial &#8211; Tic Tac Toe</title>
	<atom:link href="http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/</link>
	<description>SDL Tutorials - Game Tutorials - Programming Tutorials</description>
	<lastBuildDate>Thu, 11 Mar 2010 22:05:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Shade</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-8/#comment-6749</link>
		<dc:creator>Shade</dc:creator>
		<pubDate>Wed, 17 Feb 2010 12:09:56 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6749</guid>
		<description>Hi all. I&#039;ve compiled successfully the code but, during the execution, it doesn&#039;t use the alpha channel showing up also the pink areas of the images.
This happens because (as it&#039;s written into documentation) the SDL_SetColorKey() method should be called before the SDL_DisplayFormatAlpha() method to use the alpha blit and the colorkey features.
I hope this could be useful.

Shade</description>
		<content:encoded><![CDATA[<p>Hi all. I&#8217;ve compiled successfully the code but, during the execution, it doesn&#8217;t use the alpha channel showing up also the pink areas of the images.<br />
This happens because (as it&#8217;s written into documentation) the SDL_SetColorKey() method should be called before the SDL_DisplayFormatAlpha() method to use the alpha blit and the colorkey features.<br />
I hope this could be useful.</p>
<p>Shade</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Jones</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-8/#comment-6216</link>
		<dc:creator>Tim Jones</dc:creator>
		<pubDate>Fri, 08 Jan 2010 15:05:48 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6216</guid>
		<description>Restler,
TTF_RenderText_Blended simply creates a new SDL surface from text and doesn&#039;t do anything else. So yes, you need to then do a call to OnDraw to display the surface. If you want to do it in one call, then have your PrintText method call OnDraw for you.</description>
		<content:encoded><![CDATA[<p>Restler,<br />
TTF_RenderText_Blended simply creates a new SDL surface from text and doesn&#8217;t do anything else. So yes, you need to then do a call to OnDraw to display the surface. If you want to do it in one call, then have your PrintText method call OnDraw for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Restler</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-8/#comment-6215</link>
		<dc:creator>Restler</dc:creator>
		<pubDate>Fri, 08 Jan 2010 15:01:33 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6215</guid>
		<description>Still not updating :/
I think I misunderstand TTF_RenderText_Blended(). Do I even have to call OnDraw() after I call this OnLoad  function(which will change name as soon as I fixed it :P)?</description>
		<content:encoded><![CDATA[<p>Still not updating :/<br />
I think I misunderstand TTF_RenderText_Blended(). Do I even have to call OnDraw() after I call this OnLoad  function(which will change name as soon as I fixed it <img src='http://www.sdltutorials.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Jones</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-8/#comment-6206</link>
		<dc:creator>Tim Jones</dc:creator>
		<pubDate>Thu, 07 Jan 2010 17:40:12 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6206</guid>
		<description>Restler,
I think you&#039;re confused in your method. Look at the line:

surface=surf_Return;
SDL_FreeSurface(surf_Return);

Remember, both surface and surf_Return are pointer, and because you did an equal operator on them, they are both pointing to the same thing. So, when you call SDL_FreeSurface on one, it affects the other as well. Basically, your function should look like this:

SDL_Surface* CSurface::OnLoad(SDL_Surface *surface, TTF_Font *font, std::string str, SDL_Color clr){
if(surface) {
SDL_FreeSurface(surface);
}
if((surface=TTF_RenderText_Blended(font, str.c_str(), clr))==NULL){
return NULL;
}
return surface;
}

Also, I would probably call it PrintText or something, OnLoad doesn&#039;t make much sense for what it&#039;s doing.</description>
		<content:encoded><![CDATA[<p>Restler,<br />
I think you&#8217;re confused in your method. Look at the line:</p>
<p>surface=surf_Return;<br />
SDL_FreeSurface(surf_Return);</p>
<p>Remember, both surface and surf_Return are pointer, and because you did an equal operator on them, they are both pointing to the same thing. So, when you call SDL_FreeSurface on one, it affects the other as well. Basically, your function should look like this:</p>
<p>SDL_Surface* CSurface::OnLoad(SDL_Surface *surface, TTF_Font *font, std::string str, SDL_Color clr){<br />
if(surface) {<br />
SDL_FreeSurface(surface);<br />
}<br />
if((surface=TTF_RenderText_Blended(font, str.c_str(), clr))==NULL){<br />
return NULL;<br />
}<br />
return surface;<br />
}</p>
<p>Also, I would probably call it PrintText or something, OnLoad doesn&#8217;t make much sense for what it&#8217;s doing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Restler</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-8/#comment-6205</link>
		<dc:creator>Restler</dc:creator>
		<pubDate>Thu, 07 Jan 2010 17:16:06 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6205</guid>
		<description>Oh, my OnLoad function looked something like this before, but I didn&#039;t think it did matter that much:

SDL_Surface* CSurface::OnLoad(SDL_Surface *surface, TTF_Font *font, std::string str, SDL_Color clr){
	SDL_Surface *surf_Return=NULL;
	if((surf_Return=TTF_RenderText_Blended(font, str.c_str(), clr))==NULL){
		return NULL;
	}
	surface=NULL;
	surface=surf_Return;
	SDL_FreeSurface(surf_Return);
	return surface;
}

Thanks!
And I&#039;ve tried so many things to get it to re-render but it simply doesn&#039;t :( I&#039;ve called both OnLoad() and OnDraw() in different places, e.g. in Point() when changing msg, I&#039;ve also tried to call both in OnRender() but not even the initial text is shown now. I thought that the order of OnLoop() and OnRender() may play a roll in the main loop, but nope, nothing happend except for that bug that made me unable to close (or even minimize) the program :P
I don&#039;t really understand what I&#039;m doing wrong here...</description>
		<content:encoded><![CDATA[<p>Oh, my OnLoad function looked something like this before, but I didn&#8217;t think it did matter that much:</p>
<p>SDL_Surface* CSurface::OnLoad(SDL_Surface *surface, TTF_Font *font, std::string str, SDL_Color clr){<br />
	SDL_Surface *surf_Return=NULL;<br />
	if((surf_Return=TTF_RenderText_Blended(font, str.c_str(), clr))==NULL){<br />
		return NULL;<br />
	}<br />
	surface=NULL;<br />
	surface=surf_Return;<br />
	SDL_FreeSurface(surf_Return);<br />
	return surface;<br />
}</p>
<p>Thanks!<br />
And I&#8217;ve tried so many things to get it to re-render but it simply doesn&#8217;t <img src='http://www.sdltutorials.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  I&#8217;ve called both OnLoad() and OnDraw() in different places, e.g. in Point() when changing msg, I&#8217;ve also tried to call both in OnRender() but not even the initial text is shown now. I thought that the order of OnLoop() and OnRender() may play a roll in the main loop, but nope, nothing happend except for that bug that made me unable to close (or even minimize) the program <img src='http://www.sdltutorials.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
I don&#8217;t really understand what I&#8217;m doing wrong here&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ersan Güray</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-7/#comment-6203</link>
		<dc:creator>Ersan Güray</dc:creator>
		<pubDate>Thu, 07 Jan 2010 01:18:13 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6203</guid>
		<description>Many thanks Tim, my next step is to put visual attraction when one wins. ;)</description>
		<content:encoded><![CDATA[<p>Many thanks Tim, my next step is to put visual attraction when one wins. <img src='http://www.sdltutorials.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Jones</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-7/#comment-6201</link>
		<dc:creator>Tim Jones</dc:creator>
		<pubDate>Wed, 06 Jan 2010 19:45:16 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6201</guid>
		<description>Restler,
The primary problem is that you have to re-render your Text surface every time the message is changed. So, whenever you modify your msg string, you need to re-render surf_Text. Also, please keep in mind that this creates a new surface every time - so you need to Free the old text surface if you want to update it when new text.</description>
		<content:encoded><![CDATA[<p>Restler,<br />
The primary problem is that you have to re-render your Text surface every time the message is changed. So, whenever you modify your msg string, you need to re-render surf_Text. Also, please keep in mind that this creates a new surface every time &#8211; so you need to Free the old text surface if you want to update it when new text.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Restler</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-7/#comment-6200</link>
		<dc:creator>Restler</dc:creator>
		<pubDate>Wed, 06 Jan 2010 19:39:34 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6200</guid>
		<description>The text is supposed to show the points, like a statboard you know. I made  the surf_Display 600x800 so the last 200px are supposed to be used for that purpose:

In CApp.h:
#include 
#include 
using namespace std;
class...{
...
private:
SDL_Surface *surf_Text;
std::string msg;
TTF_Font *f;
};

in CApp::CApp(){
...
surf_Text=NULL;
msg=&quot;Tic Tac Toe&quot;;
}

in OnInit(){
  if(TTF_Init()==-1){
    return false;
  }
  if((f=TTF_OpenFont(&quot;C:\\WINDOWS\\Fonts\\arial.ttf&quot;, 36))==NULL){
    return false;
  }
  SDL_Color color={255, 255, 255}; //for some reason I had to declare and initiate color simultaniously, it didn&#039;t work to declare it in CApp.h and initiate it hear...
  if((surf_Text=CSurface::OnLoad(f, msg, color))==NULL){
    return false;
  }
}
surf_Text is made with a function to load text. In CSurface.h:
  #include 
  #include 
  ...
  public:
    static SDL_Surface *OnLoad(TTF_Font *font, std::string str, SDL_Color clr);

In CSurface.cpp:
  SDL_Surface* CSurface::OnLoad(TTF_Font *font, std::string str, SDL_Color clr){
    SDL_Surface *surf_Return=NULL;
    if((surf_Return=TTF_RenderText_Blended(font, str.c_str(), clr))==NULL){
      return NULL;
    }else
      return surf_Return;
}

Now I should be able to use OnDraw() normally, so in OnRender(){
  ...  
  if(winner==X_WINS){
    CSurface::OnDraw(surf_Display, surf_WinX, 100, 200);
    CSurface::OnDraw(surf_Display, surf_Text, 200, 260);
  }
  ...
  SDL_Flip(surf_Display);
}

Also, in OnLoop.cpp I have a function stating:
void CApp::Points(int winner){
	if(winner==1){
		winsX++;
		msg=&quot;X: &quot;+winsX++;
	}else if(winner==2){
		winsO++;
		msg=&quot;O: &quot;+winsO++;
	}
}

and lastly in OnCleanup(){
... 
  SDL_FreeSurface(surf_Text);
  TTF_CloseFont(f);
  TTF_Quit();
  SDL_Quit();
}

I don&#039;t get any errors but the text stays on &quot;Tic Tac Toe&quot;, which I think means it doesn&#039;t update when msg is changed in Points(int);
(I also noticed that when I had this code implemented, I couldn&#039;t close the application normally.)

Hopefully that was descriptive enough ^^&#039;
Thanks again</description>
		<content:encoded><![CDATA[<p>The text is supposed to show the points, like a statboard you know. I made  the surf_Display 600&#215;800 so the last 200px are supposed to be used for that purpose:</p>
<p>In CApp.h:<br />
#include<br />
#include<br />
using namespace std;<br />
class&#8230;{<br />
&#8230;<br />
private:<br />
SDL_Surface *surf_Text;<br />
std::string msg;<br />
TTF_Font *f;<br />
};</p>
<p>in CApp::CApp(){<br />
&#8230;<br />
surf_Text=NULL;<br />
msg=&#8221;Tic Tac Toe&#8221;;<br />
}</p>
<p>in OnInit(){<br />
  if(TTF_Init()==-1){<br />
    return false;<br />
  }<br />
  if((f=TTF_OpenFont(&#8220;C:\\WINDOWS\\Fonts\\arial.ttf&#8221;, 36))==NULL){<br />
    return false;<br />
  }<br />
  SDL_Color color={255, 255, 255}; //for some reason I had to declare and initiate color simultaniously, it didn&#8217;t work to declare it in CApp.h and initiate it hear&#8230;<br />
  if((surf_Text=CSurface::OnLoad(f, msg, color))==NULL){<br />
    return false;<br />
  }<br />
}<br />
surf_Text is made with a function to load text. In CSurface.h:<br />
  #include<br />
  #include<br />
  &#8230;<br />
  public:<br />
    static SDL_Surface *OnLoad(TTF_Font *font, std::string str, SDL_Color clr);</p>
<p>In CSurface.cpp:<br />
  SDL_Surface* CSurface::OnLoad(TTF_Font *font, std::string str, SDL_Color clr){<br />
    SDL_Surface *surf_Return=NULL;<br />
    if((surf_Return=TTF_RenderText_Blended(font, str.c_str(), clr))==NULL){<br />
      return NULL;<br />
    }else<br />
      return surf_Return;<br />
}</p>
<p>Now I should be able to use OnDraw() normally, so in OnRender(){<br />
  &#8230;<br />
  if(winner==X_WINS){<br />
    CSurface::OnDraw(surf_Display, surf_WinX, 100, 200);<br />
    CSurface::OnDraw(surf_Display, surf_Text, 200, 260);<br />
  }<br />
  &#8230;<br />
  SDL_Flip(surf_Display);<br />
}</p>
<p>Also, in OnLoop.cpp I have a function stating:<br />
void CApp::Points(int winner){<br />
	if(winner==1){<br />
		winsX++;<br />
		msg=&#8221;X: &#8220;+winsX++;<br />
	}else if(winner==2){<br />
		winsO++;<br />
		msg=&#8221;O: &#8220;+winsO++;<br />
	}<br />
}</p>
<p>and lastly in OnCleanup(){<br />
&#8230;<br />
  SDL_FreeSurface(surf_Text);<br />
  TTF_CloseFont(f);<br />
  TTF_Quit();<br />
  SDL_Quit();<br />
}</p>
<p>I don&#8217;t get any errors but the text stays on &#8220;Tic Tac Toe&#8221;, which I think means it doesn&#8217;t update when msg is changed in Points(int);<br />
(I also noticed that when I had this code implemented, I couldn&#8217;t close the application normally.)</p>
<p>Hopefully that was descriptive enough ^^&#8217;<br />
Thanks again</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Jones</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-7/#comment-6199</link>
		<dc:creator>Tim Jones</dc:creator>
		<pubDate>Wed, 06 Jan 2010 12:31:03 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6199</guid>
		<description>Restler,
There are no differences between the two, as they both end up as SDL Surfaces. What text are you trying to render? Can you paste some code?</description>
		<content:encoded><![CDATA[<p>Restler,<br />
There are no differences between the two, as they both end up as SDL Surfaces. What text are you trying to render? Can you paste some code?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Restler</title>
		<link>http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/comment-page-7/#comment-6197</link>
		<dc:creator>Restler</dc:creator>
		<pubDate>Tue, 05 Jan 2010 21:31:54 +0000</pubDate>
		<guid isPermaLink="false">http://devhub.lostfish.org/sdl-tutorial-4/#comment-6197</guid>
		<description>Hello again, I have trouble updating the ttf-text! The idea was that, for every game over, a winner is appointed and the points are updated. I made three BMPs with &quot;X wins&quot;/&quot;O wins&quot;/&quot;Draw&quot; and they now work properly, thanks to Tim on: http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/#comment-4356  :D
The texts however render once but never updates, although I make them into surfaces and do exactly the same way as with the pics. Are there differences between rendering pic-surfaces and text-pic-surfaces (made with surface=RenderText_Blended(...))? I tried googling but failed to find any answer on that. :(</description>
		<content:encoded><![CDATA[<p>Hello again, I have trouble updating the ttf-text! The idea was that, for every game over, a winner is appointed and the points are updated. I made three BMPs with &#8220;X wins&#8221;/&#8221;O wins&#8221;/&#8221;Draw&#8221; and they now work properly, thanks to Tim on: <a href="http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/#comment-4356" rel="nofollow">http://www.sdltutorials.com/sdl-tutorial-tic-tac-toe/#comment-4356</a>  <img src='http://www.sdltutorials.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
The texts however render once but never updates, although I make them into surfaces and do exactly the same way as with the pics. Are there differences between rendering pic-surfaces and text-pic-surfaces (made with surface=RenderText_Blended(&#8230;))? I tried googling but failed to find any answer on that. <img src='http://www.sdltutorials.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
