drag and drop of images using opengl c++ -


i want create game similare 1 http://www.sciencekids.co.nz/gamesactivities/movinggrowing.html

1-how move image according coordinates mouse? know how translate object drow polygon not images?

2- how check if in right plce , make stuck there used gltranslate image didn't move , , tried copypixl kept copying image every 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 in right place stuck else retuen 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 body"); intiate(); glutdisplayfunc(display); glutmousefunc(mouse); glutmainloop(); }  

1-how move image according coordinates mouse? know how translate object drow polygon not images?

first , foremost: please don't use gldrawpixels. use textures instead, applied regular geometry. opengl doesn't deal user input, you'll have implement mouse interaction yourself. never place opengl drawing commands in input event handler. in input event handler, change variables, set flags, etc. don't draw. flags set, issue redraw can draw updates.

2- how check if in right plce , make stuck there

opengl drawing api, not scene graph. tell draw , that's it. if things not looking you're expecting them, you're not drawing them right.

pro-tip: place opengl commands in drawing routine. not call opengl functions anywhere else. stuff in initiate function belongs in display function.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -