You Like My Tutorials? Click The Banner To Keep 'Em Coming!

glGameDeveloper(): The Game Developer's Source for OpenGL Coding
Main Menu
Latest News
Archived News
Tutorials
Links
E-Mail Me

Other
Message Board
My Guestbook

Tutorials -- Texture Mapping
 


Texture Mapping Polygons Page 2 of 5
< Previous Jump to Page: 1 | 2 | 3 | 4 | 5 Next >

How To Load a Bitmap to a Texture

Now open "main.cpp" and make sure you have these lines at the top:

#include "main.h"
#include "texture.h"

Then add this line to your Init() function (I added the tab for you =]).

	SetTextureFilter(TF_BILINEAR);

The TF_BILINEAR constant is defined in texture.h. You can also set this to TF_NONE for no filtering, or TF_TRILINEAR for trilinear filtering. If you're new to constants, check out my Quick Intro to Constants tutorial. Then come back here and continue this tutorial.

First, near the top of your main.cpp or somewhere in main.h you can define constants to reference each texture. Use these as an example.

int TEX_TILE;

Note that we are not using const ints, just ints, and that we aren't giving them values. This is so that when we load the texture, it will return the identifier of that texture.

Now you can add lines like these to your Init() function.

	TEX_TILE = LoadTexture("tile1.bmp", false, false);

To find out what the two bool values that need passed to LoadTexture(), open up texture.cpp and check the description of the LoadTexture() function.

To make these textures active, just call this function when you want to use it.

	glBindTexture(GL_TEXTURE_2D, TEX_TILE);

That's one heck of a simple way of working with textures, if I do say so myself. Lets move on and draw a set of textured polygons!

Texture Mapping Polygons Page 2 of 5
< Previous Jump to Page: 1 | 2 | 3 | 4 | 5 Next >

This site best viewed with MS Internet Explorer 5.0 at 16-bit color and at least 800x600.

All Contents of this site are Copyright 1999, 2000 Joe Zimmerman. No part of this site (code, HTML, etc.) may be reproduced without my permission.

Click Here!