00001 #include "tester/TesterApp.h"
00002 #include "camera/camera.h"
00003 #include "input/Input.h"
00004 #include "trees/Tree.h"
00005
00006 Camera camera;
00007 Tester *tester;
00008 Tree *tree;
00009
00010 int mousexPos = -1, mouseyPos = -1;
00011
00012 void TriangleMouseMotion(int xPos, int yPos)
00013 {
00014 if(mousexPos < 0 && mouseyPos < 0)
00015 mousexPos = xPos, mouseyPos = yPos;
00016
00017 int dx = xPos - mousexPos;
00018 int dy = yPos - mouseyPos;
00019
00020 mousexPos = xPos;
00021 mouseyPos = yPos;
00022
00023 if(InputMouseIsDown(GLUT_LEFT_BUTTON))
00024 {
00025 camera.RotateLR(((float)dx)/300.0*3.14159f);
00026 camera.RotateUD(-((float)dy)/300.0*3.14159f);
00027 }
00028
00029 }
00030 void InitLighting() {
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 glEnable(GL_LIGHTING);
00051
00052 GLfloat ambient_light[] = {0.4f, 0.4f, 0.4f, 1.0f};
00053 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_light);
00054
00055
00056 GLfloat light0Position[] = {0.0f, 0.0f, 1.0f, 0.0f};
00057 GLfloat light0Direction[]= {0.0f, 0.0f, -1.0f, 0.0f};
00058 GLfloat light0Ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
00059 GLfloat light0Diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
00060 GLfloat light0Specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
00061
00062 glEnable(GL_LIGHT0);
00063 glLightfv(GL_LIGHT0, GL_POSITION, light0Position);
00064
00065
00066
00067 glLightfv(GL_LIGHT0, GL_AMBIENT, light0Ambient);
00068 glLightfv(GL_LIGHT0, GL_DIFFUSE, light0Diffuse);
00069 glLightfv(GL_LIGHT0, GL_SPECULAR, light0Specular);
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 GLfloat grassSpecular[] = {1.0f, 1.0f, 1.0f, 1.0f};
00112 GLfloat grassShininess[] = {0.0f};
00113 GLfloat grassDiffuse[] = {0.0f, 0.9f, 0.0f, 1.0f};
00114 GLfloat grassAmbient[] = {0.0f, 0.9f, 0.0f, 1.0f};
00115 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, grassSpecular);
00116 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, grassShininess);
00117 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, grassDiffuse);
00118 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, grassAmbient);
00119 }
00120 void TriangleDraw()
00121 {
00122 camera.Draw();
00123 glLoadIdentity();
00124 InitLighting();
00125 glColor3f(0.0f, 0.8f, 0.1f);
00126 glBegin(GL_QUADS);
00127 glNormal3f(0.0f, 1.0f, 0.0f);
00128 glVertex3f(100.0f, 0.0f, 100.0f);
00129 glVertex3f(-100.0f, 0.0f, 100.0f);
00130 glVertex3f(-100.0f, 0.0f, -100.0f);
00131 glVertex3f(100.0f, 0.0f, -100.0f);
00132 glEnd();
00133 if(tree)
00134 tree->Draw();
00135 }
00136
00137 void TriangleUpdate()
00138 {
00139 if(InputKeyIsDown('W'))
00140 camera.Forward();
00141 if(InputKeyIsDown('A'))
00142 camera.Left();
00143 if(InputKeyIsDown('S'))
00144 camera.Backward();
00145 if(InputKeyIsDown('D'))
00146 camera.Right();
00147
00148 if(tree) tree->Update();
00149 }
00150
00151 void TriangleCleanup()
00152 {
00153
00154 }
00155 void foo(void *msg)
00156 {
00157 tester->ConsoleWrite((char*)msg);
00158
00159 }
00160 void NewButton(void *label)
00161 {
00162
00163 tree = new Tree();
00164 }
00165 void NewSlider(void *controlVar)
00166 {
00167 tester->CreateSlider("foobar3", (float*)controlVar, -3.14159/8, 3.14159/8, 0.0f);
00168 }
00169
00170 void TriangleInit()
00171 {
00172
00173 tester->CreateButton("New Tree",NewButton,"foobar");
00174
00175 glClearColor( 0., 0., 0., 1. );
00176
00177 InputSetMouseMotion(TriangleMouseMotion);
00178 }
00179
00180
00181 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
00182 {
00183 tester = TesterGet();
00184 tester->SetInitFunc(TriangleInit);
00185
00186 if(tester->Init(hInst))
00187 {
00188 tester->SetUpdateFunc(TriangleUpdate);
00189 tester->SetDrawFunc(TriangleDraw);
00190 tester->SetExitFunc(TriangleCleanup);
00191 tester->SetMouseMotionFunc(InputSystemMouseMotion);
00192 tester->SetMouseButtonFunc(InputSystemMouseButton);
00193 tester->SetKeyDownFunc(InputSystemKeyDown);
00194 tester->SetKeyUpFunc(InputSystemKeyUp);
00195 tester->Main();
00196 }
00197
00198 return 0;
00199 }