-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasics.cpp
More file actions
144 lines (108 loc) · 3.04 KB
/
Copy pathbasics.cpp
File metadata and controls
144 lines (108 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <cstdlib>
#include <iostream>
#include <GL/glut.h>
GLint WINDOW_WIDTH = 500,
WINDOW_HEIGHT = 500;
void init();
void draw_test();
void mouse_test(GLint button, GLint action, GLint x, GLint y);
void mouse_test2(GLint x, GLint y);
void mouse_test3(GLint x, GLint y);
void keybord_test(GLubyte key, GLint x, GLint y);
void keybord_test2(GLint key, GLint x, GLint y);
void test_create_menu();
void menu_test(GLint item_number);
//=================================================================================================
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
GLint screen_width = glutGet(GLUT_SCREEN_WIDTH),
screen_height = glutGet(GLUT_SCREEN_HEIGHT);
glutInitWindowPosition((screen_width - WINDOW_WIDTH) / 2, (screen_height - WINDOW_WIDTH) / 2);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_WIDTH);
glutCreateWindow("OpenGL manipulação de entradas (teclado/mouse)");
init();
glutDisplayFunc(draw_test);
glutMouseFunc(mouse_test);
glutPassiveMotionFunc(mouse_test2);
glutMotionFunc(mouse_test3);
glutKeyboardFunc(keybord_test);
glutSpecialFunc(keybord_test2);
glutMainLoop();
return EXIT_SUCCESS;
}
void init()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
gluOrtho2D(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT);
}
void draw_test()
{
glClear(GL_COLOR_BUFFER_BIT);
std::cout<<"Desenho\n";
glFlush();
}
void mouse_test(GLint button, GLint action, GLint x, GLint y)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
{
std::cout<<"Esquerda";
break;
}
case GLUT_MIDDLE_BUTTON:
{
std::cout<<"Meio";
break;
}
case GLUT_RIGHT_BUTTON:
{
std::cout<<"Direita";
break;
}
default: break;
}
if(action == GLUT_DOWN)
std::cout<<" preciona";
else //GLUT_UP
std::cout<<" libera";
// x cresce da esquerda pra direita. O y cresce de cima para baixo
std::cout<<" em (x:"<<x<<", y:"<<y<<")";
std::cout<<"\n";
}
void mouse_test2(GLint x, GLint y)
{
std::cout<<"Movendo mouse sem clicar para posicao (x:"<<x<<", y:"<<y<<")\n";
}
void mouse_test3(GLint x, GLint y)
{
std::cout<<"Arrastando o mouse para posicao (x:"<<x<<", y:"<<y<<")\n";
}
void keybord_test(GLubyte key, GLint x, GLint y)
{
GLint m = glutGetModifiers();
if(m == GLUT_ACTIVE_SHIFT)
std::cout<<"Shift ou Caps ";
else if(m == GLUT_ACTIVE_CTRL)
std::cout<<"Control ";
else if(m == GLUT_ACTIVE_ALT)
std::cout<<"Alt ";
//VERIFICAR TABELA ASCII QUANDO O CTRL ESTIVER PRECIONADO COM ALGUMA LETRA
if(m == GLUT_ACTIVE_CTRL && (GLint) key == 4)
exit(EXIT_SUCCESS);
std::cout<<"Tecla: "<<(GLint) key<<" (x:"<<x<<", y:"<<y<<")\n";
//ESC = 27
if (key == 27)
glutReshapeWindow(WINDOW_WIDTH, WINDOW_HEIGHT);
}
void keybord_test2(GLint key, GLint x, GLint y)
{
//GLUT_KEY_F1 .. GLUT_KEY_F12
//GLUT_KEY_UP, GLUT_KEY_DOWN, GLUT_KEY_LEFT, GLUT_KEY_RIGHT
//GLUT_KEY_PAGE_DOWN, GLUT_KEY_HOME etc.
std::cout<<"Tecla especial: "<<key<<" (x:"<<x<<", y:"<<y<<")\n";
if(key == GLUT_KEY_F11)
glutFullScreen();
}