无法让netbeans正确链接GLEW

时间:2016-03-02 17:55:27

标签: c++ opengl netbeans linker glew

我正在运行一个基本的openGL程序,它使用命令

在命令提示符下编译并运行正常

g ++ gltest.cpp -std = c ++ 11 -lglew32s -lglfw3 -lgdi32 -lopengl32 -o gltest.exe

但是当我尝试在netbeans中使用它时,它给了我一堆“未定义的引用`_imp____glewCreateShader'”错误。所有对glew函数的引用。

我在链接器选项中放置了所需的库

enter image description here

enter image description here

这是代码:

// g++ gldrop.cpp -std=c++11 -lglew32s -lglfw3 -lgdi32 -lopengl32 -o gldrop.exe 

#define GLEW_STATIC
#include <iostream>
#include "gl\glew.h"
#include "gl\glfw3.h"
#include "shaderM.cpp"
#include "glm\glm\gtc\matrix_transform.hpp"
#include "glm\glm\glm.hpp"

#include "data.cpp"

GLFWwindow* window;

int main(int argv, char** argc)
{
//initialize GLFW
if (!glfwInit())
{
    std::cout << "Failed to initialize GLFW \n";
    return -1;
}

glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

//create GLFW window
window = glfwCreateWindow(640, 480, "GL", NULL, NULL);

glfwMakeContextCurrent(window);
glewExperimental = true;

//initialize GLEW
if(glewInit() != GLEW_OK)
{
    std::cout << "failed to initialize glew";
    return -1;
}

glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

//background
glClearColor(0.4f, 0.3f, 0.7f, 0.0f);

//depth test
glEnable(GL_DEPTH_TEST);
//takes fragments closer to the camera
glDepthFunc(GL_LESS);

//Vertex array object                                                
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

//Vertex buffer
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

//color buffer
GLuint colorbuffer;
glGenBuffers(1, &colorbuffer);
glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW);

//create shaders and attach them to a program object
GLuint program = rigShadersToProgram();

GLuint matrixID = glGetUniformLocation(program, "MVP");
//projection matrix 45 degree FoV, 4:3 ratio, display range 0.1 - 100
glm::mat4 projection = glm::perspective(70.0f, 4.0f/3.0f, 0.1f, 100.0f);
//camera matrix
glm::mat4 view = glm::lookAt(
                    glm::vec3(4,3,-3), //camera is at (4,3,-3)
                    glm::vec3(0,0, 0), //looks at origin
                    glm::vec3(0,1, 0)  //head is up
                    );
//model matrix identity matrix
glm::mat4 model = glm::mat4(1.0f);
//model-view-projection
glm::mat4 MVP   = projection * view * model;

while (!glfwWindowShouldClose(window))
{
    //clear the screen
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //use the compiled shaders
    glUseProgram(program);
    //send transformation matrix to currently bound shader 
    glUniformMatrix4fv(matrixID, 1, GL_FALSE, &MVP[0][0]);

    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

    glVertexAttribPointer(
        0,          //index 
        3,          //size
        GL_FLOAT,   //type
        GL_FALSE,   //normalized?
        0,          //stride
        0           //array buffer offset
    );

    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);

    glVertexAttribPointer(
        1,          //index 
        3,          //size
        GL_FLOAT,   //type
        GL_FALSE,   //normalized?
        0,          //stride
        0           //array buffer offset
    );

    //draw triangle
    glDrawArrays(GL_TRIANGLES, 0, 12*3); //start @ vertex 0, 3 verticies

    glfwSwapBuffers(window);
    glfwPollEvents();
}

glDeleteBuffers(1, &vertexbuffer);
glDeleteBuffers(1, &colorbuffer);
glDeleteProgram(program);
glDeleteVertexArrays(1, &vao);

glfwTerminate();

return 0;

}

不确定为什么它不会识别库。

1 个答案:

答案 0 :(得分:1)

你在哪里下载glew32?
也许你下载了Visual C版本,如果不是你可以解压错版本(64位)。

我听到的另一件事(首先试试) 我在mingw上遇到了glew32s的问题,由于某种原因它不起作用,使用常规的glew32。它应该仍然适用于预处理器并静态编译而没有任何问题。