
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "SDL.h"

#define SCREEN_BPP	16			/* bitdepth of colors */
#define TRUE 1
#define FALSE 0

double xPos;
double yPos;
double MinX=-2.0;
double MaxX=2.0;
double MinY=-2.0;
double MaxY=2.0;
double MinZ=-1.0;
double MaxZ=1.0;
double RADIUS=0.1;
int DRAWCIRCLE;

void display(void) {			/* clear all pixels */
	glClear(GL_COLOR_BUFFER_BIT);
	DrawAxis();
	if (DRAWCIRCLE == 1) DrawMyStuff();
	else DrawMyStuffRectangle();
	SDL_GL_SwapBuffers();	
		/* Force writing all pending OpenGL actions to the screen */
	glFlush();
}

void DrawMyStuff() {			/* The Drawing Routine */
	GLUquadricObj *p;

	glPushMatrix();
	p = gluNewQuadric();
	glColor3f(1.0, 1.0, 0.0);	/* Set drawing color to yellow */
	yPos = 4 * xPos - 4 * xPos * xPos;	/* Caluclate y val of parabola */
	glTranslatef(xPos, yPos, 0.0);
	gluQuadricDrawStyle(p, GLU_FILL);
		/* Use GLU_SILHOUETTE for a circle outline */
	gluDisk(p, 0, 0.1, 20, 1);	/* gluDisk(p, innerRadius, outerRadius,
								 * slices, rings); */
	glPopMatrix();
	if (xPos <= 1) xPos += .001;
} 

void DrawMyStuffRectangle() {
	glColor3f(1.0, 1.0, 0.0);
	yPos = 4*xPos -  4*xPos*xPos;	/* Calculate y value of parabola */
	glRectf(xPos, yPos, xPos+.4, yPos+.4);
	if (xPos <= 1) xPos += .001;
}

void DrawAxis() {
	glColor3f(0.0,0.0,0.0);
	glBegin(GL_LINES);
	glVertex2f(MinX, 0);
	glVertex2f(MaxX, 0);
	glVertex2f(0 , MinY);
	glVertex2f(0 , MaxY);
	glEnd();
	glFlush();
}

void myinit(void) {				/* select clearing (background) color */
	SDL_WM_SetCaption("My Window", NULL);
		/* Set window caption and icon caption, respectively */
	xPos = -1.0;
	DRAWCIRCLE = 1;
	glClearColor(0.5, 0.5, 0.5, 0.0);	/* These RGB values make gray */

	/* initialize viewing values */
	glMatrixMode(GL_PROJECTION);	/* Select Matrix Mode */
	glLoadIdentity();			/* Provide Base Matrix */
	glOrtho(MinX, MaxX, MinY, MaxY, MinZ, MaxZ);	/* Set window dims */
	/* Parameters:  glOrtho(Left, Right, Bottom, Top, Front, Back) */
	DrawAxis();
}

void KeyPressed(SDL_keysym *keysym) {
	switch (keysym->sym) {		/* which key is it? */
		case SDLK_F1:			/* F1 */
			ToggleFullScreen();	/* Toggle fullscreen/windowed mode */
			break;
		case SDLK_ESCAPE:		/* if it is ESC */
		case SDLK_q:
			Quit(0);
			break;
		case SDLK_r:
			DRAWCIRCLE = 0;
			break;
		case SDLK_c:
			DRAWCIRCLE = 1;
			break;
		default:
			break;
	}
}

inline void mouse(SDL_Event event) {
	if(event.type == SDL_MOUSEBUTTONDOWN && 
		event.button.button == 1)	/* Left button clicked */ 
		xPos = -1.0;
}

