Jump to content
  • Advertisement
Sign in to follow this  

SOIL dosn't work in linux?

This topic is 3398 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been using SDL for a small "game engine"- I had it working in windows, and have been making sure it works in linux too. Everything else works, except when it comes to loading the image through SOIL.When I try to run the block:
    GLuint tex_2d = SOIL_load_OGL_texture
	(
		"/media/500gb1/programming files/my projects/linux programming/engine_check_3/brick.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
	);
I get the message "Segmentation fault" in the other window, and the main window closes upon opening. I am using Code::Blocks compiler, Ubuntu 8.04 64bit. I added SOIL to the library, and have SOIL.h included. Any Ideas? google isn't providing any answers :/

Share this post


Link to post
Share on other sites
Advertisement
Do you have a 32-bit version of Linux somewhere that you can test it with? If not, maybe you could try installing under VirtualBox or QEmu. I'm not sure that some libraries work with 64-bit systems.

My past experience with 64-bit Linux has some mixed measures of triumph mixed with failure. Also, if you have 32-bit OpenGL drivers on 64-bit Linux that can cause a few conflicts as well.

Share this post


Link to post
Share on other sites
The openGL stuff seems to work fine- I can use SDL to load BMP's fine. I don't have a 32bit version of linux installed anywhere right now, so can't test it :-/ It did work in win XP 64bit fine though.

Is there any other good image loading libraries (and any suggestions on any model loading libraries) that are platform independent?

Thanks!

Share this post


Link to post
Share on other sites
You can use SDL_image. It dynamically loads what is necessary (libpng, jpeglib, libtiff). If you use libpng you will need these shared libraries. Example code:


GLint graphics_loadTexture(const char filename[], GLuint index) {
SDL_Surface *surface; /* Store information here, size, etc */

if ((surface = IMG_Load(filename))) {
/* GLU will convert textures to POT before sending to GL */
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture[index]);
glBindTexture(GL_TEXTURE_2D, texture[index]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
SDL_PixelFormat *format = surface->format;

if (format->Amask) /* Check for alpha channel */
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, surface->w, surface->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
else
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
}
else {
fprintf(stderr, "SDL could not load %s.\n%s\n", filename, SDL_GetError());
fb_quit(1);
}

/* Free the SDL_Surface only if it was successfully created */
if (surface)
SDL_FreeSurface(surface);
else
return -1;

return texture[index];
}


gluBuild2DMipmaps() will convert to power of the 2 on the fly. I know SOIL does this too with this function but SOIL also did not work for me on Linux so I found a way to make it work with SDL_image. Right now with a function like this you are limited to static textures (single frame). If you want multiple frames with this, you load the others off-screen and toggle. You need another function for positioning.


GLvoid graphics_positionTexture(GLfloat vertexX[], GLfloat vertexY[], GLfloat vertexZ[]) {

glBegin(GL_QUADS); /* Do not change this order */
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( vertexX[0], vertexY[0], vertexZ[0] ); /* Top left corner */
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( vertexX[1], vertexY[1], vertexZ[1] ); /* Bottom left corner */
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( vertexX[2], vertexY[2], vertexZ[2] ); /* Bottom right corner */
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( vertexX[3], vertexY[3], vertexZ[3] ); /* Top right corner */
glEnd();

return;
}


To calculate the vertexes, decide your height in one array (vertexY) like this:


GLfloat vertexY[] = { 0.0f, 0.2f, 0.2f, 0.0f };


Then declare vertexX[4] and if it's flat facing you can use this for vertexZ[4]:

GLfloat vertexZ[] = { 0.0f, 0.0f, 0.0f, 0.0f };

Otherwise you need to figure out this one on your own :P

I have a function that three functions to scale textures properly according to a given float height. I use for loops to iterate through the arrays.

int i;
for ( i = 0; i < 2; i++ ) screenMain_selectionX = graphics_centreAtX(0.6f,
graphics_scaleTextureWidth(graphics_getTextureWidth(mainSelector), graphics_getTextureHeight(mainSelector), 0.18f));
for ( i = 2; i < 4; i++ ) screenMain_selectionX = screenMain_selectionX[i-2] +
graphics_scaleTextureWidth(graphics_getTextureWidth(mainSelector), graphics_getTextureHeight(mainSelector), 0.18f);



GLint graphics_getTextureHeight(const char filename[]) {
GLint height;
SDL_Surface *temp;

if ((temp = IMG_Load(filename))) {
height = temp->h;
}
else
return -1.0;

if (temp)
SDL_FreeSurface(temp);

return height;
}

GLint graphics_getTextureWidth(const char filename[]) {
GLint width;
SDL_Surface *temp;

if ((temp = IMG_Load(filename))) {
width = temp->w;
}
else
return -1.0;

if (temp)
SDL_FreeSurface(temp);

return width;
}

GLfloat graphics_scaleTextureWidth(GLuint pWidth, GLuint pHeight, GLfloat destHeight) {
GLfloat destWidth;

destWidth = ((GLfloat)pWidth / (GLfloat)pHeight) * destHeight;

return destWidth;
}


Hope this helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!