-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
155 lines (121 loc) · 4.34 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
//----------------------------------------------------------------------------//
// main.cpp //
// Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger //
//----------------------------------------------------------------------------//
// This program is free software; you can redistribute it and/or modify it //
// under the terms of the GNU General Public License as published by the Free //
// Software Foundation; either version 2 of the License, or (at your option) //
// any later version. //
//----------------------------------------------------------------------------//
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
//----------------------------------------------------------------------------//
// Includes //
//----------------------------------------------------------------------------//
#include "global.h"
#include "shader.h"
#include "viewer.h"
GLuint programID;
//----------------------------------------------------------------------------//
// GLUT callback functions //
//----------------------------------------------------------------------------//
void displayFunc()
{
// render the scene
theViewer.onRender( programID);
}
void exitFunc()
{
// shut the viewer instance down
theViewer.onShutdown();
}
void idleFunc()
{
// redirect to the viewer instance
theViewer.onIdle(programID);
}
void keyboardFunc(unsigned char key, int x, int y)
{
// redirect the message to the viewer instance
theViewer.onKey(key, x, theViewer.getHeight() - y - 1);
}
void motionFunc(int x, int y)
{
// redirect the message to the viewer instance
theViewer.onMouseMove(x, theViewer.getHeight() - y - 1);
}
void mouseFunc(int button, int state, int x, int y)
{
// redirect the message to the viewer instance
if(state == GLUT_DOWN)
{
theViewer.onMouseButtonDown(button, x, theViewer.getHeight() - y - 1);
}
else if(state == GLUT_UP)
{
theViewer.onMouseButtonUp(button, x, theViewer.getHeight() - y - 1);
}
}
void reshapeFunc(int width, int height)
{
// set the new width/height values
theViewer.setDimension(width, height);
}
//----------------------------------------------------------------------------//
// Main entry point of the application //
//----------------------------------------------------------------------------//
// Set up the shaders we are to use. 0 indicates error.
int main(int argc, char *argv[])
{
// initialize the GLUT system
glutInit(&argc, argv);
// create our view instance
if(!theViewer.onCreate(argc, argv))
{
std::cerr << "Creation of the viewer failed." << std::endl;
return -1;
}
// register our own exit callback
atexit(exitFunc);
#ifdef __APPLE__
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_3_2_CORE_PROFILE | GLUT_MULTISAMPLE);
// glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
#else
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
#endif
glutInitWindowSize(theViewer.getWidth(), theViewer.getHeight());
glutCreateWindow(theViewer.getCaption().c_str());
if(theViewer.getFullscreen()) glutFullScreen();
//glutSetCursor(GLUT_CURSOR_NONE);
// Initialize GLEW
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
programID= LoadShaders("shaded.vert", "shaded.frag");
if (programID == 0){
std::cout << "Shaders did not load" << std::endl;
return 1;
}
glUseProgram(programID);
std::cout << "Program ID init: " << programID << std::endl;
// register all GLUT callback functions
glutIdleFunc(idleFunc);
glutMouseFunc(mouseFunc);
glutMotionFunc(motionFunc);
glutPassiveMotionFunc(motionFunc);
glutReshapeFunc(reshapeFunc);
glutDisplayFunc(displayFunc);
glutKeyboardFunc(keyboardFunc);
// initialize our viewer instance
if(!theViewer.onInit(programID))
{
std::cerr << "Initialization of the viewer failed." << std::endl;
return -1;
}
glutMainLoop();
return 0;
}
//----------------------------------------------------------------------------//