按键时glfwPollEvents()不调用keycallback

时间:2012-10-11 21:46:41

标签: c++ opengl input glfw

我有下面的代码,如果我使用glfwGetKey()似乎工作,但因为它不会退出循环,甚至似乎都没有调用输入函数。我尝试传递*输入而不是输入,但没有骰子。可能导致这种情况的原因是什么?

#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;
}

}

1 个答案:

答案 0 :(得分:5)

我认为你的程序唯一的问题是你没有在其他glfw函数之前调用glfwInit()。

根据GLFW User Guide的第5页,您必须在库中的任何其他函数之前调用glfwInit以确保正常运行。

另外,不要传递*输入,只传递输入。