example.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. // Small GLUT application to test different scene rotation paradigms
  2. //
  3. #include <igl/readOBJ.h>
  4. #include <igl/writeOBJ.h>
  5. #include <igl/writeOFF.h>
  6. #include <igl/readWRL.h>
  7. #include <igl/report_gl_error.h>
  8. #include <igl/triangulate.h>
  9. #include <igl/readOFF.h>
  10. #include <igl/readMESH.h>
  11. #include <igl/draw_mesh.h>
  12. #include <igl/draw_floor.h>
  13. #include <igl/pathinfo.h>
  14. #include <igl/list_to_matrix.h>
  15. #include <igl/quat_to_mat.h>
  16. #include <igl/per_face_normals.h>
  17. #include <igl/material_colors.h>
  18. #include <igl/trackball.h>
  19. #include <igl/snap_to_canonical_view_quat.h>
  20. #include <igl/REDRUM.h>
  21. #include <igl/Camera.h>
  22. #include <igl/ReAntTweakBar.h>
  23. #include <igl/PI.h>
  24. #define IGL_HEADER_ONLY
  25. #include <igl/lens_flare.h>
  26. #include <Eigen/Core>
  27. #include <Eigen/Geometry>
  28. #include <GLUT/glut.h>
  29. #include <Carbon/Carbon.h>
  30. #include <string>
  31. #include <vector>
  32. #include <stack>
  33. #include <iostream>
  34. bool eyes_visible = true;
  35. double x=6,y=232,z=61;
  36. std::vector<igl::Flare> flares;
  37. std::vector<GLuint> shine_ids;
  38. std::vector<GLuint> flare_ids;
  39. int shine_tic;
  40. Eigen::MatrixXd V,N;
  41. Eigen::VectorXd Vmid,Vmin,Vmax;
  42. double bbd = 1.0;
  43. Eigen::MatrixXi F;
  44. struct State
  45. {
  46. igl::Camera camera;
  47. } s;
  48. // See README for descriptions
  49. enum ROTATION_TYPE
  50. {
  51. ROTATION_TYPE_IGL_TRACKBALL = 0,
  52. ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
  53. NUM_ROTATION_TYPES = 2,
  54. } rotation_type;
  55. std::stack<State> undo_stack;
  56. std::stack<State> redo_stack;
  57. bool is_rotating = false;
  58. int down_x,down_y;
  59. igl::Camera down_camera;
  60. int width,height;
  61. Eigen::Vector4f light_pos(-0.1,-0.1,0.9,0);
  62. #define REBAR_NAME "temp.rbr"
  63. igl::ReTwBar rebar;
  64. // No-op setter, does nothing
  65. void TW_CALL no_op(const void * /*value*/, void * /*clientData*/)
  66. {
  67. }
  68. void TW_CALL get_camera_rotation(void * value, void *clientData)
  69. {
  70. using namespace std;
  71. // case current value to double
  72. double * quat = (double *)(value);
  73. std::copy(s.camera.rotation,s.camera.rotation+4,quat);
  74. }
  75. void push_undo()
  76. {
  77. undo_stack.push(s);
  78. // Clear
  79. redo_stack = std::stack<State>();
  80. }
  81. void reshape(int width, int height)
  82. {
  83. ::width = width;
  84. ::height = height;
  85. glViewport(0,0,width,height);
  86. // Send the new window size to AntTweakBar
  87. TwWindowSize(width, height);
  88. }
  89. void push_scene()
  90. {
  91. using namespace igl;
  92. using namespace std;
  93. const double angle = s.camera.angle;
  94. glMatrixMode(GL_PROJECTION);
  95. glPushMatrix();
  96. glLoadIdentity();
  97. double zNear = 1e-2;
  98. double zFar = 100;
  99. double aspect = ((double)width)/((double)height);
  100. // Amount of scaling needed to "fix" perspective z-shift
  101. double z_fix = 1.0;
  102. // 5 is far enough to see unit "things" well
  103. const double camera_z = 2;
  104. // Test if should be using true orthographic projection
  105. if(angle == 0)
  106. {
  107. glOrtho(
  108. -0.5*camera_z*aspect,
  109. 0.5*camera_z*aspect,
  110. -0.5*camera_z,
  111. 0.5*camera_z,
  112. zNear,
  113. zFar);
  114. }else
  115. {
  116. // Make sure aspect is sane
  117. aspect = aspect < 0.01 ? 0.01 : aspect;
  118. gluPerspective(angle,aspect,zNear,zFar);
  119. z_fix = 2.*tan(angle/2./360.*2.*M_PI);
  120. }
  121. glMatrixMode(GL_MODELVIEW);
  122. glPushMatrix();
  123. glLoadIdentity();
  124. gluLookAt(0,0,camera_z,0,0,0,0,1,0);
  125. // Adjust scale to correct perspective
  126. glScaled(z_fix,z_fix,z_fix);
  127. // scale, pan
  128. glScaled( s.camera.zoom, s.camera.zoom, s.camera.zoom);
  129. double mat[4*4];
  130. quat_to_mat(s.camera.rotation,mat);
  131. glMultMatrixd(mat);
  132. }
  133. void push_object()
  134. {
  135. using namespace igl;
  136. glPushMatrix();
  137. glScaled(2./bbd,2./bbd,2./bbd);
  138. glTranslated(-Vmid(0),-Vmid(1),-Vmid(2));
  139. }
  140. void pop_object()
  141. {
  142. glPopMatrix();
  143. }
  144. void pop_scene()
  145. {
  146. glMatrixMode(GL_PROJECTION);
  147. glPopMatrix();
  148. glMatrixMode(GL_MODELVIEW);
  149. glPopMatrix();
  150. }
  151. // Set up double-sided lights
  152. void lights()
  153. {
  154. using namespace std;
  155. using namespace Eigen;
  156. glEnable(GL_LIGHTING);
  157. glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
  158. glEnable(GL_LIGHT0);
  159. glEnable(GL_LIGHT1);
  160. float WHITE[4] = {0.8,0.8,0.8,1.};
  161. float GREY[4] = {0.4,0.4,0.4,1.};
  162. float BLACK[4] = {0.,0.,0.,1.};
  163. Vector4f pos = light_pos;
  164. glLightfv(GL_LIGHT0,GL_AMBIENT,GREY);
  165. glLightfv(GL_LIGHT0,GL_DIFFUSE,WHITE);
  166. glLightfv(GL_LIGHT0,GL_SPECULAR,BLACK);
  167. glLightfv(GL_LIGHT0,GL_POSITION,pos.data());
  168. pos(0) *= -1;
  169. pos(1) *= -1;
  170. pos(2) *= -1;
  171. glLightfv(GL_LIGHT1,GL_AMBIENT,GREY);
  172. glLightfv(GL_LIGHT1,GL_DIFFUSE,WHITE);
  173. glLightfv(GL_LIGHT1,GL_SPECULAR,BLACK);
  174. glLightfv(GL_LIGHT1,GL_POSITION,pos.data());
  175. }
  176. void init_flare()
  177. {
  178. }
  179. void draw_flare()
  180. {
  181. using namespace igl;
  182. using namespace Eigen;
  183. glPushMatrix();
  184. glScaled(bbd*0.5,bbd*0.5,bbd*0.5);
  185. Vector3f light(0,0.1,0);
  186. lens_flare_draw(flares,shine_ids,flare_ids,light,1.0,shine_tic);
  187. glPopMatrix();
  188. }
  189. void draw_eyes()
  190. {
  191. using namespace Eigen;
  192. using namespace std;
  193. using namespace igl;
  194. #define NUM_LEDS 2
  195. Vector3d LED_pos[NUM_LEDS];
  196. LED_pos[0] = Vector3d( x,y,z);
  197. LED_pos[1] = Vector3d(-x,y,z);
  198. enum LEDMethod
  199. {
  200. LED_METHOD_COLORED_CIRCLE = 0,
  201. LED_METHOD_OUTLINED_CIRCLE = 1,
  202. LED_METHOD_TEXTURE_FLARE = 2
  203. } method = LED_METHOD_TEXTURE_FLARE;
  204. for(int l = 0;l<NUM_LEDS;l++)
  205. {
  206. glPushMatrix();
  207. glTranslated(LED_pos[l](0), LED_pos[l](1), LED_pos[l](2));
  208. const double r = 2.0;
  209. const float color[4] = {1,0,0,1};
  210. glScaled(r,r,r);
  211. switch(method)
  212. {
  213. case LED_METHOD_COLORED_CIRCLE:
  214. {
  215. glEnable(GL_COLOR_MATERIAL);
  216. glColorMaterial(GL_FRONT,GL_AMBIENT);
  217. glColor4fv(color);
  218. glBegin(GL_TRIANGLE_FAN);
  219. glVertex3d(0,0,0);
  220. for(double theta = 0;theta<2.*PI;theta+=2.*PI/15.)
  221. {
  222. glVertex3d(cos(theta),sin(theta),0);
  223. }
  224. glEnd();
  225. break;
  226. }
  227. case LED_METHOD_OUTLINED_CIRCLE:
  228. {
  229. glEnable(GL_COLOR_MATERIAL);
  230. glDisable(GL_LIGHTING);
  231. glColorMaterial(GL_FRONT,GL_DIFFUSE);
  232. glBegin(GL_TRIANGLE_FAN);
  233. glColor4fv(color);
  234. glVertex3d(0,0,0);
  235. glColor4f(0,0,0,1);
  236. for(double theta = 0;theta<2.*PI;theta+=2.*PI/15.)
  237. {
  238. glVertex3d(cos(theta),sin(theta),0);
  239. }
  240. glEnd();
  241. break;
  242. }
  243. case LED_METHOD_TEXTURE_FLARE:
  244. {
  245. draw_flare();
  246. break;
  247. }
  248. }
  249. glPopMatrix();
  250. }
  251. }
  252. void display()
  253. {
  254. using namespace igl;
  255. using namespace std;
  256. glClearColor(0,0,0,0);
  257. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  258. glEnable(GL_DEPTH_TEST);
  259. glEnable(GL_BLEND);
  260. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  261. glEnable(GL_NORMALIZE);
  262. lights();
  263. push_scene();
  264. push_object();
  265. // Set material properties
  266. glDisable(GL_COLOR_MATERIAL);
  267. const float NEAR_BLACK[4] = {0.1,0.1,0.1,1.0};
  268. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, NEAR_BLACK);
  269. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MIDNIGHT_BLUE_DIFFUSE);
  270. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SILVER_SPECULAR);
  271. glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128);
  272. draw_mesh(V,F,N);
  273. if(eyes_visible)
  274. {
  275. draw_eyes();
  276. }
  277. pop_object();
  278. // Draw a nice floor
  279. glPushMatrix();
  280. const double floor_offset =
  281. -2./bbd*(V.col(1).maxCoeff()-Vmid(1));
  282. glTranslated(0,floor_offset,0);
  283. const float GREY[4] = {0.5,0.5,0.6,1.0};
  284. const float DARK_GREY[4] = {0.2,0.2,0.3,1.0};
  285. draw_floor(GREY,DARK_GREY);
  286. glPopMatrix();
  287. pop_scene();
  288. report_gl_error();
  289. TwDraw();
  290. glutSwapBuffers();
  291. glutPostRedisplay();
  292. }
  293. void mouse_wheel(int wheel, int direction, int mouse_x, int mouse_y)
  294. {
  295. using namespace std;
  296. push_undo();
  297. if(wheel == 0)
  298. {
  299. static double mouse_scroll_y = 0;
  300. const double delta_y = 0.125*direction;
  301. mouse_scroll_y += delta_y;
  302. // absolute scale difference when changing zooms (+1)
  303. const double z_diff = 0.01;
  304. GLint viewport[4];
  305. glGetIntegerv(GL_VIEWPORT,viewport);
  306. if(TwMouseMotion(mouse_x, viewport[3] - mouse_y))
  307. {
  308. TwMouseWheel(mouse_scroll_y);
  309. }else
  310. {
  311. s.camera.zoom *= (1.0+double(direction)*z_diff);
  312. const double min_zoom = 0.01;
  313. const double max_zoom = 10.0;
  314. s.camera.zoom = min(max_zoom,max(min_zoom,s.camera.zoom));
  315. }
  316. }else
  317. {
  318. if(!is_rotating)
  319. {
  320. // Change viewing angle (reshape will take care of adjust zoom)
  321. const double a_diff = 1.0;
  322. s.camera.angle += double(direction)*a_diff;
  323. const double min_angle = 15.0;
  324. s.camera.angle =
  325. min(90.0,max(min_angle,s.camera.angle));
  326. }
  327. }
  328. }
  329. void mouse(int glutButton, int glutState, int mouse_x, int mouse_y)
  330. {
  331. using namespace std;
  332. using namespace Eigen;
  333. using namespace igl;
  334. bool tw_using = TwEventMouseButtonGLUT(glutButton,glutState,mouse_x,mouse_y);
  335. switch(glutButton)
  336. {
  337. case GLUT_RIGHT_BUTTON:
  338. case GLUT_LEFT_BUTTON:
  339. {
  340. switch(glutState)
  341. {
  342. case 1:
  343. // up
  344. glutSetCursor(GLUT_CURSOR_INHERIT);
  345. is_rotating = false;
  346. break;
  347. case 0:
  348. if(!tw_using)
  349. {
  350. push_undo();
  351. glutSetCursor(GLUT_CURSOR_CYCLE);
  352. // collect information for trackball
  353. is_rotating = true;
  354. down_camera = s.camera;
  355. down_x = mouse_x;
  356. down_y = mouse_y;
  357. }
  358. break;
  359. }
  360. break;
  361. }
  362. // Scroll down
  363. case 3:
  364. {
  365. mouse_wheel(0,-1,mouse_x,mouse_y);
  366. break;
  367. }
  368. // Scroll up
  369. case 4:
  370. {
  371. mouse_wheel(0,1,mouse_x,mouse_y);
  372. break;
  373. }
  374. // Scroll left
  375. case 5:
  376. {
  377. mouse_wheel(1,-1,mouse_x,mouse_y);
  378. break;
  379. }
  380. // Scroll right
  381. case 6:
  382. {
  383. mouse_wheel(1,1,mouse_x,mouse_y);
  384. break;
  385. }
  386. }
  387. }
  388. void mouse_drag(int mouse_x, int mouse_y)
  389. {
  390. using namespace igl;
  391. using namespace std;
  392. using namespace Eigen;
  393. if(is_rotating)
  394. {
  395. glutSetCursor(GLUT_CURSOR_CYCLE);
  396. switch(rotation_type)
  397. {
  398. case ROTATION_TYPE_IGL_TRACKBALL:
  399. {
  400. // Rotate according to trackball
  401. igl::trackball<double>(
  402. width,
  403. height,
  404. 2.0,
  405. down_camera.rotation,
  406. down_x,
  407. down_y,
  408. mouse_x,
  409. mouse_y,
  410. s.camera.rotation);
  411. break;
  412. }
  413. case ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP:
  414. {
  415. Quaterniond down_q;
  416. copy(down_camera.rotation,down_camera.rotation+4,down_q.coeffs().data());
  417. Vector3d axis(0,1,0);
  418. const double speed = 2.0;
  419. Quaterniond q;
  420. q = down_q *
  421. Quaterniond(
  422. AngleAxisd(
  423. M_PI*((double)(mouse_x-down_x))/(double)width*speed/2.0,
  424. axis.normalized()));
  425. q.normalize();
  426. {
  427. Vector3d axis(1,0,0);
  428. const double speed = 2.0;
  429. if(axis.norm() != 0)
  430. {
  431. q =
  432. Quaterniond(
  433. AngleAxisd(
  434. M_PI*(mouse_y-down_y)/(double)width*speed/2.0,
  435. axis.normalized())) * q;
  436. q.normalize();
  437. }
  438. }
  439. copy(q.coeffs().data(),q.coeffs().data()+4,s.camera.rotation);
  440. break;
  441. }
  442. default:
  443. break;
  444. }
  445. }
  446. }
  447. void init_relative()
  448. {
  449. using namespace Eigen;
  450. using namespace igl;
  451. using namespace std;
  452. per_face_normals(V,F,N);
  453. Vmax = V.colwise().maxCoeff();
  454. Vmin = V.colwise().minCoeff();
  455. Vmid = 0.5*(Vmax + Vmin);
  456. bbd = (Vmax-Vmin).norm();
  457. }
  458. KeyMap keyStates ;
  459. bool IS_KEYDOWN( uint16_t vKey )
  460. {
  461. uint8_t index = vKey / 32 ;
  462. uint8_t shift = vKey % 32 ;
  463. return keyStates[index].bigEndianValue & (1 << shift) ;
  464. }
  465. void undo()
  466. {
  467. using namespace std;
  468. if(!undo_stack.empty())
  469. {
  470. redo_stack.push(s);
  471. s = undo_stack.top();
  472. undo_stack.pop();
  473. }
  474. }
  475. void redo()
  476. {
  477. using namespace std;
  478. if(!redo_stack.empty())
  479. {
  480. undo_stack.push(s);
  481. s = redo_stack.top();
  482. redo_stack.pop();
  483. }
  484. }
  485. void key(unsigned char key, int mouse_x, int mouse_y)
  486. {
  487. using namespace std;
  488. GetKeys(keyStates);
  489. const bool command_down = IS_KEYDOWN(kVK_Command);
  490. const bool shift_down = IS_KEYDOWN(kVK_Shift);
  491. switch(key)
  492. {
  493. // ESC
  494. case char(27):
  495. rebar.save(REBAR_NAME);
  496. // ^C
  497. case char(3):
  498. exit(0);
  499. case 'z':
  500. case 'Z':
  501. if(command_down)
  502. {
  503. if(shift_down)
  504. {
  505. redo();
  506. }else
  507. {
  508. undo();
  509. }
  510. break;
  511. }else
  512. {
  513. push_undo();
  514. igl::snap_to_canonical_view_quat<double>(
  515. s.camera.rotation,
  516. 1.0,
  517. s.camera.rotation);
  518. break;
  519. }
  520. default:
  521. if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
  522. {
  523. cout<<"Unknown key command: "<<key<<" "<<int(key)<<endl;
  524. }
  525. }
  526. }
  527. int main(int argc, char * argv[])
  528. {
  529. using namespace std;
  530. using namespace Eigen;
  531. using namespace igl;
  532. string filename = "../shared/beast.obj";
  533. if(argc < 2)
  534. {
  535. cerr<<"Usage:"<<endl<<" ./example input.obj"<<endl;
  536. cout<<endl<<"Opening default mesh..."<<endl;
  537. }else
  538. {
  539. // Read and prepare mesh
  540. filename = argv[1];
  541. }
  542. // print key commands
  543. cout<<"[Click] and [drag] Rotate model using trackball."<<endl;
  544. cout<<"[Z,z] Snap rotation to canonical view."<<endl;
  545. cout<<"[⌘ Z] Undo."<<endl;
  546. cout<<"[⇧ ⌘ Z] Redo."<<endl;
  547. cout<<"[^C,ESC] Exit."<<endl;
  548. // dirname, basename, extension and filename
  549. string d,b,ext,f;
  550. pathinfo(filename,d,b,ext,f);
  551. // Convert extension to lower case
  552. transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
  553. vector<vector<double > > vV,vN,vTC;
  554. vector<vector<int > > vF,vFTC,vFN;
  555. if(ext == "obj")
  556. {
  557. // Convert extension to lower case
  558. if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN))
  559. {
  560. return 1;
  561. }
  562. }else if(ext == "off")
  563. {
  564. // Convert extension to lower case
  565. if(!igl::readOFF(filename,vV,vF,vN))
  566. {
  567. return 1;
  568. }
  569. }else if(ext == "wrl")
  570. {
  571. // Convert extension to lower case
  572. if(!igl::readWRL(filename,vV,vF))
  573. {
  574. return 1;
  575. }
  576. //}else
  577. //{
  578. // // Convert extension to lower case
  579. // MatrixXi T;
  580. // if(!igl::readMESH(filename,V,T,F))
  581. // {
  582. // return 1;
  583. // }
  584. // //if(F.size() > T.size() || F.size() == 0)
  585. // {
  586. // boundary_faces(T,F);
  587. // }
  588. }
  589. if(vV.size() > 0)
  590. {
  591. if(!list_to_matrix(vV,V))
  592. {
  593. return 1;
  594. }
  595. triangulate(vF,F);
  596. }
  597. init_relative();
  598. // Init glut
  599. glutInit(&argc,argv);
  600. if( !TwInit(TW_OPENGL, NULL) )
  601. {
  602. // A fatal error occured
  603. fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
  604. return 1;
  605. }
  606. // Create a tweak bar
  607. rebar.TwNewBar("TweakBar");
  608. rebar.TwAddVarCB("camera_rotation", TW_TYPE_QUAT4D, no_op,get_camera_rotation, NULL, "open readonly=true");
  609. TwEnumVal RotationTypesEV[NUM_ROTATION_TYPES] =
  610. {
  611. {ROTATION_TYPE_IGL_TRACKBALL,"igl trackball"},
  612. {ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP,"two a... fixed up"},
  613. };
  614. TwType RotationTypeTW =
  615. ReTwDefineEnum(
  616. "RotationType",
  617. RotationTypesEV,
  618. NUM_ROTATION_TYPES);
  619. rebar.TwAddVarRW( "rotation_type", RotationTypeTW, &rotation_type,"keyIncr=] keyDecr=[");
  620. rebar.TwAddVarRW( "x",TW_TYPE_DOUBLE, &x,"");
  621. rebar.TwAddVarRW( "y",TW_TYPE_DOUBLE, &y,"");
  622. rebar.TwAddVarRW( "z",TW_TYPE_DOUBLE, &z,"");
  623. rebar.TwAddVarRW( "eyes_visible",TW_TYPE_BOOLCPP, &eyes_visible,"key=e");
  624. rebar.load(REBAR_NAME);
  625. // Init antweakbar
  626. glutInitDisplayString( "rgba depth double samples>=8 ");
  627. glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)/2.0);
  628. glutCreateWindow("upright");
  629. glutDisplayFunc(display);
  630. glutReshapeFunc(reshape);
  631. glutKeyboardFunc(key);
  632. glutMouseFunc(mouse);
  633. glutMotionFunc(mouse_drag);
  634. glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
  635. // Init flares
  636. lens_flare_load_textures(shine_ids,flare_ids);
  637. const float RED[3] = {1,0,0};
  638. const float GREEN[3] = {0,1,0};
  639. const float BLUE[3] = {0,0,1};
  640. lens_flare_create(RED,GREEN,BLUE,flares);
  641. glutMainLoop();
  642. return 0;
  643. }