The width and height must be at least 64 pixels, and for compatability reasons, shouldn't be more than 256 pixels. The image height and width MUST be a power of 2. Before I start explaining the code there are a few VERY important things you need to know about the images you plan to use as textures. If the file doesn't exist NULL is sent back meaning the texture couldn't be loaded. The job of this code is to load in a bitmap file. Now immediately after the above code, and before ReSizeGLScene(), we want to add the following section of code. LRESULTĜALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) // Declaration For WndProc GLuint texture // Storage For One Texture ( NEW ) HINSTANCE hInstance // Holds The Instance Of The Applicationīool keys // Array Used For The Keyboard Routine HWND hWnd=NULL // Holds Our Window Handle HGLRC hRC=NULL // Permanent Rendering Context HDC hDC=NULL // Private GDI Device Context #include // Header File For The GLaux Library #include // Header File For The GLu32 Library #include // Header File For The OpenG元2 Library #include // Header File For Standard Input/Output ( NEW ) If you wanted to load in more than one texture, you would change the number one to the number of textures you wish to load. The last line GLuint texture sets aside storage space for one texture. These variables will be used to rotate the cube on the x axis, the y axis, and the z axis. Then we add three new floating point variables. In order to use fopen() later in the code we need to include this line. Adding this header file allows us to work with files. Lets start off by adding five new lines of code to the top of lesson one. An update of the code which is responsible for loading the texture can be found here: The theory of this tutorial is still valid though. Important: This way of loading textures is deprecated and does not work anymore with current versions of Visual Studio. The single texture mapped quad will use alot less processing power. A missile made out of polygons could be made up of hundreds or thousands of polygons. The texture mapped missile would only be one quad moving across the screen. Which do you think will look better? A photograph or an object made up of triangles and squares? By using texture mapping, not only will it look better, but your program will run faster. With texture mapping, you can take a real picture of a missile and make the picture fly across the screen. Up until this tutorial we'd probably make the entire missile out of polygons, and fancy colors. Lets say you wanted a missile to fly across the screen. Learning how to texture map has many benefits.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |