| |||||||||||
|
Main Menu Other |
Tutorials -- Texture Mapping | ||||||||||
|
Texture Mapping PolygonsFirst off, make sure you've read the previous beginner tutorials. This and future tutorials will be based on it so it helps if you're new to OpenGL. Texture mapping is one of the simplest ways to add detail to a scene without adding much to it's complexity. In this tutorial, I will explain how to open a bitmap, tell opengl how to use it, and how to apply a texture to a polygon. First of all, lets go over loading a bitmap into memory. First we load some header info, which tells us the width and height of the bitmap. Then we load the actual bitmap into memory. This is done by reading the red, green, and blue values for every pixel into a block of memory. We won't store the alpha values in the bitmaps, instead we can set transparency depending on the color of the pixel. In this tutorial, I have the code set up so that if the pixel is bright pink, it's fully transparent. This color is hideously ugly so its the least likely to be used. =] It's also set so that we can optionally use the average of the red, green, and blue values (from now on I'll call this just rgb or rgba) and set our alpha to that. This works perfect for when we want to load our font bitmaps. When we load those, we want the fonts to be antialiased. More on that in the Outputting Textured Fonts tutorial. Also, the font bitmaps require that we load the bitmap backwards (because bitmaps are stored backwards, so we're really loading them forward... make sense? =]). Also, let me explain Bilinear and Trilinear filtering. Bilinear means that we're filtering polygons that are up close to the viewer. This can be done with or without MipMapping. MipMapping, if you don't know, means to use less detailed textures for far away polygons. That way they don't "sparkle". The thing is, mipmapped textures also need filtering. That's where trilinear filtering comes in. It filters polygons that are far away from the viewer. Bilinear means filtering on the X and Y coordinates. Trilinear adds the Z coordinate. Got it? Ok, on to the code. Download this zip file and add the two well-documented files in it to your project. To do that, just unzip the zip file to your project directory, then go to the "Project" menu, "Add to project", "Files...", and add texture.cpp and texture.h. Make sure you also extract tile1.bmp, which we'll use to demonstrate texturing.
|
|||||||||||