- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想开始使用 OpenGL 3+ 和 4,但我在使用 Glew 时遇到了问题。我试图将 glew32.lib 包含在附加依赖项中,并且我已将库和 .dll 移动到主文件夹中,因此不应该有任何路径问题。我得到的错误是:
Error 5 error LNK2019: unresolved external symbol __imp__glewInit referenced in function "void __cdecl init(void)" (?init@@YAXXZ) C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader
Error 4 error LNK2019: unresolved external symbol __imp__glewGetErrorString referenced in function "void __cdecl init(void)" (?init@@YAXXZ) C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader
Error 3 error LNK2001: unresolved external symbol __imp____glewGenBuffers C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader
Error 1 error LNK2001: unresolved external symbol __imp____glewBufferData C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader
Error 2 error LNK2001: unresolved external symbol __imp____glewBindBuffer C:\Users\Mike\Desktop\Test Folder\ModelLoader through VBO\ModelLoader\main.obj ModelLoader
这是我的大部分代码:
#define NOMINMAX
#include <vector>
#include <memory>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <Windows.h>
#include <cstdio>
#include <time.h>
#include "GL\glew.h"
#include "glut.h"
#pragma comment(lib, "glew32.lib")
#pragma comment(lib, "opengl32.lib")
using namespace std;
GLsizei screen_width, screen_height;
float camera[3] = {0.0f, 10.0f, -15.0f};
float xPos = 0;
float yPos = 10;
float zPos = -15;
float orbitDegrees = 0;
clock_t sTime;
float fPS;
int fCount;
GLdouble* modelV;
GLdouble* projM;
GLint* vPort;
//Lights settings
GLfloat light_ambient[]= { 0.1f, 0.1f, 0.1f, 0.1f };
GLfloat light_diffuse[]= { 1.0f, 1.0f, 1.0f, 0.0f };
GLfloat light_specular[]= { 1.0f, 1.0f, 1.0f, 0.0f };
GLfloat light_position[]= { 100.0f, 0.0f, -10.0f, 1.0f };
//Materials settings
GLfloat mat_ambient[]= { 0.5f, 0.5f, 0.0f, 0.0f };
GLfloat mat_diffuse[]= { 0.5f, 0.5f, 0.0f, 0.0f };
GLfloat mat_specular[]= { 1.0f, 1.0f, 1.0f, 0.0f };
GLfloat mat_shininess[]= { 1.0f };
typedef struct Vectors {
float x;
float y;
float z;
}Vector;
typedef struct Polys {
Vector v;
Vector vt;
Vector vn;
int texture;
} Poly;
vector<Vector> vecs;
vector<Vector> normVecs;
vector<Vector> textVecs;
vector<Poly> polyList;
void loadModel(string filepath);
void createTex(string ref);
void render();
// An array of 3 vectors which represents 3 vertices
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
void render()
{
}
void createTex(string ref)
{
}
void loadModel(string filepath)
{
}
void resize (int p_width, int p_height)
{
if(screen_width==0 && screen_height==0) exit(0);
screen_width=p_width; // Obtain the new screen width values and store it
screen_height=p_height; // Height value
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear both the color and the depth buffer so to draw the next frame
glViewport(0,0,screen_width,screen_height); // Viewport transformation
glMatrixMode(GL_PROJECTION); // Projection transformation
glLoadIdentity(); // Initialize the projection matrix as identity
gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,10000.0f);
glutPostRedisplay(); // This command redraw the scene (it calls the same routine of glutDisplayFunc)
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glPushMatrix();
glLoadIdentity(); // Initialize the model matrix as identity
gluLookAt(xPos, yPos, zPos, /* look from camera XYZ */
0, yPos, 0, /* look at the origin */
0, 1, 0); /* positive Y up vector */
glRotatef(orbitDegrees, 0.f, 1.0f, 0.0f);
//glTranslatef(0.0,0.0,-20); // We move the object forward (the model matrix is multiplied by the translation matrix)
//rotation_x = 30;
//rotation_x = rotation_x + rotation_x_increment;
//rotation_y = rotation_y + rotation_y_increment;
//rotation_z = rotation_z + rotation_z_increment;
//if (rotation_x > 359) rotation_x = 0;
//if (rotation_y > 359) rotation_y = 0;
//if (rotation_z > 359) rotation_z = 0;
// glRotatef(rotation_x,1.0,0.0,0.0); // Rotations of the object (the model matrix is multiplied by the rotation matrices)
//glRotatef(rotation_y,0.0,1.0,0.0);
// glRotatef(rotation_z,0.0,0.0,1.0);
//if (objarray[0]->id_texture!=-1)
//{
// glBindTexture(GL_TEXTURE_2D, objarray[0]->id_texture); // We set the active texture
// glEnable(GL_TEXTURE_2D); // Texture mapping ON
// printf("Txt map ON");
//}
//else
// glDisable(GL_TEXTURE_2D); // Texture mapping OFF
glGetDoublev(GL_PROJECTION_MATRIX, modelV);
glGetDoublev(GL_PROJECTION_MATRIX, projM);
glGetIntegerv(GL_VIEWPORT, vPort);
if(clock() > sTime)
{
fPS = fCount;
fCount = 0;
sTime = clock() + CLOCKS_PER_SEC;
}
render();
glDisable(GL_LIGHTING);
GLdouble pos[3];
gluUnProject(100, yPos, -14, modelV, projM, vPort, &pos[0], &pos[1], &pos[2]);
char buffer2[255];
int pAmmount = sprintf(buffer2,"FPS: %.2f", fPS);
//glRasterPos3f(pos[0], pos[1], pos[2]);
for(int i = 0; i < pAmmount; i++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, buffer2[i]);
}
glEnable(GL_LIGHTING);
/*glPopMatrix();
glPushMatrix();
glTranslatef(5.0,0.0,-20.0);
objarray[1]->render();*/
glPopMatrix();
glFlush(); // This force the execution of OpenGL commands
glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer
fCount++;
}
void keyboard(unsigned char k, int x, int y)
{
switch(k)
{
case 'w':
yPos++;
break;
case 's':
yPos--;
break;
case 'a':
xPos--;
break;
case 'd':
xPos++;
break;
case 'q':
orbitDegrees--;
break;
case 'e':
orbitDegrees++;
break;
case 'z':
zPos--;
break;
case 'x':
zPos++;
break;
}
}
void initWindow(GLsizei screen_width, GLsizei screen_height)
{
glClearColor(0.0, 0.0, 0.0, 0.0); // Clear background color to black
// Viewport transformation
glViewport(0,0,screen_width,screen_height);
// Projection transformation
glMatrixMode(GL_PROJECTION); // Specifies which matrix stack is the target for matrix operations
glLoadIdentity(); // We initialize the projection matrix as identity
gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,10000.0f); // We define the "viewing volume"
gluLookAt(camera[0], camera[1], camera[2], /* look from camera XYZ */
0, 0, 0, /* look at the origin */
0, 1, 0); /* positive Y up vector */
try
{
//loadModel("Goku habit dechiré.obj");
loadModel("Flooring.obj");;
}
catch(string& filepath)
{
cerr << "Model could not be loaded: " << filepath << endl;
filepath = "Model could not be loaded: " + filepath;
wostringstream sString;
sString << filepath.c_str();
MessageBox(HWND_DESKTOP, sString.str().c_str(), L"Error: loadModel(string filepath)", MB_OK);
}
//Lights initialization and activation
glLightfv (GL_LIGHT1, GL_AMBIENT, light_ambient);
glLightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv (GL_LIGHT1, GL_DIFFUSE, light_specular);
glLightfv (GL_LIGHT1, GL_POSITION, light_position);
glEnable (GL_LIGHT1);
glEnable (GL_LIGHTING);
//Materials initialization and activation
glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_specular);
glMaterialfv (GL_FRONT, GL_POSITION, mat_shininess);
//Other initializations
glShadeModel(GL_SMOOTH); // Type of shading for the polygons
//glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Texture mapping perspective correction
//glEnable(GL_TEXTURE_2D); // Texture mapping ON
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled)
glEnable(GL_CULL_FACE); // Enable the back face culling
glEnable(GL_DEPTH_TEST); // Enable the depth test
glEnable(GL_NORMALIZE);
/*float* matrix = new float[16];
glGetFloatv(GL_PROJECTION_MATRIX, matrix);
for(int i = 0; i < 4; i++)
{
cout << matrix[0] << " " << matrix[1] << " " << matrix[2] << " " << matrix[3] << endl;
matrix += 3;
}*/
modelV = new GLdouble[16];
projM = new GLdouble[16];
vPort = new GLint[4];
sTime = clock() + CLOCKS_PER_SEC;
}
void init()
{
GLenum GlewInitResult;
GlewInitResult = glewInit();
if (GLEW_OK != GlewInitResult) {
fprintf(
stderr,
"ERROR: %s\n",
glewGetErrorString(GlewInitResult)
);
exit(EXIT_FAILURE);
}
// This will identify our vertex buffer
GLuint vertexbuffer;
// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &vertexbuffer);
// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
}
int main(int argc, char **argv)
{
screen_width = 800;
screen_height = 800;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(screen_width,screen_height);
glutInitWindowPosition(0,0);
glutCreateWindow("ModelLoader");
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc (resize);
glutKeyboardFunc(keyboard);
//glutKeyboardFunc(keyboard);
//glutSpecialFunc(keyboard_s);
initWindow(screen_width, screen_height);
init();
glutMainLoop();
return 0;
}
最佳答案
你有一个链接问题。您没有向链接器提供 glew lib 文件的正确路径。因此,链接器无法找到您正在调用的函数的编译代码。
从您的日志来看,您似乎在 Windows 上工作。如果您使用的是 Visual Studio,请右键单击您的项目。选择链接器,然后选择输入。验证 Additional dependencies 是否包含 glew lib 的路径。
请注意,链接时不需要 dll。这将仅在运行时加载(请记住将其放在与可执行文件相同的文件夹中或系统路径中列出的路径中)。
关于c++ - Glew 问题, Unresolved external 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11059971/
使用glew,我正在尝试链接简单的程序 #include int main (int argc, const char * argv[]) { glewInit(); return
我有一个动态库,在构建中包含glew.c,并使用GLEW_STATIC 构建。如果另一个库链接到同一个应用程序并且还以某种方式包含 GLEW,是否有可能由于单一定义规则而导致 Linux 出现问题?
我在 Macintosh 上使用终端。 要编译的命令是基本的: g++ -c String.cpp -o String.o g++ -c FileIO.cpp -o FileIO.o g++ -c
我正在配置一个与 glut 一起工作的程序来与 Qt 一起工作。我正在使用 Qt 5.1.1。并且似乎从 Qt4 到 Qt5 已经丢失了一些 openGL 功能。在我的程序中,我创建了一个 QOpen
我正在尝试做 openGLbook.com 教程。我收到这个常见错误: 1>------ Build started: Project: OpenGL Startup, Configurati
我读过这个 [1],但在我的例子中,CMake 说它找不到 glew。 我在 Windows 上,我的 CMake 模块文件夹中有一个 FindGLEW.cmake 文件,大概是在我安装 CMake-
这很奇怪。我想在我的 gl 程序中实现着色器。 但 GLEW 告诉我,我的系统不支持着色器: //glut init and glew init ... if (GLEW_ARB_vertex_sha
我想使用三角扇绘制不同的图形,但我不知道如何让程序绘制第二个图形。每次我想更改颜色或绘制新图形时,是否需要第二个 vertexShaderSource 和第二个 fragmentShaderSourc
我现在对尝试链接这个 glew 库感到非常沮丧 这是构建日志: g++ -o test.exe "src\\test.o" -lglew32 -lglfw -lglu32 -lopengl32 src
当我尝试在 CLion 中构建我的项目时,我遇到了来自 cmake 的链接错误。我已经尝试过其他线程所说的:将 opengl 放在最后,将 glu 放在第一位,更改我的 include 的顺序并设置
我遇到了这个问题,不知道该怎么办? 'abc.exe': Loaded 'D:\Windows\SysWOW64\nvoglv32.dll', Cannot find or open the PDB
我只是想使用 SDL 2.0 和 glew 1.9 创建一个 openGL 上下文 构建项目时没有问题,但在调试时,GLEW 初始化失败,我该怎么做才能解决这个问题? 我正在使用 visual stu
我正在使用以下代码检查是否有任何错误: glfwInit(); glewExperimental = GL_TRUE; if (glewInit() != 0) { std::cout <<
不知何故,我无法在多个头文件中获取 Glew。它只是提示 Gl 已经在 GLEW 之前定义了。 简而言之,我有以下文件结构: 程序.h 包括: , 和 "SceneManager.h" . 场景管理器
我的机器有 OpenGL 2.0,由于一些奇怪的原因,头文件 gl.h 不包含着色器函数。所以,有人建议我使用 GLEW。我正确安装了 GLEW,并将 glew32s 链接到我的编译器,我还在我的 m
我需要在 Ubuntu 11.10 中加载扩展。我尝试构建 GLEW,但出现以下奇怪错误... ~/Downloads/glew-1.7.0$ make cc -shared -Wl,-soname=
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我试图通过将源文件添加到我的项目来跳过 glew 的“链接步骤”,以使代码更加灵活(目标 32 位和 64 位,只需稍作修改)。我已经使用 Code::Blocks 和 mingw 32 位实现了 3
出于我无法理解的原因,glew 在静态链接时根本不起作用。有没有一种方法可以简单地将 glew.h、glxew.h、wglew.h 和 glew.c 源文件包含到我的项目中并使用 #include "
我编译了 GLEW 库。它似乎工作正常,这里是 make install 的输出: install -d -m 0755 "/usr/include/GL" install -m 0644 inclu
我是一名优秀的程序员,十分优秀!