-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
winmain.cpp
127 lines (101 loc) · 3.54 KB
/
winmain.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
/*
* Polygon Reduction Demo by Stan Melax (c) 1998
* Permission to use any of this code wherever you want is granted..
* Although, please do acknowledge authorship if appropriate.
*
* This module contains the window setup code, mouse input, timing
* routines, and that sort of stuff. The interesting modules
* to see are bunnygut.cpp and progmesh.cpp.
*
* The windows 95 specific code for this application was taken from
* an example of processing mouse events in an OpenGL program using
* the Win32 API from the www.opengl.org web site.
*
* Under Project->Settings, Link Options, General Category
* Add:
* Opengl32.lib glu32.lib winmm.lib
* to the Object/Library Modules
*
* You will need have OpenGL libs and include files to compile this
* Go to the www.opengl.org web site if you need help with this.
*/
// 2014 update, just inlined the needed vector things in the vecmatquat_minimal.h file.
// original code was from 1998 and wasn't using the best conventions.
// For example, quaternions are xyzw now, not rxyz.
#define NOMINMAX
#include <windows.h> /* must include this before GL/gl.h */
#include <GL/gl.h> /* OpenGL header file */
#include <GL/glu.h> /* OpenGL utilities header file */
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>
#pragma comment(lib,"winmm.lib") // for the timing functions fps deltat
#include "../include/glwin.h" // a minimial opengl on windows wrapper, just a header, no lib/dll.
// Functions and Variables from bunny module
extern void InitModel();
extern char * RenderModel();
extern float3 model_position; // position of bunny
extern float4 model_orientation; // orientation of bunny
// Global Variables
float DeltaT = 0.1f;
float FPS;
void CalcFPSDeltaT()
{
static int timeinit=0;
static int start,start2,current,last;
static int frame=0, frame2=0;
if(!timeinit){
frame=0;
start=timeGetTime();
timeinit=1;
}
frame++;
frame2++;
current=timeGetTime(); // found in winmm.lib
double dif=(double)(current-start)/CLOCKS_PER_SEC;
double rv = (dif)? (double)frame/(double)dif:-1.0;
if(dif>2.0 && frame >10) {
start = start2;
frame = frame2;
start2 = timeGetTime();
frame2 = 0;
}
DeltaT = (float)(current-last)/CLOCKS_PER_SEC;
if(current==last) {
DeltaT = 0.1f / CLOCKS_PER_SEC; // it just cant be 0
}
// if(DeltaT>1.0) DeltaT=1.0;
FPS = (float)rv;
last = current;
}
int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst,
LPSTR lpszCmdLine, int nCmdShow)
{
InitModel(); // initializes some data structures and does progressive mesh polygon reduction algorithm
GLWin glwin("bunnylod by Stan Melax");
float3 MouseVectorOld;
while (glwin.WindowUp())
{
if(glwin.MouseState)
model_orientation=qmul(VirtualTrackBall(float3(0,0,0),model_position,MouseVectorOld,glwin.MouseVector),model_orientation);
MouseVectorOld = glwin.MouseVector;
CalcFPSDeltaT();
// main drawing loop
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLoadIdentity();
// camera at default (zero) position and orientation
char * s=RenderModel();
glLoadIdentity();
glColor3f(1,1,0);
glwin.PrintString({ 0, -2 },s); // print returned status string from rendermodel() current vert and tri count
glwin.PrintString({ 5, 1 },"Demo by Stan Melax (c)1998");
glwin.PrintString({ 5, 2 },"Model by Viewpoint Datalabs (c)1996");
glwin.PrintString({ 0, -1 }, "FPS: %5.2f ", FPS);
glPopMatrix();
glFlush();
glwin.SwapBuffers();
}
return 0;
}