C 让GLEW工作有困难吗

C 让GLEW工作有困难吗,c,opengl,sdl,unresolved-external,glew,C,Opengl,Sdl,Unresolved External,Glew,注意:返回的glGetString(GL_版本):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___

注意:返回的glGetString(GL_版本):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的全部原因。见:

除此错误外,还有一些警告值得注意:

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>
#包括
#包括
#包括“sdl.h”
#包括“sdl_opengl.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);
}
#包括
#包括
#包括“sdl.h”
#包括“sdl_opengl.h”
#包括
#包括
Uint32 loadTexture(字符*文件名)
{
Uint32-id;
SDL_表面*img=NULL;
//使用SDL加载到内存中
img=SDL\u LoadBMP(文件名);
//生成此纹理的id
glGenTextures(1,&id);
//使用此纹理
glBindTexture(GL_纹理_2D,id);
//通过OpenGL将纹理加载到视频内存中
glTexImage2D(
GL_纹理_2D,
0,
德国劳埃德大学,
img->w,
img->h,
0,
德国劳埃德大学,
GL_无符号字节,
img->像素
);
//设置mip映射设置
glTexParameteri(GL_纹理2D、GL_纹理最小过滤器、GL_线性);
glTexParameteri(GL_纹理2D、GL_纹理MAG_过滤器、GL_线性);
SDL_自由曲面(img);
返回id;
}
Uint32 tex;
void init()
{
glClearColor(0.0,0.0,0.0,1.0);
glMatrixMode(GL_投影);
glLoadIdentity();
格洛托(0.0,1.0,1.0,0.0,-1.0,1.0);
glMatrixMode(GLU模型视图);
glEnable(GL_纹理_2D);
tex=loadTexture(“fireball.bmp”);
}
void foo()
{
Uint32 vboId;
glGenBuffers(1,&vboId);
}
无效显示()
{
glClear(GLU颜色缓冲位);
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);
格伦德();
}
int main()
{
Uint32正在运行=1;
SDL_表面*屏幕=空;
SDL_事件;
Uint32启动;
Uint32 FPS=30;
SDL_Init(SDL_Init_EVERYTHING);
屏幕=SDL_设置视频模式(640、480、32,SDL_OPENGL);
init();
同时(正在运行)
{
start=SDL_GetTicks();
while(SDL_事件和事件))
{
开关(事件类型)
{
案例SDL_退出:正在运行=0;中断;
}
}
显示();
SDL_GL_SwapBuffers();
如果(1000/FPS>SDL_GetTicks()-start)
{
SDL_延迟(1000/FPS-(SDL_GetTicks()-start));
}
}
SDL_退出();
返回(0);
}

您是否确实链接到了GLEW库?仅仅告诉VS目录在哪里是不够的;您必须告诉它要链接到哪个库

测试是否链接到库的一种快速方法是删除它并重新编译。如果VC没有抱怨找不到特定的库,那么你就没有链接到它

另外,像我为GLEW所做的那样,简单地将SDL安装到我的VC inc、lib和System32目录中是一个好主意吗


在那里安装GLEW不是一个好主意,更不用说其他任何东西了。VisualStudio不像Linux安装;没有库和头的全局存储库。您可以将VS项目指向特定的库和头文件(如果需要,您甚至可以全局设置这些库和头文件)。别管VS目录。

你真的链接到了GLEW库吗?仅仅告诉VS目录在哪里是不够的;您必须告诉它要链接到哪个库

测试是否链接到库的一种快速方法是删除它并重新编译。如果VC没有抱怨找不到特定的库,那么你就没有链接到它

另外,像我为GLEW所做的那样,简单地将SDL安装到我的VC inc、lib和System32目录中是一个好主意吗


在那里安装GLEW不是一个好主意,更不用说其他任何东西了。VisualStudio不像Linux安装;没有库和头的全局存储库。您可以将VS项目指向特定的库和头文件(如果需要,您甚至可以全局设置这些库和头文件)。别管VS目录。

glGenBuffers第二个参数是指向GLuint(GLuint)的指针,而不是指向GLuint(GLuint*,这是您要传递的内容)的指针的指针。相反,请执行以下操作:

Uint32 vboId;

glGenBuffers(1, &vboId);

glGenBuffers第二个参数是指向GLuint(GLuint)的指针,而不是指向GLuint(GLuint*,这是您要传递的内容)的指针。相反,请执行以下操作:

Uint32 vboId;

glGenBuffers(1, &vboId);

我注意到您没有包括对glewInit()的调用,如果您计划使用glew,请确保在使用它提供的任何openGL函数指针之前调用它。

我注意到您没有包括对glewInit()的调用,如果您计划使用glew,请确保在使用它提供的任何openGL函数指针之前调用它。

我将把glew移动到C:\并以正常方式将我的VS指向它。我将把glew移动到C:\并以正常方式将我的VS指向它。我编辑了我的帖子。对不起,那是无意的。问题以这样或那样的方式持续存在。你说得对。我编辑了我的帖子。对不起,那是无意的。问题以这样或那样的方式持续存在。不过你是对的。