#include <GLShaderManager.h>

#include <GLTools.h>

#include <glut/glut.h>

GLBatch triangleBatch;

GLShaderManager shaderManager;

// the window size changes to accept the new width and height, where 0,0 represent the lower-left coordinates of the viewport in the window, w, h represent pixels

void ChangeSize(int w,int h)

{

GlViewport (0, 0, w, h);

}

// Make a one-time setup for the program

void SetupRC()

{

// Set the background color

GlClearColor (0.0 f, f, 0.0 1.0 f, 1.0 f);

// Initialize the shader manager

shaderManager.InitializeStockShaders();

// Set the triangle, where the array vVert contains x,y, cartesian pairs of all 3 vertices.

GLfloat vVerts[] = {

0.5 f, f 0.0, 0.0, f

0.5 f, f 0.0, 0.0 f,

0.0 f, f 0.5, 0.0 f,

};

// batch processing

triangleBatch.Begin(GL_TRIANGLES,3);

triangleBatch.CopyVertexData3f(vVerts);

triangleBatch.End();

}

// Start rendering

void RenderScene(void)

{

// Clear a specific buffer or group of buffers

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);

// Set a set of floating-point numbers to represent red

GLfloat vRed [] = {0.0 1.0 f, f, f 0.0, 1.0} f;

// Passes to the storage shader, the GLT_SHADER_IDENTITY shader, which simply renders the geometry on the screen using the specified color and default Cartesian coordinates

shaderManager.UseStockShader(GLT_SHADER_IDENTITY,vRed);

// Submit the shader

triangleBatch.Draw();

// Will render in the background buffer and then swap to the foreground at the end

glutSwapBuffers();

}

int main(int argc,char* argv[])

{

// Set the current working directory for MAC OS X

gltSetWorkingDirectory(argv[0]);

// Initialize the GLUT library

glutInit(&argc, argv);

/* Initialize the double buffer window, where GLUT_DOUBLE, GLUT_RGBA, GLUT_DEPTH, GLUT_STENCIL indicate respectively

Double buffered window, RGBA color mode, depth testing, template buffer */

glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL);

//GLUT window size, title window

GlutInitWindowSize (800600);

glutCreateWindow(“Triangle”);

// Register the callback function

glutReshapeFunc(ChangeSize);

glutDisplayFunc(RenderScene);

// There are no problems with driver initialization.

GLenum err = glewInit();

if(GLEW_OK ! = err) {

fprintf(stderr,”glew error:%s\n”,glewGetErrorString(err));

return 1;

}

/ / call SetupRC

SetupRC();

glutMainLoop();

return 0;

}