使用未声明的标识符GluBuildMipMaps(emscripten)

时间:2015-11-19 15:25:22

标签: c++ opengl webgl sdl emscripten

我使用SDL创建了一个OpenGL程序。我已经尝试使用emscripten编译成HTML5 + JS,但是我收到了这个错误:

emscripten error

我无法理解,为什么我会收到此错误。 GluBuildMipMaps在glu.hhttps://github.com/kripken/emscripten/blob/master/system/include/GL/glu.h

中定义

glm错误也令人困惑,因为我已经将glm库复制到glm目录,并且它包含在我使用它的地方。

修改

纯文本的错误消息:

D:\proj\e_bead>emcc main.cpp MyApp.cpp ObjParser_OGL3.cpp -s FULL_ES2=1 -O3 --me
mory-init-file 0
In file included from MyApp.cpp:2:
./GLUtils.hpp:148:2: error: use of undeclared identifier 'gluBuild2DMipmaps'
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, loaded_img->w, loaded_i...
        ^
MyApp.cpp:194:25: error: no matching function for call to 'translate'
  ...spaceShipTransform = glm::translate<float>(randnum, randnum, randnum);
                               ^~~~~~~~~~~~~~~~~~~~~
./glm/gtc/matrix_transform.inl:40:35: note: candidate function template not
      viable: requires 2 arguments, but 3 were provided
        GLM_FUNC_QUALIFIER tmat4x4<T, P> translate
                                         ^
./glm/gtx/transform.inl:36:35: note: candidate function template not viable:
      requires single argument 'v', but 3 arguments were provided
        GLM_FUNC_QUALIFIER tmat4x4<T, P> translate(
                                         ^
MyApp.cpp:199:25: error: no matching function for call to 'translate'
  ...spaceShipTransform = glm::translate<float>(randnum, randnum, randnum);
                               ^~~~~~~~~~~~~~~~~~~~~
./glm/gtc/matrix_transform.inl:40:35: note: candidate function template not
      viable: requires 2 arguments, but 3 were provided
        GLM_FUNC_QUALIFIER tmat4x4<T, P> translate
                                         ^
./glm/gtx/transform.inl:36:35: note: candidate function template not viable:
      requires single argument 'v', but 3 arguments were provided
        GLM_FUNC_QUALIFIER tmat4x4<T, P> translate(
                                         ^
MyApp.cpp:234:9: error: no matching function for call to 'translate'
        mvp *= glm::translate(0.0f, 5.0f, 0.0f);
               ^~~~~~~~~~~~~~
./glm/gtc/matrix_transform.inl:40:35: note: candidate function template not
      viable: requires 2 arguments, but 3 were provided
        GLM_FUNC_QUALIFIER tmat4x4<T, P> translate
                                         ^
./glm/gtx/transform.inl:36:35: note: candidate function template not viable:
      requires single argument 'v', but 3 arguments were provided
        GLM_FUNC_QUALIFIER tmat4x4<T, P> translate(
                                         ^
4 errors generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting

EDIT2

我已将glm库复制到glm目录中,并将其包含在此代码中:

// GLM
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtx/transform2.hpp"

纹理加载代码,其中调用gluBuild2DMipmaps

GLuint TextureFromFile(const char* filename)
{
    SDL_Surface* loaded_img = IMG_Load(filename);  

    int img_mode = 0;

    if ( loaded_img == 0 )
    {
        std::cout << "[TextureFromFile] Error when loading image: " << filename << std::endl;
        return 0;
    }

    #if SDL_BYTEORDER == SDL_LIL_ENDIAN
        if ( loaded_img->format->BytesPerPixel == 4 )
            img_mode = GL_BGRA;
        else
            img_mode = GL_BGR;
    #else
        if ( loaded_img->format->BytesPerPixel == 4 )
            img_mode = GL_RGBA;
        else
            img_mode = GL_RGB;
    #endif

    GLuint tex;
    glGenTextures(1, &tex);

    glBindTexture(GL_TEXTURE_2D, tex);
    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, loaded_img->w, loaded_img->h, img_mode, GL_UNSIGNED_BYTE, loaded_img->pixels);

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

    SDL_FreeSurface( loaded_img );

    return tex;
}

EDIT3

我已根据GLUtils.hpp的回答对Robert Rouhani进行了修改,现在我不会在此行收到编译错误:

glBindTexture(GL_TEXTURE_2D, tex);
//gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, loaded_img->w, loaded_img->h, img_mode, GL_UNSIGNED_BYTE, loaded_img->pixels);

glTexImage2D(GL_TEXTURE_2D,
    0,
    GL_RGB,
    loaded_img->w,
    loaded_img->h,
    0,
    img_mode,
    GL_UNSIGNED_BYTE,
    loaded_img->pixels);
glGenerateMipmap(GL_TEXTURE_2D); // /!\ Allocate the mipmaps /!\

1 个答案:

答案 0 :(得分:1)

我对emscripten不太熟悉,但从某些搜索看起来您选择FULL_ES2=1意味着您获得了整个OpenGL ES 2.0 API。我猜这意味着您获得的唯一包含目录是GLES2而不是GL,即包含您链接到的glu.h的文件夹。

GLU现在已有近20年的历史,仅适用于OpenGL 1.3(2001年发布)。这意味着您无法在ES 2.0中使用它。您想要的是glGenerateMipmap glHintGL_GENERATE_MIPMAP_HINT选项。一个例子:

//Create the mipmapped texture
glGenTextures(1, &ColorbufferName);
glBindTexture(ColorbufferName);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_UNSIGNED_BYTE, NULL);
glGenerateMipmap(GL_TEXTURE_2D); // /!\ Allocate the mipmaps /!\

取自this article

至于glm错误,看起来它正好找到glm,它只是不喜欢你使用它的方式(并且只适用于translate函数) 。你可以发布MyApp.cpp中的相关行(带错误的行以及上下文中的一些行)?

其他人已经与emscripten合作了,也许这封邮件列表帖子对您有所帮助:https://groups.google.com/forum/#!topic/emscripten-discuss/b6DY3GCDlug

编辑:对于glm错误

你只是使用错误的包含。

您想要的是glm/gtx/transform.hpp