Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #ifndef WIN32 //if using windows then do windows specific stuff.
- #define WIN32_LEAN_AND_MEAN //remove MFC overhead from windows.h which can cause slowness
- #define WIN32_EXTRA_LEAN
- #include <windows.h>
- #endif
- #include <stdio.h>
- #include <GL/gl.h>
- #include <GL/glut.h>
- #include <GL/glu.h>
- #include <conio.h>//needed for getch
- #define W 800
- #define H 600
- class Botaum
- {
- public:
- float y1;
- float y2;
- float x1;
- float x2;
- int meuStatus;
- char letra;
- void draw();
- private:
- };
- void Botaum::draw()
- {
- //glRectf(-0.9f,0.9f, -0.8f, 0.8f);
- glColor3f(1.0f, 0.0f, 0.0f);
- if(meuStatus == 1)
- {
- glColor3f(1, 0, 0);
- glRasterPos3f(-0.1,0.0f,0.0f);
- glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, letra);
- glutSwapBuffers();
- glColor3f(0.0f, 1.0f, 0.0f);
- }
- //glRectf(x1,y1, x2, y2);
- glRectf(0.5, 0, 0.6, 0.1);
- glutSwapBuffers();
- }
- Botaum b[4];
- void MyMouse(int button, int state, int x, int y)
- {
- if(button == GLUT_LEFT_BUTTON)
- {
- float mx = ((((float)x * -2.0) / W)+1.0)*-1.0;
- float my = ((((float)y * -2.0) / H)-1.0)*-1.0;
- printf("y: %d\n",y/2);
- //printf(" Meu : %.2f , %.2f - %.2f~%.2f , %.2f~%.2f\n",mx,my,b[0].x1,b[0].x2,b[0].y1,b[0].y2);
- for(int i = 0; i < 4; i ++)
- {
- if((mx > b[i].x1 && mx < b[i].x2)&&(my > b[i].y1 && my < b[i].y2))
- {
- if(state == GLUT_DOWN)
- {
- b[i].meuStatus = 1;
- printf("\a");
- }
- else if(state == GLUT_UP)
- {
- b[i].meuStatus = 0;
- }
- }
- }
- }
- glutPostRedisplay();
- }
- void display()
- {
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- int i;
- for( i = 0; i < 4; i ++ )
- {
- b[i].draw();
- }
- glutSwapBuffers();
- }
- void setup()
- {
- int i;
- //b[0].x1 = 0.0;
- for( i = 0; i < 4; i ++ )
- {
- //b[i].x1 = -0.9 + (i * 0.20);
- b[i].y1 = 0.9;
- //b[i].x2 = -0.8 + (i * 0.20);
- b[i].y2 = 0.8;
- b[i].meuStatus = 0;
- }
- }
- int main(int argc, char *argv[])
- {
- for(int i = 0; i < 4; i++)
- {
- printf("Digite a letra do botao %d: ",i);
- scanf("%c",&b[i].letra);
- fflush(stdin);
- }
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- glutInitWindowSize(W,H);
- glutCreateWindow("Hello World");
- setup();
- glutDisplayFunc(display);
- glutMouseFunc(MyMouse);
- glutMainLoop();
- getch();//pause here to see results or lack there of
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement