thegermanpole
thegermanpole

Reputation: 133

glfwPollEvents() doesn't call keycallback on key press

I have the code down below, it seems to be working if I use glfwGetKey(), but as it is it doesn't exit the loop,nor even seem to call the input function. I tried passing *input instead of input, but no dice. What could be causing this?

#include <display.h>
#include <GL/glfw.h>
#include <stdlib.h>
#include <stdio.h>

bool running;

void GLFWCALL input( int key, int action )
{
    //if(key == GLFW_KEY_ESC ){
        running = false;
    //}
printf("%d",key);
}


int main(int argc, char* argv[])
{
running = true;
if(argc==3){
    int width = atoi(argv[1]);
    int height = atoi(argv[2]);
    Display d(width,height);
    glfwSetKeyCallback( *input );
    d.open();
    while(running){
    glfwPollEvents();
    printf("Running");

    }
    printf("\n %d,%d %d\n", width,height,GLFW_KEY_ESC);
    d.close();
    return 1;
}
else {
    printf("Usage: GLFW_play width height");
    return 0;
}

}

Upvotes: 3

Views: 3543

Answers (1)

MikeMx7f
MikeMx7f

Reputation: 937

I think the only problem with your program is that you don't call glfwInit() before the other glfw functions.

According to page 5 of the GLFW User Guide, you must call glfwInit before any other function from the library to ensure proper functionality.

Also, don't pass *input, just pass input.

Upvotes: 5

Related Questions