Hi,
I’m sorry for what I’m sure will be a very easy question. But I cant understand how to load an image from a file to use as a texture map. I’ve read many tutorials and I couldn’t understand them. I was wondering if anyone could give me some advice on how to do this.
At the moment I have created a texture and applied it but I don’t know how to open a file and apply that texture.
void makeCheckImage(void)
{
int i, j, c;
for (i = 0; i < checkImageHeight; i++)
{
for (j = 0; j < checkImageWidth; j++)
{
c = (((i&0x8)==0)^(j&0x8)==0)*255;
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;
checkImage[i][j][3] = (GLubyte) 255;
}
}
}
static void texture(void)
{
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,checkImageWidth,
checkImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE,checkImage);
}