让 GLEW 工作时遇到问题
注意:glGetString(GL_VERSION) 返回:2.1.0 - Build 8.15.10.2361
我已将 GLEW 安装到 System32、VCDir/lib 和 VCDir/include 目录。因此链接器在查找 GLEW 的必要位时不应该有任何问题。我遇到的问题是以下代码:
void foo()
{
Uint32 vboId;
glGenBuffers(1, &vboId);
}
给我以下错误:
unresolved external symbol __imp____glewGenBuffers
这个错误是我决定安装 GLEW 的全部原因。请参阅:无法解析的外部符号_glGenBuffers错误
除了此错误之外,还有一些警告有点令人担忧:
Warning 1 warning C4028: formal parameter 3 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4855 1 Prototek
Warning 2 warning C4028: formal parameter 3 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4857 1 Prototek
Warning 3 warning C4028: formal parameter 2 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4859 1 Prototek
Warning 4 warning C4028: formal parameter 2 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4861 1 Prototek
Warning 5 warning C4028: formal parameter 3 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4868 1 Prototek
Warning 6 warning C4028: formal parameter 3 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4869 1 Prototek
另外,像我为 GLEW 所做的那样,简单地将 SDL 安装到我的 VC inc、lib 和 System32 目录是个好主意吗?
我的 #include 位于文件顶部,如下所示:
#include <stdio.h>
#include <glew.h>
#include "sdl.h"
#include "sdl_opengl.h"
#include <gl/GLU.h>
#include <gl/GL.h>
但如果需要,这里是整个代码正文:
#include <stdio.h>
#include <glew.h>
#include "sdl.h"
#include "sdl_opengl.h"
#include <gl/GLU.h>
#include <gl/GL.h>
Uint32 loadTexture(char* fileName)
{
Uint32 id;
SDL_Surface *img = NULL;
//load into memory using SDL
img = SDL_LoadBMP(fileName);
//generate an id for this texture
glGenTextures(1, &id);
//use this texture
glBindTexture(GL_TEXTURE_2D, id);
//load the texture into video memory via OpenGL
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGB,
img->w,
img->h,
0,
GL_BGR,
GL_UNSIGNED_BYTE,
img->pixels
);
//set mip map settings
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SDL_FreeSurface(img);
return id;
}
Uint32 tex;
void init()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
tex = loadTexture("fireball.bmp");
}
void foo()
{
Uint32 vboId;
glGenBuffers(1, &vboId);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, tex);
glBegin(GL_QUADS);
glTexCoord2f(0.5, 0.5);
glVertex3f(0.25, 0.25, 0.0);
glTexCoord2f(1.0, 0.5);
glVertex3f(0.5, 0.25, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(0.5, 0.5, 0.0);
glTexCoord2f(0.5, 1.0);
glVertex3f(0.25, 0.5, 0.0);
glEnd();
}
int main()
{
Uint32 isRunning = 1;
SDL_Surface *screen = NULL;
SDL_Event event;
Uint32 start;
Uint32 FPS = 30;
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
init();
while(isRunning)
{
start = SDL_GetTicks();
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT: isRunning = 0; break;
}
}
display();
SDL_GL_SwapBuffers();
if(1000 / FPS > SDL_GetTicks() - start)
{
SDL_Delay(1000 / FPS - (SDL_GetTicks() - start));
}
}
SDL_Quit();
return(0);
}
note: glGetString(GL_VERSION) returned: 2.1.0 - Build 8.15.10.2361
I have installed GLEW to System32, and VCDir/lib and VCDir/include directories. So the linker should not have any issues finding the necessary bits of GLEW. The trouble I am having though is that the following code:
void foo()
{
Uint32 vboId;
glGenBuffers(1, &vboId);
}
Gives me the following error:
unresolved external symbol __imp____glewGenBuffers
This error was the entire reason I decided to install GLEW. See: unresolved external symbol _glGenBuffers error
In addition to this error, there are a few warnings that are a bit concerning:
Warning 1 warning C4028: formal parameter 3 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4855 1 Prototek
Warning 2 warning C4028: formal parameter 3 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4857 1 Prototek
Warning 3 warning C4028: formal parameter 2 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4859 1 Prototek
Warning 4 warning C4028: formal parameter 2 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4861 1 Prototek
Warning 5 warning C4028: formal parameter 3 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4868 1 Prototek
Warning 6 warning C4028: formal parameter 3 different from declaration c:\sdl-1.2.14\include\sdl_opengl.h 4869 1 Prototek
Also, is it a good idea to simply install SDL to my VC inc and lib and System32 directories as I have done for GLEW?
My #include's at the top of my file look like this:
#include <stdio.h>
#include <glew.h>
#include "sdl.h"
#include "sdl_opengl.h"
#include <gl/GLU.h>
#include <gl/GL.h>
But in case it is needed, here is the entire body of code:
#include <stdio.h>
#include <glew.h>
#include "sdl.h"
#include "sdl_opengl.h"
#include <gl/GLU.h>
#include <gl/GL.h>
Uint32 loadTexture(char* fileName)
{
Uint32 id;
SDL_Surface *img = NULL;
//load into memory using SDL
img = SDL_LoadBMP(fileName);
//generate an id for this texture
glGenTextures(1, &id);
//use this texture
glBindTexture(GL_TEXTURE_2D, id);
//load the texture into video memory via OpenGL
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGB,
img->w,
img->h,
0,
GL_BGR,
GL_UNSIGNED_BYTE,
img->pixels
);
//set mip map settings
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SDL_FreeSurface(img);
return id;
}
Uint32 tex;
void init()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
tex = loadTexture("fireball.bmp");
}
void foo()
{
Uint32 vboId;
glGenBuffers(1, &vboId);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, tex);
glBegin(GL_QUADS);
glTexCoord2f(0.5, 0.5);
glVertex3f(0.25, 0.25, 0.0);
glTexCoord2f(1.0, 0.5);
glVertex3f(0.5, 0.25, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(0.5, 0.5, 0.0);
glTexCoord2f(0.5, 1.0);
glVertex3f(0.25, 0.5, 0.0);
glEnd();
}
int main()
{
Uint32 isRunning = 1;
SDL_Surface *screen = NULL;
SDL_Event event;
Uint32 start;
Uint32 FPS = 30;
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
init();
while(isRunning)
{
start = SDL_GetTicks();
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT: isRunning = 0; break;
}
}
display();
SDL_GL_SwapBuffers();
if(1000 / FPS > SDL_GetTicks() - start)
{
SDL_Delay(1000 / FPS - (SDL_GetTicks() - start));
}
}
SDL_Quit();
return(0);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我注意到您没有包含对 glewInit() 的调用,如果您计划使用 glew,请确保在使用它提供的任何 openGL 函数指针之前调用它。
I noticed you didn't include a call to glewInit(), if you are planning to use glew make sure you call it before using any of the openGL function pointers it provides.
您实际上链接到了 GLEW 库吗?仅仅告诉 VS 目录在哪里是不够的;你必须告诉它要链接到哪个库。
测试是否链接到该库的快速方法是将其删除并重新编译。如果 VC 没有抱怨找不到某个特定的库,那么你就没有链接到它。
在那里安装 GLEW 并不是一个好主意,更不用说其他任何东西了。 Visual Studio 不像 Linux 安装;没有库和标头的全局存储库。您可以将 VS 项目指向特定的库和头文件(如果需要,您甚至可以全局设置它们)。保留 VS 目录。
Did you actually link to the GLEW library? Simply telling VS where the directory is isn't enough; you have to tell it what library to link to.
A quick way to test if you're linking to the library is to delete it and recompile. If VC doesn't complain about not being able to find a particular library, then you didn't link to it.
It wasn't a good idea to install GLEW there, let alone anything else. Visual Studio is not like a Linux install; there isn't a global repository of libraries and headers. It is up to you to point your VS project to the particular libraries and header files (you can even set these globally if you want). Leave the VS directories alone.
glGenBuffers 第二个参数是指向 GLuint 的指针 (GLuint ),而不是指向 GLuint 指针的指针 (GLuint *,这是您传递的内容)。相反,请执行以下操作:
glGenBuffers second parameter is a pointer to a GLuint (GLuint ), not a Pointer to a Pointer to a GLuint (GLuint *, which is what you're passing). Instead, do this: