我对 glfw3 和 glew 有一些问题。
这是代码:
#pragma comment(lib, "glew32.lib")
#pragma comment(lib, "glfw3dll.lib")
#include <iostream>
#include "GLEW\glew.h"
#include "GLFW\glfw3.h"
void error_callback(int error, const char* description)
{
std::cerr << description << std::endl;
}
void input_callback(GLFWwindow* wnd, int key, int scancode, int action, int mods)
{
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(wnd, GL_TRUE);
}
int main(int argc, char** argv)
{
//init glfw
if(!glfwInit()) return EXIT_FAILURE;
//error callback
glfwSetErrorCallback(error_callback);
//create window with opengl 4.3 core profil context
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(1024, 768, "glfw openGL", NULL, NULL);
if(!window)
{
glfwTerminate();
return EXIT_FAILURE;
}
//input callback
glfwSetKeyCallback(window, input_callback);
//binding context
glfwMakeContextCurrent(window);
//init glew
glewExperimental = GL_TRUE;
if(GLEW_OK != glewInit())
{
glfwDestroyWindow(window);
glfwTerminate();
return EXIT_FAILURE;
}
//generate a vertex buffer object
GLuint vbo;
glGenBuffers(1, &vbo);
//set clear color
glClearColor(100.f/255, 149.f/255, 237.f/255, 1.0);
//main loop
while(!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
//destroy window
glfwDestroyWindow(window);
//terminate glfw
glfwTerminate();
return EXIT_SUCCESS;
}
这是我得到的错误:
error LNK2019: symbole externe non rÚsolu __imp__glClear@4 rÚfÚrencÚ dans la fonction _main C:\Users\Adrien\Documents\CPP\GlfwSetup\GlfwSetup\main.obj GlfwSetup
error LNK2019: symbole externe non rÚsolu __imp__glClearColor@16 rÚfÚrencÚ dans la fonction _main C:\Users\Adrien\Documents\CPP\GlfwSetup\GlfwSetup\main.obj GlfwSetup
如果我评论 glClearColor 和 glClear 行,程序运行良好(甚至 glGenBuffers 部分)。所以我不明白为什么我可以使用一些openGl函数但不能使用其他一些函数。
操作系统:Windows 7 64 位。IDE:视觉工作室 2012 快递。glfw 版本:3. glew 版本 1.10.0。