1 | #include "framework.h" |
---|
2 | |
---|
3 | int verbose = 1; |
---|
4 | |
---|
5 | void DrawGLScene() |
---|
6 | { |
---|
7 | rotatorP += rotatorV; |
---|
8 | |
---|
9 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
---|
10 | glLoadIdentity(); // Reset the view |
---|
11 | |
---|
12 | glMatrixMode(GL_PROJECTION); |
---|
13 | glLoadIdentity(); |
---|
14 | gluPerspective(45.0f,500/375,0.1f,dist * 5.0f); |
---|
15 | gluLookAt (dist*sin(rotatorP),dist ,dist*cos(rotatorP), 0,0,0, 0,1,0); |
---|
16 | |
---|
17 | obj->draw(); |
---|
18 | |
---|
19 | SDL_GL_SwapBuffers(); // Swap the buffers |
---|
20 | } |
---|
21 | |
---|
22 | |
---|
23 | int main(int argc, char *argv[]) |
---|
24 | { |
---|
25 | Uint8* keys; // This variable will be used in the keyboard routine |
---|
26 | int done=FALSE; // We aren't done yet, are we? |
---|
27 | |
---|
28 | // Create a new OpenGL window with the title "Cone3D Basecode" at |
---|
29 | // 640x480x32, fullscreen and check for errors along the way |
---|
30 | if(wHandler.CreateGLWindow("Whandler Basecode", 500, 375, 32, FALSE) == FALSE) |
---|
31 | { |
---|
32 | // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit |
---|
33 | printf("Could not initalize OpenGL :(\n\n"); |
---|
34 | wHandler.KillGLWindow(); |
---|
35 | return 0; |
---|
36 | } |
---|
37 | |
---|
38 | printf ("%i, %i\n", wHandler.screen->w, wHandler.screen->h); |
---|
39 | if (argc>=3) |
---|
40 | obj = new Object (argv[1], atof(argv[2])); |
---|
41 | else if (argc>=2) |
---|
42 | obj = new Object(argv[1]); |
---|
43 | else |
---|
44 | obj = new Object(); |
---|
45 | |
---|
46 | glEnable(GL_LIGHTING); |
---|
47 | glEnable(GL_DEPTH_TEST); |
---|
48 | |
---|
49 | GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0}; |
---|
50 | GLfloat light0Position[] = {10.0, 10.0, 10.0, 0.0}; |
---|
51 | GLfloat light1Position[] = {-10.0, -7.0, -6.0, 0.0}; |
---|
52 | GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0}; |
---|
53 | |
---|
54 | glEnable(GL_LIGHT0); |
---|
55 | glLightfv(GL_LIGHT0, GL_POSITION, light0Position); |
---|
56 | glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); |
---|
57 | glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight); |
---|
58 | |
---|
59 | glEnable(GL_LIGHT1); |
---|
60 | glLightfv(GL_LIGHT1, GL_POSITION, light1Position); |
---|
61 | glLightfv(GL_LIGHT1, GL_DIFFUSE, whiteLight); |
---|
62 | glLightfv(GL_LIGHT1, GL_SPECULAR, whiteLight); |
---|
63 | |
---|
64 | rotatorP = .0; |
---|
65 | rotatorV = .0; |
---|
66 | dist = 5.0; |
---|
67 | // Build the font from a TGA image font.tga in the data directory |
---|
68 | // Hide the mouse cursor |
---|
69 | SDL_ShowCursor(2); |
---|
70 | |
---|
71 | // This is the main loop for the entire program and it will run until done==TRUE |
---|
72 | while(!done) |
---|
73 | { |
---|
74 | // Draw the scene |
---|
75 | DrawGLScene(); |
---|
76 | // And poll for events |
---|
77 | SDL_Event event; |
---|
78 | while ( SDL_PollEvent(&event) ) { |
---|
79 | switch (event.type) { |
---|
80 | case SDL_MOUSEMOTION: |
---|
81 | if (verbose >=3) |
---|
82 | printf("Mouse motion about %d,%d Pixels to (%d,%d).\n", |
---|
83 | event.motion.xrel, event.motion.yrel, |
---|
84 | event.motion.x, event.motion.y); |
---|
85 | break; |
---|
86 | case SDL_MOUSEBUTTONDOWN: |
---|
87 | if (event.button.button == 4) |
---|
88 | { |
---|
89 | printf("MouseWheel up\n"); |
---|
90 | dist *= .5; |
---|
91 | } |
---|
92 | else if (event.button.button == 5) |
---|
93 | { |
---|
94 | printf("MouseWheel down\n"); |
---|
95 | dist *= 2; |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | printf("MouseButton %d pressed at (%d,%d).\n", |
---|
100 | event.button.button, event.button.x, event.button.y); |
---|
101 | rotatorV = ( (float)wHandler.screen->w/2 -event.button.x) / (float)wHandler.screen->w / 100.0; |
---|
102 | } |
---|
103 | |
---|
104 | break; |
---|
105 | /* case SDL_MOUSEBUTTONUP: |
---|
106 | printf("MouseButton %d released at (%d,%d).\n", |
---|
107 | event.button.button, event.button.x, event.button.y); |
---|
108 | break; |
---|
109 | */ |
---|
110 | // If a quit event was recieved |
---|
111 | case SDL_QUIT: |
---|
112 | // then we're done and we'll end this program |
---|
113 | done=TRUE; |
---|
114 | break; |
---|
115 | default: |
---|
116 | break; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | // Get the state of the keyboard keys |
---|
121 | keys = SDL_GetKeyState(NULL); |
---|
122 | |
---|
123 | // and check if ESCAPE has been pressed. If so then quit |
---|
124 | if(keys[SDLK_ESCAPE]) done=TRUE; |
---|
125 | } |
---|
126 | |
---|
127 | // Kill the GL & SDL screens |
---|
128 | delete obj; |
---|
129 | wHandler.KillGLWindow(); |
---|
130 | // And quit |
---|
131 | return 0; |
---|
132 | } |
---|