Jump to content
  • Advertisement
Sign in to follow this  
opprobriumark

Loading Bitmaps w/ Linux & GLUT

This topic is 4841 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

My crew and I are trying to make our game run on both Windows and Linux machines. We are using OpenGL and the GLUT API's. For Windows, I use the glaux libraries to load a bitmap, but this doesn't seem to work on Linux. How do I do it? I need a format that has an alpha channel. Mark

Share this post


Link to post
Share on other sites
Advertisement
Hey, I've looked into DevIL and have had success loading images and displaying them both on Windows and Linux machines. I'm now having a problem with using multiple images. In my application, I load all the textures first and later use their GL ID's to map them to quads. It seems that with DevIL, the last texture loaded is the only one displayed. I don't understand why this is happening...? Here's my function for loading textures and getting GL ID's:

bool loadTexture(GLuint *textureID, char *filename)
{
ILuint ImageName;

//generate image name
ilGenImages(1, &ImageName);

//bind image so DevIL performs functions on it
ilBindImage(ImageName);

//load the image
ilLoad(IL_TGA, filename);
iluFlipImage();

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

if(*textureID = ilutGLBindTexImage())
return true;
else
return false;

return true;
}

Please help!

Mark

Share this post


Link to post
Share on other sites
Nothing in there immediately leaps out at me as being wrong.

I'm at work and don't have time to experiment, but you could compare your texture loading code to the code I use in this:

http://www.gamedev.net/community/forums/topic.asp?topic_id=322227

which I know does work (ignore most of it unless you like the idea, just look at the texture pool load function).

Share this post


Link to post
Share on other sites
I've made my code look almost exactly like TexturePool::Load() and I still have the same problem. Even when I explicitly bind a specific GL texture through glBindTexture(), the last loaded devIL image is the one used. I'm using a simple textured quad example. The following is my definition:



//IN HEADER FILE /////////////////////
class TexturedQuad : public Quad
{
public:
// detailed constructor
TexturedQuad(const GLuint& textureID, const GLfloat& width, const GLfloat& height,
const GLfloat& xPos, const GLfloat& yPos, const GLfloat& xTexPos, const GLfloat& yTexPos,
const GLfloat& texWidth, const GLfloat& texHeight): Quad(width, height, xPos, yPos),
_textureID(textureID), _xTexPos(xTexPos), _yTexPos(yTexPos), _texWidth(texWidth), _texHeight(texHeight)
{
}

// constructor for splash screen
TexturedQuad(const GLuint& textureID): Quad(800.0f, 600.0f, 400.0f, 300.0f),
_textureID(textureID), _xTexPos(0.0f), _yTexPos(0.0f), _texWidth(1.0f), _texHeight(1.0f)
{
}

virtual void draw();

private:
GLuint _textureID;
GLfloat _xTexPos;
GLfloat _yTexPos;
GLfloat _texWidth;
GLfloat _texHeight;
};



//IN .CPP FILE ////////////////////////
void TexturedQuad::draw()
{
glBindTexture(GL_TEXTURE_2D, _textureID);
glTexCoord2f(_xTexPos, _yTexPos); glVertex2f(_xPos - _width/2, _yPos - _height/2);
glTexCoord2f(_xTexPos + _texWidth, _yTexPos); glVertex2f(_xPos + _width/2, _yPos - _height/2);
glTexCoord2f(_xTexPos + _texWidth, _yTexPos + _texHeight); glVertex2f(_xPos + _width/2, _yPos + _height/2);
glTexCoord2f(_xTexPos, _yTexPos + _texHeight); glVertex2f(_xPos - _width/2, _yPos + _height/2);
return;
}

Obviously, I am passing in the correct ID's to the constructor and a draw() is between a glBegin()..glEnd() pair. What could be going wrong?


Mark

Share this post


Link to post
Share on other sites
Unless there's something you explicitly need in GLUT, consider using SDL instead. It'll work on Windows and Linux (as well as Macs and others), works fine with OpenGL, and has bitmap loading functions. Look at the tutorials at the SDL site to get started, and this code snippet for how to use OpenGL textures in SDL.

Share this post


Link to post
Share on other sites
I got it to work. It turns out that I was trying to glBindTexture() within glBegin()...glEnd(). Luckily my friend pointed out the error. Pretty dumb of me. Thanks guys for your help.

Mark

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!