Blit a byte array to screen in SDL
<p>I am implementing a software rasterizer for school and I would like to simply pass to SDL a buffer with pixels and tell it the format that they are in (RGB, 24b per pixel). SDL would then render that to screen. </p>

<p>I have tried using SDL_Surface but it seems to only work with images or data with headers since the following fails:</p>

<pre><code>    unsigned char pixels[BYTES_PER_PIXEL * SCREEN_WIDTH * SCREEN_HEIGHT];
    // ... all pixels are filled with white color

    imageSurface = SDL_CreateRGBSurfaceFrom(pixels,
      SCREEN_WIDTH,
      SCREEN_HEIGHT,
      sizeof(unsigned char) * BYTES_PER_PIXEL,       // depth
      SCREEN_WIDTH * BYTES_PER_PIXEL,               // pitch (row length * BPP)
      0x000000ff,                                   // red mask
      0x0000ff00,                                   // green mask
      0x00ff0000,                                   // blue mask
      0);                                           // alpha mask
</code></pre>

<p>The error is: SDL_CreateRGBSurfaceFrom failed: Unknown pixel format.
What is the fastest way to do it in SDL? Also would there be a speed difference between that approach and drawing to an OpenGL texture which I would then render onto a full screen quad?</p>