Advertisement
FoguinhoS

Untitled

Oct 10th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #include <windows.h>
  2. #ifndef WIN32 //if using windows then do windows specific stuff.
  3. #define WIN32_LEAN_AND_MEAN //remove MFC overhead from windows.h which can cause slowness
  4. #define WIN32_EXTRA_LEAN
  5.  
  6. #include <windows.h>
  7. #endif
  8. #include <stdio.h>
  9. #include <GL/gl.h>
  10. #include <GL/glut.h>
  11. #include <GL/glu.h>
  12. #include <conio.h>//needed for getch
  13. #define W 800
  14. #define H 600
  15.  
  16.  
  17.  
  18. class Botaum
  19. {
  20. public:
  21. float y1;
  22. float y2;
  23. float x1;
  24. float x2;
  25. int meuStatus;
  26. char letra;
  27. void draw();
  28. private:
  29. };
  30.  
  31. void Botaum::draw()
  32. {
  33.  
  34. //glRectf(-0.9f,0.9f, -0.8f, 0.8f);
  35. glColor3f(1.0f, 0.0f, 0.0f);
  36. if(meuStatus == 1)
  37. {
  38. glColor3f(1, 0, 0);
  39. glRasterPos3f(-0.1,0.0f,0.0f);
  40. glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, letra);
  41. glutSwapBuffers();
  42. glColor3f(0.0f, 1.0f, 0.0f);
  43. }
  44. //glRectf(x1,y1, x2, y2);
  45. glRectf(0.5, 0, 0.6, 0.1);
  46. glutSwapBuffers();
  47. }
  48.  
  49. Botaum b[4];
  50.  
  51.  
  52. void MyMouse(int button, int state, int x, int y)
  53. {
  54.  
  55. if(button == GLUT_LEFT_BUTTON)
  56. {
  57. float mx = ((((float)x * -2.0) / W)+1.0)*-1.0;
  58. float my = ((((float)y * -2.0) / H)-1.0)*-1.0;
  59. printf("y: %d\n",y/2);
  60. //printf(" Meu : %.2f , %.2f - %.2f~%.2f , %.2f~%.2f\n",mx,my,b[0].x1,b[0].x2,b[0].y1,b[0].y2);
  61. for(int i = 0; i < 4; i ++)
  62. {
  63.  
  64.  
  65. if((mx > b[i].x1 && mx < b[i].x2)&&(my > b[i].y1 && my < b[i].y2))
  66. {
  67.  
  68.  
  69. if(state == GLUT_DOWN)
  70. {
  71. b[i].meuStatus = 1;
  72. printf("\a");
  73. }
  74. else if(state == GLUT_UP)
  75. {
  76. b[i].meuStatus = 0;
  77. }
  78. }
  79.  
  80. }
  81. }
  82.  
  83. glutPostRedisplay();
  84. }
  85.  
  86.  
  87. void display()
  88. {
  89. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  90. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  91. int i;
  92. for( i = 0; i < 4; i ++ )
  93. {
  94. b[i].draw();
  95. }
  96. glutSwapBuffers();
  97. }
  98.  
  99.  
  100. void setup()
  101. {
  102. int i;
  103. //b[0].x1 = 0.0;
  104.  
  105. for( i = 0; i < 4; i ++ )
  106. {
  107. //b[i].x1 = -0.9 + (i * 0.20);
  108. b[i].y1 = 0.9;
  109. //b[i].x2 = -0.8 + (i * 0.20);
  110. b[i].y2 = 0.8;
  111. b[i].meuStatus = 0;
  112. }
  113. }
  114.  
  115.  
  116. int main(int argc, char *argv[])
  117. {
  118. for(int i = 0; i < 4; i++)
  119. {
  120. printf("Digite a letra do botao %d: ",i);
  121. scanf("%c",&b[i].letra);
  122. fflush(stdin);
  123. }
  124. glutInit(&argc, argv);
  125. glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
  126. glutInitWindowSize(W,H);
  127. glutCreateWindow("Hello World");
  128. setup();
  129. glutDisplayFunc(display);
  130. glutMouseFunc(MyMouse);
  131.  
  132. glutMainLoop();
  133.  
  134.  
  135.  
  136. getch();//pause here to see results or lack there of
  137. return 0;
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement