-
Notifications
You must be signed in to change notification settings - Fork 0
/
sceneLoader.cpp
198 lines (167 loc) · 6.36 KB
/
sceneLoader.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
/***************************************************************************/
/* sceneLoader.cpp */
/* ----------------------- */
/* */
/* A basic OpenGL program that reads in a scene file and displays it. */
/* Note that not all the keywords and functionality of the ray tracer */
/* is implemented, especially odd material and object types. Some */
/* types are implemented as other types (e.g., "WardTriangles" are */
/* simply more efficient triangles for a ray tracer, but is fine for */
/* OpenGL to handle with a default "Triangle" class). */
/* */
/* Chris Wyman (02/01/2008) */
/***************************************************************************/
#include "sceneLoader.h"
#include "RenderingTechniques/renderingData.h"
#include "RenderingTechniques/renderingMethods.h"
Scene *scene = 0;
FrameRate *frameSpeed = 0;
FrameGrab *frameGrab = 0;
extern RenderingData *data;
FrameBuffer *Reflect;
FrameBuffer *Reflect2;
FrameBuffer *ReflectFloor;
FrameBuffer *Temp1;
FrameBuffer *Temp2;
extern bool Mirror2Drawn;
int bounces = 1;
GLSLProgram *FloorProg;
extern float reflectmatrix[];
extern float reflectmatrix2[];
int width=1024;
int height=1024;
double rotate = 0; //To rotate the fan
void DisplayCallback( void )
{
frameSpeed->StartFrame();
//Do reflections for the floor (into buffer)
DrawFloorReflectedSceneToBuffer();
glLoadIdentity();
scene->LookAtMatrix();
//Reflection (Into Buffer)
//for(int i=0;i<bounces;i++)
//{
Draw1stReflectedSceneToBuffer(0,Reflect);
Draw2ndReflectedSceneToBuffer(bounces,Reflect2);
//}
// Into the main FBO texture, draw the scene with no special effects
data->fbo->mainWin->BindBuffer();
data->fbo->mainWin->ClearBuffers();
glLoadIdentity();
scene->LookAtMatrix();
scene->SetupEnabledLightsWithCurrentModelview();
// Draw the scene
DrawFloorMirror();
DrawFirstMirror(0);
DrawSecondMirror(0);
DrawSceneStuff();
data->fbo->mainWin->UnbindBuffer();
// Copy the final rendering to the screen
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
data->fbo->mainWin->DisplayAsFullScreenTexture( FBO_COLOR0 );
// If a screen capture is desired, do it now (before writing timer text)
if (data->ui->captureScreen)
{
frameGrab->CaptureFrame();
data->ui->captureScreen = false;
}
//Reset if mirror2 has been drawn
Mirror2Drawn = 0;
DisplayTimer( frameSpeed->EndFrame(), 1024, 1024 );
glFlush();
glutSwapBuffers();
//Rotate the fan
rotate += .5;
if(rotate >= 360) rotate = 0;
glutPostRedisplay();
}
int main(int argc, char* argv[] )
{
bool verbose = false;
char scenefile[ 256 ];
char windowTitle[ 512 ];
printf("**************************************************************************\n");
printf("* Chris Wyman's Basic OpenGL Scene Loader *\n");
printf("**************************************************************************\n");
// Read in the command line parameters
printf("(+) Parsing any command line parameters...\n");
if (argc < 1)
{
printf("Usage: %s <sceneFile>\n", argv[0]);
exit(0);
}
for( int i=1; i < argc; i++ )
{
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help") ||
!strcmp(argv[i], "-?") || !strcmp(argv[i], "/?") )
{
printf("Usage: %s <sceneFile>\n", argv[0]);
exit(0);
}
else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "-verbose"))
verbose = true;
else
{
strncpy( scenefile, argv[i], 255 );
break;
}
}
// Load the specified scene from file.
scene = new Scene( scenefile, verbose );
sprintf( windowTitle, "Chris Wyman's Basic Scene Loader (Displaying: %s)", scenefile );
printf("(+) Initializing OpenGL state...\n");
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA );
glutInitWindowSize( scene->GetWidth(), scene->GetHeight() );
glutCreateWindow( windowTitle );
glewInit();
// Check to make sure this card supports all the features used by this program
if (!GLEW_VERSION_2_0)
FatalError("Machine lacks support for OpenGL 2.0!");
if (!GLEW_EXT_framebuffer_object)
FatalError("Machine lacks support for OpenGL's framebuffer_object extension!");
if (!GLEW_ARB_texture_float)
FatalError("Machine lacks support for OpenGL's texture_float extension!");
if (!GLEW_ARB_vertex_buffer_object)
FatalError("Machine lacks support for OpenGL's vertex_buffer_object extension!");
// There's probably a bunch of other extenstions that I just use automatically now
// But I suspect if all three of these pass then the card/driver should work for
// this basic framework.
// Set the GLUT callback functions
glutDisplayFunc( DisplayCallback );
glutReshapeFunc( ReshapeCallback );
glutIdleFunc( IdleCallback );
glutMouseFunc( MouseButtonCallback );
glutMotionFunc( MouseMotionCallback );
glutKeyboardFunc( KeyboardCallback );
glutSpecialFunc( SpecialKeyboardCallback );
// Other program setup
frameSpeed = new FrameRate( 50 );
frameGrab = new FrameGrab();
Reflect = new FrameBuffer(GL_TEXTURE_2D,width,height,0,GL_RGB,1,1,0,"Reflect");
Reflect2 = new FrameBuffer(GL_TEXTURE_2D,width,height,0,GL_RGB,1,1,0,"Reflect2");
ReflectFloor=new FrameBuffer(GL_TEXTURE_2D,width,height,0,GL_RGB,1,1,0,"Floor");
Temp1 = new FrameBuffer(GL_TEXTURE_2D,width,height,0,GL_RGB,1,1,0,"Temp1");
Temp2 = new FrameBuffer(GL_TEXTURE_2D,width,height,0,GL_RGB,1,1,0,"Temp2");
// Make sure any preprocessing that needs to be done occurs
scene->Preprocess();
InitMirror();
LoadSilModel();
LoadGoochShader();
LoadSelectionModels();
InitExtraWalls();
// Initialized various data needed in the various rendering (display) callbacks
InitializeRenderingData();
//Adjust the far plane on the camera
Camera* cam = scene->GetCamera();
cam->SetFar(40.0);
// Run the display!
printf("(+) Starting Main Loop...\n" );
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_NORMALIZE );
glEnable( GL_CULL_FACE );
scene->GetLight(0)->Enable();
glutMainLoop();
return 0;
}