1 | #include "windowHandler.h" // Include the Whandler Basecode |
---|
2 | #include "object.h" |
---|
3 | |
---|
4 | int verbose = 2; |
---|
5 | WindowHandler wHandler; // Create an instance of the whandler basecode class |
---|
6 | Object* obj; |
---|
7 | Object* obj2; |
---|
8 | Object* obj3; |
---|
9 | float rotator = 0.0; |
---|
10 | GLfloat whiteLight[] = {1.0, 1.0, 0.0,1.0}; |
---|
11 | |
---|
12 | void DrawGLScene() |
---|
13 | { |
---|
14 | rotator +=.001; |
---|
15 | |
---|
16 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
---|
17 | glLoadIdentity(); // Reset the view |
---|
18 | |
---|
19 | glMatrixMode(GL_PROJECTION); |
---|
20 | glLoadIdentity(); |
---|
21 | gluPerspective(45.0f,500/375,0.1f,100.0f); |
---|
22 | gluLookAt (5*sin(rotator),7.5,5*cos(rotator), 0,0,0, 0,1,0); |
---|
23 | whiteLight[1] = .5+.5*sin(rotator*10); |
---|
24 | whiteLight[2] = .5+.5*sin(rotator*10); |
---|
25 | |
---|
26 | GLfloat lightPosition[] = {10.0*sin(rotator*10), 10, 19.0, 0.0}; |
---|
27 | glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); |
---|
28 | |
---|
29 | glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); |
---|
30 | obj->draw(); |
---|
31 | |
---|
32 | SDL_GL_SwapBuffers(); // Swap the buffers |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | int main(int argc, char *argv[]) |
---|
37 | { |
---|
38 | Uint8* keys; // This variable will be used in the keyboard routine |
---|
39 | int done=FALSE; // We aren't done yet, are we? |
---|
40 | |
---|
41 | // Create a new OpenGL window with the title "Cone3D Basecode" at |
---|
42 | // 640x480x32, fullscreen and check for errors along the way |
---|
43 | if(wHandler.CreateGLWindow("Whandler Basecode", 500, 375, 32, FALSE) == FALSE) |
---|
44 | { |
---|
45 | // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit |
---|
46 | printf("Could not initalize OpenGL :(\n\n"); |
---|
47 | wHandler.KillGLWindow(); |
---|
48 | return 0; |
---|
49 | } |
---|
50 | if (argc>=3) |
---|
51 | obj = new Object (argv[1], atof(argv[2])); |
---|
52 | else if (argc>=2) |
---|
53 | obj = new Object(argv[1]); |
---|
54 | else |
---|
55 | obj = new Object(); |
---|
56 | |
---|
57 | GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0}; |
---|
58 | glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); |
---|
59 | glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight); |
---|
60 | glEnable(GL_LIGHTING); |
---|
61 | glEnable(GL_LIGHT0); |
---|
62 | glEnable(GL_DEPTH_TEST); |
---|
63 | |
---|
64 | // Build the font from a TGA image font.tga in the data directory |
---|
65 | // Hide the mouse cursor |
---|
66 | SDL_ShowCursor(0); |
---|
67 | |
---|
68 | // This is the main loop for the entire program and it will run until done==TRUE |
---|
69 | while(!done) |
---|
70 | { |
---|
71 | // Draw the scene |
---|
72 | DrawGLScene(); |
---|
73 | // And poll for events |
---|
74 | SDL_Event event; |
---|
75 | while ( SDL_PollEvent(&event) ) { |
---|
76 | switch (event.type) { |
---|
77 | // If a quit event was recieved |
---|
78 | case SDL_QUIT: |
---|
79 | // then we're done and we'll end this program |
---|
80 | done=TRUE; |
---|
81 | break; |
---|
82 | default: |
---|
83 | break; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | // Get the state of the keyboard keys |
---|
88 | keys = SDL_GetKeyState(NULL); |
---|
89 | |
---|
90 | // and check if ESCAPE has been pressed. If so then quit |
---|
91 | if(keys[SDLK_ESCAPE]) done=TRUE; |
---|
92 | } |
---|
93 | |
---|
94 | // Kill the GL & SDL screens |
---|
95 | delete obj; |
---|
96 | wHandler.KillGLWindow(); |
---|
97 | // And quit |
---|
98 | return 0; |
---|
99 | } |
---|