<?xml version='1.0' encoding='utf-8'?>
<rss version='2.0'>
   <channel>
      <title>Programming and Web Development Tutorials</title>
      <link>http://tutorials.dreamincode.net</link>
      <description>Web Development, Programming, and Coding Community. Browse forums, snippets, and tutorials to get you on the right track. Experts in C++, PHP, VisualBasic, HTML, JavaScript, ColdFusion, and more!</description>
         <item>
            <link>http://forums.dreamincode.net/showtopic67058.htm</link>
            <title>wxWidgets Part III: Creating a Notepad application in C++ Tutorials</title>
            <description>&lt;!--sizeo:4--&gt;&lt;span style=&quot;font-size:14pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;wxWidgets Part III&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;br /&gt;&lt;!--sizeo:3--&gt;&lt;span style=&quot;font-size:12pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;Creating a notepad&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://www.dreamincode.net/forums/index.php?act=Attach&amp;amp;type=post&amp;amp;id=8602&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;In this tutorial, we&amp;#39;re going to take quite a big step~ but one that I think is manageable. It&amp;#39;s possible to make a notepad application in just 74 lines, with plenty of line spacing. We&amp;#39;re going to look at:&lt;ul&gt;&lt;li&gt;Event handling&lt;/li&gt;&lt;li&gt;Creating a menu bar&lt;ul&gt;&lt;li&gt;The wxMenuBar class&lt;/li&gt;&lt;li&gt;The wxMenu class&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;The wxTextCtrl class&lt;/li&gt;&lt;/ul&gt; &lt;br /&gt;Before I start, I&amp;#39;d like to say that &lt;i&gt;I know&lt;/i&gt; it&amp;#39;s best to split classes across seperate files. But I&amp;#39;m putting all of this in one file so that it&amp;#39;s more concise, and easier to read.&lt;br /&gt;&lt;br /&gt;So, let&amp;#39;s get started on our program&amp;#33;&lt;br /&gt;&lt;br /&gt;First off, let&amp;#39;s include the main wx header: [code=cpp]#include &amp;lt;wx/wx.h&amp;gt;[/code]&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;!--sizeo:3--&gt;&lt;span style=&quot;font-size:12pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;Designing the class&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;/b&gt;&lt;br /&gt;Next, we need to start writing our Notepad class~ It&amp;#39;s going to inherit a wxFrame. I&amp;#39;ve commented it plenty so that you can see what&amp;#39;s going on: [code=cpp]class Notepad : public wxFrame {&lt;br /&gt;    public:&lt;br /&gt;        Notepad(); // our default constructor&lt;br /&gt;&lt;br /&gt;    private:&lt;br /&gt;        wxMenuBar *menu; // the menu bar&lt;br /&gt;        wxMenu *file; // the file menu (keep this simple&lt;br /&gt;        wxTextCtrl *text; // the main text area&lt;br /&gt;        void OnSave(wxCommandEvent &amp;amp;event); // the click event for &amp;quot;save&amp;quot;&lt;br /&gt;        void OnOpen(wxCommandEvent &amp;amp;event); // the click event for &amp;quot;open&amp;quot;&lt;br /&gt;        void OnExit(wxCommandEvent &amp;amp;event); // the click event for &amp;quot;close&amp;quot;&lt;br /&gt;        // declare some ID values for our menu items&lt;br /&gt;        // these can be anything, but I personally tend to start from 1,000&lt;br /&gt;        enum MenuControls {&lt;br /&gt;            idSave = 1000,&lt;br /&gt;            idOpen, idExit&lt;br /&gt;        };&lt;br /&gt;        // this bit&amp;#39;s important~&lt;br /&gt;        // it&amp;#39;s a macro, which is basically saying we want to define some events&lt;br /&gt;        // (events such as clicking menu items in the menu)&lt;br /&gt;        DECLARE_EVENT_TABLE()&lt;br /&gt;};[/code]&lt;br /&gt;Clear? It should be. Basically, we&amp;#39;ve only got one thing which is public, and that&amp;#39;s the constructor for our notepad. Next, we have some private objects, the menu bar, the menu, and the text area. This should be pretty simple at the minute, there&amp;#39;s no new syntax up until that last line... what&amp;#39;s this? [il]DECLARE_EVENT_TABLE()[/il]&lt;br /&gt;A macro. By doing this, we&amp;#39;re basically saying that our application should have some event handlers, which we define in something called an &lt;i&gt;event table&lt;/i&gt; in a moment.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;!--sizeo:3--&gt;&lt;span style=&quot;font-size:12pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;Defining an event table&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;/b&gt;&lt;br /&gt;This bit&amp;#39;s new. It&amp;#39;s a great way to assign event handlers when you get used to it. An event table is basically where we assign functions to specific events using those IDs we created earlier. Basically, by passing a number and a method name, we assign that method name a value, or a key. This key is then assigned to items later (in this case, menu items) as the event handler. Don&amp;#39;t worry if this doesn&amp;#39;t make sense right now, it will become clear later on. [code=cpp]BEGIN_EVENT_TABLE(Notepad, wxFrame) // begin the event table for our Notepad class, which inherits wxFrame&lt;br /&gt;    EVT_MENU(idSave, Notepad::OnSave) // set an event for our idSave, and the function OnSave&lt;br /&gt;    EVT_MENU(idOpen, Notepad::OnOpen) // set an event for open&lt;br /&gt;    EVT_MENU(idExit, Notepad::OnExit) // set an event for exit&lt;br /&gt;END_EVENT_TABLE() // end the event table[/code]&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;!--sizeo:3--&gt;&lt;span style=&quot;font-size:12pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;The constructor&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;/b&gt;&lt;br /&gt;As with any OOP program that you&amp;#39;ve written in the past, we need to set up our object in the constructor. In the constructor for our notepad application, we need to add some menu items to the menu, add the menu to the menu bar, and add the text area to the main frame. Sounds like a lot, but it&amp;#39;s actually quite simple.&lt;br /&gt;Our constructor is actually going to do a default operation to the wxFrame constructor. We do this like so: [code=cpp]Notepad::Notepad() : wxFrame(NULL, wxID_ANY, wxT(&amp;quot;wxNotepad&amp;quot;), wxDefaultPosition, wxSize(650,500)) {[/code] I know, I know~ it&amp;#39;s long. But once this class is done, we don&amp;#39;t have to do anything to it, other than show it.&lt;br /&gt;&lt;br /&gt;Next, we need to instantiate our menu and our menu bar: [code=cpp]    this-&amp;gt;menu = new wxMenuBar(); // instantiate our menu bar&lt;br /&gt;    this-&amp;gt;file = new wxMenu(); // instantiate our file menu for our menu bar[/code]&lt;br /&gt;That was simple&amp;#33;&lt;br /&gt;&lt;br /&gt;Now it&amp;#39;s time to [il]Append()[/il] an item to our menu. Here, we&amp;#39;re going to pass two parameters: &lt;ol type='1'&gt;&lt;li&gt;The ID number of our event handler~ this is where that enum comes in handy. Remember how we did this in the event table:&lt;br /&gt;[il]EVT_MENU(idSave, Notepad::OnSave) // set an event for our idSave, and the function OnSave[/il]&lt;br /&gt;So, we&amp;#39;re passing that idSave index to Append() as if to say &amp;quot;we&amp;#39;re going to associate [il]Notepad::OnSave[/il] as the event handler.&lt;/li&gt;&lt;li&gt;A wxString, formatted in a specific way: The text (with an ampersand (&amp;amp;) to signify which key shortcut to use, a tab (&amp;#092;t) and then the keyboard shortcut, which is assigned automatically according to the string we pass now. Great, it&amp;#39;s done automatically&amp;#33;&lt;/li&gt;&lt;/ol&gt;[code=cpp]this-&amp;gt;file-&amp;gt;Append(idSave, wxT(&amp;quot;&amp;amp;Save File&amp;#092;tCtrl-S&amp;quot;)); // add a save option to the menu bar[/code]**Remember that we use [il]wxT(&amp;quot;&amp;quot;)[/il] to format a string as a wxString.&lt;br /&gt;&lt;br /&gt;Next, we&amp;#39;re going to add an &amp;quot;Open&amp;quot; option, using a similar process to the last line: [code=cpp]this-&amp;gt;file-&amp;gt;Append(idOpen, wxT(&amp;quot;&amp;amp;Open File&amp;#092;tCtrl-O&amp;quot;));[/code]&lt;br /&gt;And now it&amp;#39;s time to add a separator, before the exit option. We can do this very simply, by calling one function (which doesn&amp;#39;t need parameters) [code=cpp]this-&amp;gt;file-&amp;gt;AppendSeparator();[/code]&lt;br /&gt;Lastly, let&amp;#39;s add an exit option: [code=cpp]this-&amp;gt;file-&amp;gt;Append(idExit, wxT(&amp;quot;E&amp;amp;xit&amp;#092;tCtrl-F4&amp;quot;));[/code]&lt;br /&gt;Next, we&amp;#39;re going to append that file menu to our menu bar. This is also as simple as calling the Append function. It takes two parameters, the actual menu to add, and the name of the menu (what to display in the menu bar) [code=cpp]this-&amp;gt;menu-&amp;gt;Append(file, wxT(&amp;quot;&amp;amp;File&amp;quot;));[/code]&lt;br /&gt;The last thing we need to do for the menu bar is actually apply it to the application, which can be done very simply: [code=cpp]this-&amp;gt;SetMenuBar(menu); // set our menu bar to be visible on the application[/code]&lt;br /&gt;Now it&amp;#39;s time for the last line of our constructor&amp;#33; Wahey&amp;#33;&lt;br /&gt;&lt;br /&gt;Basically, all we need to do now is add the text area itself, which is quite simple~ the wxTextCtrl constructor takes quite a lot of arguments, each of which I&amp;#39;m going to explain now: &lt;ol type='1'&gt;&lt;li&gt;The first parameter is the parent, so we pass this (this is the owner)&lt;/li&gt;&lt;li&gt;wxID_ANY ~ the ID of the control. Since it doesn&amp;#39;t matter, we can just pass wxID_ANY&lt;/li&gt;&lt;li&gt;The third, wxt(&amp;quot;&amp;quot;) is the text to put in the text area straight away. We pass an empty string here&lt;/li&gt;&lt;li&gt;wxDefaultPosition: the position of the control&lt;/li&gt;&lt;li&gt;wxDefaultSize: the size of the control&lt;/li&gt;&lt;li&gt;And lastly, we have the style~ we want two styles here, wxTE_MULTILINE and wxTE_PROCESS_ENTER. This way, we enable multi-line editing, and allow the user to press enter to move on to a new line. (Otherwise, the enter keypress is processed internally)&lt;/li&gt;&lt;/ol&gt;[code=cpp]    this-&amp;gt;text = new wxTextCtrl(this, wxID_ANY, wxT(&amp;quot;&amp;quot;), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_MULTILINE);&lt;br /&gt;} // end of the constructor&amp;#33;[/code]&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;!--sizeo:3--&gt;&lt;span style=&quot;font-size:12pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;Defining those events~ what to do, what to do?&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;/b&gt;&lt;br /&gt;First off, the save event. We need to create a save dialog, show it, and check if the user clicked OK. If they did, then we want to save the contents to a file (which is very simple)&lt;br /&gt;So, let&amp;#39;s open up that function&amp;#33; [code=cpp]void Notepad::OnSave(wxCommandEvent &amp;amp;event) {[/code] &lt;br /&gt;First off, we need to create a FileDialog. If you&amp;#39;re coming from developing in .NET, you&amp;#39;ll probably be thinking that you can use a SaveFileDialog. WRONG&amp;#33; We use a [il]wxFileDialog[/il], and specify that we want it to be a save dialog within the parameters. [code=cpp]    wxFileDialog *saveDialog = new wxFileDialog(this, wxT(&amp;quot;Save File~&amp;quot;), wxT(&amp;quot;&amp;quot;), wxT(&amp;quot;&amp;quot;),&lt;br /&gt;                                                wxT(&amp;quot;Text Files (*.txt)|*.txt|C++ Files (*.cpp)|*.cpp&amp;quot;), wxSAVE);[/code]&lt;br /&gt;This is another one which takes a lot of parameters, so I&amp;#39;ll explain them all now: &lt;ol type='1'&gt;&lt;li&gt;this ~ the parent of the object&lt;/li&gt;&lt;li&gt;wxT(&amp;quot;Save File~&amp;quot;) ~ the title of the dialog&lt;/li&gt;&lt;li&gt;The next two, I&amp;#39;ve passed empty strings. These are the default directory, and the default file. (You can define them if you wish, but you don&amp;#39;t have to)&lt;/li&gt;&lt;li&gt;Next, we have the filter. The filter accepts a specific format: &amp;quot;the text to display|*.filetype|another type|*.otherfiletype&amp;quot; (if you&amp;#39;re familiar with .NET, you should be familiar with this)&lt;/li&gt;&lt;li&gt;And lastly, the style of the dialog: wxSAVE, since we want a save dialog&lt;/li&gt;&lt;/ol&gt; &lt;br /&gt;Next, we actually need to display the dialog box, and determine what the user pressed (OK or Cancel) After that, we save the contents of the text area to the file specified: [code=cpp]int response = saveDialog-&amp;gt;ShowModal();&lt;br /&gt;    if (response == wxID_OK) { // if the user clicked OK, we should save the text&lt;br /&gt;        this-&amp;gt;text-&amp;gt;SaveFile(saveDialog-&amp;gt;GetPath()); // this is pretty cool. we can save it with just one line&amp;#33;&lt;br /&gt;        // wxTextCtrl has a member function called SaveFile, which you simple pass the path to and it will save&lt;br /&gt;        // our dialog has a member function called GetPath, which will return the entire path and file name&lt;br /&gt;    }&lt;br /&gt;} // end of the event handler[/code]&lt;br /&gt;&lt;br /&gt;Since the open file event is almost identical, I&amp;#39;ll post the code now~ the only difference is that we specify wxOPEN instead of wxSAVE: [code=cpp]void Notepad::OnOpen(wxCommandEvent &amp;amp;event) {&lt;br /&gt;    wxFileDialog *openDialog = new wxFileDialog(this, wxT(&amp;quot;Open File~&amp;quot;), wxT(&amp;quot;&amp;quot;), wxT(&amp;quot;&amp;quot;),&lt;br /&gt;                                                wxT(&amp;quot;Text Files (*.txt)|*.txt|C++ Files (*.cpp)|*.cpp&amp;quot;), wxOPEN);&lt;br /&gt;    int response = openDialog-&amp;gt;ShowModal();&lt;br /&gt;    if (response == wxID_OK) {&lt;br /&gt;        this-&amp;gt;text-&amp;gt;LoadFile(openDialog-&amp;gt;GetPath());&lt;br /&gt;    }&lt;br /&gt;}[/code]&lt;br /&gt;&lt;br /&gt;And the last event is the close event. This one is simple, it&amp;#39;s only one line long. We call [il]Destroy()[/il] to basically dispose of the window and any resources used:[code=cpp]void Notepad::OnExit(wxCommandEvent &amp;amp;event) {&lt;br /&gt;    this-&amp;gt;Destroy(); // close the window, and get clear any resources used (eg, memory)&lt;br /&gt;}[/code]&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;!--sizeo:3--&gt;&lt;span style=&quot;font-size:12pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;Almost there... Let&amp;#39;s implement it in our app&amp;#33;&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;/b&gt;&lt;br /&gt;And now for the bit that you&amp;#39;ve been waiting for. Implementing the app, so we can actually compile it&amp;#33; w00t&amp;#33; This shouldn&amp;#39;t be anything new, provided that you&amp;#39;ve read &lt;a href=&quot;http://www.dreamincode.net/forums/showtopic66948.htm&quot; target=&quot;_blank&quot;&gt;Part II&lt;/a&gt;. [code=cpp]class MainApp : public wxApp {&lt;br /&gt;    public: // remember this from part 2? very simple from here on in, we&amp;#39;re almost done&lt;br /&gt;        virtual bool OnInit();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;bool MainApp::OnInit() {&lt;br /&gt;    // create a new Notepad (we used a wxFrame in part 2)&lt;br /&gt;    Notepad *main = new Notepad();&lt;br /&gt;    main-&amp;gt;Show(true); // show it&lt;br /&gt;&lt;br /&gt;    return true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// and lastly, we just have to implement our application&amp;#33;&lt;br /&gt;IMPLEMENT_APP(MainApp)[/code]&lt;br /&gt;Now, compile and run~ you should have a basic notepad application&amp;#33; Note that you don&amp;#39;t have the keyboard shortcuts to copy, paste, etc~ but if you highlight some text, and right click, you get a pretty big context menu, with plenty of options. And if you&amp;#39;re feeling up to the task, you could try adding them as a new menu to your menu bar&amp;#33;&lt;br /&gt;&lt;br /&gt;And finally, here is the entire program, just in case you got lost along the way: [code=cpp]#include &amp;lt;wx/wx.h&amp;gt;&lt;br /&gt;&lt;br /&gt;class Notepad : public wxFrame {&lt;br /&gt;    public:&lt;br /&gt;        Notepad(); // our default constructor&lt;br /&gt;&lt;br /&gt;    private:&lt;br /&gt;        wxMenuBar *menu; // the menu bar&lt;br /&gt;        wxMenu *file; // the file menu (keep this simple&lt;br /&gt;        wxTextCtrl *text; // the main text area&lt;br /&gt;        void OnSave(wxCommandEvent &amp;amp;event); // the click event for &amp;quot;save&amp;quot;&lt;br /&gt;        void OnOpen(wxCommandEvent &amp;amp;event); // the click event for &amp;quot;open&amp;quot;&lt;br /&gt;        void OnExit(wxCommandEvent &amp;amp;event); // the click event for &amp;quot;close&amp;quot;&lt;br /&gt;        // declare some ID values for our menu items&lt;br /&gt;        // these can be anything, but I personally tend to start from 1,000&lt;br /&gt;        enum MenuControls {&lt;br /&gt;            idSave = 1000,&lt;br /&gt;            idOpen, idExit&lt;br /&gt;        };&lt;br /&gt;        // this bit&amp;#39;s important~&lt;br /&gt;        // it&amp;#39;s a macro, which is basically saying we want to define some events&lt;br /&gt;        // (events such as clicking menu items in the menu)&lt;br /&gt;        DECLARE_EVENT_TABLE()&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// this is our event table, where we assign functions to specific events&lt;br /&gt;// using those IDs we created earlier&lt;br /&gt;// basically, by passing a number and a method name, we assign that method name a value, or a key&lt;br /&gt;// this key is then assigned to items later (in this case, menu items) as the event handler&lt;br /&gt;// don&amp;#39;t worry if this doesn&amp;#39;t make sense right now, it will become clear later on&lt;br /&gt;BEGIN_EVENT_TABLE(Notepad, wxFrame) // begin the event table for our Notepad class, which inherits wxFrame&lt;br /&gt;    EVT_MENU(idSave, Notepad::OnSave) // set an event for our idSave, and the function OnSave&lt;br /&gt;    EVT_MENU(idOpen, Notepad::OnOpen) // set an event for open&lt;br /&gt;    EVT_MENU(idExit, Notepad::OnExit) // set an event for exit&lt;br /&gt;END_EVENT_TABLE() // end the event table&lt;br /&gt;&lt;br /&gt;// our constructor, which does all this stuff for the wxFrame constructor&lt;br /&gt;// this makes it easier to simply create our notepad object later~&lt;br /&gt;Notepad::Notepad() : wxFrame(NULL, wxID_ANY, wxT(&amp;quot;wxNotepad&amp;quot;), wxDefaultPosition, wxSize(650,500)) {&lt;br /&gt;    this-&amp;gt;menu = new wxMenuBar(); // instantiate our menu bar&lt;br /&gt;    this-&amp;gt;file = new wxMenu(); // instantiate our file menu for our menu bar&lt;br /&gt;    this-&amp;gt;file-&amp;gt;Append(idSave, wxT(&amp;quot;&amp;amp;Save File&amp;#092;tCtrl-S&amp;quot;)); // add a save option to the menu bar&lt;br /&gt;    // note how we passed &amp;quot;idSave&amp;quot; as the first argument? This means that we&amp;#39;re assigning OnSave&lt;br /&gt;    // as an event handler when the user clicks the save menu item&lt;br /&gt;    // now we do the same for our &amp;quot;open&amp;quot; option, assigning the OnOpen event to it&lt;br /&gt;    this-&amp;gt;file-&amp;gt;Append(idOpen, wxT(&amp;quot;&amp;amp;Open File&amp;#092;tCtrl-O&amp;quot;));&lt;br /&gt;    this-&amp;gt;file-&amp;gt;AppendSeparator(); // add a separator (between our file I/O options and our exit option&lt;br /&gt;    this-&amp;gt;file-&amp;gt;Append(idExit, wxT(&amp;quot;E&amp;amp;xit&amp;#092;tCtrl-F4&amp;quot;)); // add an exit option to the file menu&lt;br /&gt;    this-&amp;gt;menu-&amp;gt;Append(file, wxT(&amp;quot;&amp;amp;File&amp;quot;)); // add the file menu to the menubar, and give it the title &amp;quot;File&amp;quot;&lt;br /&gt;    this-&amp;gt;SetMenuBar(menu); // set our menu bar to be visible on the application&lt;br /&gt;&lt;br /&gt;    // lastly in our constructor, we&amp;#39;re going to add the text area~ we need to pass quite a few parameters here&lt;br /&gt;    // the first parameter is the parent, so we pass this (this is the owner)&lt;br /&gt;    // wxID_ANY ~ the ID of the control. Since it doesn&amp;#39;t matter, we can just pass wxID_ANY&lt;br /&gt;    // the third, wxt(&amp;quot;&amp;quot;) is the text to put in the text area straight away. We pass an empty string here&lt;br /&gt;    // wxDefaultPosition: the position of the control&lt;br /&gt;    // wxDefaultSize: the size of the control&lt;br /&gt;    // and lastly, we have the style~ we want two styles here, wxTE_MULTILINE and wxTE_PROCESS_ENTER&lt;br /&gt;    // this way, we enable multi-line editing, and allow the user to press enter to move on to a new line&lt;br /&gt;    this-&amp;gt;text = new wxTextCtrl(this, wxID_ANY, wxT(&amp;quot;&amp;quot;), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_MULTILINE);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// now it&amp;#39;s time to define our save event (for when the user clicks &amp;quot;Save&amp;quot;&lt;br /&gt;void Notepad::OnSave(wxCommandEvent &amp;amp;event) {&lt;br /&gt;    // first, we create a wxFileDialog, which takes a number of parameters&lt;br /&gt;    // this ~ the parent of the object&lt;br /&gt;    // wxt(&amp;quot;Save File~&amp;quot;) ~ the title of the dialog&lt;br /&gt;    // the next two, I&amp;#39;ve passed empty strings. These are the default directory, and the default file&lt;br /&gt;    // (you can define them if you wish, but you don&amp;#39;t have to)&lt;br /&gt;    // next, we have the filter. The filter accepts a specific format:&lt;br /&gt;    // &amp;quot;the text to display|*.filetype|another type|*.otherfiletype&lt;br /&gt;    // and lastly, the style of the dialog: wxSAVE, since we want a save dialog&lt;br /&gt;    wxFileDialog *saveDialog = new wxFileDialog(this, wxT(&amp;quot;Save File~&amp;quot;), wxT(&amp;quot;&amp;quot;), wxT(&amp;quot;&amp;quot;),&lt;br /&gt;                                                wxT(&amp;quot;Text Files (*.txt)|*.txt|C++ Files (*.cpp)|*.cpp&amp;quot;), wxSAVE);&lt;br /&gt;    // next, we display the dialog box&lt;br /&gt;    // it will return one of 2 values: wxID_OK, or wxID_CANCEL (whichever button the user clicked)&lt;br /&gt;    int response = saveDialog-&amp;gt;ShowModal();&lt;br /&gt;    if (response == wxID_OK) { // if the user clicked OK, we should save the text&lt;br /&gt;        this-&amp;gt;text-&amp;gt;SaveFile(saveDialog-&amp;gt;GetPath()); // this is pretty cool. we can save it with just one line&amp;#33;&lt;br /&gt;        // wxTextCtrl has a member function called SaveFile, which you simple pass the path to and it will save&lt;br /&gt;        // our dialog has a member function called GetPath, which will return the entire path and file name&lt;br /&gt;    }&lt;br /&gt;} // end of the event handler&lt;br /&gt;&lt;br /&gt;// next, we have our open dialog, which is practically the same as our save dialog, so I won&amp;#39;t go into detail&lt;br /&gt;// note how we pass wxOPEN instead of wxSAVE as the style though~&lt;br /&gt;void Notepad::OnOpen(wxCommandEvent &amp;amp;event) {&lt;br /&gt;    wxFileDialog *openDialog = new wxFileDialog(this, wxT(&amp;quot;Open File~&amp;quot;), wxT(&amp;quot;&amp;quot;), wxT(&amp;quot;&amp;quot;),&lt;br /&gt;                                                wxT(&amp;quot;Text Files (*.txt)|*.txt|C++ Files (*.cpp)|*.cpp&amp;quot;), wxOPEN);&lt;br /&gt;    int response = openDialog-&amp;gt;ShowModal();&lt;br /&gt;    if (response == wxID_OK) {&lt;br /&gt;        this-&amp;gt;text-&amp;gt;LoadFile(openDialog-&amp;gt;GetPath());&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// if the user clicks exit (from the menu) then we should close the window&lt;br /&gt;void Notepad::OnExit(wxCommandEvent &amp;amp;event) {&lt;br /&gt;    this-&amp;gt;Destroy(); // close the window, and get clear any resources used (eg, memory)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// now all that&amp;#39;s left is the implementation&amp;#33; we need to create our MainApp class&lt;br /&gt;class MainApp : public wxApp {&lt;br /&gt;    public: // remember this from part 2? very simple from here on in, we&amp;#39;re almost done&lt;br /&gt;        virtual bool OnInit();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;bool MainApp::OnInit() {&lt;br /&gt;    // create a new Notepad (we used a wxFrame in part 2)&lt;br /&gt;    Notepad *main = new Notepad();&lt;br /&gt;    main-&amp;gt;Show(true); // show it&lt;br /&gt;&lt;br /&gt;    return true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// and lastly, we just have to implement our application&amp;#33;&lt;br /&gt;IMPLEMENT_APP(MainApp)[/code]&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;!--sizeo:3--&gt;&lt;span style=&quot;font-size:12pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;Where do I go from here?&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;/b&gt;&lt;br /&gt;Well, that&amp;#39;s it for this series of tutorials (for now, at least)&lt;br /&gt;If there&amp;#39;s anything that you&amp;#39;re still not sure of, please feel free to leave a comment on this tutorial, requesting one~ hopefully, I&amp;#39;ll be able to get it done within 24-48 hours of you requesting it.&lt;br /&gt;&lt;br /&gt;Remember that you can check out the &lt;a href=&quot;http://docs.wxwidgets.org/&quot; target=&quot;_blank&quot;&gt;wxWidgets documentation&lt;/a&gt; if you get stuck along the way. Also, keep an eye on &lt;a href=&quot;http://www.dreamincode.net/?p=kudos&amp;amp;kudosmember=68172&quot; target=&quot;_blank&quot;&gt;my contributions&lt;/a&gt;~ you never know when a tutorial or snippet might crop up.&lt;br /&gt;&lt;br /&gt;Happy coding&amp;#33; &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;</description>
			<pubDate>Fri, 10 Oct 2008 11:55:38 -0600</pubDate>
			<category>C++ Tutorials</category>
			<author>gabehabe</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic66970.htm</link>
            <title>C++ templates and operator overloading basics in C++ Tutorials</title>
            <description>Nice write up &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/icon_up.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:^:&quot; border=&quot;0&quot; alt=&quot;icon_up.gif&quot; /&gt;</description>
			<pubDate>Fri, 10 Oct 2008 05:16:36 -0600</pubDate>
			<category>C++ Tutorials</category>
			<author>gabehabe</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic66948.htm</link>
            <title>wxWidgets Part II: Hello, wxWidgets&#33; in C++ Tutorials</title>
            <description>&lt;!--sizeo:4--&gt;&lt;span style=&quot;font-size:14pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;wxWidgets: Part II&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;br /&gt;&lt;!--sizeo:3--&gt;&lt;span style=&quot;font-size:12pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;Hello, wxFrame&amp;#33;&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;br /&gt;&lt;br /&gt;So, hopefully you&amp;#39;ve read &lt;a href=&quot;http://www.dreamincode.net/forums/showtopic66934.htm&quot; target=&quot;_blank&quot;&gt;part one&lt;/a&gt;, and got a development environment set up. In this tutorial, we&amp;#39;re actually going to start writing some code&amp;#33; Hooray&amp;#33; OMG, code FTW, right? Right&amp;#33;&lt;br /&gt;&lt;br /&gt;The end result isn&amp;#39;t going to be the most impressive thing in the world, but it&amp;#39;s an important one~ wxWidgets is actually quite short and to the point, but the program structure is very different compared to your typical C++ program. The code may look a little confusing at first, but for those of you who have made a window using the Win32 API, you&amp;#39;ll know what I mean when I say this:&lt;br /&gt;It&amp;#39;s short. You can create a window in just 15 lines, with plenty of spacing to see what&amp;#39;s going on.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NOTE:&lt;/b&gt; My example is 15 lines long with spacing. Many examples out on the web actually use about 26, because they design a class which is not necessary at this stage. I&amp;#39;m making this as simple as possible to demostrate the pure power of the wxWidgets toolkit.&lt;br /&gt;&lt;br /&gt;This tutorial is going to be brief, but it&amp;#39;s important that you understand the structure of the program itself before we get in-depth. When writing a wxWidgets application, you don&amp;#39;t even have to write a main() function&amp;#33; &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/ohmy.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:o&quot; border=&quot;0&quot; alt=&quot;ohmy.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Like I said before, wxWidgets is short and to the point. It also heavily focuses on object oriented program. If you don&amp;#39;t have any experience with objects, I &lt;i&gt;strongly&lt;/i&gt; recommend that you read up on them before getting into this code.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Before we start, what do we need to include?&lt;/b&gt;&lt;br /&gt;We actually only need to include one header in our application. It&amp;#39;s the main wxWidgets header file: [code=cpp]#include &amp;lt;wx/wx.h&amp;gt;[/code]&lt;br /&gt;&lt;b&gt;Writing the MainApp class&lt;/b&gt;&lt;br /&gt;This is going to be our main application, as the name suggests. We&amp;#39;re going to create a class, and inherit [il]wxApp[/il]. All that we need to do is override one virtual function: [il]bool OnInit();[/il]&lt;br /&gt;&lt;br /&gt;This is basically the function that will be called when our class is initialised. So, without further ado, let&amp;#39;s get started&amp;#33; [code=cpp]class MainApp : public wxApp {&lt;br /&gt;    public:&lt;br /&gt;        virtual bool OnInit();&lt;br /&gt;};[/code]&lt;br /&gt;How simple is that?&amp;#33; And it doesn&amp;#39;t get too much more difficult, either.&lt;br /&gt;&lt;br /&gt;Let&amp;#39;s now define this [il]OnInit()[/il] function. So, we want to create a wxFrame, and show it. Simple as that&amp;#33; The constructor for a wxFrame takes quite a few parameters, which I&amp;#39;ll cover soon: [code=cpp]bool MainApp::OnInit() {&lt;br /&gt;    wxFrame *content = new wxFrame(NULL, wxID_ANY, wxT(&amp;quot;Hello cliche&amp;#33; Hello wxWidgets&amp;#33;&amp;quot;), wxDefaultPosition, wxSize(350, 150));&lt;br /&gt;    content-&amp;gt;Show(true);&lt;br /&gt;&lt;br /&gt;    return true;&lt;br /&gt;}[/code]&lt;br /&gt;Can you believe that there&amp;#39;s only one line left after this? &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/ohmy.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:o&quot; border=&quot;0&quot; alt=&quot;ohmy.gif&quot; /&gt; How great is this?&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What are all these things in the wxFrame constructor, then?&lt;/b&gt;&lt;br /&gt;The first parameter is the parent of the wxFrame being created. We&amp;#39;re passing NULL~ this is the main wxFrame, and it isn&amp;#39;t going to have a parent.&lt;br /&gt;&lt;br /&gt;Secondly, we have the window ID. wxID_ANY is basically just saying it can be any ID, it doesn&amp;#39;t matter. You can pass -1 as the ID, which is the default ID.&lt;br /&gt;&lt;br /&gt;The third parameter is the title of the window. We have something else that&amp;#39;s completely new here: [il]wxT(&amp;quot;text&amp;quot;);[/il]&lt;br /&gt;Well, wxWidgets has pretty much got it&amp;#39;s own everything. Including its own string class, called... yep, you guessed it: wxString. [il]wxT()[/il] is basically a quick way to format a string.&lt;br /&gt;&lt;br /&gt;The fourth parameter is the location of the window. We&amp;#39;re passing wxDefaultPosition, to give our wxFrame a default start position. Makes sense, doesn&amp;#39;t it? &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Lastly, we have [il]wxSize(int width, int height)[/il] which basically defines the size of our window.&lt;br /&gt;&lt;br /&gt;So after breaking it up, it should make a lot more sense. Lastly, we&amp;#39;ve got this [il]content-&amp;gt;Show(true);[/il] which is simply saying that we want to show our wxFrame on the screen.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;And finally, that last line&amp;#33; No main here&amp;#33;&lt;/b&gt;&lt;br /&gt;All we have to do now is &lt;i&gt;implement our application&lt;/i&gt;. (Our wxApp class, which we called MainApp)&lt;br /&gt;We can do this in one line: [code=cpp]IMPLEMENT_APP(MainApp)[/code]&lt;br /&gt;&lt;b&gt;NOTE THAT THERE IS NO SEMI-COLON&lt;/b&gt;&lt;br /&gt;This probably seems weird to you, but like I said before, wxWidgets pretty much just follows its own rules. You&amp;#39;ll see a lot of stuff like this in the coming tutorials.&lt;br /&gt;&lt;br /&gt;Here&amp;#39;s the complete code: [code=cpp]#include &amp;lt;wx/wx.h&amp;gt;&lt;br /&gt;&lt;br /&gt;class MainApp : public wxApp {&lt;br /&gt;    public:&lt;br /&gt;        virtual bool OnInit();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;bool MainApp::OnInit() {&lt;br /&gt;    wxFrame *content = new wxFrame(NULL, wxID_ANY, wxT(&amp;quot;Hello cliche&amp;#33; Hello wxWidgets&amp;#33;&amp;quot;), wxDefaultPosition, wxSize(350, 150));&lt;br /&gt;    content-&amp;gt;Show(true);&lt;br /&gt;&lt;br /&gt;    return true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;IMPLEMENT_APP(MainApp)[/code]&lt;br /&gt;(Like I said, it&amp;#39;s very concise)&lt;br /&gt;&lt;br /&gt;Until next time~&lt;br /&gt;&lt;br /&gt;Happy coding&amp;#33; &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;</description>
			<pubDate>Thu, 09 Oct 2008 15:47:40 -0600</pubDate>
			<category>C++ Tutorials</category>
			<author>gabehabe</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic66945.htm</link>
            <title>Beginner&#39;s Guide to PHP-GTK in PHP Tutorials</title>
            <description>Nice guide. Thanks  &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/biggrin.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:D&quot; border=&quot;0&quot; alt=&quot;biggrin.gif&quot; /&gt;</description>
			<pubDate>Sun, 12 Oct 2008 10:55:46 -0600</pubDate>
			<category>PHP Tutorials</category>
			<author>weldan</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic66934.htm</link>
            <title>wxWidgets Part I: Getting set up in C++ Tutorials</title>
            <description>Welcome to the wonderful world of wxWidgets&amp;#33; In this series of tutorials, I&amp;#39;m going to be explaining how to develop software in C++ using wxWidgets.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;So, what&amp;#39;s this wxWidgets stuff?&lt;/b&gt;&lt;br /&gt;wxWidgets is a very interesting toolkit, which is compatible with pretty much any operating system&amp;#33; That&amp;#39;s right, you can make your software for a whole range of platforms, including:&lt;ul&gt;&lt;li&gt;Win32&lt;/li&gt;&lt;li&gt;Mac OS X&lt;/li&gt;&lt;li&gt;GTK+&lt;/li&gt;&lt;li&gt;X11&lt;/li&gt;&lt;li&gt;Motif&lt;/li&gt;&lt;li&gt;WinCE&lt;/li&gt;&lt;li&gt;and more&amp;#33;&lt;/li&gt;&lt;/ul&gt; &lt;br /&gt;It&amp;#39;s compatible with a whole bunch of languages, including C++, Perl and C# ~ but in these tutorials, I&amp;#39;ll be covering development in C++&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What should I already know?&lt;/b&gt;&lt;br /&gt;As with all programming concepts, it&amp;#39;s important that you&amp;#39;ve got a good understanding of as many of the key principals as possible. Loops, functions, etc~ oh, and object oriented programming (OOP) is a must&amp;#33;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;OK, OK~ let me get started&amp;#33;&lt;/b&gt;&lt;br /&gt;It can be quite tedious to set up wxWidgets. Unfortunately, I can only cover the setup for Windows~ sorry everyone else&amp;#33; You can check out the &lt;a href=&quot;http://wiki.wxwidgets.org/Main_Page&quot; target=&quot;_blank&quot;&gt;wxWiki&lt;/a&gt;, you should be able to find everything you need there. Also, if you have any questions, let me know and I&amp;#39;ll do my best to help. &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;br /&gt;&lt;b&gt;So let&amp;#39;s get started&lt;/b&gt;&lt;br /&gt;Wait... what do we need? Well, a compiler. Obviously. You&amp;#39;ll also need to download wxWidgets, and preferably an IDE. (My choice: Code::Blocks)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Where can I get all this stuff from?&lt;/b&gt;&lt;br /&gt;First off, get your compiler. &lt;a href=&quot;http://www.mingw.org/&quot; target=&quot;_blank&quot;&gt;MinGW&lt;/a&gt; is a great compiler for Windows, and that&amp;#39;s what I&amp;#39;ll be using. The Microsoft installer is available from &lt;a href=&quot;http://downloads.sourceforge.net/mingw/MinGW-5.1.4.exe?modtime=1209244789&amp;amp;big_mirror=1&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;As I mentioned earlier, my IDE of choice is &lt;a href=&quot;http://www.codeblocks.org/&quot; target=&quot;_blank&quot;&gt;Code::Blocks&lt;/a&gt;. It&amp;#39;s cross platform, but since this tutorial covers Windows, you can get the Windows installer directly from &lt;a href=&quot;http://sourceforge.net/project/downloading.php?groupname=codeblocks&amp;amp;filename=codeblocks-8.02-setup.exe&amp;amp;use_mirror=dfn&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Last but certainly not least, you&amp;#39;re going to need the &lt;a href=&quot;http://www.wxwidgets.org/&quot; target=&quot;_blank&quot;&gt;wxWidgets&lt;/a&gt; toolkit itself&amp;#33; The Microsoft installer is available &lt;a href=&quot;http://sourceforge.net/project/downloading.php?groupname=wxwindows&amp;amp;filename=wxMSW-2.8.9-Setup.exe&amp;amp;use_mirror=heanet&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;, and for you non-Windows users, check out the downloads page &lt;a href=&quot;http://www.wxwidgets.org/downloads/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;OK, so what now? Install your compiler (MinGW) and wxWidgets. Install them to the root of your drive, so on Windows, you should have:&lt;br /&gt;&lt;b&gt;C:/MinGW&lt;/b&gt;&lt;br /&gt;&lt;b&gt;C:/wxWidgets-2.8.9&lt;/b&gt; (or some other version)&lt;br /&gt;&lt;br /&gt;Now you&amp;#39;re going to need to clean and compile the source code.  Fortunately for you Windows user though, I&amp;#39;ve set up a nice little batch script to do all the work for you. If you want to get it set up automatically, use &lt;a href=&quot;http://www.dreamincode.net/code/snippet2597.htm&quot; target=&quot;_blank&quot;&gt;this batch script.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you want to do it manually, all you have to do is follow the code in that snippet, typing each command into the command line. (NOT RECOMMENDED&amp;#33;)&lt;br /&gt;(Remember that REM is simply a comment, and not part of the code)&lt;br /&gt;&lt;br /&gt;So now it&amp;#39;s time to set up Code::Blocks. This bit&amp;#39;s pretty easy. Install it (preferably to the default directory in Program Files, but it doesn&amp;#39;t matter) and run the exe.&lt;br /&gt;&lt;br /&gt;You should now be in front of your new favourite IDE. &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Go to File&amp;gt;New&amp;gt;Project, and find wxWidgets Project. (It should be right at the bottom)&lt;br /&gt;&lt;br /&gt;Follow the instructions until you reach a dialog asking which version you want to use. This should be self explanatory, but (at the time of writing this tutorial) wxWidgets 2.8.x is the latest, so select that.&lt;br /&gt;&lt;br /&gt;Next, it will probably ask you to set up wxWidgets. Open the Global Variable Editor, and paste this into the &amp;quot;base&amp;quot; text box:&lt;br /&gt;[il]C:&amp;#092;wxWidgets-2.8.9[/il] (or wherever you installed it to)&lt;br /&gt;&lt;br /&gt;Now click close, and continue on through the setup.&lt;br /&gt;&lt;br /&gt;You will now be asked to select the setting which match your installation. Check all three boxes (they should be &amp;quot;driver&amp;quot; &amp;quot;monolithic&amp;quot; and &amp;quot;unicode.&amp;quot;) If you read the batch script, this will make sense. If not, don&amp;#39;t worry about it, it&amp;#39;s not important. &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Continue on through the project setup, and you should eventually have a template prepared for you. This bit&amp;#39;s important:&lt;br /&gt;&lt;b&gt;YOU CAN ONLY COMPILE FOR &amp;quot;RELEASE&amp;quot;&lt;/b&gt;&lt;br /&gt;This is because we configured wxWidgets for release earlier (again, you&amp;#39;ll know if you read the batch script. Don&amp;#39;t worry if you didn&amp;#39;t)&lt;br /&gt;&lt;br /&gt;So, change the Build target to Release, and hit F9 (Compile and run)&lt;br /&gt;&lt;br /&gt;That&amp;#39;s it&amp;#33; You should now have a window open, built using the example code from the Code::Blocks template&amp;#33;&lt;br /&gt;&lt;br /&gt;*Note: I apologise if the end setup (for Code::Blocks) is a little off. I had to do this from memory, since it&amp;#39;s only necessary to do it once. &lt;br /&gt;&lt;br /&gt;And that&amp;#39;s it&amp;#33; It was a long setup, but over the next tutorials in this series, you&amp;#39;re going to find out why it was worth it&amp;#33;&lt;br /&gt;&lt;br /&gt;Happy coding&amp;#33; &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;***Please feel free to ask &lt;i&gt;any&lt;/i&gt; questions regarding this setup. I know it can be tedious, I had problems myself when setting it up. I&amp;#39;ll do my best to answer them. &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;</description>
			<pubDate>Thu, 09 Oct 2008 14:06:58 -0600</pubDate>
			<category>C++ Tutorials</category>
			<author>gabehabe</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic66480.htm</link>
            <title>Perlin Noise in C++ Tutorials</title>
            <description>Hi there, guys&lt;br /&gt;&lt;br /&gt;I&amp;#39;m here to teach you something about Perlin Noise. You know, that magical thing that gives infinite possibilties and is usefull in every single game.&lt;br /&gt;&lt;br /&gt;To be honest with you, it&amp;#39;s not that very difficult, but it can be if it&amp;#39;s not explained right.&lt;br /&gt;&lt;br /&gt;First, the theoratical side:&lt;br /&gt;&lt;br /&gt;Now, what exactly is perlin noise? Well, it is some pseudo random coherent noise. Let me explain that bit by bit:&lt;br /&gt; *Pseudo random: This means that it appears random, but you get the same result twice every time you call it. Think of the rand() function. You might have &lt;br /&gt; noticed that if you not seed it it always will give number 13 as first. If it was to be fully random you would get a different number everytime.&lt;br /&gt; &lt;br /&gt; *Coherent: This means that it is very smooth. Here&amp;#39;s a picture of some non-coherent noise.&lt;br /&gt; &lt;br /&gt;  &lt;img src=&quot;http://img399.imageshack.us/img399/4121/noncoherentso6.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;  This is coherent noise&lt;br /&gt;&lt;br /&gt;  &lt;img src=&quot;http://img145.imageshack.us/img145/739/noisefinishedsk0.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Imagine that you zoom in on that non-coherent noise, and as you zoom in, you see that there are transitions between those pixels, and there you go,&lt;br /&gt;coherent noise&amp;#33;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://img384.imageshack.us/img384/8960/noisemj0.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;But that contrast is a bit high, don&amp;#39;t you, let&amp;#39;s smooth it out a bit:&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://img145.imageshack.us/img145/2033/perlinnoisexq0.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;There we go, looks much better, doesn&amp;#39;t it?&lt;br /&gt;&lt;br /&gt;But if you want to use it as a heightmap, it will be a bit too smooth, don&amp;#39;t you think? Well, let me show you how to improve that by using octaves.&lt;br /&gt;Maybe this image will help explain:&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://img145.imageshack.us/img145/609/octaveswa6.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;So, the smoothed noise is image a. If We zoom out on that noise, we get image b, and if we zoom out on b, u get image c. If u add a,b,c,... U get this:&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://img145.imageshack.us/img145/739/noisefinishedsk0.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;And this is what we are going for.&lt;br /&gt;&lt;br /&gt;Now, lets take that what we have learned and bring it in the practical side.&lt;br /&gt;&lt;br /&gt;First of all, we&amp;#39;ll need a pseudo-random number generator:&lt;br /&gt;&lt;br /&gt;I searched a bit on the web and I came across this one:&lt;br /&gt;&lt;br /&gt; 1D&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;inline double findnoise&amp;#40;double x&amp;#41;&lt;br /&gt;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt; int x = &amp;#40;x&amp;#60;&amp;#60;13&amp;#41; ^ x;&lt;br /&gt; return &amp;#40;double&amp;#41;&amp;#40; 1.0 - &amp;#40; &amp;#40;x * &amp;#40;x * x * 15731 + 789221&amp;#41; + 1376312589&amp;#41; &amp;amp; Ox7fffffff&amp;#41; / 1073741824.0&amp;#41;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Here&amp;#39;s the 2D version&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;inline double findnoise2&amp;#40;double x,double y&amp;#41;&lt;br /&gt;{&lt;br /&gt; int n=&amp;#40;int&amp;#41;x+&amp;#40;int&amp;#41;y*57;&lt;br /&gt; n=&amp;#40;n&amp;#60;&amp;#60;13&amp;#41;^n;&lt;br /&gt; int nn=&amp;#40;n*&amp;#40;n*n*60493+19990303&amp;#41;+1376312589&amp;#41;&amp;amp;0x7fffffff;&lt;br /&gt; return 1.0-&amp;#40;&amp;#40;double&amp;#41;nn/1073741824.0&amp;#41;;&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Don&amp;#39;t ask me how it works because I dont know how it works myself, something with prime numbers... But what I do know is that it returns a value between&lt;br /&gt;-1 and 1, just like our perlin noise function.&lt;br /&gt;&lt;br /&gt;Now, as I&amp;#39;ve explained before, we get coherent noise because we look between the pixels, so our perlin noise function must be able to accept&lt;br /&gt;double numbers. So we have to interpolate between the pixels. Interpolate is like taking the average, but a little bit more complicated. We&amp;#39;ll be using&lt;br /&gt;cosine interpoliation. It gives a very nice effect because it looks like a curve. But I wont explain too much, that&amp;#39;s maybe for another tutorial.&lt;br /&gt;Here is it.&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;inline double interpolate&amp;#40;double a,double b,double x&amp;#41;&lt;br /&gt;{&lt;br /&gt; double ft=x * 3.1415927;&lt;br /&gt; double f=&amp;#40;1.0-cos&amp;#40;ft&amp;#41;&amp;#41;* 0.5;&lt;br /&gt; return a*&amp;#40;1.0-f&amp;#41;+b*f;&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Now you might ask: &amp;quot;Hey, what about the 2D version?&amp;quot;. Well, let me explain this. Let&amp;#39;s take the average of a and b and call it d.&lt;br /&gt;Let&amp;#39;s also take c and d and call it e. And if we take the average of d and e it would equal to the average of a b c and d.&lt;br /&gt;This enables us to stick to 1 dimension, making the code alot easier. Now, I&amp;#39;ll combine these into one function. It uses SDL for image handling.&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;double noise&amp;#40;double x,double y&amp;#41;&lt;br /&gt;{&lt;br /&gt; double floorx=&amp;#40;double&amp;#41;&amp;#40;&amp;#40;int&amp;#41;x&amp;#41;;//This is kinda a cheap way to floor a double integer.&lt;br /&gt; double floory=&amp;#40;double&amp;#41;&amp;#40;&amp;#40;int&amp;#41;y&amp;#41;;&lt;br /&gt; double s,t,u,v;//Integer declaration&lt;br /&gt; s=findnoise2&amp;#40;floorx,floory&amp;#41;; &lt;br /&gt; t=findnoise2&amp;#40;floorx+1,floory&amp;#41;;&lt;br /&gt; u=findnoise2&amp;#40;floorx,floory+1&amp;#41;;//Get the surrounding pixels to calculate the transition.&lt;br /&gt; v=findnoise2&amp;#40;floorx+1,floory+1&amp;#41;;&lt;br /&gt; double int1=interpolate1&amp;#40;s,t,x-floorx&amp;#41;;//Interpolate between the values.&lt;br /&gt; double int2=interpolate1&amp;#40;u,v,x-floorx&amp;#41;;//Here we use x-floorx, to get 1st dimension. Don&amp;#39;t mind the x-floorx thingie, it&amp;#39;s part of the cosine formula.&lt;br /&gt; return interpolate1&amp;#40;int1,int2,y-floory&amp;#41;;//Here we use y-floory, to get the 2nd dimension.&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;And there we are, a perlin noise function. It returns a value between -1 and 1. To convert this to a 0-256 RGB value, we simple multiply it by 128,&lt;br /&gt;then add 128 to it. But in the theory section I mentioned something about octaves, well I&amp;#39;ll show it now. I call this result clouds.&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;SDL_Surface *Render_Clouds&amp;#40;int w,int h,double zoom,double p, int r, int g, int b&amp;#41;//w and h speak for themselves, zoom wel zoom in and out on it, I usually&lt;br /&gt;{//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use 75. P stands for persistence, this controls the roughness of the picture, i use 1/2&lt;br /&gt; int octaves=2;&lt;br /&gt; SDL_Surface *ret=SDL_CreateRGBSurface&amp;#40;SDL_SWSURFACE,w,h,24,0,0,0,0&amp;#41;;//Create an empty image.&lt;br /&gt; for&amp;#40;int y=0;y&amp;#60;h;y++&amp;#41;&lt;br /&gt; {//Loops to loop trough all the pixels&lt;br /&gt;&amp;nbsp;&amp;nbsp;for&amp;#40;int x=0;x&amp;#60;w;x++&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; double getnoise =0;&lt;br /&gt;&amp;nbsp;&amp;nbsp; for&amp;#40;int a=0;a&amp;#60;octaves-1;a++&amp;#41;//This loops trough the octaves.&lt;br /&gt;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double frequency = pow&amp;#40;2,a&amp;#41;;//This increases the frequency with every loop of the octave.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double amplitude = pow&amp;#40;p,a&amp;#41;;//This decreases the amplitude with every loop of the octave.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;getnoise += noise2&amp;#40;&amp;#40;&amp;#40;double&amp;#41;x&amp;#41;*frequency/zoom,&amp;#40;&amp;#40;double&amp;#41;y&amp;#41;/zoom*frequency&amp;#41;*amplitude;//This uses our perlin noise functions. It calculates all our zoom and frequency and amplitude&lt;br /&gt;&amp;nbsp;&amp;nbsp; }//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;It gives a decimal value, you know, between the pixels. Like 4.2 or 5.1&lt;br /&gt;&amp;nbsp;&amp;nbsp; int color= &amp;#40;int&amp;#41;&amp;#40;&amp;#40;getnoise*128.0&amp;#41;+128.0&amp;#41;;//Convert to 0-256 values.&lt;br /&gt;&amp;nbsp;&amp;nbsp; if&amp;#40;color&amp;#62;255&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;color=255;&lt;br /&gt;&amp;nbsp;&amp;nbsp; if&amp;#40;color&amp;#60;0&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;color=0;&lt;br /&gt;&amp;nbsp;&amp;nbsp; SetPixel&amp;#40;ret,x,y,&amp;#40;int&amp;#41;&amp;#40;&amp;#40;r/255.0&amp;#41;*&amp;#40;double&amp;#41;color&amp;#41;,&amp;#40;int&amp;#41;&amp;#40;&amp;#40;g/255.0&amp;#41;*&amp;#40;double&amp;#41;color&amp;#41;,&amp;#40;int&amp;#41;&amp;#40;&amp;#40;b/255.0&amp;#41;*&amp;#40;double&amp;#41;color&amp;#41;&amp;#41;;//This colours the image with the RGB values &lt;br /&gt;&amp;nbsp;&amp;nbsp;}//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; given at the beginning in the function.&lt;br /&gt; }&lt;br /&gt; return ret;&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;And this gives some nice clouds. I hope you enjoyed this tutorial, and I there&amp;#39;s enough request, I&amp;#39;ll make a more in-depth sequel.</description>
			<pubDate>Mon, 06 Oct 2008 14:20:19 -0600</pubDate>
			<category>C++ Tutorials</category>
			<author>manhaeve5</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic66176.htm</link>
            <title>Creating a basic Notepad Application in Java Tutorials</title>
            <description>Nice tutorial&amp;#33; &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/icon_up.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:^:&quot; border=&quot;0&quot; alt=&quot;icon_up.gif&quot; /&gt;</description>
			<pubDate>Sun, 05 Oct 2008 09:55:02 -0600</pubDate>
			<category>Java Tutorials</category>
			<author>Locke37</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic66135.htm</link>
            <title>Flash/Python socket connections and communication in Flash Tutorials</title>
            <description>&lt;b&gt;Before we start&lt;/b&gt; &lt;br /&gt;This tutorial requires that you have Flash and Python installed on your computer. To download Python go here:&lt;br /&gt;&lt;a href=&quot;http://python.org/&quot; target=&quot;_blank&quot;&gt;http://python.org/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;In this tutroail&lt;/b&gt;&lt;br /&gt;We will be creating a simple Flash client side script that will open a socket connection with our server (which we will be creating in Python), recieve a message from the server and send a message to the server, which the server will acknowledge and print out as well.&lt;br /&gt;&lt;br /&gt;NOTE - This tutorial uses the Flash Sandbox, and doesn&amp;#39;t work for general web activity at this point in time.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Creating the server&lt;/b&gt;&lt;br /&gt;The server script for this tutorial is a simple script that will begin listening for socket connections on port number 2727. When a socket connection is made the server will print the client information (IP and socket), print out the data the client sent, and then send a reply to the client.&lt;br /&gt;&lt;br /&gt;Starting out we will need to import the sockets class, otherwise the script is dead in the water:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;import socket&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Now, we need to get the server to allow socket connections, bind to a port, and start listneing for connection attempts.&lt;br /&gt;&lt;br /&gt;This can be done in 3 lines:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;mySocket = socket.socket &amp;#40; socket.AF_INET, socket.SOCK_STREAM &amp;#41;&lt;br /&gt;mySocket.bind &amp;#40; &amp;#40; &amp;#39;&amp;#39;, 2727 &amp;#41; &amp;#41;&lt;br /&gt;mySocket.listen &amp;#40; 5 &amp;#41;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;Basically all that happens is the server creates a variable called [inline]myScoket[/inline] amd sets it to the socket input stream. Then it binds [inline]mySocket[/inline] to no host (defaults to localhost) and port number [inline]2727[/inline]. After that it starts listening for socket connections and will allow a total of [inline]5[/inline] connections to be open at once.&lt;br /&gt;&lt;br /&gt;Now that the hard part is done we need to add a handle for incoming socket connections and messages:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;while True&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;channel, details = mySocket.accept&amp;#40;&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print &amp;#39;We have opened a connection with&amp;#39;, details&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;txt = channel.recv &amp;#40; 100 &amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print txt&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;channel.send &amp;#40; &amp;#34;This is a response test - attempt 1&amp;#092;0&amp;#34; &amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;channel.close&amp;#40;&amp;#41;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;This creates an infinite loop (to keep the application running until you close it) and allow connections. Upon receiving a connection the variables [inline]channel[/inline] and [inline]details[/inline] are set. The details are IP address and socket that the client is communicating from, and the channel is the data stream.&lt;br /&gt;&lt;br /&gt;Once the socket connection has been accepted the server outputs [inline]We have opened a connection with &amp;lt;IP, PORT&amp;gt;[/inline] Then recieves the data which was sent (100 bits at a time until the data stream is finished), and prints the message out. After completing this the server sends a reply to the client in plain text. &lt;br /&gt;&lt;br /&gt;NOTICE - The reply message ends with [inline]&amp;#092;0[/inline] this is a null byte character, which Flash requires to know that the end of the data stream has come.&lt;br /&gt;&lt;br /&gt;And, after the reply is sent the server halts the connection.&lt;br /&gt;&lt;br /&gt;Here is a look at the whole thing:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;import socket&lt;br /&gt;mySocket = socket.socket &amp;#40; socket.AF_INET, socket.SOCK_STREAM &amp;#41;&lt;br /&gt;mySocket.bind &amp;#40; &amp;#40; &amp;#39;&amp;#39;, 2727 &amp;#41; &amp;#41;&lt;br /&gt;mySocket.listen &amp;#40; 5 &amp;#41;&lt;br /&gt;while True&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;channel, details = mySocket.accept&amp;#40;&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print &amp;#39;We have opened a connection with&amp;#39;, details&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;txt = channel.recv &amp;#40; 100 &amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print txt&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;channel.send &amp;#40; &amp;#34;This is a response test - attempt 1&amp;#092;0&amp;#34; &amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;channel.close&amp;#40;&amp;#41;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Flash side&lt;/b&gt;&lt;br /&gt;On the Flash side of life things are a bit easier, all we have to do is create a new [inline]XMLSocket[/inline], tell it what port and host to connect with and give it a few functions on how to act under certain circumstances.&lt;br /&gt;&lt;br /&gt;Starting off, lets create the socket variable:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;var sock&amp;#58;XMLSocket = new XMLSocket&amp;#40;&amp;#41;;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;This, as you would expect, creates a new [inline]XMLSocket[/inline] called [inline]sock[/inline].&lt;br /&gt;&lt;br /&gt;Connecting with the server is as easy as this:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;sock.connect&amp;#40;&amp;#39;localhost&amp;#39;, 2727&amp;#41;;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;Which tells the socket to go for the [inline]localhost[/inline] on port [inline]2727[/inline] - The same port the server is listening on.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;New, we need to set up a few functions:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;sock.onConnect = function&amp;#40;myStatus&amp;#58;Boolean&amp;#41;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;#40;myStatus&amp;#41;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace&amp;#40;&amp;#34;Connected&amp;#34;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace&amp;#40;&amp;#34;Connection failed&amp;#34;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;sock.onData = function&amp;#40;msg&amp;#58;String&amp;#41;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace&amp;#40;&amp;#34;Recieved&amp;#58; &amp;#34;+msg&amp;#41;;&lt;br /&gt;}&lt;br /&gt;sock.onClose = function&amp;#40;&amp;#41;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace&amp;#40;&amp;#34;Connection Closed&amp;#34;&amp;#41;;&lt;br /&gt;}&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;The above functions tell the socket connection how to act given the various calls allowed by ActionScript 2.0, and output the various messages accordingly. By this time (after reading a few of my other tutorials) I hope you will be able to understand what is going on there.&lt;br /&gt;&lt;br /&gt;Now, the simple thing is left - sending a message to the server. This is accomplished like so:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;sock.send&amp;#40;&amp;#34;testing it out - Flash style &amp;#58;&amp;#41;&amp;#34;&amp;#41;;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;The full AS 2.0 code:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;var sock&amp;#58;XMLSocket = new XMLSocket&amp;#40;&amp;#41;;&lt;br /&gt;sock.connect&amp;#40;&amp;#39;localhost&amp;#39;, 2727&amp;#41;;&lt;br /&gt;sock.onConnect = function&amp;#40;myStatus&amp;#58;Boolean&amp;#41;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;#40;myStatus&amp;#41;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace&amp;#40;&amp;#34;Connected&amp;#34;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace&amp;#40;&amp;#34;Connection failed&amp;#34;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;sock.onData = function&amp;#40;msg&amp;#58;String&amp;#41;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace&amp;#40;&amp;#34;Recieved&amp;#58; &amp;#34;+msg&amp;#41;;&lt;br /&gt;}&lt;br /&gt;sock.onClose = function&amp;#40;&amp;#41;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trace&amp;#40;&amp;#34;Connection Closed&amp;#34;&amp;#41;;&lt;br /&gt;}&lt;br /&gt;sock.send&amp;#40;&amp;#34;testing it out - Flash style &amp;#58;&amp;#41;&amp;#34;&amp;#41;;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Running it&lt;/b&gt;&lt;br /&gt;When you have everything finished, you will want to run it. This is accomplished simply by starting up the server (this must be done first), and then in your .fla file (In Flash) pressing CTRL+Enter (this will fire up the Flash SWF in the Flash sandbox and allows for a TON of security pass overs. As this is the case you will be albe to see the script working without having to jump through any hoops.&lt;br /&gt;&lt;br /&gt;Here is what you will get as output:&lt;br /&gt;&lt;b&gt;Server&lt;/b&gt;:&lt;br /&gt;&lt;!--quoteo--&gt;&lt;div class='quotetop'&gt;QUOTE&lt;/div&gt;&lt;div class='quotemain'&gt;&lt;!--quotec--&gt;We have opened a connection with &amp;lt;&amp;#39;127.0.0.1&amp;#39;, 1364&amp;gt;&lt;br /&gt;testing it out - Flash style &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;!--QuoteEnd--&gt;&lt;/div&gt;&lt;!--QuoteEEnd--&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Flash&lt;/b&gt;&lt;br /&gt;&lt;!--quoteo--&gt;&lt;div class='quotetop'&gt;QUOTE&lt;/div&gt;&lt;div class='quotemain'&gt;&lt;!--quotec--&gt;Connected&lt;br /&gt;Recieved: This is a response test - attempt 1&lt;br /&gt;Connection Closed&lt;!--QuoteEnd--&gt;&lt;/div&gt;&lt;!--QuoteEEnd--&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The End&lt;/b&gt;&lt;br /&gt;Hopefully you enjoyed this tutorial and can see some useful applications of it. I will probably post another tutorial when I get things working online so you can have things playing outside of the sandbox.&lt;br /&gt;&lt;br /&gt;Until next time - Keep Flashing &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;</description>
			<pubDate>Sat, 04 Oct 2008 22:42:24 -0600</pubDate>
			<category>Flash Tutorials</category>
			<author>BetaWar</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic65903.htm</link>
            <title>Papervision 2.0 Plane in Flash Tutorials</title>
            <description>If you have used custom classes in flash before, you will already be familiar with importing and utilizing those classes.  One of the these classes is called Papervision and it allows you to code 3D features in Flash using ActionScript3.  You can download the classes necessary to run Papervsion from their google code site. &lt;a href=&quot;http://papervision3d.googlecode.com/files/Papervision3D_2.0_beta_1_src.zip&quot; target=&quot;_blank&quot;&gt; DOWNLOAD &lt;/a&gt;&lt;br /&gt;Once you have downloaded the zip file, extract it. Then create a new folder anywhere outside that zip folder, to store your custom ActionScript classes.  Inside of the zip folder copy the “org” folder (inside “src”) into the new folder you created for classes.  Now open up Flash CS3. Before you begin the project go to “Edit” and then “Preferences”. Choose the category ActionScript and the ActionScript 3 Settings.  Then click the crosshair (browse) and choose the folder that you created (it should be one level above the “org” folder.)&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://farm4.static.flickr.com/3129/2907960801_c285098190.jpg?v=0&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Now comes the fun part.  Create a new ActionScript 3 document and open up your web browser or “My Pictures” folder.  Bring about 10 or so images onto the stage of your project and make sure that you scale them down to fit on the stage.&lt;br /&gt;Once you are satisfied with the images that you have chosen, arrange them however you like, then select them all. Convert to symbol(F8) and make sure that the registration is set to the top left and that Movie Clip is chosen.  Name it anything that you want and click “OK”.  Now click the instance of the symbol that you created and, for the purpose of this tutorial,  name it “imageGallery”. &lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://farm4.static.flickr.com/3029/2907960755_e1125878bc.jpg?v=0&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt; &lt;br /&gt;Now that “imageGallery” has been set up you should move it all the way off the stage.  OK, lets code.  Open up the actions panel by selecting any frame and pressing F9.  In the actions panel we need to import our Papervision3D classes. which will give us the ability to access the objects, methods and properties within Papervision3D.&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;import org.papervision3d.cameras.*;&lt;br /&gt;import org.papervision3d.objects.primitives.*;&lt;br /&gt;import org.papervision3d.materials.*;&lt;br /&gt;import org.papervision3d.render.*;&lt;br /&gt;import org.papervision3d.view.*;&lt;br /&gt;import org.papervision3d.scenes.*;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Next we initialize a viewport which is basically a 3D MovieClip, which we will add to our stage. We will also need a scene where we will add objects and a camera to  focus on a specific part of our scene.  Last we need a rendering engine to make the scene viewable. &lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;var viewport&amp;#58;Viewport3D = new Viewport3D&amp;#40;0,0, true,true&amp;#41;;&lt;br /&gt;var render&amp;#58;BasicRenderEngine= new BasicRenderEngine&amp;#40;&amp;#41;;&lt;br /&gt;var scene&amp;#58;Scene3D = new Scene3D&amp;#40;&amp;#41;;&lt;br /&gt;var camera&amp;#58;Camera3D = new Camera3D&amp;#40;&amp;#41;;&lt;br /&gt;addChild&amp;#40;viewport&amp;#41;;&lt;br /&gt;camera.zoom = 10;&lt;br /&gt;camera.focus = 100;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Now that our scene is initialized we can add a plane which will hold our “imageGallery” MovieClip.  To create a plane simply type.&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;var picPlane&amp;#58;Plane = new Plane&amp;#40;picPlaneMaterial, imageGallery.width, imageGallery.height,10,10&amp;#41;;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt; This will create define a plane but what will the plane hold?  To give that plane a visual we must create a material which will be our “imageGallery” so paste this code above the previous line. &lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;var picPlaneMaterial&amp;#58;MovieMaterial = new MovieMaterial&amp;#40;imageGallery&amp;#41;;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;  We will also want the material to be visible on both sides so enter &lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;picPlaneMaterial.oneSide = false;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Now all we have to do is add the plane to the scene and render the scene.&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;scene.addChild&amp;#40;picPlane&amp;#41;;&lt;br /&gt;render.renderScene&amp;#40;scene, camera, viewport&amp;#41;;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Run the movie (ctrl-enter) and you should see your pictures in the center of the stage.  This is good but the real benefit of using Papervision is to allow the user to view content in 3D space, so we are going to let the end user rotate the plane.  Replace the render scene with a function the runs every frame and evaluates the users mouse position in relation to the center of the stage in order to rotate the plane.  &lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;stage.addEventListener&amp;#40;Event.ENTER_FRAME, positionAndRender&amp;#41;&lt;br /&gt;function positionAndRender&amp;#40;evt&amp;#58;Event&amp;#41; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var rateOfChange&amp;#58;uint = 100;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;picPlane.rotationY += &amp;#40;&amp;#40;stage.stageWidth/2&amp;#41; - mouseX&amp;#41;/rateOfChange;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;picPlane.rotationX += &amp;#40;&amp;#40;stage.stageHeight/2&amp;#41; - mouseY&amp;#41;/rateOfChange;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;render.renderScene&amp;#40;scene, camera, viewport&amp;#41;;&lt;br /&gt;}&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt; Test your movie and you should see something like this.&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;http://farm4.static.flickr.com/3191/2907960655_3a0e8b8e70.jpg?v=0&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;So thats it, but you don&amp;#39;t have to be done yet.  Try changing the frame rate or even try to display the “imageGallery” on a cylinder, sphere or cube.  To get more help consult the documentation for Papervision3D at &lt;a href=&quot;http://www.flashbookmarks.com/PV3D-GreatWhite-DOC/&quot; target=&quot;_blank&quot;&gt;http://www.flashbookmarks.com/PV3D-GreatWhite-DOC/&lt;/a&gt;.&lt;br /&gt;Feel free to contact me with any questions.</description>
			<pubDate>Thu, 02 Oct 2008 19:28:09 -0600</pubDate>
			<category>Flash Tutorials</category>
			<author>Kerplope</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic65330.htm</link>
            <title>Blinking Text for Beginners in Visual Basic Tutorials</title>
            <description>Hi guys,&lt;br /&gt;Most of you had created many programs for various purpose. But have you ever thought of some animation in your program..&lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Here I am going to mention a small tutorial on creating a blinking text effect. It is for pure beginners.&lt;br /&gt;&lt;br /&gt;First of all open the Visual Basic using &lt;b&gt;Start&lt;/b&gt;&amp;gt;&lt;b&gt;Programs&lt;/b&gt;&amp;gt;&lt;b&gt;Microsoft Visual Studio&lt;/b&gt;&amp;gt;&lt;b&gt;Visual Basic 6.0&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;Then select &lt;b&gt;Standard EXE&lt;/b&gt; and click &lt;b&gt;open&lt;/b&gt;.&lt;br /&gt;You will get a blank &lt;b&gt;Form&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;From the toolbox(in left side), select &lt;b&gt;Command Button&lt;/b&gt; and create two buttons in your form(say, &lt;b&gt;Command1&lt;/b&gt; and &lt;b&gt;Command2&lt;/b&gt;).&lt;br /&gt;Also, create a Timer in your form(say, &lt;b&gt;Timer1&lt;/b&gt;)&lt;br /&gt;&lt;br /&gt;Then open the code window(View menu&amp;gt; View Code).&lt;br /&gt;Then write the code as below:&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;Private Sub Command1_Click&amp;#40;&amp;#41;&lt;br /&gt;Timer1.Interval = 100 &amp;#39;interval of the timer&lt;br /&gt;Timer1.Enabled = True &amp;#39;starting the animation&lt;br /&gt;Label1.Caption = &amp;#34;Welcome&amp;#34; &amp;#39;text to display&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Command2_Click&amp;#40;&amp;#41;&lt;br /&gt;Timer1.Enabled = False &amp;#39;stopping the animation&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load&amp;#40;&amp;#41;&lt;br /&gt;Timer1.Enabled = False &amp;#39;disabling the animation on loading the form&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Timer1_Timer&amp;#40;&amp;#41;&lt;br /&gt;If Label1.Visible = True Then &amp;#39;checking whether it is visible&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Label1.Visible = False &amp;#39;if visible then, make it invisible&lt;br /&gt;ElseIf Label1.Visible = False Then &amp;#39;checking whether it is invisible&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Label1.Visible = True &amp;#39;if invisible then, make it visible&lt;br /&gt;End If&lt;br /&gt;End Sub&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;I had included most of the comments in the code itself. I think you understand my coding. If you have any doubt, please feel free to contact me....&lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;-Akhilesh B Chandran</description>
			<pubDate>Sat, 27 Sep 2008 22:59:21 -0600</pubDate>
			<category>Visual Basic Tutorials</category>
			<author>akhileshbc</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic64740.htm</link>
            <title>C++ Basics 1 - Comments and Data Types in C++ Tutorials</title>
            <description>Nice writeup~ I like the way you even managed to show some basic OOP principals in such an intro topic. &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;A few things to say though. [il]printf()[/il] is a C-standard function. It&amp;#39;s compatible with C++ since C++ is backwards compatible with C, but it&amp;#39;s more common to stick with C++ standards where possible. (example, for basic console I/O)&lt;br /&gt;&lt;br /&gt;So, [code=cpp]printf(&amp;quot;The Student %s&amp;#092;n&amp;quot;, test-&amp;gt;getName());[/code] will actually be [code=cpp]cout &amp;lt;&amp;lt; &amp;quot;The Student &amp;quot; &amp;lt;&amp;lt; test-&amp;gt;getName();[/code]&lt;br /&gt;&lt;br /&gt;Also, [il]char*[/il] is C standard for strings~ why not make use of the [il]string[/il] class?&lt;br /&gt;&lt;br /&gt;Lastly, I think you missed explaining the purpose of that get() function. It&amp;#39;s used to access a private variable.&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/smile.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:)&quot; border=&quot;0&quot; alt=&quot;smile.gif&quot; /&gt;</description>
			<pubDate>Tue, 07 Oct 2008 06:37:11 -0600</pubDate>
			<category>C++ Tutorials</category>
			<author>gabehabe</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic64523.htm</link>
            <title>File Generation - DETAILED Creation + Writing in PHP Tutorials</title>
            <description>&lt;!--quoteo(post=424008:date=25 Sep, 2008 &amp;#045; 11&amp;#58;56 AM:name=Nykc)--&gt;&lt;div class='quotetop'&gt;QUOTE(Nykc &amp;#064; 25 Sep, 2008 &amp;#045; 11&amp;#58;56 AM) [snapback]424008[/snapback]&lt;/div&gt;&lt;div class='quotemain'&gt;&lt;!--quotec--&gt;&lt;br /&gt;Hey I like this guy already.....&lt;br /&gt;&lt;br /&gt;Very nice tutorial.  I was trying to do something similiar in PERL.  PHP works for me as well..&lt;br /&gt;&lt;br /&gt;Gracias&amp;#33;&amp;#33;&amp;#33;&amp;#33;&lt;br /&gt;&lt;!--QuoteEnd--&gt;&lt;/div&gt;&lt;!--QuoteEEnd--&gt;&lt;br /&gt;&lt;br /&gt;First off, thanks for the complement&amp;#33; &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/biggrin.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:D&quot; border=&quot;0&quot; alt=&quot;biggrin.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Second, just thought you should note that this script only supports text files up to 200kb in size.  When I tested this, I used a text file with 500 file names... and it was only 9.8kb..... so unless you need to generate more than 10,000 files (LOL) you might need to use arrays and multiple functions to complete what you need done... but I doubt anyone will ever need to generate more than 10,000 files, so this works for now &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/tongue.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;:P&quot; border=&quot;0&quot; alt=&quot;tongue.gif&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Cheers&amp;#33;</description>
			<pubDate>Thu, 25 Sep 2008 13:26:58 -0600</pubDate>
			<category>PHP Tutorials</category>
			<author>pr4y</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic64306.htm</link>
            <title>Game Programming in Linux for Windows Programmers - Part 3 in C++ Tutorials</title>
            <description>&lt;a href=&quot;http://www.dreamincode.net/forums/index.php?act=ST&amp;amp;f=48&amp;amp;t=64143&amp;amp;st=0#entry419619&quot; target=&quot;_blank&quot;&gt;Previous Tutorial&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hello there-&amp;#33; Have fun reading a little background on the purpose of this tutorial series (especially since this is the tutorial for compiling on different operating systems), skip to the first bold heading if you just want the tutorial but I really hope you read the background... please :3&lt;br /&gt;&lt;br /&gt;Everyone sane has a computer with one of the big 3 operating systems. Even if you&amp;#39;re partially insane, you still probably have Linux, Windows, or a Mac. As you probably know Windows is used in 90% of computers because of Microsoft&amp;#39;s evil but clever marketing techniques. So... What does make an operating system good for games? Let&amp;#39;s think about this for a moment and come up with a list...&lt;br /&gt;&lt;br /&gt;An operating system good for games is:&lt;br /&gt;- &lt;i&gt;Stable&lt;/i&gt;, because it&amp;#39;s annoying to play a game only to have it crash often making you restart &lt;img src=&quot;style_emoticons/&lt;#EMO_DIR#&gt;/anime2.gif&quot; style=&quot;vertical-align:middle&quot; emoid=&quot;&amp;gt;.&amp;lt;&quot; border=&quot;0&quot; alt=&quot;anime2.gif&quot; /&gt;&lt;br /&gt;- &lt;i&gt;Yielding to resources&lt;/i&gt;, so that when the user is playing a video game, a good amount of resources are availiable to the game.&lt;br /&gt;- &lt;i&gt;Simple and organized&lt;/i&gt;, when the user does want to play a game, they don&amp;#39;t want to have to enter many commands, the list of games should be readily availiable and start when clicked upon.&lt;br /&gt;- &lt;i&gt;Supportive of hardware&lt;/i&gt;, so when a user gets a game, they can be sure it will work on their computer because the operating system took care of the hardware drivers.&lt;br /&gt;&lt;br /&gt;My audiance for this tutorial is Windows game programmers, so you probably are one yourself. You&amp;#39;ve been using Windows, and I&amp;#39;m going to talk about both XP and Vista. People keep saying Windows is unstable, but this only really applies to Vista- but&amp;#33; Vista has been getting patches to make it at least run for longer than 30 minutes. Windows actually does yield resources when told to, as long as you tell it to, but Vista is a resource hog. You can&amp;#39;t deny Vista&amp;#39;s basic hefty memory usage and CPU overhead because I can prove it to someone who did a clean unmodified install by opening task manager. However, both are organized and the game is either on your desktop, or where Vista takes it further by having a Games window. Also excelling as a gaming operating system, both have support for drivers mostly, and companies are getting on the ball with writing drivers for Vista. The reason I switched to Linux is for point 2- the fact Vista eats up many resources. However, making a game a Linux-exclusive worse than making a game that&amp;#39;s Windows-exclusive since most people will have Windows. &lt;i&gt;The goal of someone who wants to convince gamers to have Linux is to show them a good game that works on Linux and Windows, but demonstrate that the Linux version runs much better because it has lots of resources&lt;/i&gt;. It&amp;#39;s going to be a long time before Microsoft even loses slightly it&amp;#39;s grip on the computer video gaming market.&lt;br /&gt;&lt;br /&gt;Next is the sexy macs. They&amp;#39;re not kawaii they&amp;#39;re &lt;i&gt;sexy&lt;/i&gt; apparently, as I hear computer nerds tell me. Awws... I like kawaii better, but in any case they are the easiest to use of the three. This makes it the best operating system for point 3. Macs are generally stable, but people don&amp;#39;t understand they are just as stable as Windows and no more (excluding Vista) since most of the fault is with all the crap that comes pre-installed in Windows machines by third parties. There&amp;#39;s little hardware that comes with Macs, and it&amp;#39;s all stuck- making it the worst in point 4 since the owner of the Mac is generally stuck with what they got unless they somehow get the manufacturer to replace the parts inside or they figure out on their own how to do that. I&amp;#39;m not sure how Macs are on resources, but it seems about the same as XP. I personally don&amp;#39;t like Macs, but I hope that more games support all the operating systems so that people can choose an operating system based on what they like rather than what games/programs it supports.&lt;br /&gt;&lt;br /&gt;Linux, is really kawaii~&amp;#33; Linux may break, but I&amp;#39;ve never had my computer crash to the point of where I couldn&amp;#39;t do anything. If something breaks, you can still continue working usually and if you know how, use the terminal to fix it. Unfortunatly, fixing a problem in Linux is very very difficult (and NO the terminal is NOT AWESOME&amp;#33;). You&amp;#39;ll most likely be surfing google for a while trying to find the answer to fixing your problem- so yes and no for being a stable system. Nothing yields resources like a Linux system, I open the process viewer to see every program and operating system process I&amp;#39;m not using asleep with very little CPU usage. Also, there&amp;#39;s so much RAM for me to use, allowing games to really push themselves further. If you have the Ubuntu version or even just GNOME installed for your custom Linux systems, games can be put in the space in between stuff in the taskbar, in the programs list, or on the desktop. It&amp;#39;s easy to look up a game with the Add/Remove programs manager in the Ubuntu version making it very organized- &amp;quot;on par&amp;quot; with a Mac. It&amp;#39;s about as supportive of hardware as Vista is, except most of it is automatically installed on the Ubuntu version of Linux. As you know from the first part of this series, enabling a video card is easy. Linux is a good operating system for programmings, but thanks to versions like Ubuntu, it&amp;#39;s becoming also a great operating system for everyone. Enough of this let&amp;#39;s get going^^&amp;#33;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Cross Platform&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Hehe, I&amp;#39;m going to spend the time to show you how to organize your libraries of code so that you don&amp;#39;t have to write the same SDL loop or event handler over and over. It&amp;#39;s a good thing to have a battle-tested library that you can just drop into your projects and work from, so let&amp;#39;s go ahead and prepare everything for work.&lt;br /&gt;&lt;br /&gt;This tutorial will cover an example of an &amp;quot;SDL Core&amp;quot;. This &amp;quot;SDL Core&amp;quot; will be made with your personal flavor of programming in it... I want this folder to contain a bundle of code files that I wrote which contains the SDL loop and some basic handling such as tilemaps and sprites. There&amp;#39;s much I will add here but for now I just want to write a generic version of the SDL loop you saw in the previous tutorial in this series.&lt;br /&gt;&lt;br /&gt;Now, we will develop our game in Linux, but you might have a Mac or Windows machine to compile on. When writing your code, you need to think of how it should be compiled on each system. Look at this code:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;/* Platform Includes */&lt;br /&gt;#ifndef COMPILE_FOR_WINDOWS&lt;br /&gt;#include &amp;#60;/usr/include/SDL/SDL.h&amp;#62;&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;#ifdef COMPILE_FOR_WINDOWS&lt;br /&gt;#define WIN32_LEAN_AND_MEAN&lt;br /&gt;#include &amp;#60;windows.h&amp;#62;&lt;br /&gt;#include &amp;#60;SDL.h&amp;#62;&lt;br /&gt;#endif&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;And this code:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;/* Main */&lt;br /&gt;#ifdef COMPILE_FOR_WINDOWS&lt;br /&gt;int WINAPI WinMain&amp;#40;HINSTANCE hinstance,HINSTANCE hprevinstance,PSTR szcmdline,int icmdshow&amp;#41;&lt;br /&gt;#endif&lt;br /&gt;#ifndef COMPILE_FOR_WINDOWS&lt;br /&gt;int main&amp;#40;int argn,char *argv&amp;#91;&amp;#93;&amp;#41;&lt;br /&gt;#endif&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Exit */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Remember that the #define / #ifndef / #endif / #ifdef things generate text, not code, so this compiles just fine on GCC and the Microsoft Compiler. Combining this with our code from the last tutorial, you get:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;/*&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;wcsdlcore.c&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WolfCoder&amp;#39;s SDL Core&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;written by, of course, WolfCoder &amp;#40;2008&amp;#41;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Version 1&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* Platform Includes */&lt;br /&gt;#ifndef COMPILE_FOR_WINDOWS&lt;br /&gt;#include &amp;#60;/usr/include/SDL/SDL.h&amp;#62;&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;#ifdef COMPILE_FOR_WINDOWS&lt;br /&gt;#define WIN32_LEAN_AND_MEAN&lt;br /&gt;#include &amp;#60;windows.h&amp;#62;&lt;br /&gt;#include &amp;#60;SDL.h&amp;#62;&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;/* My Includes */&lt;br /&gt;#include &amp;#34;wcsdlcore.h&amp;#34;&lt;br /&gt;&lt;br /&gt;/* Globals */&lt;br /&gt;SDL_Surface *screen;&lt;br /&gt;SDL_Event main_event;&lt;br /&gt;unsigned long ticks;&lt;br /&gt;unsigned long duration;&lt;br /&gt;double time_step;&lt;br /&gt;unsigned int frame_rate = 120;&lt;br /&gt;&lt;br /&gt;/* Gets the time step value */&lt;br /&gt;double wcsdlcore_time_step&amp;#40;&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return time_step;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* Handles SDL events and returns a 0 if the game should exit */&lt;br /&gt;int wcsdlcore_handle_events&amp;#40;&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Get all events */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while&amp;#40;SDL_PollEvent&amp;#40;&amp;amp;main_event&amp;#41;&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* End program */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;#40;main_event.type == SDL_QUIT&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Return the exit code for quitting or continuing */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* Main */&lt;br /&gt;#ifdef COMPILE_FOR_WINDOWS&lt;br /&gt;int WINAPI WinMain&amp;#40;HINSTANCE hinstance,HINSTANCE hprevinstance,PSTR szcmdline,int icmdshow&amp;#41;&lt;br /&gt;#endif&lt;br /&gt;#ifndef COMPILE_FOR_WINDOWS&lt;br /&gt;int main&amp;#40;int argn,char *argv&amp;#91;&amp;#93;&amp;#41;&lt;br /&gt;#endif&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Initialize SDL */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SDL_Init&amp;#40;SDL_INIT_VIDEO | SDL_INIT_TIMER&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;screen = SDL_SetVideoMode&amp;#40;SCREEN_X,SCREEN_Y,0,SDL_HWSURFACE | SDL_DOUBLEBUF&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Initialize the game */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;wcsdlcore_init&amp;#40;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Enter the main loop */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;duration = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ticks = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;time_step = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while&amp;#40;wcsdlcore_handle_events&amp;#40;&amp;#41;&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Clear the screen */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SDL_FillRect&amp;#40;screen,NULL,SDL_MapRGB&amp;#40;screen-&amp;#62;format,0,0,0&amp;#41;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Sample the time */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;duration = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ticks = SDL_GetTicks&amp;#40;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Handle one frame of the game */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;wcsdlcore_main&amp;#40;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Flip buffers */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SDL_Flip&amp;#40;screen&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Record the time that has passed, checking for the 49 or so day wrap error */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;#40;SDL_GetTicks&amp;#40;&amp;#41;-ticks &amp;#62; 0&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;duration = SDL_GetTicks&amp;#40;&amp;#41;-ticks;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Wait for the maximum FPS */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while&amp;#40;SDL_GetTicks&amp;#40;&amp;#41;-ticks &amp;#60; &amp;#40;1000/frame_rate&amp;#41;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;time_step = &amp;#40;double&amp;#41;&amp;#40;duration&amp;#41;/&amp;#40;1000/16&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Clean-up the game */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;wcsdlcore_exit&amp;#40;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Quit SDL */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SDL_Quit&amp;#40;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Exit */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;And for the wcsdlcore.h file:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;#ifndef WCSDLCORE_H&lt;br /&gt;#define WCSDLCORE_H&lt;br /&gt;&lt;br /&gt;/* Defines */&lt;br /&gt;#ifndef SCREEN_X&lt;br /&gt;#define SCREEN_X 320&lt;br /&gt;#endif&lt;br /&gt;#ifndef SCREEN_Y&lt;br /&gt;#define SCREEN_Y 240&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;/* Functions to be written by developer */&lt;br /&gt;extern void wcsdlcore_init&amp;#40;&amp;#41;; /* Initializes the game, this gets called once before entering the main loop */&lt;br /&gt;extern void wcsdlcore_main&amp;#40;&amp;#41;; /* Handles one frame of the game and is called for every frame */&lt;br /&gt;extern void wcsdlcore_exit&amp;#40;&amp;#41;; /* Cleans up the game&amp;#39;s resources, this is called once after exiting the main loop */&lt;br /&gt;&lt;br /&gt;/* Functions provided by WolfCoder&amp;#39;s SDL Core */&lt;br /&gt;extern double wcsdlcore_time_step&amp;#40;&amp;#41;; /* Returns the time_step value, multiply this by all the speed to achieve correct speeds */&lt;br /&gt;&lt;br /&gt;#endif&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Lastly, when writing a library, we need to write a test program. The wcsdlcore_init()/ect. functions are missing and need to be written. Here&amp;#39;s a stub file called test.c:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;/*&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;test.c&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Tests WolfCoder&amp;#39;s SDL Core&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;written by, of course, WolfCoder &amp;#40;2008&amp;#41;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;/* My Includes */&lt;br /&gt;#include &amp;#34;wcsdlcore.h&amp;#34;&lt;br /&gt;&lt;br /&gt;/* Game initialize */&lt;br /&gt;void wcsdlcore_init&amp;#40;&amp;#41;&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* Game main */&lt;br /&gt;void wcsdlcore_main&amp;#40;&amp;#41;&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* Game exit */&lt;br /&gt;void wcsdlcore_exit&amp;#40;&amp;#41;&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Let&amp;#39;s run this mess through GCC. I wrote the following Makefile and did the &lt;i&gt;Tools-&amp;gt;Build&lt;/i&gt; command from GEdit as usual:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;# Test run WolfCoder&amp;#39;s SDL Core&lt;br /&gt;compile-run&amp;#58;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;test.c&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;make compile&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gcc -c -Wall test.c&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gcc -lSDL wcsdlcore.o wcsprite.o test.o -o wcsdlcore-test&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;./wcsdlcore-test&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rm test.o&lt;br /&gt;&lt;br /&gt;# Clean&lt;br /&gt;clean&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rm *~&lt;br /&gt;&lt;br /&gt;# Comple WolfCoder&amp;#39;s SDL Core&lt;br /&gt;compile&amp;#58;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;wcsdlcore.c wcsdlcore.h wcsprite.c wcsprite.h&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gcc -c -Wall wcsdlcore.c wcsprite.c&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;It works just fine, we&amp;#39;ve got our window and everything, and our bundle of code does what it needs. If you plan on making a Windows version of your game, then read on~ Make a new Win32 project in Microsoft Visual Studio. Since this is Linux game programming for Windows users, chances are you&amp;#39;ve got the system you&amp;#39;ve been developing on all this time. You still need it if you want to ensure that you can compile ports. Create the new project, &lt;i&gt;MOVE&lt;/i&gt; all your files into the part of the project where the Microsoft Compiler will compile and do the following shown in the picture (right click on the Source Files folder):&lt;br /&gt;&lt;img src=&quot;http://i103.photobucket.com/albums/m134/WolfCoder/externalcode.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;You need to download the Windows version of the SDL library. The folder you get looks like this on the inside:&lt;br /&gt;&lt;img src=&quot;http://i103.photobucket.com/albums/m134/WolfCoder/sdlfolder.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Add your .c files, and then do the same for the .h files on the &lt;i&gt;Header Files&lt;/i&gt; folder. Now, remember the COMPILE_FOR_WINDOWS macro we put in there? Here&amp;#39;s what you do next, it should be Project-&amp;gt;Properties as shown here:&lt;br /&gt;&lt;img src=&quot;http://i103.photobucket.com/albums/m134/WolfCoder/projectprop.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Click on the section here and link the SDL folder (it&amp;#39;s the SDL folder wherever it is, and then &amp;#092;include) you have to the project as shown:&lt;br /&gt;&lt;img src=&quot;http://i103.photobucket.com/albums/m134/WolfCoder/sdllink.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Now right click the Resource Files and add existing file as shown in the picture. You&amp;#39;ll find the sdl.lib inside the lib folder inside the SDL folder:&lt;br /&gt;&lt;img src=&quot;http://i103.photobucket.com/albums/m134/WolfCoder/sdllib.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Alright, now copy and paste the SDL.dll and put it right next to your project. It varies where you put it but if you are tired of this just paste it into the C:&amp;#092;&amp;#092;Windows&amp;#092;System32&amp;#092; folder so that any program will run. Rememeber to put SDL.dll right with your game when giving your game out to people though, and it has to be the sdl-runtime.dll (rename it to SDL.dll once it&amp;#39;s with your .exe file).&lt;br /&gt;&lt;br /&gt;And then click on the section shown here:&lt;br /&gt;&lt;img src=&quot;http://i103.photobucket.com/albums/m134/WolfCoder/preprocessor.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;You add COMPILE_FOR_WINDOWS in there. This is the same as #define COMPILE_FOR_WINDOWS everywhere but you don&amp;#39;t actually have to write it, ensuring that it works and that your code compiles for Windows on Windows, and for Linux on Linux. Go ahead and build, and then run the code and you should get this:&lt;br /&gt;&lt;img src=&quot;http://i103.photobucket.com/albums/m134/WolfCoder/sdlwin.png&quot; border=&quot;0&quot; alt=&quot;IPB Image&quot; /&gt;&lt;br /&gt;&lt;br /&gt;You should now have a folder containing a Microsoft Visual Studio project, and in the code folder is the Makefile along with the code files, and the Linux version of the program if you made it earlier in Linux. You can put this on a thumbdrive, or multi-boot your machine and compile it and it should work. Just remember your COMPILE_FOR_WINDOWS macro to be check and used on things that are platform-specific, but only in wcsdlcore.c should you really need it.&lt;br /&gt;&lt;br /&gt;How was that? There&amp;#39;s other things you could still use the macro for. For example, you could use the macro to put exclusive features in your game for each operating system for fun- or to have the in-game user interface mimic the user interface style of Linux or Windows. Just because you&amp;#39;re using a platform-independant library doesn&amp;#39;t mean you can&amp;#39;t add some extra fun things to each platform.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Your Personal Library&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;It&amp;#39;s all up and ready&amp;#33; Are you ready for the fun to begin? The idea behind this library is to pack the series of SDL commands inside so that you don&amp;#39;t have call them outside of the core. This makes it easier to write a game without worrying about including SDL everywhere. Let&amp;#39;s write a function that allows us to lock the main surface, write pixels, and unlock, but much simpler and without SDL functions in test.c.&lt;br /&gt;&lt;br /&gt;Recall our set_sdl_pixel function in the previous tutorial:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;/* Sets a pixel in a surface, paying attention to pixel format */&lt;br /&gt;void set_sdl_pixel&amp;#40;SDL_PixelFormat *what,void *pixel,int width,int x,int y,int r,int g,int b&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint8 *bit8;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint16 *bit16;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint32 *bit32;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Address memory according to the width */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;#40;what-&amp;#62;BitsPerPixel&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 8&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit8 = &amp;#40;Uint8*&amp;#41;pixel;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit8&amp;#91;width*y+x&amp;#93; = SDL_MapRGB&amp;#40;what,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 16&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit16 = &amp;#40;Uint16*&amp;#41;pixel;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit16&amp;#91;&amp;#40;width/2&amp;#41;*y+x&amp;#93; = SDL_MapRGB&amp;#40;what,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 32&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit32 = &amp;#40;Uint32*&amp;#41;pixel;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit32&amp;#91;&amp;#40;width/4&amp;#41;*y+x&amp;#93; = SDL_MapRGB&amp;#40;what,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Let&amp;#39;s modify this so that all we need to provide is x,y and r,g,b to the function. This is a pretty minor function, it&amp;#39;s not like a sprite-handling code so we can just put it in wcsdlcore.c. Look closely at the modified version:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;/* Sets a pixel in a surface, paying attention to pixel format */&lt;br /&gt;SDL_PixelFormat *set_pixel_format;&lt;br /&gt;int set_pixel_width;&lt;br /&gt;void *set_pixels;&lt;br /&gt;void wcsdlcore_set_pixel&amp;#40;int x,int y,int r,int g,int b&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint8 *bit8;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint16 *bit16;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint32 *bit32;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Address memory according to the width */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;#40;set_pixel_format-&amp;#62;BitsPerPixel&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 8&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* 8-bit modes &amp;#40;indexed color */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit8 = &amp;#40;Uint8*&amp;#41;set_pixels;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit8&amp;#91;set_pixel_width*y+x&amp;#93; = SDL_MapRGB&amp;#40;set_pixel_format,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 16&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* 16-bit high color */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit16 = &amp;#40;Uint16*&amp;#41;set_pixels;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit16&amp;#91;&amp;#40;set_pixel_width/2&amp;#41;*y+x&amp;#93; = SDL_MapRGB&amp;#40;set_pixel_format,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 32&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* 32-bit true color with possible ALPHA */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit32 = &amp;#40;Uint32*&amp;#41;set_pixels;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit32&amp;#91;&amp;#40;set_pixel_width/4&amp;#41;*y+x&amp;#93; = SDL_MapRGB&amp;#40;set_pixel_format,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;We added some globals which belong to the function, but can be quickly set by functions that lock and unlock the screen... Er... Hehe, we make mistakes often, don&amp;#39;t we? Let&amp;#39;s make this function safer by causing it to do nothing if it is not safe to do anything. I also changed the name of the function so it&amp;#39;s consistent with the library. Let&amp;#39;s add another global variable to that list and modify the very top of the function:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;int set_pixel_safety = 0;&lt;br /&gt;void wcsdlcore_set_pixel&amp;#40;int x,int y,int r,int g,int b&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint8 *bit8;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint16 *bit16;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint32 *bit32;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Do nothing if it is not safe to set a pixel */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;#40;set_pixel_safety == 0&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;br /&gt;/* THE CODE CONTINUES HERE LIKE BEFORE */&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Alright then, let&amp;#39;s add functions that lock the surface and release it so we can call them in our test.c file:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;/* Sets a pixel in a surface, paying attention to pixel format */&lt;br /&gt;SDL_PixelFormat *set_pixel_format;&lt;br /&gt;int set_pixel_width;&lt;br /&gt;void *set_pixels;&lt;br /&gt;int set_pixel_safety = 0;&lt;br /&gt;void wcsdlcore_set_pixel&amp;#40;int x,int y,int r,int g,int b&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint8 *bit8;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint16 *bit16;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uint32 *bit32;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Do nothing if it is not safe to set a pixel */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;#40;set_pixel_safety == 0&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Address memory according to the width */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;#40;set_pixel_format-&amp;#62;BitsPerPixel&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 8&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* 8-bit modes &amp;#40;indexed color */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit8 = &amp;#40;Uint8*&amp;#41;set_pixels;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit8&amp;#91;set_pixel_width*y+x&amp;#93; = SDL_MapRGB&amp;#40;set_pixel_format,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 16&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* 16-bit high color */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit16 = &amp;#40;Uint16*&amp;#41;set_pixels;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit16&amp;#91;&amp;#40;set_pixel_width&amp;#41;*y+x&amp;#93; = SDL_MapRGB&amp;#40;set_pixel_format,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 32&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* 32-bit true color with possible ALPHA */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit32 = &amp;#40;Uint32*&amp;#41;set_pixels;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bit32&amp;#91;&amp;#40;set_pixel_width&amp;#41;*y+x&amp;#93; = SDL_MapRGB&amp;#40;set_pixel_format,r,g,b&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* Locks the surface so that pixels can be drawn */&lt;br /&gt;void wcsdlcore_begin_pixels&amp;#40;&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Lock the surface */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;#40;SDL_LockSurface&amp;#40;screen&amp;#41; &amp;#33;= 0&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return; /* Failure */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Get values for set pixel */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set_pixel_width = screen-&amp;#62;pitch;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set_pixel_format = screen-&amp;#62;format;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set_pixels = screen-&amp;#62;pixels;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Change the set pixel width here */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;#40;set_pixel_format-&amp;#62;BitsPerPixel&amp;#41;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 16&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set_pixel_width /= 2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 32&amp;#58;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set_pixel_width /= 4;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Make it safe to set pixels */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set_pixel_safety = 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* Unlocks the surface to resume normal operation */&lt;br /&gt;void wcsdlcore_end_pixels&amp;#40;&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Unlock and make unsafe */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SDL_UnlockSurface&amp;#40;screen&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set_pixel_safety = 0;&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Since we&amp;#39;re going to draw lots of pixels, the width is calculated in the begin pixels function. Looks simple right? Let&amp;#39;s reference these in wcsdlcore.h so that test.c can use them. Let&amp;#39;s modify wcsdlcore.h:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;#ifndef WCSDLCORE_H&lt;br /&gt;#define WCSDLCORE_H&lt;br /&gt;&lt;br /&gt;/* Defines */&lt;br /&gt;#ifndef SCREEN_X&lt;br /&gt;#define SCREEN_X 320&lt;br /&gt;#endif&lt;br /&gt;#ifndef SCREEN_Y&lt;br /&gt;#define SCREEN_Y 240&lt;br /&gt;#endif&lt;br /&gt;&lt;br /&gt;/* Functions to be written by developer */&lt;br /&gt;extern void wcsdlcore_init&amp;#40;&amp;#41;; /* Initializes the game, this gets called once before entering the main loop */&lt;br /&gt;extern void wcsdlcore_main&amp;#40;&amp;#41;; /* Handles one frame of the game and is called for every frame */&lt;br /&gt;extern void wcsdlcore_exit&amp;#40;&amp;#41;; /* Cleans up the game&amp;#39;s resources, this is called once after exiting the main loop */&lt;br /&gt;&lt;br /&gt;/* Functions provided by WolfCoder&amp;#39;s SDL Core */&lt;br /&gt;extern double wcsdlcore_time_step&amp;#40;&amp;#41;; /* Returns the time_step value, multiply this by all the speed to achieve correct speeds */&lt;br /&gt;extern void wcsdlcore_set_pixel&amp;#40;int x,int y,int r,int g,int b&amp;#41;; /* Sets a pixel ONLY WHEN wcsdlcore_begin_pixels was called */&lt;br /&gt;extern void wcsdlcore_begin_pixels&amp;#40;&amp;#41;; /* Enables the wcsdlcore_set_pixel function to work */&lt;br /&gt;extern void wcsdlcore_end_pixels&amp;#40;&amp;#41;; /* Call this when you&amp;#39;re done using the wcsdlcore_set_pixel function for the current frame */&lt;br /&gt;&lt;br /&gt;#endif&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;Now let&amp;#39;s apply our new functions by drawing a red pixel at (10,20) like before. This is test.c and all we have to do now is add the following to our main frame function:&lt;br /&gt;&lt;br /&gt;&lt;!--c1--&gt;&lt;div class='codetop'&gt;CODE&lt;/div&gt;&lt;div class='codemain'&gt;&lt;!--ec1--&gt;&lt;br /&gt;/* Game main */&lt;br /&gt;void wcsdlcore_main&amp;#40;&amp;#41;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Draw some pixels */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;wcsdlcore_begin_pixels&amp;#40;&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;wcsdlcore_set_pixel&amp;#40;10,20,255,0,0&amp;#41;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;wcsdlcore_end_pixels&amp;#40;&amp;#41;;&lt;br /&gt;}&lt;br /&gt;&lt;!--c2--&gt;&lt;/div&gt;&lt;!--ec2--&gt;&lt;br /&gt;&lt;br /&gt;We&amp;#39;ve crammed all that code into three functions we can use, now whenver you want a quick set-pixel sort of application to test something, you can drop the code in the project and all you have to write is another file like test.c and include wcsdlcore.h. It&amp;#39;ll even compile according to the platform like you set up earlier&amp;#33;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Homework? Hehe~&amp;#33;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;You&amp;#39;ve learned how to set up a project folder that contains both a Microsoft Visual Studio project for Windows &lt;i&gt;and&lt;/i&gt; a simple Makefile project for Linux. You&amp;#39;ve also learned how to organize bundles of code for use as libraries. So whenever you want to make an SDL project, just get out your SDL Core bundle of code and compile it with your project.&lt;br /&gt;&lt;br /&gt;Here&amp;#39;s ideas for practicing stuff you learned in this section~&lt;br /&gt;&lt;br /&gt;- Try writing a library that makes writing a DEBUG log to a .txt file easy. Have a function that opens the file, one that closes it, and one that writes a string or number to it, and adds a line feed if told to. This way you can put this in your game and if something goes wrong, you have a text file telling you all the errors that occured and when they occured.&lt;br /&gt;&lt;br /&gt;- Try writing the previous dots.c demo but &lt;i&gt;ONLY&lt;/i&gt; in test.c and &lt;i&gt;WITHOUT INCLUDING SDL&lt;/i&gt; in that test.c file, all the includes you need are stdlib.h for the rand and wcsdlcore.h for the SDL Core we wrote.&lt;br /&gt;&lt;br /&gt;- If you wrote a version of the dots.c demo for test.c, now compile it for Linux and Windows.&lt;br /&gt;&lt;br /&gt;- And for a real challenge, write a library that draws lines without crashing the engine if the lines go offscreen, and then off of that, add support for particle effects using lines and pixels. This is for you advanced programmers out there who already know how to do this, or those wanting a hefty challenge for this level.&lt;br /&gt;&lt;br /&gt;Until the next time, have fun^^</description>
			<pubDate>Thu, 18 Sep 2008 12:05:30 -0600</pubDate>
			<category>C++ Tutorials</category>
			<author>WolfCoder</author>
         </item>
         <item>
            <link>http://forums.dreamincode.net/showtopic64143.htm</link>
            <title>Game Programming in Linux for Windows Programmers - Part 2 in C++ Tutorials</title>
            <description>&lt;!--sizeo:1--&gt;&lt;span style=&quot;font-size:8pt;line-height:100%&quot;&gt;&lt;!--/sizeo--&gt;&lt;a href=&quot;http://www.dreamincode.net/forums/index.php?act=ST&amp;amp;f=48&amp;amp;t=63945&amp;amp;st=0#entry418798&quot; target=&quot;_blank&quot;&gt;Previous Tutorial&lt;/a&gt;&lt;!--sizec--&gt;&lt;/span&gt;&lt;!--/sizec--&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Prepare Yourself&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;What do you think of Ubuntu Linux so far? It&amp;#39;s actually a pretty cool operating system to program in as you&amp;#39;ve seen. There wasn&amp;#39;t any web surfing to find libraries, it was all linked in the package manager so SDL was only a few clicks away. It is really the version of Linux for human beings... (Although I might not really be human *cough*) I&amp;#39;m glad I never opened the terminal in the last tutorial. Let&amp;#39;s go over the checklist of things you should know, and go back over them if you&amp;#39;re not sure about any one:&lt;br /&gt;&lt;br /&gt;- Using Ubuntu&amp;#39;s default interface (called GNOME), basically creating new files and folders&lt;br /&gt;  &lt;i&gt;You create new files and folders quickly from the right click &amp;quot;drop menu&amp;quot;.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;- Creating a .c file and writing your program&lt;br /&gt;  &lt;i&gt;Just create a new file with .c, .cpp, or .h at the end&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;- Creating a basic Makefile that compiles a single file&lt;br /&gt;  &lt;i&gt;Remember to always name it Makefile without any dots or file extensions&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;- Using the External Tools plugin which you enabled in GEdit to use Tools-&amp;gt;Build to compile the first thing in the Makefile&lt;br /&gt;  &lt;i&gt;You don&amp;#39;t always have to have the Makefile in the view, you can do it right after you were done editing the .c file as long as the .c file is in the same directory as the Makefile&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;You should be able to at least create hello worlds and guessing games with whatever c knowledge you might have. Probably not, but you should at least learn a little c. In fact, if you are rusty in c, I recommend you practice the above steps to practice writing c so that compiling the demos in this tutorial is easy and you understand what&amp;#39;s going on.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Working With SDL&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Foreward:&lt;/i&gt;&lt;br /&gt;SDL was made to make it easy to make games for any system, hence why I picked it for Linux. It&amp;#39;s great to write something that will compile on other systems like Mac and Windows, because even though you&amp;#39;re writing a Linux game, many people still use Windows. This sort of reminds me of a tutorial I originally learned game programming from, except it was for DirectX. He wrote like he talked to make it fun to read, but instead of kawaii references to Anime or animals, his was full of 80s movie quotes and strange SCI-Fi jokes. Anyways, he made the comparison that Microsoft might be the evil guys, but they got all the powerful tools. So while he&amp;#39;s got the &amp;quot;imperial star destroyer&amp;quot;, we&amp;#39;ve got the &amp;quot;half-converted rebel transport&amp;quot; as he puts it. But my half-converted rebel transport is really cool and kawaii looking, and it&amp;#39;s got a really cute login screen&amp;#33; The author of that Windows game programming book knows who he is, and this is practically the good and holy version of his ungodly tome, but you&amp;#39;ll find pure and good game programming knowledge in both of them so give it a read if you come across that book even though it&amp;#39;s sort of old now.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Let&amp;#39;s go&amp;#33;&lt;/i&gt;&lt;br /&gt;Alright, let me explain a bit of what SDL does. SDL stands for Simple DirectMedia Layer... Kind of like a free open source version of DirectDraw only much easier to use. There&amp;#39;s a blob of HTML files in the installation directory... Somewhere... But you can probably find the SDL docs on the internet, you won&amp;#39;t need them here but it&amp;#39;s good for reference anyway. Hold on to your hats, knees, arms, ears, tail, or what have you because it&amp;#39;s going to get bumpy again as we learn new things&amp;#33;&lt;br /&gt;&lt;br /&gt;First off, when writing an SDL game, the SDL runtimes are installed in your operating system and probably by default so most of your Linux pals could probably just run your game right from the get go. If not just tell them to search for &amp;quot;sdl&amp;quot; in the Synaptic Package Manager like you did. What we installed was the developer files, the libSDL and the SDL.h that&amp;#39;s buried in /usr/include/SDL/SDL.h or whatever I put the last tutorial. A windows version of the game is compiled, but when giving the game to your Windows buddies, you should just place SDL.dll right alongside the .exe file so that they can run it right there.&lt;br /&gt;&lt;br /&gt;Hm... Now... What should be a good first SDL demo... *thinks* well, for now let&amp;#39;s get a blank window up again. No, we&amp;#39;re not going to use the hack-together from the last tutorial, I want to walk you through each step of making an SDL window, alright? Here are two functions:&lt;br /&gt;&lt;br /&gt;- SDL_Init&lt;br /&gt;- SDL_Quit&lt;br /&gt;&lt;br /&gt;You simply call SDL_Init where you want the video system to start and SDL_Quit where you want the video system to end. Just be sure to call SDL_Quit so that the system is closed properly and there&amp;#39;s no memory leaks. SDL_Init has a bunch of flags for initializing just the parts of SDL that you need. You need to OR these together with the | character, so that&lt;br /&gt;&lt;br /&gt;SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO);&lt;br /&gt;&lt;br /&gt;Initializes the video and timer. Now we need a window, it&amp;#39;s best to make windowed games with optional fullscreen since fullscreen doesn&amp;#39;t work quite right on all Linux systems. This is the function we need:&lt;br /&gt;&lt;br /&gt;- SDL_SetVideoMode&lt;br /&gt;&lt;br /&gt;This creates a &lt;i&gt;primary surface&lt;/i&gt; to draw on top of. This is the main display surface, and it&amp;#39;s the one the player gets to see. What we need is two of these working in a swap mode called &lt;i&gt;double buffering&lt;/i&gt;. This way, the player sees our pretty picture when it&amp;#39;s done, and not in the middle of drawing. The function call:&lt;br /&gt;&lt;br /&gt;SDL_SetVideoMode(320,240,0,SDL_HWSURFACE | SDL_DOUBLEBUF);&lt;br /&gt;&lt;br /&gt;Will open a window holding a 320x240 primary surface inside using your video card hardware for performance (SDL_HWSURFACE as opposed to SDL_SWSURFACE) and it also asks for a double buffer using SDL_DOUBLEBUF. Later there is SDL_OPENGL and SDL_OPENGLBLIT for combining the use of OpenGL, but it&amp;#39;s something for advanced users so don&amp;#39;t worry about it. We need an event loop to hold the window open, but not lock up the system. Look at the function:&lt;br /&gt;&lt;br /&gt;- SDL_PollEvent&lt;br /&gt;&lt;br /&gt;This function returns 1 if there&amp;#39;s events. Events... Events? In SDL, events are simple things such as closing a window, using the mouse or keyboard, and related events. You need a variable of type SDL_Event 