case GLFW_KEY_W:
y_location+=5;
break;
case GLFW_KEY_S:
y_location-=5;
break;
case GLFW_KEY_A:
x_location-=5;
break;
case GLFW_KEY_87:
x_location+=5;
break;
Unfortunately, it does not compile. It keeps saying [quote]In function ‘void handleKeypress(int, int)’
|23|error: ‘GLFW_KEY_W’ was not declared in this scope|
|26|error: ‘GLFW_KEY_S’ was not declared in this scope|
|29|error: ‘GLFW_KEY_A’ was not declared in this scope|
|32|error: ‘GLFW_KEY_D’ was not declared in this scope|
[/quote]
So, what I am doing wrong this time? Thanks for the effort.
It’s difficult to help without seeing more of the code, however there is at least one error in what you’ve put above as there is no GLFW_KEY_87, I think you mean GLFW_KEY_W which has number 87. Note that for the printable keys you can also use their upper case character representation, such as'W' in this case.
Well, let’s see if this code might be of some help:
void GLFWCALL handleKeypress (int key, int press) {
switch (key) {
case GLFW_KEY_ESC:
exit(1);
break;
case GLFW_KEY_RIGHT:
rotate_y+=5;
break;
case GLFW_KEY_LEFT:
rotate_y-=5;
break;
case GLFW_KEY_UP:
rotate_x+=5;
break;
case GLFW_KEY_DOWN:
rotate_x-=5;
break;
case GLFW_KEY_W:
y_location+=5;
break;
case GLFW_KEY_S:
y_location-=5;
break;
case GLFW_KEY_A:
x_location-=5;
break;
case GLFW_KEY_D:
x_location+=5;
break;
}
}
Such code will simply not compile unless I comment out everything between
This helps a lot actually, since you are using GLFW_KEY_ESC which only exists in GLFW 2, not GLFW 3 (GLFW 3 has GLFW_KEY_ESCAPE).
So it looks like you are using GLFW 2 not GLFW 3. GLFW 2 does not have the 0-9 and A-Z keys defined using GLFW_KEY_? so you need to using 'W', 'S', 'A', 'D' or switch to GLFW 3. If you switch do read http://www.glfw.org/docs/latest/moving_guide.html#moving_keys.
So do I have to know the corresponding ascii numbers of these keys? I ask that because the “key” bariable is an int. Or shall I change it to a char and use [quote]case ‘w’[/quote]