1
votes

There is a strange issue with Eclipse and SDL textures in C OpenGL programming on FC15.

For set-up test purpose, the NeHe example code is used: http://bigdaddysurf.com/blog/?p=21

The program runs and loads the texture if we run it on console with

$ make
$ ./lesson07 

-- therefore, all the environment required libs are installed and present in the linux development environment. However, if we try to do the same on IDE Eclipse, the program runs, but no texture is loaded, so we can only see a white box with no texture on it.

The setup for the project environment has the libs into the Linker Libraries(L), such as SDL, SDLmain, SDL_image, GL, GLU, etc -- e.g.: OpenGL and GLUT in Eclipse on OS X

Programs with SDL works fine for input with keyboard etc. However, the texture does not load.

In the Makefile provided from NeHe that is used run the command line in the console, I noticed the following info:

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

Then, reading the Makefile that is generated automatically on IDE Eclipse, I observed that apparently this additional flag is missing: sdl-config --cflags --libs. Should be this additional flag what is preventing the command SDL_LoadBMP to display the texture?

If so, some suggestion about how to properly tune this additional info for the Eclipse's settings to allow the generated IDE Makefile to work properly?

About the way the texture is loaded, here is the function:

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;
}

All comments are highly appreciated.

1

1 Answers

3
votes

Is the path to the texture file hardcoded? Is it realative? Then then the program must be started from the right directory so that the relative path will actually evaluate the texture, otherwise no file is found and no texture loaded.

IDEs tend to compile and run the compiled binaries in build directories, breaking any hardcoded file paths. Eclipse simply doesn't start the program with the right working directory. There are various ways to detect the location of the applications binary, depending on the OS. See http://autopackage.org/docs/binreloc for techniques to how to determine the program binary location.