Hi again Chetan …
There is a little bit progress ( the rectangle is shaking up, down, left & right when the right mouse button is pressed now
)
Here is the complete code:
#include <string.h>
#include <GL/glut.h>
#include <GL/glaux.h>
#include <stdio.h>
//#include “glui.h”
float xy_aspect;
int last_x, last_y;
float lastMouseX, lastMouseY;
float dragx, dragy;
bool dragging = false;
int x, y;
int main_window;
// Rectangle para.s
float x1=10.00f ,y1=-40.00f,x2=-60.00,y2=-50.00, D=0.0;
/**************************************** Draw user bar **********/
void drawbar (void)
{
glPushMatrix();
glTranslatef(dragx,dragy,0.0f);
glColor3f(1.0, 1.0, 1.0);
glRectf(x1,y1,x2,y2);
glPopMatrix();
}
/**************************************** myGlutKeyboard() **********/
void myGlutKeyboard(unsigned char Key, int x, int y)
{
switch(Key)
{
case 27:
case ‘q’:
case ‘Q’:
case ‘x’:
case ‘X’:
exit(0);
break;
};
glutPostRedisplay();
}
/***************************************** myGlutMenu() ***********/
void myGlutMenu( int value )
{
myGlutKeyboard( value, 0, 0 );
}
/***************************************** myGlutIdle() ***********/
void myGlutIdle( void )
{
/* According to the GLUT specification, the current window is
undefined during an idle callback. So we need to explicitly change
it if necessary */
if ( glutGetWindow() != main_window )
glutSetWindow(main_window);
glutPostRedisplay();
}
/***************************************** myGlutMouse() **********/
void myGlutMouse(int button, int button_state, int x, int y )
{
switch(button)
{
case GLUT_RIGHT_BUTTON:
if (button_state == GLUT_DOWN)
{ dragging = true ; y = 600 - y ; // Win(0,0)
// is left top
lastMouseX = x;
lastMouseY = y ;}
else
dragging = false ;
// default:
// break;
}
}
/***************************************** myGlutMotion() **********/
void myGlutMotion(int x, int y )
{
if (dragging) {// y = 600 - y; // win(0,0)
//is left top
dragx = x - lastMouseX;
dragy = y - lastMouseY;
glutPostRedisplay( );
lastMouseX = x;
lastMouseY = y ;}
}
/**************************************** myGlutReshape() *************/
void myGlutReshape( int x, int y )
{
int tx, ty, tw, th;
//viewport_area( &tx, &ty, &tw, &th );
glViewport( tx, ty, tw, th );
xy_aspect = (float)tw / (float)th;
glutPostRedisplay();
}
/***************************************** myGlutDisplay() *****************/
void myGlutDisplay( void )
{
glViewport(0, 0, 580, 600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)580/(GLfloat)600, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW); // Sets the projection matrix.
glLoadIdentity(); // Reset the modelview matrix.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears the screen.
glLoadIdentity(); // Reset modelview matrix for new frame.
glTranslatef(0.0f,0.0f, -200.0f); //zoom the “camera” out a bit
drawbar ( ) ;
glutSwapBuffers();
}
/**************************************** main() ********************/
void main(int argc, char* argv[])
{
//
/ Initialize GLUT and create window /
//
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowPosition( 50, 50 );
glutInitWindowSize( 800, 600 );
main_window = glutCreateWindow( "My New Game " );
glutDisplayFunc( myGlutDisplay );
glutReshapeFunc( myGlutReshape );
glutKeyboardFunc( myGlutKeyboard );
glutSpecialFunc( NULL );
glutMouseFunc( myGlutMouse );
glutMotionFunc( myGlutMotion );
//
/ Enable z-buferring /
//
glEnable(GL_DEPTH_TEST);
glutIdleFunc( myGlutIdle );
/**** Regular GLUT main loop ****/
glutMainLoop();
}
Thanks a lot Chetan ,even if you can’t solve the problem . 
[This message has been edited by glcrazy (edited 11-20-2003).]