在 Ubuntu 14.04 中使用 SOIL

     2023-02-22     89

关键词:

【中文标题】在 Ubuntu 14.04 中使用 SOIL【英文标题】:Using SOIL in Ubuntu 14.04 【发布时间】:2016-05-16 15:45:34 【问题描述】:

我 时遇到了一些实际问题。我已经设法让 SOIL 在 Windows 环境中工作,并将代码从 Windows 移植到 ubuntu。

我确信我已经设法让 SOIL 安装在我的 Ubuntu 机器上。我有 libSOIL.a 和 libSOIL.so 文件以及 SOIL.h

然而,当我开始使用我的代码时,一切都出错了。这是我逐步构建的代码,因此在继续添加其他功能之前,我已经测试了代码片段。

我正在开发的代码非常简单(实际上,这只是为了尝试获得适用于许多平台的东西),它只是渲染一个围绕其中心旋转并具有纹理贴图的 3D 立方体。我希望使用 SOIL 来加载纹理。以前我已经使用我自己的例程加载纹理检查了这一切,这很好。一旦我将加载纹理的行更改为 SOIL 函数,它现在就会失败。

我使用的代码是

SOIL_load_OGL_texture("/home/ubuntu/Documents/OpenGL3/OpenGL_Basic_Engine/c2_4_DrawCubeTextureAdvanced/Textures/Crate.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS);

这是自此代码的上一个版本以来所做的唯一更改。

我通过简单的“fopen”和“ifelse”检查确保该文件是可打开的,我什至安装了 Code::Blocks,这样我就有了一个可以单步调试的调试器按行。当我的调试器进入 SOIL 函数并尝试单步执行该函数时,程序返回分段错误并退出,甚至没有将我发送到 SOIL 函数。

如果有人有任何想法,我将不胜感激,因为我已经为这个问题苦苦挣扎了好几个星期了!

干杯

*********编辑****************

让我们看看我现在是否可以在这里获得所有必需的信息(我不得不将机器移到我的 ubuntu 上以获得源代码)

首先我的代码是 C++(但我认为 SOIL 是用 C 编写的?-因此有两个标签)

失败的源文件如下:

 #include "CubeTextureAdvanced.h"


#ifdef _WIN32
#include <BasicEngine\Engine.h>
#include "soil\SOIL.h"
#elif __linux__
#include "../BasicEngine/Engine.h"
#include "/usr/local/include/SOIL.h"
#include <pthread.h>
#endif


using namespace BasicEngine;

#ifdef __linux__
void junk()      //dummy procedure to allow pthread to be linked
    int i;
    i = pthread_getconcurrency();


#endif

int main(int argc, char **argv)

    std::cout << "create new engine" << std::endl;
    Engine* engine = new Engine();
    engine->Init();

    std::cout << "get shader manager and create programme" << std::endl;
    engine->GetShader_Manager()->CreateProgram("cubeShader", "/home/ubuntu/Documents/OpenGL3/OpenGL_Basic_Engine/c2_4_DrawCubeTextureAdvanced/Shaders/Cube_Vertex_Shader.glsl",
    "/home/ubuntu/Documents/OpenGL3/OpenGL_Basic_Engine/c2_4_DrawCubeTextureAdvanced/Shaders/Cube_Fragment_Shader.glsl");

    std::cout << "get shader manager and get shader" << std::endl;
    CubeTextureAdvanced* cube = new CubeTextureAdvanced();
    int program = engine->GetShader_Manager()->GetShader("cubeShader");
    if (program != 0)
    
        cube->SetProgram(program);
        cube->Create();
    
    else
    
        std::cout << "invalid program..."; std::cin.get();
    

   //this is the routine that works to load textures that i wish to replace with SOIL
   //unsigned int texture = engine->GetTexture_Loader()->LoadTexture("Textures\\Crate.bmp", 256, 256);
  //cube->SetTexture("Create", texture);

    std::cout << "use SOIL to load an OpenGL Texture" << std::endl;

    FILE * pFile;

    pFile = fopen("/home/ubuntu/Documents/OpenGL3/OpenGL_Basic_Engine/c2_4_DrawCubeTextureAdvanced/Textures/Crate.bmp", "r");

    if(pFile != NULL)
    
        std::cout << "FILE OPEN" << std::endl;
        fclose(pFile);
    

    GLuint Texturetmp;

    Texturetmp = SOIL_load_OGL_texture("/home/ubuntu/Documents/OpenGL3/OpenGL_Basic_Engine/c2_4_DrawCubeTextureAdvanced/Textures/Crate.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS);

     std::cout << Texturetmp << std::endl;
     std::cout << "loaded texture" << std::endl;

     cube->SetTexture("Create", Texturetmp);

     std::cout << "get the models manager and set the model" << std::endl;
     engine->GetModels_Manager()->SetModel("cube", cube);


     std::cout << "run the programme" << std::endl;
     engine->Run();

     delete engine;
     return (0);
 

我在终端运行的编译命令是:

g++ -Wall -Wextra ./../BasicEngine/Engine.cpp ./../BasicEngine/Core/Init/Init_GLUT.cpp ./../BasicEngine/Core/Init/Init_GLEW.cpp ./../BasicEngine/Managers/Models_Manager.cpp ./../BasicEngine/Managers/Scene_Manager.cpp ./../BasicEngine/Managers/Shader_Manager.cpp ./CubeTextureAdvanced.cpp ./../BasicEngine/Rendering/Models/Model.cpp ./../BasicEngine/Rendering/Texture/TextureLoader.cpp main.cpp -lglut -lGL -lGLU -lGLEW -lpthread -lX11 -lSOIL -std=gnu++11 -o main 

返回的警告有几个type qualifiers ignoredunused parameters。但是没有任何涉及 SOIL 函数调用或任何暗示在那之前可能会停止 SOIL 工作的问题(我知道)。

其他可能有帮助的源文件是 init_GLUT 和 init_GLEW 文件,如下所示:

init_GLUT:

#include "../Init/Init_GLUT.h"

using namespace BasicEngine;
using namespace Core::Init;

Core::IListener* Init_GLUT::listener = NULL;
Core::WindowInfo Init_GLUT::windowInformation;

#ifdef __linux__

Display                 *dpy;
Window                  root;
GLint                   att[] =  GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None ;
XVisualInfo             *vi;
Colormap                cmap;
XSetWindowAttributes    swa;
Window                  win;
GLXContext              glc;
XWindowAttributes       gwa;
XEvent                  xev;


void Init_GLUT::linuxinit()


    std::cout << "Linux detected" << std::endl;

    dpy = XOpenDisplay(NULL);

    if (dpy == NULL)
    
        std::cout << "\n\tcannont connect to X server\n\n" << std::endl;
        exit(0);
    

    root = DefaultRootWindow(dpy);

    vi = glXChooseVisual(dpy, 0, att);

    if (vi == NULL)
    
         std::cout << "\n\tno appropriate visual found\n\n" << std::endl;
         exit(0);
    
    else
    
        printf("\n\tvisual %p selected\n", (void*)vi->visualid); //%p creates a hexadecimal output like in glxinfo
    

    cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);

    swa.colormap = cmap;
    swa.event_mask = ExposureMask | KeyPressMask;

    std::cout << "end of Linux compiler directives" << std::endl;





#endif

void Init_GLUT::init(const Core::WindowInfo& windowInfo,
const Core::ContextInfo& contextInfo,
const Core::FramebufferInfo& framebufferInfo)


    windowInformation = windowInfo;

    //i need some fake things here
    int fakeargc = 1;
    char* fakeargv[] =  "fake", NULL ;
    glutInit(&fakeargc, fakeargv);

    if (contextInfo.core)
    
        glutInitContextVersion(contextInfo.major_version,
        contextInfo.minor_version);
        glutInitContextProfile(GLUT_CORE_PROFILE);
    
    else
    
        //doesn't matter in compatibility mode
        glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);
    

    //old functions from main.cpp now using info from the structures
    glutInitDisplayMode(framebufferInfo.flags);
    glutInitWindowPosition(windowInfo.position_x, windowInfo.position_y);
    glutInitWindowSize(windowInfo.width, windowInfo.height);

    glutCreateWindow(windowInfo.name.c_str());

    std::cout << "GLUT:initialised" << std::endl;

#ifdef _WIN32
    //Lets add some debug capability
    glEnable(GL_DEBUG_OUTPUT);
#endif

    Core::Init::Init_GLEW::Init();

#ifdef _WIN32
    glDebugMessageCallback(DebugOutput::myCallback, NULL);
    glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, TRUE);
#endif

    //these call backs are used for rendering
    glutIdleFunc(idleCallback);
    glutCloseFunc(closeCallback);
    glutDisplayFunc(displayCallback);
    glutReshapeFunc(reshapeCallback);

    //init GLEW (can be called in main.cpp)


    //clean up
    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

    //our method to display some info. Needs contextInfo and windowinfo
    printOpenGLInfo(windowInfo, contextInfo);


//starts the rendering loop
void Init_GLUT::run()

    std::cout << "GLUT:\t Start Running" << std::endl;
    glutMainLoop();


void Init_GLUT::close()

    std::cout << "GLUT:\t Finished" << std::endl;
    glutLeaveMainLoop;


void Init_GLUT::idleCallback(void)

    //do nothing, just redisplay
    glutPostRedisplay();


void Init_GLUT::displayCallback()

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor(0.0, 0.0, 0.0, 1);
    glutSwapBuffers;

    if (listener)
    
        listener->notifyBeginFrame();
        listener->notifyDisplayFrame();

        glutSwapBuffers();

        listener->notifyEndFrame();
     



