I'll list phases you're going to need in order to use textures with OpenGL (as it's seen on GLEngine http://www.freewebs.com/loknar/ You can find data loading functions for BMP, PNG, JPG and GIF there):
Code:
- glEnable(GL_TEXTURE_2D);
- Allocate memory for texture data (array that contains pixel data for example RGB format)
- glGenTextures(1,@TextureIndex);
- glBindTexture(GL_TEXTURE_2D,TextureIndex);
- glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,TextureQuality);
(where TextureQuality can be either GL_LINEAR or GL_NEAREST)
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
TextureQuality)
- glTexImage2D(GL_TEXTURE_2D, 0, n, tex.sizeX, tex.sizeY, 0,
Format, GL_UNSIGNED_BYTE, tex.Data)
(where format can be for example GL_RGB or GL_RGBA
and n meaning number of values per pixel)
- Free texture memory
- Enjoy :wink:
- Call glBindTexture(GL_TEXTURE_2D,TextureIndex);
to recall your texture or value 0 to not use any.
Edit: Also, texture sizes matter to graphics card! Image of 500x500 may show white completely where 128x512 or 1024x1024 will show as they are power of 2. Scrap glaux unit for being severely outdated.. aand finally use glTexCoord2f for each vertex to actually see the image.
Bookmarks