i want to create a game similare to this one http://www.sciencekids.co.nz/gamesactivities/movinggrowing.html
1-how to move the image according to coordinates from the mouse? i know how to translate an object that i drow like polygon but not images?
2- how to check if its in right plce and make it stuck there i used gltranslate but the image didn't move , and tried copypixl but it kept copying the image every where the mouse hits .
#include <windows.h>
#include <GL/glut.h>
#include <gl/glaux.h>
#pragma comment(lib,"glaux.lib")
AUX_RGBImageRec *image ;
GLsizei wh = 600, ww = 800;
//-----------------------------------------------------------------------------------------------
void display(void){
image = new AUX_RGBImageRec();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
image = auxDIBImageLoad(L"boy.bmp");
glDrawPixels(image->sizeX, image->sizeY, GL_RGB,
GL_UNSIGNED_BYTE,image->data);
glFlush();
}
//-----------------------------------------------------------------------------------------------
void mouse (int btn , int state , int x , int y){
int h = wh-y ;
if(btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
/*glPushMatrix();*/
/*glTranslatef(x , h , 0);*/
glRasterPos2i(x,h);
glCopyPixels(0,0,image->sizeX, image->sizeY,GL_COLOR);
//glPopMatrix();}
if(btn == GLUT_LEFT_BUTTON && state == GLUT_UP) {
// check if it is in right place to stuck it else will retuen to original place
}
}glFlush();
}
//-----------------------------------------------------------------------------------------------
void intiate(){
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0,ww,0,wh);
}
//-----------------------------------------------------------------------------------------------
void main()
{
glutInitDisplayMode (GLUT_RGB);
glutInitWindowSize (ww, wh);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Inside my Body");
intiate();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}