void Init_GLUT::reshapeCallback(int width, int height)

    if (windowInformation.isReshapable == true)
    
        if (listener)
        
            listener->notifyReshape(width, height, windowInformation.width, windowInformation.height);
        
        windowInformation.width = width;
        windowInformation.height = height;
    


void Init_GLUT::closeCallback()

    close();


void Init_GLUT::enterFullscreen()

    glutFullScreen();


void Init_GLUT::exitFullscreen()

    glutLeaveFullScreen();


void Init_GLUT::setListener(Core::IListener* iListener)

    listener = iListener;


void Init_GLUT::printOpenGLInfo(const Core::WindowInfo& windowInfo,
const Core::ContextInfo& contextInfo)

    const unsigned char* renderer = glGetString(GL_RENDERER);
    const unsigned char* vendor = glGetString(GL_VENDOR);
    const unsigned char* version = glGetString(GL_VERSION);

    std::cout << "*******************************************************************************" << std::endl;

    std::cout << "GLUT:\tVendor : " << vendor << std::endl;
    std::cout << "GLUT:\tRenderer : " << renderer << std::endl;
    std::cout << "GLUT:\tOpenGl version: " << version << std::endl;
    std::cout << "GLUT:\tInitial window is '" << windowInfo.name << "', with dimensions (" << windowInfo.width
    << "X" << windowInfo.height;
    std::cout << ") starts at (" << windowInfo.position_x << "X" << windowInfo.position_y;
    std::cout << ") and " << ((windowInfo.isReshapable) ? "is" : "is not ") << " redimensionable" << std::endl;
    std::cout << "GLUT:\tInitial Framebuffer contains double buffers for" << std::endl;

    std::cout << "GLUT:\t OpenGL context is " << contextInfo.major_version << "." << contextInfo.minor_version;
    std::cout << " and profile is " << ((contextInfo.core) ? "core" : "compatibility") << std::endl;

    std::cout << "*****************************************************************" << std::endl;

init_GLEW:

#include "../Init/Init_GLEW.h"

using namespace BasicEngine;
using namespace Core;
using namespace Core::Init;

void Init_GLEW::Init()

    glewExperimental = true;
    if (glewInit() == GLEW_OK)
    
        std::cout << "GLEW: Initialised" << std::endl;
    
    if (glewIsSupported("GL_VERSION_4_5"))
    
        std::cout << "GLEW Version is 4.5 :) \n";
    
    else
    
        std::cout << "GLEW 4.5 not supported :( \n";
    



最后我的SOIL.h文件内容如下:

/**
    @mainpage SOIL

    Jonathan Dummer
    2007-07-26-10.36

    Simple OpenGL Image Library

    A tiny c library for uploading images as
    textures into OpenGL.  Also saving and
    loading of images is supported.

    I'm using Sean's Tool Box image loader as a base:
    http://www.nothings.org/

    I'm upgrading it to load TGA and DDS files, and a direct
    path for loading DDS files straight into OpenGL textures,
    when applicable.

    Image Formats:
    - BMP       load & save
    - TGA       load & save
    - DDS       load & save
    - PNG       load
    - JPG       load

    OpenGL Texture Features:
    - resample to power-of-two sizes
    - MIPmap generation
    - compressed texture S3TC formats (if supported)
    - can pre-multiply alpha for you, for better compositing
    - can flip image about the y-axis (except pre-compressed DDS files)

    Thanks to:
    * Sean Barret - for the awesome stb_image
    * Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts
   * everybody at gamedev.net
**/

#ifndef HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY
#define HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY

#ifdef __cplusplus
extern "C" 
#endif

/**
    The format of images that may be loaded (force_channels).
    SOIL_LOAD_AUTO leaves the image in whatever format it was found.
    SOIL_LOAD_L forces the image to load as Luminous (greyscale)
    SOIL_LOAD_LA forces the image to load as Luminous with Alpha
    SOIL_LOAD_RGB forces the image to load as Red Green Blue
    SOIL_LOAD_RGBA forces the image to load as Red Green Blue Alpha
**/
enum

    SOIL_LOAD_AUTO = 0,
    SOIL_LOAD_L = 1,
    SOIL_LOAD_LA = 2,
    SOIL_LOAD_RGB = 3,
    SOIL_LOAD_RGBA = 4
;

/**
    Passed in as reuse_texture_ID, will cause SOIL to
    register a new texture ID using glGenTextures().
    If the value passed into reuse_texture_ID > 0 then
    SOIL will just re-use that texture ID (great for
    reloading image assets in-game!)
**/
enum

    SOIL_CREATE_NEW_ID = 0
;

/**
    flags you can pass into SOIL_load_OGL_texture()
    and SOIL_create_OGL_texture().
    (note that if SOIL_FLAG_DDS_LOAD_DIRECT is used
    the rest of the flags with the exception of
    SOIL_FLAG_TEXTURE_REPEATS will be ignored while
    loading already-compressed DDS files.)

    SOIL_FLAG_POWER_OF_TWO: force the image to be POT
    SOIL_FLAG_MIPMAPS: generate mipmaps for the texture
    SOIL_FLAG_TEXTURE_REPEATS: otherwise will clamp
    SOIL_FLAG_MULTIPLY_ALPHA: for using (GL_ONE,GL_ONE_MINUS_SRC_ALPHA)  blending
    SOIL_FLAG_INVERT_Y: flip the image vertically
    SOIL_FLAG_COMPRESS_TO_DXT: if the card can display them, will convert RGB to DXT1, RGBA to DXT5
    SOIL_FLAG_DDS_LOAD_DIRECT: will load DDS files directly without _ANY_ additional processing
    SOIL_FLAG_NTSC_SAFE_RGB: clamps RGB components to the range [16,235]
    SOIL_FLAG_CoCg_Y: Google YCoCg; RGB=>CoYCg, RGBA=>CoCgAY
    SOIL_FLAG_TEXTURE_RECTANGE: uses ARB_texture_rectangle ; pixel indexed & no repeat or MIPmaps or cubemaps
**/
enum

    SOIL_FLAG_POWER_OF_TWO = 1,
    SOIL_FLAG_MIPMAPS = 2,
    SOIL_FLAG_TEXTURE_REPEATS = 4,
    SOIL_FLAG_MULTIPLY_ALPHA = 8,
    SOIL_FLAG_INVERT_Y = 16,
    SOIL_FLAG_COMPRESS_TO_DXT = 32,
    SOIL_FLAG_DDS_LOAD_DIRECT = 64,
    SOIL_FLAG_NTSC_SAFE_RGB = 128,
    SOIL_FLAG_CoCg_Y = 256,
    SOIL_FLAG_TEXTURE_RECTANGLE = 512
;

/**
    The types of images that may be saved.
    (TGA supports uncompressed RGB / RGBA)
    (BMP supports uncompressed RGB)
    (DDS supports DXT1 and DXT5)
**/
enum

    SOIL_SAVE_TYPE_TGA = 0,
    SOIL_SAVE_TYPE_BMP = 1,
    SOIL_SAVE_TYPE_DDS = 2
 ;

/**
    Defines the order of faces in a DDS cubemap.
    I recommend that you use the same order in single
    image cubemap files, so they will be interchangeable
    with DDS cubemaps when using SOIL.
**/
#define SOIL_DDS_CUBEMAP_FACE_ORDER "EWUDNS"

/**
    The types of internal fake HDR representations

    SOIL_HDR_RGBE:      RGB * pow( 2.0, A - 128.0 )
    SOIL_HDR_RGBdivA:   RGB / A
    SOIL_HDR_RGBdivA2:  RGB / (A*A)
**/
enum

    SOIL_HDR_RGBE = 0,
    SOIL_HDR_RGBdivA = 1,
    SOIL_HDR_RGBdivA2 = 2
;

