//--------------------------------------------------------------------------------------------------
// file: tomprogs_opengl_tutorial_01.cpp
// description: Contains the whole code used in the OpenGL Tutorial 01 at www.tomprogs.at
//--------------------------------------------------------------------------------------------------
// Copyright (c) 2008 - 2010, Thomas Geymayer
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
//    * Redistributions of source code must retain the above copyright notice, this list of 
//      conditions and the following disclaimer.
//    * Redistributions in binary form must reproduce the above copyright notice, this list of
//      conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//--------------------------------------------------------------------------------------------------

#include "SDL.h"
#include "SDL_opengl.h"

#include <iostream> // für Konsolenausgaben
 
using std::cout;    // Wir verwenden std::cout und
using std::endl;    // std::endl für die Konsolenausgaben
 
// Die main Funktion muss unter Windows unbedingt
// diese Form haben, da es ansonsten zu einem
// Linkerfehler kommen würde.
int main(int argc, char **argv)
{
  if( SDL_Init( SDL_INIT_VIDEO ) != 0 ) // Initialisieren des SDL Video Subsystems
  {
    cout << "Die SDL konnte nicht initalisiert werden (" << SDL_GetError() << ")" << endl;
    return 1;
  }
 
  cout << "Willkommen zum SDL Testprogramm." << endl;

  
  // Fenstertitel setzen:
  // Der erste Text steht in der Titelleiste des Fensters und der zweite in der Taskleiste.
  SDL_WM_SetCaption( "Tomprogs Game Tutorials - First Try", "Tomprogs - First Try" );

  // Doublebuffering aktivieren
  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

  // Ein OpenGL Fenster mit einer Auflösung von 800*600 Pixeln und
  // einer Farbtiefe von 32 Pixeln erzeugen.
  SDL_SetVideoMode( 800, 600, 32, SDL_OPENGL );
  
  // Enlosschleife
  while(true)
  {
    SDL_Event event; // Hier wird immer die neue Nachricht gespeichert

    while( SDL_PollEvent(&event) ) // Holen der nächsten Nachricht
    {
      // Bestimmen des Nachrichtentyps
      switch(event.type)
      {
        // Bei einer SDL_QUIT Nachricht sollte das Programm beendet werden.
        // Sie wird zb. verschickt wenn man auf das X beim Programmfenster
        // klickt.
        case SDL_QUIT:
          SDL_Quit(); // Herunterfahren der SDL
          exit(0);
          break;
        default:
          break;
      }
    }

    // Hierher kommt dann alles was das Spiel am Laufen hält...

  }
  
  SDL_Quit(); // Herunterfahren der SDL Bibliotheken

  return 0;
}

