title: C++ Anti-aliased line for beginner to SDL
body: <p>Original question:</p>
  
  <blockquote>
    <p>I've been asked prior to a job interview to understand how an
    anti-aliased line is drawn in a framebuffer, using C or C++. I haven't
    used C, and it's been a few years for me since last using C++. I am a
    complete beginner when it comes to graphics. My C++ experience has
    mostly been in simple command-line programs and sorting methods. The
    company does not care if I grab the code online, they want me to
    understand it but still have a working executable.</p>
    
    <p>I've used <a href="http://lazyfoo.net/SDL_tutorials/lesson01/windows/msvsnet2010e/index.php" rel="nofollow">this tutorial</a> to set up SDL libraries in MS VC++ 2012
    Express, and <a href="http://en.wikipedia.org/wiki/Talk%3aXiaolin_Wu%27s_line_algorithm#Using_Wu.27s_line_algorithm_in_SDL" rel="nofollow">this algorithm</a> for the actual anti-aliasing. I have
    a good understanding of the algorithm, though I'm currently having
    trouble getting it to compile. I just want a line to be drawn, and
    then I can go forward with setting the code up to the skeleton class
    definitions I was given. This is what I have included aside from what
    is on that page with the algorithm:</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;math.h&gt;
  #include "conio.h"
  #include "stdlib.h"
  #include "stdio.h"
  #include "SDL.h"
  
  const double HEIGHT = 240;
  const double WIDTH = 320;
  const double X0 = 25.6;
  const double X1 = 64.7;
  const double Y0 = 30;
  const double Y1 = 42;
  
  int round(double number)
  {
      return number &lt; 0.0 ? ceil(number - 0.5) : floor(number + 0.5);
  }
  
  void main()
  {
    Uint32 pixelColor = 00000000000000000000000000000000;
  
    SDL_Surface* myScreen = SDL_CreateRGBSurface(SDL_ALPHA_OPAQUE,WIDTH,HEIGHT,32, 0x000000FF,
  </code></pre>
    
    <p>0x0000FF00, 0x00FF0000, 0xFF000000);</p>
  
  <pre><code>  WULinesAlpha(X0, X1, Y0, Y1,pixelColor,myScreen);
  
    return;
  }
  </code></pre>
    
    <p>I'm getting the following errors:</p>
    
    <p>Error 21  error LNK2019: unresolved external symbol _SDL_main
    referenced in function _main Error    22  error LNK1120: 1 unresolved
    externals</p>
    
    <p>I've seen a few code examples saying the main function has to look
    like this:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  }
  </code></pre>
    
    <p>Again, graphics stuff is unfamiliar to me so I know my main function
    is likely very wrong; I'm anticipating some shaking heads. Can someone
    explain what is happening/what I need to do?</p>
  </blockquote>
  
  <p>New:</p>
  
  <p>I have now replaced my main function with the following code, based on NomNomNom069's YouTube video: "C++ SDL Tutorial 2 Creating a Screen and Handling Basic Input"</p>
  
  <pre><code>#include "SDL.h"
  
  int main(int argc, char * args[])
  {
      bool running = true;
      //initialize SDL
      if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
      {
          running = false;
      }
  
      //set up screen
      SDL_Surface *screen;
  
      screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_HWSURFACE);
  
      if (screen == NULL)
      {
          running = false;
      }
  
      SDL_Event occur;
  
      //main application loop
      while (running)
      {
          SDL_PollEvent(&amp;occur);
  
          if (occur.type == SDL_QUIT)
          {
              running = false;
          }
  
          //drawing occurs here
          SDL_FillRect(screen, NULL, 0);
          SDL_Flip(screen);
      }
  
      //quit SDL
      SDL_Quit();
  
      return 0;
  }
  </code></pre>
  
  <p>No errors, and I get a window to pop up. Awesome.</p>
  
  <p>My question now is regarding how/where to call <code>WuLinesAlpha</code>. This function calls for 4 <code>double</code>s, a <code>Uint32</code> variable, and an <code>SDL_Surface*</code>. I have my <code>double</code>s, I set the <code>Uint32</code> to <code>0x000000FF</code>, and I assume that the <code>SDL_Surface</code> I have set up as <code>screen</code> is the one passed in.</p>
  
  <p>I've toyed around with where the <code>WuLinesAlpha</code> function call goes and I keep getting the black screen. I thought, as explained in the video, it would go in the loop but nothing has happened. Are there any more SDL commands I should be calling?</p>