/**
    Loads an image from disk into an OpenGL texture.
    \param filename the name of the file to upload as a texture
    \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_load_OGL_texture
    (
        const char *filename,
        int force_channels,
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Loads 6 images from disk into an OpenGL cubemap texture.
    \param x_pos_file the name of the file to upload as the +x cube face
    \param x_neg_file the name of the file to upload as the -x cube face
    \param y_pos_file the name of the file to upload as the +y cube face
    \param y_neg_file the name of the file to upload as the -y cube face
    \param z_pos_file the name of the file to upload as the +z cube face
    \param z_neg_file the name of the file to upload as the -z cube face
    \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_load_OGL_cubemap
   (
        const char *x_pos_file,
        const char *x_neg_file,
        const char *y_pos_file,
        const char *y_neg_file,
        const char *z_pos_file,
        const char *z_neg_file,
        int force_channels,
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Loads 1 image from disk and splits it into an OpenGL cubemap texture.
    \param filename the name of the file to upload as a texture
    \param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc.
    \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_load_OGL_single_cubemap
    (
        const char *filename,
        const char face_order[6],
        int force_channels,
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Loads an HDR image from disk into an OpenGL texture.
    \param filename the name of the file to upload as a texture
    \param fake_HDR_format SOIL_HDR_RGBE, SOIL_HDR_RGBdivA, SOIL_HDR_RGBdivA2
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_load_OGL_HDR_texture
    (
        const char *filename,
        int fake_HDR_format,
        int rescale_to_max,
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Loads an image from RAM into an OpenGL texture.
    \param buffer the image data in RAM just as if it were still in a file
    \param buffer_length the size of the buffer in bytes
    \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_load_OGL_texture_from_memory
    (
        const unsigned char *const buffer,
        int buffer_length,
        int force_channels,
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Loads 6 images from memory into an OpenGL cubemap texture.
    \param x_pos_buffer the image data in RAM to upload as the +x cube face
    \param x_pos_buffer_length the size of the above buffer
    \param x_neg_buffer the image data in RAM to upload as the +x cube face
    \param x_neg_buffer_length the size of the above buffer
    \param y_pos_buffer the image data in RAM to upload as the +x cube face
    \param y_pos_buffer_length the size of the above buffer
    \param y_neg_buffer the image data in RAM to upload as the +x cube face
    \param y_neg_buffer_length the size of the above buffer
    \param z_pos_buffer the image data in RAM to upload as the +x cube face
    \param z_pos_buffer_length the size of the above buffer
    \param z_neg_buffer the image data in RAM to upload as the +x cube face
    \param z_neg_buffer_length the size of the above buffer
    \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_load_OGL_cubemap_from_memory
    (
        const unsigned char *const x_pos_buffer,
        int x_pos_buffer_length,
        const unsigned char *const x_neg_buffer,
        int x_neg_buffer_length,
        const unsigned char *const y_pos_buffer,
        int y_pos_buffer_length,
        const unsigned char *const y_neg_buffer,
        int y_neg_buffer_length,
        const unsigned char *const z_pos_buffer,
        int z_pos_buffer_length,
        const unsigned char *const z_neg_buffer,
        int z_neg_buffer_length,
        int force_channels,
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Loads 1 image from RAM and splits it into an OpenGL cubemap texture.
    \param buffer the image data in RAM just as if it were still in a file
    \param buffer_length the size of the buffer in bytes
    \param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc.
    \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_load_OGL_single_cubemap_from_memory
    (
        const unsigned char *const buffer,
        int buffer_length,
        const char face_order[6],
        int force_channels,
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Creates a 2D OpenGL texture from raw image data.  Note that the raw data is
    _NOT_ freed after the upload (so the user can load various versions).
    \param data the raw data to be uploaded as an OpenGL texture
    \param width the width of the image in pixels
    \param height the height of the image in pixels
    \param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_create_OGL_texture
    (
        const unsigned char *const data,
        int width, int height, int channels,
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Creates an OpenGL cubemap texture by splitting up 1 image into 6 parts.
    \param data the raw data to be uploaded as an OpenGL texture
    \param width the width of the image in pixels
    \param height the height of the image in pixels
    \param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
    \param face_order the order of the faces in the file, and combination of NSWEUD, for North, South, Up, etc.
    \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
    \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
    \return 0-failed, otherwise returns the OpenGL texture handle
**/
unsigned int
    SOIL_create_OGL_single_cubemap
    (
        const unsigned char *const data,
        int width, int height, int channels,
        const char face_order[6],
        unsigned int reuse_texture_ID,
        unsigned int flags
    );

/**
    Captures the OpenGL window (RGB) and saves it to disk
    \return 0 if it failed, otherwise returns 1
**/
int
    SOIL_save_screenshot
    (
        const char *filename,
        int image_type,
        int x, int y,
        int width, int height
    );

/**
    Loads an image from disk into an array of unsigned chars.
    Note that *channels return the original channel count of the
    image.  If force_channels was other than SOIL_LOAD_AUTO,
    the resulting image has force_channels, but *channels may be
    different (if the original image had a different channel
    count).
    \return 0 if failed, otherwise returns 1
**/
unsigned char*
    SOIL_load_image
    (
        const char *filename,
        int *width, int *height, int *channels,
        int force_channels
    );

/**
    Loads an image from memory into an array of unsigned chars.
    Note that *channels return the original channel count of the
    image.  If force_channels was other than SOIL_LOAD_AUTO,
    the resulting image has force_channels, but *channels may be
    different (if the original image had a different channel
    count).
    \return 0 if failed, otherwise returns 1
**/
unsigned char*
    SOIL_load_image_from_memory
    (
        const unsigned char *const buffer,
        int buffer_length,
        int *width, int *height, int *channels,
        int force_channels
    );

/**
    Saves an image from an array of unsigned chars (RGBA) to disk
    \return 0 if failed, otherwise returns 1
**/
int
    SOIL_save_image
    (
        const char *filename,
        int image_type,
        int width, int height, int channels,
        const unsigned char *const data
    );

/**
    Frees the image data (note, this is just C's "free()"...this function is
    present mostly so C++ programmers don't forget to use "free()" and call
    "delete []" instead [8^)
**/
void
    SOIL_free_image_data
    (
        unsigned char *img_data
    );

/**
    This function resturn a pointer to a string describing the last thing
    that happened inside SOIL.  It can be used to determine why an image
    failed to load.
**/
const char*
    SOIL_last_result
    (
        void
    );


#ifdef __cplusplus

#endif

#endif /* HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY    */

我将libSOIL.a 存储在/usr/lib

我也尝试过将libSOIL.a 也存储在usr/local/lib 中,但这似乎无济于事。

SOIL.husr/local/include

希望现在这些信息足以让某人发现我的(新手)错误。

为大量代码道歉。

还必须访问 www.in2gpu.com,我一直在关注其教程,才能让我走到这一步。

干杯

【问题讨论】:

您是否使用-Wall -Wextra 选项编译您的代码?如果是,您确定没有警告吗? 我们需要很多更可靠的信息:1) 包含失败语句的文件的源代码 2) 两个库和 soil.h 头文件的实际位置。 3) 编译语句 4) 链接语句。如果没有这些关键细节,我们可能无法为您提供任何可靠的帮助,因为我们只能猜测。 您的源代码是用 C 还是 C++ 编写的?这是两种不同的语言,尽管大部分语法是通用的。由于类、STL、迭代器等原因存在巨大差异。--并且-- 在 C 中,函数、变量等的名称与 C++ 中的 mangled 不同。重要的是,这些库是如何编译/链接的? soil.h文件的内容是什么? 建议将std::cout &lt;&lt; "GLEW Version is 4.5 :) \n"; 等行替换为:std::cout &lt;&lt; "GLEW Version is 4.5 :) &lt;&lt; std::endl ; 注意:除非链接语句包含static 作为参数,否则不会使用libSOIL.a 文件。否则,将使用libSOIL.so 文件。 【参考方案1】:

我怀疑库等没有正确链接。

建议使用makefile,类似于:

CC := /usr/bin/g++
RM := /usr/bin/rm

SRCS := ./../BasicEngine/Engine.cpp \
        ./../BasicEngine/Core/Init/Init_GLUT.cpp \
        ./../BasicEngine/Core/Init/Init_GLEW.cpp \
        ./../BasicEngine/Managers/Models_Manager.cpp \
        ./../BasicEngine/Managers/Scene_Manager.cpp \
        ./../BasicEngine/Managers/Shader_Manager.cpp \
        ./CubeTextureAdvanced.cpp \
        ./../BasicEngine/Rendering/Models/Model.cpp \
        ./../BasicEngine/Rendering/Texture/TextureLoader.cpp

TEMP := $(basename $(SRCS))

OBJS := $(addsuffix .o, $(TEMP))

NAME := main

CFLAGS := -Wall -Wextra -Wconversion -std=gnu++11 -c

LFLAGS :=  -lglut -lGL -lGLU -lGLEW -lpthread -lX11 -lSOIL

.PHONY: all
all : $(NAME)

%.o:%.cpp
<tab>$(CC) $(CFLAGS) -o $@ $< -I.

$(NAME): $(OBJS)
<tab>$(CC) -o $@ $^ $(LFLAGS)

PHONY: clean
clean:
<tab> $(RM) -f $(OBJS)
<tab> $(RM) -f $(NAME)

注意:将&lt;tab&gt; 替换为制表符

然后使用类似的东西编译/链接:

make -f makefile

【讨论】:

makefile 可以通过生成dependencies 文件(带有.d 后缀)并将这一行:%.o:%.cpp 修改为:%.o:%.cpp %.d 来显着改进 如果要使用gdbddd进行调试,则在CFLAGS宏和LFLAGS宏的定义中添加-ggdb参数 我已尝试按照您的建议使用 make 文件,但当程序尝试调用 SOIL-load_OGL_texture 时,我仍然遇到分段错误。将%.d 添加到%.o:%.cpp 会导致make 文件失败:(

在 Ubuntu 14.04 中使用 XAMPP 进行 Xdebug

】在Ubuntu14.04中使用XAMPP进行Xdebug【英文标题】:XdebugwithXAMPPinUbuntu14.04【发布时间】:2015-02-0717:29:37【问题描述】:系统配置Ubuntu14.04Xamppv5.6.3在xampp之后安装php5-devsudo/opt/lampp/lamppstart现在想安装Xdebugwihinxampp,我尝试了可用的3方... 查看详情

如何在 Ubuntu 14.04 上的 QT creator 中使用 Boost 库

】如何在Ubuntu14.04上的QTcreator中使用Boost库【英文标题】:HowtouseBoostlibraryinQTcreatoronUbuntu14.04【发布时间】:2016-09-2408:12:51【问题描述】:我想在Ubuntu14.04上使用QTcreator中的C++Boost库,尝试了很多方法后,我仍然报错。我使用以下... 查看详情

在 64 位 Ubuntu 14.04 中使用 Nvidia *和* AMD GPU 进行 OpenCL 开发

】在64位Ubuntu14.04中使用Nvidia*和*AMDGPU进行OpenCL开发【英文标题】:UsingNvidia*and*AMDGPUsinaUbuntu14.04,64bitforOpenCLdevelopment【发布时间】:2015-03-2811:02:24【问题描述】:我正在尝试让AMD和NVidiaGPU在同一台Ubuntu14.04PC中运行,以便在两者上... 查看详情

ubuntu14.04中如何查看磁盘空间使用情况

首先要介绍的是Ubuntu14.04中内置的系统监视器小工具,我们可以直接搜索“系统监视器”打开。在Ubuntu14.04中系统监视器的文件系统选项卡中,我们可以像使用Windows一样看到当前磁盘已使用的空间、剩余空间和空间占用百分比。... 查看详情

无法在 Python3、Ubuntu14.04 中使用 pip 安装 NumPy

】无法在Python3、Ubuntu14.04中使用pip安装NumPy【英文标题】:CannotinstallNumPyusingpipinPython3,Ubuntu14.04【发布时间】:2017-03-2108:33:01【问题描述】:我在尝试pipinstallNumPy时收到此错误:pip配置了需要TLS/SSL的位置,但是Python中的ssl模块不... 查看详情

ubuntu14.04中的redis-server:绑定地址已经在使用中

】ubuntu14.04中的redis-server:绑定地址已经在使用中【英文标题】:redis-serverinubuntu14.04:Bindaddressalreadyinuse【发布时间】:2016-01-0200:28:15【问题描述】:我在ubuntu上通过在终端上输入以下命令启动了redis服务器:$redis-server这会导致以... 查看详情

程序在 Ubuntu 14.04 和 GCC 中无法正确编译

】程序在Ubuntu14.04和GCC中无法正确编译【英文标题】:ProgramNotCompilingCorrectlyInUbuntu14.04andGCC【发布时间】:2014-06-0322:48:22【问题描述】:我最近使用Ubuntu14.04LTS对我的WindowsPC进行了双启动,我使用Code::Blocks作为我选择的IDE,并使用... 查看详情

在 Ubuntu 14.04 和 matlab 2014Ra 上使用犰狳在 mex 中出现分段错误

】在Ubuntu14.04和matlab2014Ra上使用犰狳在mex中出现分段错误【英文标题】:SegmentationfaultinmexwitharmadilloonUbuntu14.04andmatlab2014Ra【发布时间】:2015-07-3008:41:24【问题描述】:我尝试将mex文件与犰狳线性代数库一起使用。一开始,我尝试... 查看详情

在 Ubuntu 14.04 上使用 python 读取音频时出错

】在Ubuntu14.04上使用python读取音频时出错【英文标题】:ErrorreadingaudiowithpythononUbuntu14.04【发布时间】:2016-01-0604:18:58【问题描述】:使用python2.7(在Ubuntu14.04中)运行以下代码时importpyaudiop=pyaudio.PyAudio()我得到以下异常:ALSAlibpcm_... 查看详情

如何在 Ubuntu 14.04 中更新到最新的 phpMyadmin

】如何在Ubuntu14.04中更新到最新的phpMyadmin【英文标题】:HowtoupdatetothenewestphpMyadmininUbuntu14.04【发布时间】:2015-11-1608:49:16【问题描述】:如何从phpmyadmin4.0.10deb1更新到最新版本?我已经尝试更新和升级。是否有一些迁移命令可以... 查看详情

QSystemTrayIcon 未显示在 Ubuntu 14.04 的通知区域中

】QSystemTrayIcon未显示在Ubuntu14.04的通知区域中【英文标题】:QSystemTrayIconnotshowinginnotificationareaonUbuntu14.04【发布时间】:2014-07-1408:45:44【问题描述】:我正在编写一个使用QSystemTrayIcon的应用程序。一切都按预期工作,但图标没有... 查看详情

如何在ubuntu14.04中使用samba共享文件

...记为它设置一个密码哟。参考技术A开启samba服务配置一下Ubuntu14.04文件服务器--samba的安装和配置_百度经验 查看详情

Python-uno 在 ubuntu 14.04 中不起作用

】Python-uno在ubuntu14.04中不起作用【英文标题】:Python-unonotworkinginubuntu14.04【发布时间】:2016-04-1810:45:57【问题描述】:我有一个使用python2.7在Ubuntu12.04中开发的python项目。它正在使用使用安装的pyoo和unopipinstallpyooapt-get-yinstallpython... 查看详情

PyAudio 无法在 Ubuntu 14.04 上使用“无法打开从属设备”的麦克风

】PyAudio无法在Ubuntu14.04上使用“无法打开从属设备”的麦克风【英文标题】:PyAudiocannotusemicrophoneonUbuntu14.04with\'unabletoopenslave\'【发布时间】:2016-02-1812:47:34【问题描述】:我已经尝试了几天在我的ubuntu14.04和PyAudio上使用麦克风... 查看详情

我在 Ubuntu 14.04 中使用 codeigniter 得到 URL not found 问题错误

】我在Ubuntu14.04中使用codeigniter得到URLnotfound问题错误【英文标题】:IgetURLnotfoundissueerrorusingcodeigniterinUbuntu14.04【发布时间】:2014-10-1912:46:37【问题描述】:我已将我的codeigniter项目与Ubuntu14.04集成。在默认控制器(即登录控制器... 查看详情

如何在 ubuntu 14.04 的 android 中安装 jdk 8

】如何在ubuntu14.04的android中安装jdk8【英文标题】:HowInstalljdk8inandroidinubuntu14.04【发布时间】:2016-09-0909:11:19【问题描述】:如何在Ubuntu14.04中使用命令行安装android-studio中的jdk1.8?安装jdk8并在android-studio中连接后,它会在xml中显... 查看详情

VirtualHost 始终在 Ubuntu 14.04 上使用 Apache 返回默认主机

】VirtualHost始终在Ubuntu14.04上使用Apache返回默认主机【英文标题】:VirtualHostalwaysreturnsdefaulthostwithApacheonUbuntu14.04【发布时间】:2014-07-0522:56:59【问题描述】:我尝试在默认的localhost之外设置一个虚拟主机。每当我尝试调用我的虚... 查看详情

在 ubuntu 14.04 LTS 中访问 localhost/phpmyadmin 时出现 401 未授权

】在ubuntu14.04LTS中访问localhost/phpmyadmin时出现401未授权【英文标题】:401Unauthorizedwhileaccessinglocalhost/phpmyadmininubuntu14.04LTS【发布时间】:2016-05-1806:33:19【问题描述】:我是Ubuntu新手。我在访问localhost/phpmyadmin时遇到了这个问题401未... 查看详情