#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>

/* 
 * Window properties 
 */
#define WINDOW_X        100
#define WINDOW_Y        100
#define WIDTH           300
#define HEIGHT          100
#define WINDOW_TITLE    "" /* Hier Namen einsetzen */

void init(int argc, char **argv, void (*func)(void));
void draw(void);
double gauss(double x, double center, double height, double sigma);

int main(int argc, char **argv) {

    /*
     * Init OpenGL and enter the event loop
     */
    init(argc, argv, draw);

    return 0;
}

/*
 * Initialize the OpenGL machine
 */
void init(int argc, char **argv, void (*func)(void)) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutInitWindowPosition(WINDOW_X, WINDOW_Y);
    glutCreateWindow(WINDOW_TITLE);
    glClearColor(0.0, 0.0, 0.0, 0.0);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, WIDTH, 0, HEIGHT, -1, 1);

    glutDisplayFunc(func);
    glutMainLoop();

    /* Not reached */
}

/*
 * Draws the scene
 */
void draw(void) {
  double wavelength; /* in nanometer */
  int x;
  double red;
  double green;
  double blue;
  
  for (x = 0; x < 300; x = x + 1)
  {
    wavelength = (double)(x + 400);
    red = 0.0; /* hier Rot-Anteil einsetzen */
    green = 0.0; /* hier Gruen-Anteil einsetzen */
    blue = (float)gauss(wavelength, 450.0, 1.0, 30.0);

    glColor3f(red,green,blue);

    glBegin(GL_LINES);
    glVertex2f(x,0);
    glVertex2f(x,100);    
    glEnd();

    glFlush();
  }
}

double gauss(double x, double center, double height, double sigma)
{
  return height * exp(-(x - center) * (x - center) / 
		      (2.0 * sigma * sigma));
}
  

