Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

166 lignes
4.2 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <GL/gl.h>
  5. #include <GL/glut.h>
  6. #include "tb.h"
  7. int w_win = 640;
  8. int h_win = 480;
  9. static void setcamera(void)
  10. {
  11. glMatrixMode (GL_PROJECTION);
  12. glLoadIdentity ();
  13. gluPerspective(40, (float)w_win / (float)h_win, 1, 1000);
  14. glMatrixMode(GL_MODELVIEW);
  15. glLoadIdentity();
  16. gluLookAt(0.0, 0.0, (float)h_win / 200.0f, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  17. }
  18. static void myinit(void)
  19. {
  20. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  21. glClearColor(0.5, 0.5, 0.7, 0.0);
  22. glColor3f(1.0, 1.0, 1.0);
  23. glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
  24. glDisable(GL_CULL_FACE);
  25. glShadeModel(GL_SMOOTH);
  26. glEnable(GL_BLEND);
  27. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  28. glEnable(GL_DEPTH_TEST);
  29. setcamera();
  30. tbInit(GLUT_LEFT_BUTTON);
  31. tbAnimate(GL_FALSE);
  32. }
  33. static void parsekey(unsigned char key, int x, int y)
  34. {
  35. switch (key)
  36. {
  37. case 27:
  38. exit(0);
  39. break;
  40. }
  41. }
  42. static void motion(int x, int y)
  43. {
  44. tbMotion(x, y);
  45. }
  46. static void mouse(int button, int state, int x, int y)
  47. {
  48. tbMouse(button, state, x, y);
  49. }
  50. static void reshape(int w, int h)
  51. {
  52. glMatrixMode (GL_MODELVIEW);
  53. glViewport (0, 0, w, h);
  54. glLoadIdentity();
  55. w_win = w;
  56. h_win = h;
  57. setcamera();
  58. tbReshape(w_win, h_win);
  59. }
  60. #define F(x) ((x)*1.01 - 0.005)
  61. #define CP glColor4f(x0,y0,z0,0.9); glVertex3f(x0,y0,z0)
  62. #define BP glColor3f(0.0,0.0,0.0); glVertex3f(F(x0),F(y0),F(z0))
  63. #define BLACK x0 = y0 = z0 = 0.0
  64. #define RED x0 = 1.0; y0 = z0 = 0.0
  65. //#define XRED x0 = 0.8; y0 = z0 = 0.0
  66. #define XRED RED
  67. #define GREEN y0 = 1.0; x0 = z0 = 0.0
  68. //#define XGREEN y0 = 0.7; x0 = z0 = 0.0
  69. #define XGREEN GREEN
  70. #define BLUE z0 = 1.0; x0 = y0 = 0.0
  71. //#define XBLUE x0 = 0.0; y0 = 0.0; z0 = 0.5
  72. #define XBLUE BLUE
  73. #define YELLOW x0 = y0 = 1.0; z0 = 0.0
  74. #define CYAN y0 = z0 = 1.0; x0 = 0.0
  75. #define MAGENTA x0 = z0 = 1.0; y0 = 0.0
  76. #define WHITE x0 = y0 = z0 = 1.0
  77. static void display(void)
  78. {
  79. float x0,y0,z0;
  80. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  81. setcamera();
  82. tbMatrix();
  83. glPushMatrix();
  84. glTranslatef(-.5, -.5, -.5);
  85. // Bounding box
  86. glBegin(GL_LINE_LOOP);
  87. BLACK; CP; RED; CP; MAGENTA; CP; BLUE; CP;
  88. CYAN; CP; WHITE; CP; YELLOW; CP; GREEN; CP;
  89. glEnd();
  90. glBegin(GL_LINES);
  91. BLACK; CP; BLUE; CP;
  92. GREEN; CP; CYAN; CP;
  93. RED; CP; YELLOW; CP;
  94. MAGENTA; CP; WHITE; CP;
  95. glEnd();
  96. // Our colour space
  97. glBegin(GL_TRIANGLES); XRED; CP; XGREEN; CP; XBLUE; CP; glEnd();
  98. glBegin(GL_TRIANGLES); XRED; CP; XGREEN; CP; YELLOW; CP; glEnd();
  99. glBegin(GL_TRIANGLES); XRED; CP; XBLUE; CP; WHITE; CP; glEnd();
  100. glBegin(GL_TRIANGLES); XRED; CP; YELLOW; CP; WHITE; CP; glEnd();
  101. glBegin(GL_TRIANGLES); XBLUE; CP; XGREEN; CP; WHITE; CP; glEnd();
  102. glBegin(GL_TRIANGLES); YELLOW; CP; XGREEN; CP; WHITE; CP; glEnd();
  103. // Better edges
  104. glBegin(GL_LINES);
  105. XBLUE; BP; XRED; BP; YELLOW; BP; XRED; BP;
  106. XBLUE; BP; XGREEN; BP; YELLOW; BP; XGREEN; BP;
  107. XBLUE; BP; WHITE; BP; YELLOW; BP; WHITE; BP;
  108. XRED; BP; XGREEN; BP;
  109. XGREEN; BP; WHITE; BP;
  110. WHITE; BP; XRED; BP;
  111. glEnd();
  112. glTranslatef(.5, .5, .4);
  113. glColor4f(.2, .2, .2, .5);
  114. glBegin(GL_QUADS);
  115. glVertex3f(0.891063,-0.45388,0);
  116. glVertex3f(0.0773943,0.151941,-0.985355);
  117. glVertex3f(-0.891063,0.45388,0);
  118. glVertex3f(-0.0773943,-0.151941,0.985355);
  119. glEnd();
  120. glPopMatrix();
  121. glutSwapBuffers();
  122. }
  123. int main(int argc, char *argv[])
  124. {
  125. glutInit(&argc, argv);
  126. glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE | GLUT_MULTISAMPLE);
  127. glutInitWindowPosition(50, 50);
  128. glutInitWindowSize(w_win, h_win);
  129. glutCreateWindow("FTGL TEST");
  130. glutDisplayFunc(display);
  131. glutKeyboardFunc(parsekey);
  132. glutMouseFunc(mouse);
  133. glutMotionFunc(motion);
  134. glutReshapeFunc(reshape);
  135. glutIdleFunc(display);
  136. myinit();
  137. glutMainLoop();
  138. return 0;
  139. }