Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <GLUT/glut.h>
- /* keep the picture data*/
- #define IMGFILE "depth_combine48_cunbus.bmp"
- #define CHANNEL 3 // color(R, G, B)
- int i,j;
- int width; // width of picture
- int height; // height of picture
- int window1, window2;
- /*
- float get_wx ;
- float get_wy ;
- float get_ww ;
- float get_wh ;
- */
- //float Xshift,Yshift;
- GLuint texture; // texture number
- GLubyte* image; // keep the BMP data
- void loadImage(const char* filepath); // read BMP
- float shiftX,shiftY;
- float mouseX,mouseY;
- float x,y;
- float a;
- float g_pressed = 0;
- void display(void)
- {
- /*diaplay the picture */
- glEnable(GL_TEXTURE_2D);
- glClear(GL_COLOR_BUFFER_BIT);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTranslated(-0.5,-0.5,0);
- /*glBegin(GL_QUADS);
- glTexCoord2f(0 , 0); glVertex2f(-0.9 , -0.9);
- glTexCoord2f(0 , 1); glVertex2f(-0.9 , 0.9);
- glTexCoord2f(1 , 1); glVertex2f(0.9 , 0.9);
- glTexCoord2f(1 , 0); glVertex2f(0.9 , -0.9);
- glEnd();
- */
- glBegin(GL_QUADS);
- glTexCoord2f(1.0, 0.0); glVertex2f(1.0, 0.0);//position
- glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
- glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 1.0);
- glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
- glDisable(GL_TEXTURE_2D);
- glEnd();
- //glClear(GL_COLOR_BUFFER_BIT);
- //glColor3d(0.0, 0.0, 0.0);//color
- glTranslated(0.5,0.5,0);
- //glTranslatef(shiftX,shiftY,0);
- x=0.1;
- y=0.1;
- glBegin(GL_LINE_LOOP);
- /*
- get_wx=glutGet( GLUT_WINDOW_X );
- get_wx=glutGet( GLUT_WINDOW_Y );
- get_wx=glutGet( GLUT_WINDOW_WIDTH );
- get_wx=glutGet( GLUT_WINDOW_HEIGHT );
- */
- glVertex2d(-x+shiftX, -y+shiftY);//左下
- glVertex2d(x+shiftX, -y+shiftY);//右下
- glVertex2d(x+shiftX, y+shiftY);//右上
- glVertex2d(-x+shiftX, y+shiftY);//カーソルの左上
- printf("ShiftX1 = %f : ShiftY1 = %f\n" , -x+shiftX , -y+shiftY);//左下
- printf("ShiftX2 = %f : ShiftY2 = %f\n" , x+shiftX , -y+shiftY);//
- printf("ShiftX3 = %f : ShiftY3 = %f\n" , x+shiftX , y+shiftY);//
- printf("ShiftX4 = %f : ShiftY4 = %f\n" , -x+shiftX , y+shiftY);//
- //get_wx=glutGet( GLUT_WINDOW_X );
- //get_wy=glutGet( GLUT_WINDOW_Y );
- //get_ww=glutGet( GLUT_WINDOW_WIDTH );
- //get_wh=glutGet( GLUT_WINDOW_HEIGHT );
- // Xshift=x+shiftX;
- // Yshift=y+shiftY;
- //glPushMatrix();
- //glTranslatef(shiftX,shiftY,0);
- // glTranslatef(0.5,0.5,0);
- //glPopMatrix();
- glEnd();
- glutSwapBuffers();
- //glFlush();
- }
- void myInit(void)
- {
- /* necessary setting for before create window*/
- //window1//
- glutInitWindowSize(600, 600); // setting for window size
- glutInitWindowPosition(0, 0); // window position
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); // setting display mode
- glutCreateWindow("OpenGL");// create window
- glClearColor (0.0, 0.0, 0.0, 1.0); // window back color
- glutDisplayFunc(display);
- //create texture
- loadImage(IMGFILE);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
- width, height, 0, GL_RGB,
- GL_UNSIGNED_BYTE, image);
- //gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, WIDTH, TEXHEIGHT,
- // GL_RGB, GL_UNSIGNED_BYTE, texture);
- free(image);}
- void keyboard(unsigned char key, int x, int y) //keyboard setting
- {
- switch (key) {
- case 'q':
- case 'Q':
- case '\033':
- exit(0);
- default:
- break;
- }
- }
- void mouse(int btn, int state, int x, int y) //mouze setting
- {
- if(btn == GLUT_LEFT_BUTTON == state == GLUT_DOWN) //when press the left button
- {
- //Xshift=x+shiftX;
- // Yshift=y+shiftY;
- mouseX = x;
- mouseY = y;
- g_pressed = 1;
- }
- else if(btn == GLUT_LEFT_BUTTON == state ==GLUT_UP) //when take off the left button
- g_pressed = 0;
- }
- void motion(int x, int y) //controll the motion by the mouse
- {
- {
- shiftX = (float)((x - mouseX)/320);
- shiftY = (float)(-(y - mouseY)/320);
- glutPostRedisplay();
- }
- /* printf("X = %d : Y = %d\n" , x , y); //diplay the position of coordinate
- printf("ShiftX = %f : ShiftY = %f\n" , shiftX , shiftY); //display the amount of the shift
- printf("mouseX = %f : mouseY = %f \n" , -x+shiftX , mouseY);
- //printf("mouseX = %f : mouseY = %f \n" , mouseX , mouseY); //display the mouseX and mouseY
- printf("wx = %f : wy = %f \n" , get_wx , get_wy);
- // printf("windowX = %f : windowY = %f \n" , get_wx , get_wy);
- printf("windowW = %f : windowH = %f \n" , get_ww , get_wh);
- */
- }
- int main(int argc, char* argv[])
- {
- glutInit(&argc, argv);
- //glutInitDisplayMode(GLUT_RGBA);
- //glutCreateWindow(argv[0]);
- myInit();
- glutDisplayFunc(display); //when need to set about display function
- glutKeyboardFunc(keyboard); //when need keyboard function
- glutMouseFunc(mouse); //when need mouse function
- glutMotionFunc(motion); //when need mouse motion function
- //glutIdleFunc(idle_func);
- glutMainLoop();
- return 0;
- }
- void loadImage(const char* filepath)
- {
- int i;
- int size; // size of picture (width , height, color)
- FILE* fp;
- /* read file */
- fp = fopen(filepath, "rb"); //read binary
- if (fp == NULL)
- {
- fprintf(stderr, "%sfail loading\n", filepath);
- exit(EXIT_FAILURE);
- }
- /* get width and height */
- fseek(fp, 18, SEEK_SET); //move fp to place where has been put width of picture
- fread(&width, 4, 1, fp);
- fread(&height, 4, 1, fp);
- /* read data of picture */
- fseek(fp, 54, SEEK_SET); //move fp to place where has been put dataof the picture
- size = width * height * CHANNEL;
- image = (GLubyte* ) malloc(size);
- if (image == NULL)
- {
- fprintf(stderr, "fail to keep the memory\n");
- exit(EXIT_FAILURE);
- }
- for (i = 0; i < size; ++i)
- fread(&image[i], sizeof(GLubyte), 1, fp);
- /* exit */
- fclose(fp);
- }
- /*範囲選択してからの裏でデータを読む
- float *file1;
- file1= (float *)malloc(画像のwidth*height*sizeof(float));
- if((fpi1=fopen(argv[1],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- fread((float *)file1,sizeof(float),[ウィンドウのwidth]*[ウィンドウのheight],fpi1);
- for(i=[ウィンドウの座標(比)(x/300*width)];i<[ウィンドウのheight];i++)
- {
- for(j=[ウィンドウの座標(比)(y/300*height)];j<[ウィンドウのwidth];j++)
- {
- dn1=file2[(i-iy)*iW+(j-ix)];
- }
- }
- free(file1);
- fclose(fpi1);*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement