#ifndef H_SFGL
#define H_SFGL
#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>

void glBeginDraw()
    {
	glEnable(GL_TEXTURE_2D);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glColor4d(1,1,1,1);
    glTranslatef(0,0,0);
    glAlphaFunc ( GL_GREATER, 1/255 ) ;
    glEnable ( GL_ALPHA_TEST ) ;
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glLoadIdentity();
	glClearColor(0.0f,0.0f,0.0f,0.0f);
    }

void glOrthoBegin()
    {
    glDisable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, GL_WIN_SIZE_X, 0, GL_WIN_SIZE_Y, -1, 1);
	glScalef(1, -1, 1);
	glTranslatef(0, -GL_WIN_SIZE_Y, 0);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
    }

void glOrthoEnd()
    {
    glEnable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
    }

int InitGL()
{
    GLfloat fogColor[4]= {1.0f, 0.0f, 0.0f, 1.0f};
    glClearColor(fogColor[0],fogColor[1],fogColor[2],1.0f);
	glFogfv(GL_FOG_COLOR, fogColor);
    glFogi(GL_FOG_MODE, GL_LINEAR);
    glFogf(GL_FOG_DENSITY, 0.01f);
    glHint(GL_FOG_HINT, GL_DONT_CARE);
    glFogf(GL_FOG_START, 0);
    glFogf(GL_FOG_END, 0);
    //glEnable(GL_FOG);
    glShadeModel(GL_SMOOTH);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    //glEnable(GL_CULL_FACE);
    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glViewport(0,0,GL_WIN_SIZE_X,GL_WIN_SIZE_Y);
    glMatrixMode(GL_PROJECTION);
    gluPerspective(45.0f,(GLfloat)GL_WIN_SIZE_X/(GLfloat)GL_WIN_SIZE_Y,0.1f,32000.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    return true;
}
#endif