Sorry for the lengthy code snippet but I have been stuck on this for about a day now, and the notes I have just don’t seem to be doing justice… I apologize for the school question hopefully its not an issue but I have no idea where else to go, professor won’t necessarily help me.
I know the reading of the image is good because if I use GL_QUADS and use my own vertex points and tex points it shows up. I believe something is going wrong when I try to call the glTexParameteri functions. Could someone look over and make sure they are correct, because I have no idea on how to even go about debugging them and tired of guessing…
Thank you
void textureShader::SetupTextureMap(void)
{
if (tShape == Box)
glTarget = GL_TEXTURE_CUBE_MAP;
else
glTarget = GL_TEXTURE_2D;
// Note that we only initialize the OpenGL texture objects if we
// don't yet have an OpenGL texture object
if (tObject <= 0)
{
// Find the number of textures that have been specified
// Multiple images are used for manually specifiying mipmaps
// and for box maps
int nImages = 0;
while (tName[nImages][0] != '\0' && nImages < MAX_IMAGES)
nImages++;
// If there are none, then do nothing and return
if (nImages < 1)
return;
// Generate the texture object and bind it to the texture target defined above
glGenTextures(1, &tObject);
glBindTexture(glTarget, tObject);
// Now, loop through the images and send them to OpenGL
for (int nImage = 0; nImage < nImages; nImage++)
{
BitmapFile texture;
if (!texture.Read(tName[nImage]))
complain("Couldn't read texture %s", tName);
// Now we will multiply the image by tFilterColor and add tConstColor.
// We do these with methods in the BitmapFile class.
if (tFilterColor[0] < .99999 || tFilterColor[1] < .99999 || tFilterColor[2] < .99999 || tFilterColor[3] < .99999)
texture.Filter(tFilterColor[0], tFilterColor[1], tFilterColor[2], tFilterColor[3]);
if (tConstColor[0] > .00001 || tConstColor[1] > .00001 || tConstColor[2] > .00001 || tConstColor[3] > .00001)
texture.Add(tConstColor[0], tConstColor[1], tConstColor[2], tConstColor[3]);
// To Do
//
// Get the width and height from the texture file
int w, h;
w = texture.Width();
h = texture.Height();
// To Do
//
// Set the image data pointer to point do the data in the texture (Hint:
// is there a method in the texture that
GLubyte *imageData;
imageData = texture.ImageData();
// To Do
//
// Set the src and target formats for the texture data. The srcFormat should
// match the format of the data in the texture file itself. Hint: what order
// are the colors stored in bitmap and targa files? The targFormat is the
// format that we want the data stored inside OpenGL. Note that these two
// may not be the same.
//
// We also need to check here for the number of bytes per pixel in the image.
// For our examples, it will be either 3 or 4. If it is 4, then there is an
// alpha channel in the data, otherwise it is three. Set the srcFormat and
// targFormat appropriately, or the data will not be read in correctly!
GLuint srcFormat = GL_BGRA, targFormat = GL_RGBA;
if(texture.BytesPerPixel() == 3)
srcFormat = GL_BGR, targFormat = GL_RGB;
// Rows in our image are stored contiguously (not aligned on a specific number
// of bytes, so set the unpack alignment to 1 --> single byte aligned
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// To Do
//
// If it is a box map (which doesn't support manual mipmap specification in RGL)
// or if only one image is supplied turn on automatic mipmap generation.
//gluBuild2DMipmaps(glTarget, 3, w, h, srcFormat, GL_UNSIGNED_BYTE, imageData);
if (nImages == 1 || tShape == Box)
glTexParameteri(glTarget, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
// To Do
//
// Send the data to OpenGL. Be very careful when sending all the data. For a first
// shot you may assume that the texture target is GL_TEXTURE2D, but you will need to
// change this command when we enable box mapping!
if (tShape != Box)
glTexImage2D(GL_TEXTURE_2D, nImage, targFormat, (GLsizei)w, (GLsizei) h, (GLint)0, srcFormat, GL_UNSIGNED_BYTE, imageData);
else
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + nImage, 0, targFormat, (GLsizei)w, (GLsizei)h, (GLint)0, srcFormat, GL_UNSIGNED_BYTE, imageData);
}
}
// To Do
//
// Now, bind the texture and set the texture parameters. You need to set several here.
// Set the parameters for how the image wraps and what kind of magnification and minification
// filter you want to use, and also, set the anisotropy level. Also set the blend mode and
// blend color. Note, if you do not do this correctly, your textxure will not show up at all,
// particularly for mipmapping. If you use a mipmapped filter without enabling mipmap generation
// above, you will get nothing!
//glBindTexture(glTarget, tObject);
glTexParameteri(glTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//this->tMinFilter);
glTexParameteri(glTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//this->tMagFilter);
glTexParameteri(glTarget, GL_TEXTURE_WRAP_S, GL_REPEAT);//this->tHorzWrap);
glTexParameteri(glTarget, GL_TEXTURE_WRAP_T, GL_REPEAT);//this->tVertWrap);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, this->tAnisotropy);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(this->tBlend, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendColor(this->tBlendColor[0], this->tBlendColor[1], this->tBlendColor[2], this->tBlendColor[3]);
// glEnable(GL_TEXTURE_2D);
}