1

すべてのGLFW3初期化コードをメインから別のファイルに入れようとしていました。コードを実行すると、GLFW がウィンドウを作成できなかったため、glew init 関数で EXC_BAD_ACCESS が返されます。コード分​​離前はすべて問題ありませんでした。GLFWのセットアップコードを他の機能に持たせることは可能ですか?

私はCとopenGLを学び始めているので、どんな助けでも大歓迎です。

これはwindow_manager.hです

typedef struct Window_manager
{
    GLFWwindow *window;
    GLuint window_width;
    GLuint window_height;
    const char *window_title;
} Window_manager;

Window_manager *set_up_window(GLuint width, GLuint height, const char *title);

window_manager.c のコード

Window_manager *set_up_window(GLuint width, GLuint height, const char *title)
{
    Window_manager *win_man = malloc(sizeof(Window_manager));
    // Init GLFW
    //glfwSetErrorCallback(error_fiutallback);

    if (!glfwInit())
    exit(EXIT_FAILURE);

    // Set all the required options for GLFW
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);

    win_man->window_width = width;
    win_man->window_height = height;
    win_man->window_title = title;
    win_man->window = glfwCreateWindow(win_man->window_width, win_man->window_height, win_man->window_title, NULL, NULL);
    glfwMakeContextCurrent(win_man->window);

    // Set the required callback functions
    //glfwSetKeyCallback(win_man->window, key_callback);

    return win_man;
}

そしてmain.cで

int main(int argc, const char * argv[])
{
    Window_manager *win_man = set_up_window(800, 600, "fjut");       
    glewExperimental = GL_TRUE;
    // Initialize GLEW to setup the OpenGL Function pointers
    GLenum err = glewInit();
    if (GLEW_OK != err)
 {
    //Problem: glewInit failed, something is seriously wrong.
    printf("Error: %s\n", glewGetErrorString(err));
 }
 fprintf(stdout, "Status: Using GLEW %s\n",
 glewGetString(GLEW_VERSION));
4

1 に答える 1

1

ウィンドウが開かない理由は、他のウィンドウ ヒントに加えて GLFW_CONTEXT_VERSION_MINOR を指定する必要があるためです。これは、たとえば次のようにして行うことができます。

glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
于 2015-06-17T12:52:34.993 に答える