rev |
line source |
nuclear@0
|
1 #include <stdio.h>
|
nuclear@0
|
2 #include <GL/glew.h>
|
nuclear@0
|
3 #include "game.h"
|
nuclear@0
|
4
|
nuclear@0
|
5 static void draw_backdrop();
|
nuclear@0
|
6
|
nuclear@0
|
7 int win_width, win_height;
|
nuclear@0
|
8
|
nuclear@0
|
9 static float cam_theta, cam_phi = 25, cam_dist = 6;
|
nuclear@0
|
10 static bool bnstate[8];
|
nuclear@0
|
11 static int prev_x, prev_y;
|
nuclear@0
|
12
|
nuclear@0
|
13
|
nuclear@0
|
14 bool game_init()
|
nuclear@0
|
15 {
|
nuclear@0
|
16 glEnable(GL_DEPTH_TEST);
|
nuclear@0
|
17 glEnable(GL_CULL_FACE);
|
nuclear@0
|
18
|
nuclear@0
|
19 glEnable(GL_LIGHTING);
|
nuclear@0
|
20 glEnable(GL_LIGHT0);
|
nuclear@0
|
21
|
nuclear@0
|
22 return true;
|
nuclear@0
|
23 }
|
nuclear@0
|
24
|
nuclear@0
|
25 void game_cleanup()
|
nuclear@0
|
26 {
|
nuclear@0
|
27 }
|
nuclear@0
|
28
|
nuclear@0
|
29 void game_update(unsigned long time_msec)
|
nuclear@0
|
30 {
|
nuclear@0
|
31 }
|
nuclear@0
|
32
|
nuclear@0
|
33 void game_display()
|
nuclear@0
|
34 {
|
nuclear@0
|
35 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
nuclear@0
|
36
|
nuclear@0
|
37 glMatrixMode(GL_MODELVIEW);
|
nuclear@0
|
38 glLoadIdentity();
|
nuclear@0
|
39 glTranslatef(0, 0, -cam_dist);
|
nuclear@0
|
40 glRotatef(cam_phi, 1, 0, 0);
|
nuclear@0
|
41 glRotatef(cam_theta, 0, 1, 0);
|
nuclear@0
|
42
|
nuclear@0
|
43 draw_backdrop();
|
nuclear@0
|
44
|
nuclear@0
|
45 glBegin(GL_QUADS);
|
nuclear@0
|
46 glNormal3f(0, 1, 0);
|
nuclear@0
|
47 glVertex3f(-1, 0, 1);
|
nuclear@0
|
48 glVertex3f(1, 0, 1);
|
nuclear@0
|
49 glVertex3f(1, 0, -1);
|
nuclear@0
|
50 glVertex3f(-1, 0, -1);
|
nuclear@0
|
51 glEnd();
|
nuclear@0
|
52 }
|
nuclear@0
|
53
|
nuclear@0
|
54 static void draw_backdrop()
|
nuclear@0
|
55 {
|
nuclear@0
|
56 glPushAttrib(GL_ENABLE_BIT);
|
nuclear@0
|
57 glDisable(GL_LIGHTING);
|
nuclear@0
|
58 glDisable(GL_DEPTH_TEST);
|
nuclear@0
|
59
|
nuclear@0
|
60 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
61 glPushMatrix();
|
nuclear@0
|
62 glLoadIdentity();
|
nuclear@0
|
63 glMatrixMode(GL_MODELVIEW);
|
nuclear@0
|
64 glPushMatrix();
|
nuclear@0
|
65 glLoadIdentity();
|
nuclear@0
|
66
|
nuclear@0
|
67 glBegin(GL_QUADS);
|
nuclear@0
|
68 glColor3f(0.9, 0.8, 0.6);
|
nuclear@0
|
69 glVertex2f(-1, -1);
|
nuclear@0
|
70 glVertex2f(1, -1);
|
nuclear@0
|
71 glColor3f(0.4, 0.5, 0.8);
|
nuclear@0
|
72 glVertex2f(1, 1);
|
nuclear@0
|
73 glVertex2f(-1, 1);
|
nuclear@0
|
74 glEnd();
|
nuclear@0
|
75
|
nuclear@0
|
76 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
77 glPopMatrix();
|
nuclear@0
|
78 glMatrixMode(GL_MODELVIEW);
|
nuclear@0
|
79 glPopMatrix();
|
nuclear@0
|
80
|
nuclear@0
|
81 glPopAttrib();
|
nuclear@0
|
82 }
|
nuclear@0
|
83
|
nuclear@0
|
84 void game_reshape(int x, int y)
|
nuclear@0
|
85 {
|
nuclear@0
|
86 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
87 glLoadIdentity();
|
nuclear@0
|
88 gluPerspective(50, (float)x / (float)y, 0.5, 500.0);
|
nuclear@0
|
89
|
nuclear@0
|
90 glViewport(0, 0, x, y);
|
nuclear@0
|
91 }
|
nuclear@0
|
92
|
nuclear@0
|
93 void game_keyboard(int bn, bool press)
|
nuclear@0
|
94 {
|
nuclear@0
|
95 if(press) {
|
nuclear@0
|
96 switch(bn) {
|
nuclear@0
|
97 case 27:
|
nuclear@0
|
98 quit();
|
nuclear@0
|
99 }
|
nuclear@0
|
100 }
|
nuclear@0
|
101 }
|
nuclear@0
|
102
|
nuclear@0
|
103 void game_mbutton(int bn, bool press, int x, int y)
|
nuclear@0
|
104 {
|
nuclear@0
|
105 bnstate[bn] = press;
|
nuclear@0
|
106 prev_x = x;
|
nuclear@0
|
107 prev_y = y;
|
nuclear@0
|
108 }
|
nuclear@0
|
109
|
nuclear@0
|
110 void game_mmotion(int x, int y)
|
nuclear@0
|
111 {
|
nuclear@0
|
112 int dx = x - prev_x;
|
nuclear@0
|
113 int dy = y - prev_y;
|
nuclear@0
|
114 prev_x = x;
|
nuclear@0
|
115 prev_y = y;
|
nuclear@0
|
116
|
nuclear@0
|
117 if(bnstate[0]) {
|
nuclear@0
|
118 cam_theta += dx * 0.5;
|
nuclear@0
|
119 cam_phi += dy * 0.5;
|
nuclear@0
|
120
|
nuclear@0
|
121 if(cam_phi < -90) cam_phi = -90;
|
nuclear@0
|
122 if(cam_phi > 90) cam_phi = 90;
|
nuclear@0
|
123
|
nuclear@0
|
124 redisplay();
|
nuclear@0
|
125 }
|
nuclear@0
|
126 if(bnstate[2]) {
|
nuclear@0
|
127 cam_dist += dy * 0.1;
|
nuclear@0
|
128 if(cam_dist < 0.0) cam_dist = 0.0;
|
nuclear@0
|
129
|
nuclear@0
|
130 redisplay();
|
nuclear@0
|
131 }
|
nuclear@0
|
132 }
|