-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
247 lines (197 loc) · 5.23 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// texturebfly.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
#include "glut.h"
#include "bitmap.h"
#include "UCFL_Utils2.h"
#include "CFLSlib\\CFLS.h"
#include "maincode.h"
#include "sim.h"
//timing
/* Startup */
__int64 countsPerSec = 0;
__int64 prevTimeStamp = 0;
float secsPerCount;
/* Per frame */
__int64 currTimeStamp;
float deltatime;
int frameCount = 0, prvframeCount = 0;
int framePerSecond=0;
int runMode=1; // 0=test mode 1=sim mode
int timerInterval=50; // how fast
GLfloat Near=0.5;
GLfloat Far=20.0;
GLfloat aspect; // screen aspect ratio
char VersionString[] = "Fuzzy Explorer V0.8.0.1 alpha";
int window1,window2;
enum { // enumerations for menu
cmdNull,
cmdExit
};
static int AppMenu;
bool timeForNextFrame=false;
bool simHasRun=false;
int err;
const GLubyte *oglVersion;
int windowWidth,windowHeight;
static void display ()
{
frameCount++;
if(frameCount%20 == 0)
{
//fps timing
QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
deltatime = (currTimeStamp - prevTimeStamp)*secsPerCount;
secsPerCount = 1.0 / (double)countsPerSec;
prevTimeStamp = currTimeStamp;framePerSecond = 20/deltatime;
prvframeCount++;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Do the 2D drawing bit
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLfloat)windowWidth, 0.0, (GLfloat)windowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
simRender();
// Check for errors and write a diagnostic string if detected.
// On error, the app will freeze (but not exit), as the buffers
// won't be swapped...
glFlush();
err = glGetError();
if (err == GL_NO_ERROR)
glutSwapBuffers();
else
printf("GL Error >>%s\n", gluErrorString(err));
}
static void display2 ()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Do the 2D drawing bit
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLfloat)windowWidth, 0.0, (GLfloat)windowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
mainRender();
// Check for errors and write a diagnostic string if detected.
// On error, the app will freeze (but not exit), as the buffers
// won't be swapped...
glFlush();
err = glGetError();
if (err == GL_NO_ERROR)
glutSwapBuffers();
else
printf("GL Error >>%s\n", gluErrorString(err));
}
static void updateIdle (void)
{
if (timeForNextFrame && simHasRun)
{
glutSetWindow(window1);
glutPostRedisplay();
glutSetWindow(window2);
glutPostRedisplay();
timeForNextFrame=false;
simHasRun=false;
}
else
if (!simHasRun) simIdle();
}
static void menuChoice (int item)
{
switch (item) {
case cmdExit:
exit(0);
break;
default:
break;
}
}
void myExitfn()
{
printf("Exiting\n");
if (runMode==1) simExit();
printf("Exit complete\n");
}
static void initGraphics (void)
{
//timing
QueryPerformanceFrequency((LARGE_INTEGER*)&countsPerSec);
secsPerCount = 1.0 / (double)countsPerSec;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
glClearColor(0.9, 0.9, 1, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
simInit();
AppMenu = glutCreateMenu(menuChoice);
glutSetMenu(AppMenu);
glutAddMenuEntry("----", cmdNull);
glutAddMenuEntry("Exit", cmdExit);
glutAttachMenu(GLUT_RIGHT_BUTTON);
atexit(myExitfn);
}
static void initGraphics2 (void)
{
glClearColor(0.9, 0.9, 1, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
mainCode();
AppMenu = glutCreateMenu(menuChoice);
glutSetMenu(AppMenu);
glutAddMenuEntry("----", cmdNull);
glutAddMenuEntry("Exit", cmdExit);
glutAttachMenu(GLUT_RIGHT_BUTTON);
atexit(myExitfn);
}
static void resize (int width, int height)
{
windowWidth=width;
windowHeight=height;
glViewport(0, 0, width, height);
}
static void asciiKey (unsigned char key, int x, int y)
{
simKey(key,x,y);
key_generic(key);
if (key==27) exit(0); /* 27 is ESC */
}
void timer(int value)
{
timeForNextFrame=true;
glutTimerFunc(timerInterval,timer,0);
simTimer(value);
mainTimer(value);
}
int main (int argc, char * argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600, 600);
//create first window
glutInitWindowPosition(50, 50);
window1 = glutCreateWindow(VersionString);
initGraphics();
glutDisplayFunc(display);
glutReshapeFunc(resize);
//create second window
glutInitWindowPosition(655, 50);
window2 = glutCreateWindow("Second");
initGraphics2();
glutDisplayFunc(display2);
glutReshapeFunc(resize);
oglVersion=glGetString(GL_VERSION);
printf("openGl version %s \n",oglVersion);
glutKeyboardFunc(asciiKey);
glutTimerFunc(timerInterval,timer,0);
glutIdleFunc(updateIdle);
glutMainLoop();
return 0;
}