PDA

View Full Version : 2D Texture Mapping



ncikw
12-14-2011, 10:13 AM
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&amp;0x8)==0)^(j&amp;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, &amp;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_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,checkImageWidth,
checkImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE,checkImage);

}

V-man
12-14-2011, 12:01 PM
There are a few image loading libs here
http://www.opengl.org/wiki/Related_toolkits_and_APIs#Image_and_Texture_Librar ies