Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: I can't Texture!

  1. #1
    Guest

    I can't Texture!

    I am having a terrible time trying to learn how to texture map a bmp file to a polygon. Every book I read is like "its simple, we'll assume you know how to load in the bmp file. Now that that is done, use these wonderful OpenGL functions to map it onto your polygon!". Wait a second! Load the bmp? Huh? I'm a quasi-good programmer in C++. I've been buying and reading several books trying to learn this little technique and cant figure it out. I understand all the GL stuff you can do, but how do I get the bmp file loaded so I can use it???? Please email me if there are some easy to read resources out there on that, or if you have a good explanation. Thanks.

    Ace Corbain

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    340

    Re: I can't Texture!

    Hi

    You have two options at this point :

    1/ you want to load the bmp yourself
    1.1/ you want to learn the BMP file format : you'll find information here http://www.wotsit.org . Once you know the file format, you can load the data into memory to be used as a texture in GL.
    1.2/ you don't care about the format, and want to use one of the wonderful Win32 API functions : LoadImage(). Look through the MSDN and you'll figure out how it works.

    2/ you prefer to use a library to handle this. I personnaly use DevIL (formerly known as OpenIL). It handles a lot of image formats and does just what I need ;-) Have a look here : http://www.imagelib.org

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2001
    Location
    Toledo OH
    Posts
    29

    Re: I can't Texture!

    at hene.gamedev.net they have a good tutorial on this. Heres some simple code for doing it. The hard part is loading the damned image file. GLUAX has a nice function for loading bmp's. It is of course the only reason any why anyone ever uses GLUAX anymore, just for that one function.
    glGenTextures(1, &barID); // Create The Texture
    glBindTexture(GL_TEXTURE_2D, barID);
    gluBuild2DMipmaps ( GL_TEXTURE_2D, GL_RGB, bar->sizeX,
    bar->sizeY, GL_RGB, GL_UNSIGNED_BYTE, bar->data);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    statusBarObj = glGenLists(1); //generate our new list
    glNewList ( statusBarObj, GL_COMPILE ); //compile it
    //glMaterialf(GL_FRONT_AND_BACK, GL_AMBIENT, 1.0);
    glBindTexture (GL_TEXTURE_2D, barID);
    glColor3f (1.0,1.0,1.0);
    glBegin ( GL_QUADS );
    glVertex3f(1.0,0.5,0.0); glTexCoord2d( 1.0f,0.0f);
    glVertex3f(1.0,1.0,0.0); glTexCoord2d( 1.0f,1.0f);
    glVertex3f(0.0,1.0,0.0); glTexCoord2d( 0.0f,1.0f);
    glVertex3f(0.0,0.5,0.0);
    glTexCoord2d( 0.0f,0.0f);
    glEnd();
    glEndList();
    glPopAttrib();

    [This message has been edited by dheitbri (edited 12-07-2001).]

    [This message has been edited by dheitbri (edited 12-07-2001).]

  4. #4
    Intern Newbie
    Join Date
    Sep 2001
    Location
    Pacifica, California, USA
    Posts
    30

    Re: I can't Texture!

    Originally posted by dheitbri:
    at hene.gamedev.net
    He meant http://nehe.gamedev.net

  5. #5
    Guest

    Re: I can't Texture!

    Ok, thanks so far for the info guys. I have been able to confirm that my problem lies in not understanding bmp format and the process of loading it. I'm looking into DevIL and glaux at this point. I'm still not quite sure how to use the texture once it is loaded. For instance, I load an image "bah.bmp" in one of these nifty loading functions, how now do I refer to it with Open GL's nifty functions? And going into further depth, if I want to use more than one texture in a program, I can only guess I use an array, so I must refer to the textures from the array. Bottom line, is there a variable the functions will set or what? Thanks again for the library referrals. My email is mushka70@aol.com if you have any more info.

    Jeremy

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2001
    Location
    Oss,n-brabant, holland
    Posts
    17

    Re: I can't Texture!

    Use glbindtexture to swap between textures. say it's 1D or 2D ( gl_texture_1d or gl_texture_2d) and give the place where you stored your new texture.

    Do you have opengl superbible 2e edition?
    It explains a lot about opengl ( also for textures ) and I think there will be told you something about "behind textures",

    got it

  7. #7
    Guest

    Re: I can't Texture!

    I know I'm close. I'm probably just overlooking one small detail. If anyone is willing to look at my .cpp file let me know. It is a simple program that just draws a cube and puts NeHe's bmp on it. The problem I'm getting is that it is all black meaning it hasn't been loaded properly, but I can't figure out why. Anyway, if you can spare a few to check out my cpp file, gimme an email and I'll send it ur way. mushka70@aol.com Thanks for all the help so far guys. Should texturing be THIS hard? I'm starting to doubt my abilities in programming.

    Ace Corbain

  8. #8
    Member Regular Contributor
    Join Date
    Apr 2001
    Posts
    340

    Re: I can't Texture!

    Did you check texture coordinates?

    Also, are you sure your image is 2^n*2^m ?

    Is TEXTURE_2D enabled?

    Just some thoughts...

  9. #9
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,962

    Re: I can't Texture!

    Don't use GLAUX.

    Maybe try a glDrawPixels with the image to ensure you have a valid array of data.

    On this page there's a gamma.zip file. It has decent code to load a 24bit BMP image and display it. You could use this code if your image is 24 bit.
    http://www.ddj.com/articles/1999/9909/

  10. #10
    Guest

    Re: I can't Texture!

    OK! Now I got textures working. Here's what I'm trying to accomplish. I want to create a sky box around an object that I can rotate around with my mouse. I got all the mechanics worked out and everything. One problem is occurring though. My object has material properties associated with it. However, the skybox reacts with the material properties. Why is this? I have the skybox being drawn in its own function. So is there something I can do to make the textures not react with the material properties of the object? Plus, it is really dark in there, even with several lights.

    Ace Corbain

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •