Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FILENAME_IN "../../bmp/ãÓÉPäx1.bmp"
- #include <stdio.h>
- #include <GLUT/glut.h>
- #include "bmpLoadSave.h"
- //ä÷êîÇÃÉvÉçÉgÉ^ÉCÉvêÈåæ
- void init();
- void display();
- void resize(int w, int h);
- void keyboard(unsigned char key, int x, int y);
- //ïœêî
- //âÊëúÇÃÉTÉCÉY
- int imgWidth, imgHeight;
- GLubyte image[MAX_HEIGHT * MAX_WIDTH];
- //ÉEÉCÉìÉhÉEÇÃÉTÉCÉY
- int width = 800;
- int height = 600;
- //ï\é¶âÊëúÇÃç∂è„énì_
- int px0 = 10;
- int py0 = 10;
- //ç∂â∫
- int qx0, qy0;
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- //ï\é¶ÉÇÅ[Éh
- glutInitDisplayMode(GLUT_RGBA);
- //ï\é¶ÉEÉBÉìÉhÉEÇÃÉTÉCÉY
- glutInitWindowSize(width, height);
- //ç∂è„ÇÃà íu
- glutInitWindowPosition(100, 100);
- //ÉEÉBÉìÉhÉEçÏê¨
- glutCreateWindow("GL_OriginalGray");
- //ÉEÉBÉìÉhÉEÇÃÉTÉCÉYïœçX
- glutReshapeFunc(resize);
- //ÉLÅ[É{Å[ÉhÇÃóòóp
- glutKeyboardFunc(keyboard);
- //ï\é¶
- glutDisplayFunc(display);
- //èâä˙ê›íË
- init();
- //ÉCÉxÉìÉgèàóùÉãÅ[ÉvÇ…ì¸ÇÈ
- glutMainLoop();
- return 0;
- }
- void init(void)
- {
- //îwåiêF
- glClearColor(0.2, 0.2, 0.2, 1.0);
- //ÉÇÉmÉNÉçâÊëúÇÃéÊìæ
- loadGrayData(image, &imgWidth, &imgHeight, FILENAME_IN);
- }
- void display(void)
- {
- //ÉJÉâÅ[ÉoÉbÉtÉ@ÇÃÉNÉäÉA
- glClear(GL_COLOR_BUFFER_BIT);
- //ç∂â∫ÇÃà íu
- qx0 = px0;
- qy0 = height - imgHeight- py0;
- if(qy0 < 0) qy0 = 0;
- glRasterPos2i(qx0, qy0);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glDrawPixels(imgWidth, imgHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
- //èIóπ
- glFlush();
- }
- void resize(int w, int h)
- {
- //ÉrÉÖÅ[É|Å[Égïœä∑
- glViewport(0, 0, w, h);
- //ÉvÉçÉWÉFÉNÉVÉáÉìçsóÒÇÃéwíËÇ∆èâä˙âª
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- //ê≥ìäâeçsóÒÇÃê›íËÅiìäâeïœä∑Åj
- gluOrtho2D(0.0, w, 0.0, h);
- width = w;
- height = h;
- }
- void keyboard(unsigned char key, int x, int y)
- {
- switch((unsigned char)key)
- {
- case 27://Esc
- exit(0);
- break;
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement