Advertisement
Kojima0502

openGL_glOriginalGray

Jan 8th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #define FILENAME_IN "../../bmp/ãÓÉPäx1.bmp"
  2.  
  3. #include <stdio.h>
  4. #include <GLUT/glut.h>
  5. #include "bmpLoadSave.h"
  6.  
  7. //ä÷êîÇÃÉvÉçÉgÉ^ÉCÉvêÈåæ
  8. void init();
  9. void display();
  10. void resize(int w, int h);
  11. void keyboard(unsigned char key, int x, int y);
  12. //ïœêî
  13. //âÊëúÇÃÉTÉCÉY
  14. int imgWidth, imgHeight;
  15. GLubyte image[MAX_HEIGHT * MAX_WIDTH];
  16. //ÉEÉCÉìÉhÉEÇÃÉTÉCÉY
  17. int width  = 800;
  18. int height = 600;
  19. //ï\é¶âÊëúÇÃç∂è„énì_
  20. int px0 = 10;
  21. int py0 = 10;
  22. //ç∂â∫
  23. int qx0, qy0;
  24.  
  25. int main(int argc, char** argv)
  26. {
  27.     glutInit(&argc, argv);
  28.    
  29.     //ï\é¶ÉÇÅ[Éh
  30.     glutInitDisplayMode(GLUT_RGBA);
  31.     //ï\é¶ÉEÉBÉìÉhÉEÇÃÉTÉCÉY
  32.     glutInitWindowSize(width, height);
  33.     //ç∂è„ÇÃà íu
  34.     glutInitWindowPosition(100, 100);
  35.     //ÉEÉBÉìÉhÉEçÏê¨
  36.     glutCreateWindow("GL_OriginalGray");
  37.     //ÉEÉBÉìÉhÉEÇÃÉTÉCÉYïœçX
  38.     glutReshapeFunc(resize);
  39.     //ÉLÅ[É{Å[ÉhÇÃóòóp
  40.     glutKeyboardFunc(keyboard);
  41.     //ï\é¶
  42.     glutDisplayFunc(display);
  43.     //èâä˙ê›íË
  44.     init();
  45.     //ÉCÉxÉìÉgèàóùÉãÅ[ÉvÇ…ì¸ÇÈ
  46.     glutMainLoop();
  47.     return 0;
  48. }
  49.  
  50. void init(void)
  51. {
  52.     //îwåiêF
  53.     glClearColor(0.2, 0.2, 0.2, 1.0);
  54.     //ÉÇÉmÉNÉçâÊëúÇÃéÊìæ
  55.     loadGrayData(image, &imgWidth, &imgHeight, FILENAME_IN);
  56. }
  57.  
  58. void display(void)
  59. {
  60.     //ÉJÉâÅ[ÉoÉbÉtÉ@ÇÃÉNÉäÉA
  61.     glClear(GL_COLOR_BUFFER_BIT);
  62.    
  63.     //ç∂â∫ÇÃà íu
  64.     qx0 = px0;
  65.     qy0 = height - imgHeight- py0;
  66.     if(qy0 < 0) qy0 = 0;
  67.     glRasterPos2i(qx0, qy0);
  68.     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  69.     glDrawPixels(imgWidth, imgHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
  70.     //èIóπ
  71.     glFlush();
  72. }
  73.  
  74. void resize(int w, int h)
  75. {
  76.     //ÉrÉÖÅ[É|Å[Égïœä∑
  77.     glViewport(0, 0, w, h);
  78.     //ÉvÉçÉWÉFÉNÉVÉáÉìçsóÒÇÃéwíËÇ∆èâä˙âª
  79.     glMatrixMode(GL_PROJECTION);
  80.     glLoadIdentity();
  81.     //ê≥ìäâeçsóÒÇÃê›íËÅiìäâeïœä∑Åj
  82.     gluOrtho2D(0.0, w, 0.0, h);
  83.    
  84.     width = w;
  85.     height = h;
  86. }
  87.  
  88. void keyboard(unsigned char key, int x, int y)
  89. {
  90.     switch((unsigned char)key)
  91.     {
  92.         case 27://Esc
  93.             exit(0);
  94.             break;
  95.            
  96.         default:
  97.             break;
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement