All tutorials in one place.

Friday, July 15, 2016

10. Funksioni i mausit

Shpeshher eshte e nevojshme qe te ralizojme neper grafika te ndryshem levizje objektesh kur perdoruesi klikon ne ekran ,ose mbi objekt. Kete e realizon funksioni I mausit glutMouseFunc I cili mer si parameter butonin qe mer vleren I majte ose I djathte, gjendjen e butonit I shtypur ose I leshuar, dhe korordinatat x dhe y te pikes se klikimit.

Ushtrim: Ndertoni nje program I cili vizaton nje drejtkendesh dhe e rretullon ate me 30 grad sa her qe klikojm ne ekran

#include<gl/glut.h>
int kendi=0;
void Display()
{
  glClear(GL_COLOR_BUFFER_BIT);
  glRotatef(kendi,0.0,0.0,1.0);
  glRectf(5.,-5.,25.,5.);
  glFlush();
}
void mouse(int buton,int sts, int x, int y)
{
  if(buton==GLUT_LEFT_BUTTON)
  {
  if(sts==GLUT_DOWN)
  {
  kendi=kendi+30;
  kendi%=360;
  }
  }
  glutPostRedisplay();
}
void init()
{
  glClearColor(0.3,0.2,0.4,1.0);
  glViewport(0,0,320,240);
  gluOrtho2D(0.0,160.0,0.0,120.0);
  glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char* argv[])
{
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  glutInitWindowSize(320,240);
  glutCreateWindow("test");
  init();
  glutDisplayFunc(Display);
  glutMouseFunc(mouse);
  glutMainLoop();
}

Share:

0 comments:

Post a Comment

Popular Posts

Categories

Tutorials House. Powered by Blogger.

Labels