drag and drop of images using opengl c++

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();
} 

Answers


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?

First and foremost: Please don't use glDrawPixels. Use textures instead, applied to regular geometry. OpenGL doesn't deal with user input, so you'll have to implement the mouse interaction yourself. Never place OpenGL drawing commands in the input event handler. In the input event handler, change some variables, set flags, etc. but don't draw. With the flags set, issue a redraw so that you can draw the updates.

2- how to check if its in right plce and make it stuck there

OpenGL is a drawing API, not a scene graph. You tell it what to draw and that's it. If things are not looking like you're expecting them, then you're not drawing them right.

Pro-Tip: Place all OpenGL commands in the drawing routine. Do not call any OpenGL functions from anywhere else. The stuff you do in your initiate function actually belongs in the display function.


Need Your Help

database backup rules

sql sql-server sql-server-2008 tsql

I want to do a backup from my database , that have to run everyday, 20 PM, but the backup of tomorrow can't override the backup of today.

What improvements can be implemented out, with collection and includes in ruby on rails?

ruby-on-rails loops include nested collect

I have a very complex query at a beginner level which I am not able to solve out. It takes my page load to around 6 7 seconds on local machine.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.