在Linux Eclipse上加载3D Texture: SDL/OpenGL



在FC15上的C OpenGL编程中,Eclipse和SDL纹理有一个奇怪的问题。

对于设置测试的目的,使用NeHe示例代码:http://bigdaddysurf.com/blog/?p=21

如果我们在控制台上使用

运行,程序将运行并加载纹理
$ make
$ ./lesson07 

——因此,所有环境所需的库都已安装并出现在Linux开发环境中。然而,如果我们尝试在IDE Eclipse上做同样的事情,程序运行,但没有加载纹理,所以我们只能看到一个没有纹理的白色框。

项目环境的设置有链接器库(L)中的库,如SDL, SDLmain, SDL_image, GL, GLU等——例如:OpenGL和GLUT在OS X上的Eclipse

程序与SDL工作良好的输入与键盘等。但是,纹理不加载。

在NeHe提供的Makefile中,在控制台中运行命令行,我注意到以下信息:

CC = gcc -Wall -ansi
all:
$(CC) lesson07.c -o lesson07 -lGL -lGLU `sdl-config --cflags --libs`

然后,阅读在IDE Eclipse上自动生成的Makefile,我观察到显然缺少了这个额外的标志:sdl-config --cflags --libs。这个额外的标志应该是什么阻止命令SDL_LoadBMP显示纹理?

如果是这样,关于如何为Eclipse的设置适当地调优这些附加信息以允许生成的IDE Makefile正常工作的建议?

关于纹理加载的方式,下面是函数:

int LoadGLTextures( )
{
/* Status indicator */
int Status = FALSE;
/* Create storage space for the texture */
SDL_Surface *TextureImage[1];
/* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
if ( ( TextureImage[0] = SDL_LoadBMP( "data/crate.bmp" ) ) )
    {
    /* Set the status to true */
    Status = TRUE;
    /* Create The Texture */
    glGenTextures( 3, &texture[0] );
    /* Load in texture 1 */
    /* Typical Texture Generation Using Data From The Bitmap */
    glBindTexture( GL_TEXTURE_2D, texture[0] );
    /* Generate The Texture */
    glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->w,
          TextureImage[0]->h, 0, GL_BGR,
          GL_UNSIGNED_BYTE, TextureImage[0]->pixels );
    /* Nearest Filtering */
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
             GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
             GL_NEAREST );
    /* Load in texture 2 */
    /* Typical Texture Generation Using Data From The Bitmap */
    glBindTexture( GL_TEXTURE_2D, texture[1] );
    /* Linear Filtering */
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
             GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
             GL_LINEAR );
    /* Generate The Texture */
    glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->w,
          TextureImage[0]->h, 0, GL_BGR,
          GL_UNSIGNED_BYTE, TextureImage[0]->pixels );
    /* Load in texture 3 */
    /* Typical Texture Generation Using Data From The Bitmap */
    glBindTexture( GL_TEXTURE_2D, texture[2] );
    /* Mipmapped Filtering */
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
             GL_LINEAR_MIPMAP_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
             GL_LINEAR );
    /* Generate The MipMapped Texture ( NEW ) */
    gluBuild2DMipmaps( GL_TEXTURE_2D, 3, TextureImage[0]->w,
               TextureImage[0]->h, GL_BGR,
               GL_UNSIGNED_BYTE, TextureImage[0]->pixels );
    }
/* Free up any memory we may have used */
if ( TextureImage[0] )
    SDL_FreeSurface( TextureImage[0] );
return Status;
}

纹理文件的路径是否硬编码?它是相对的吗?然后,程序必须从正确的目录启动,这样相对路径才能实际计算纹理,否则找不到文件,也不会加载纹理。

ide倾向于在构建目录中编译和运行编译后的二进制文件,从而破坏任何硬编码的文件路径。Eclipse只是没有在正确的工作目录下启动程序。根据操作系统的不同,有多种方法可以检测应用程序二进制文件的位置。有关如何确定程序二进制位置的技术,请参阅http://autopackage.org/docs/binreloc。

最新更新