1

注: glGetString(GL_VERSION) が返されました: 2.1.0 - ビルド 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 で行ったように、VC inc と lib および System32 ディレクトリに SDL をインストールするだけでよいでしょうか?

ファイルの先頭にある #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);
}
4

3 に答える 3

2

glewInit()の呼び出しが含まれていないことに気付きました。glewの使用を計画している場合は、提供されているopenGL関数ポインターを使用する前に必ず呼び出してください。

于 2011-08-11T02:51:58.657 に答える
1

実際にGLEWライブラリにリンクしましたか?ディレクトリがどこにあるかをVSに伝えるだけでは不十分です。リンクするライブラリを指定する必要があります。

ライブラリにリンクしているかどうかをテストする簡単な方法は、ライブラリを削除して再コンパイルすることです。VCが特定のライブラリを見つけることができないことについて文句を言わない場合は、そのライブラリにリンクしていません。

また、GLEWの場合と同じように、SDLをVC inc、lib、およびSystem32ディレクトリにインストールすることをお勧めしますか?

GLEWをそこにインストールするのは、他のことは言うまでもなく、良い考えではありませんでした。VisualStudioはLinuxインストールのようなものではありません。ライブラリとヘッダーのグローバルリポジトリはありません。VSプロジェクトが特定のライブラリとヘッダーファイルを指すようにするのはあなた次第です(必要に応じて、これらをグローバルに設定することもできます)。VSディレクトリはそのままにしておきます。

于 2011-08-07T02:46:55.750 に答える
1

glGenBuffers の 2 番目のパラメータは、GLuint へのポインタ (GLuint ) であり、GLuint へのポインタへのポインタ (GLuint *、これはあなたが渡しているものです) ではありません。代わりに、次のようにします。

Uint32 vboId;

glGenBuffers(1, &vboId);
于 2011-08-07T02:52:13.353 に答える