Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #include <GL/glut.h> // (or others, depending on the system in use)
  2. #include "sgi.h"
  3.  
  4.  
  5. GLsizei w, h;
  6. int width, height, depth;
  7. unsigned char *image = NULL;
  8. int Status;
  9.  
  10. void init(void);
  11. void reshape(int w, int h);
  12. void lineSegment(void);
  13. void mainSelect(int);
  14. void fileSelect(int);
  15. void displaySelect(int);
  16. void GrayScaleImage();
  17. void NegativeImage(); //선언
  18.  
  19.  
  20. void init(void) {
  21. glClearColor(1.0, 1.0, 1.0, 0.0); // Set display-window color to white.
  22. glMatrixMode(GL_PROJECTION); // Set projection parameters.
  23. gluOrtho2D(0.0, 200.0, 0.0, 150.0);
  24. }
  25.  
  26. void reshape(int w, int h)
  27. {
  28. glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  29. height = (GLint)h;
  30. glMatrixMode(GL_PROJECTION);
  31. glLoadIdentity();
  32. gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
  33. glMatrixMode(GL_MODELVIEW);
  34. glLoadIdentity();
  35. }
  36.  
  37.  
  38. void display(void)
  39. {
  40.  
  41. glClear(GL_COLOR_BUFFER_BIT);
  42. glRasterPos2i(0, 0);
  43.  
  44. glDrawPixels(width, height, GL_RGB,
  45. GL_UNSIGNED_BYTE, image);
  46. glFlush();
  47. }
  48.  
  49. void mainSelect(int value)
  50. {
  51. Status = value;
  52. switch (value) {
  53. case 666:
  54. printf("exit\n");
  55. exit(0);
  56. break;
  57. }
  58. }
  59.  
  60. void fileSelect(int value)
  61. {
  62. char *filename;
  63. Status = value;
  64. switch (value) {
  65.  
  66. //이미지 추가하기.
  67. case 0:
  68. filename = "sample.rgb";
  69. image = read_sgi(filename, &width, &height, &depth);
  70. glutReshapeWindow(width, height);
  71. display();
  72. break;
  73. case 1:
  74. filename = "train.bmp";
  75. image = read_bmp(filename, &width, &height, &depth);
  76. glutReshapeWindow(width, height);
  77. display();
  78. break;
  79. case 2:
  80. filename = "desert.bmp";
  81. image = read_bmp(filename, &width, &height, &depth);
  82. glutReshapeWindow(width, height);
  83. display();
  84. break;
  85. }
  86. }
  87.  
  88. void displaySelect(int value)
  89. {
  90. Status = value;
  91. switch (value) {
  92. case 10:
  93. NegativeImage();
  94. display();
  95. break;
  96. }
  97. }
  98. //Negative 색상을 만들어 주는 코드. 이미지 색상값을 어떻게 주느냐에 따라 r,g,b color와 Negative lmage를 만들수 있음.
  99. void NegativeImage() {
  100. int i, j;
  101. int r, g, b;
  102. for (j = 0; j<height; j++) {
  103. for (i = 0; i<width * 3; i = i + 3) {
  104. r = image[j*width * 3 + i + 0];
  105. g = image[j*width * 3 + i + 1];
  106. b = image[j*width * 3 + i + 2];
  107.  
  108. image[j*width * 3 + i + 2] = r;
  109. image[j*width * 3 + i + 1] = g;
  110. image[j*width * 3 + i + 0] = b;
  111. }
  112. }
  113. }
  114. //GrayScale 색상을 변환해주는 코드.
  115. void GrayScaleImage() {
  116. int i, j, L;
  117. int r, g, b;
  118. for (j = 0; j<height; j++) {
  119. for (i = 0; i<width * 3; i = i + 3) {
  120. r = image[j*width * 3 + i + 0];
  121. g = image[j*width * 3 + i + 1];
  122. b = image[j*width * 3 + i + 2];
  123. L=(0.30*image[j*width * 3 + i + 0]) +(0.59*image[j*width * 3 + i + 1])+(0.11*image[j*width * 3 + i+ 2]);
  124. }
  125. }
  126.  
  127. }
  128.  
  129.  
  130. void main(int argc, char** argv) {
  131.  
  132. int fileMenu, displayMenu, mainMenu;
  133.  
  134. glutInit(&argc, argv); // Initialize GLUT.
  135. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // Set display mode.
  136. // glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  137.  
  138.  
  139. glutInitWindowPosition(50, 100); // Set top-left display-window position.
  140. glutInitWindowSize(300, 300); // Set display-window width and height.
  141. glutCreateWindow("An Example OpenGL Program"); // Create display window.
  142.  
  143. init(); // Execute initialization procedure.
  144. glutDisplayFunc(display); // Send graphics to display window.
  145. glutReshapeFunc(reshape);
  146.  
  147. fileMenu = glutCreateMenu(fileSelect);
  148. glutAddMenuEntry("sample.rgb", 0);
  149. glutAddMenuEntry("train.bmp", 1);
  150. glutAddMenuEntry("desert.bmp", 2);
  151.  
  152. displayMenu = glutCreateMenu(displaySelect);
  153. glutAddMenuEntry("Negative Image", 10);
  154. glutAddMenuEntry("GrayScale Image", 20); //메뉴바 생성 코드.
  155.  
  156. mainMenu = glutCreateMenu(mainSelect);
  157. glutAddSubMenu("File", fileMenu);
  158. glutAddSubMenu("Display", displayMenu);
  159.  
  160. glutAddMenuEntry("Quit", 666);
  161. glutSetMenu(mainMenu);
  162. glutAttachMenu(GLUT_RIGHT_BUTTON);
  163.  
  164. glutMainLoop(); // Display everything and wait.
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement