GL3W和GLFW未定义的参考错误

时间:2017-02-25 08:33:09

标签: c++ opengl glfw

我在尝试使用GL3W和GLFW编写OpenGL应用程序时遇到了问题。 每次我构建代码Code :: Blocks(使用GNU GCC编译器)我都会得到几个 几个gl3w *和glfw *函数的“未定义引用”错误。我重新检查了我的构建选项 (链接器:opengl32,glu32,gdi32;搜索目录/编译器:include [表示GL,GL3,GLFW和一些帮助器头];搜索目录/链接器:lib-mingw [glfw3 libraries]), 但一切看起来都很正这是我的代码:

//////////////////////////////////////////////////////////////////////////////
//
//  Triangles.cpp
//
//////////////////////////////////////////////////////////////////////////////
#include <iostream>
using namespace std;

#include "GL3/gl3.h"
#include "GL3/gl3w.h"
#include "GLFW/glfw3.h"
#include "LoadShaders.h"

#define BUFFER_OFFSET(a) ((void*)(a))

enum VAO_IDs { Triangles, NumVAOs };
enum Buffer_IDs { ArrayBuffer, NumBuffers };
enum Attrib_IDs { vPosition = 0 };

GLuint  VAOs[NumVAOs];
GLuint  Buffers[NumBuffers];

const GLuint  NumVertices = 6;

//----------------------------------------------------------------------------
//
// init
//

void
init( void )
{
    glGenVertexArrays( NumVAOs, VAOs ); //Error gl3w
    glBindVertexArray( VAOs[Triangles] ); //Error gl3w

    GLfloat  vertices[NumVertices][2] = {
        { -0.90f, -0.90f }, {  0.85f, -0.90f }, { -0.90f,  0.85f },  // Triangle 1
        {  0.90f, -0.85f }, {  0.90f,  0.90f }, { -0.85f,  0.90f }   // Triangle 2
    };

    glCreateBuffers( NumBuffers, Buffers ); //Error gl3w
    glBindBuffer( GL_ARRAY_BUFFER, Buffers[ArrayBuffer] ); //Error gl3w
    glBufferStorage( GL_ARRAY_BUFFER, sizeof(vertices), vertices, 0); //Error gl3w

    ShaderInfo  shaders[] =
    {
        { GL_VERTEX_SHADER, "media/shaders/triangles/triangles.vert" },
        { GL_FRAGMENT_SHADER, "media/shaders/triangles/triangles.frag" },
        { GL_NONE, NULL }
    };

    GLuint program = LoadShaders( shaders ); //Error LoadShaders
    glUseProgram( program ); //Error gl3w

    glVertexAttribPointer( vPosition, 2, GL_FLOAT,
                           GL_FALSE, 0, BUFFER_OFFSET(0) ); //Error gl3w
    glEnableVertexAttribArray( vPosition ); //Error gl3w
}

//----------------------------------------------------------------------------
//
// display
//

void
display( void )
{
    static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };

    glClearBufferfv(GL_COLOR, 0, black); //Error gl3w

    glBindVertexArray( VAOs[Triangles] ); //Error gl3w
    glDrawArrays( GL_TRIANGLES, 0, NumVertices ); //Error gl3w
}

//----------------------------------------------------------------------------
//
// main
//

int
main( int argc, char** argv )
{
    glfwInit(); //Error glfw

    GLFWwindow* window = glfwCreateWindow(800, 600, "Triangles", NULL, NULL); //Error glfw

    glfwMakeContextCurrent(window); //Error glfw
    gl3wInit();//Error gl3w

    init();

    while (!glfwWindowShouldClose(window))//Error glfw
    {
        display();
        glfwSwapBuffers(window);//Error glfw
        glfwPollEvents();//Error glfw
    }

    glfwDestroyWindow(window);//Error glfw

    glfwTerminate();//Error glfw
}

所有错误都是未定义的参考错误

感谢您提供任何帮助!

1 个答案:

答案 0 :(得分:0)

您需要编译gl3w.c并将glfw.lib添加到关联的库中(您添加opengl32, glu32, gdi32的地方)