Alittle help with textures
This is the code i'm using to load a texture in a png file. i do realize i have many mistakes in it and would greatly welcpme help. If it makes a difernce, it is in the display function.
Code:
NSData *raw = [NSData dataWithContentsOfFile:
pic];
NSBitmapImageRep *rep =
[NSBitmapImageRep imageRepWithData: raw];
glEnable(GL_TEXTURE_2D);
glGenTextures(1,&texID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
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_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
[rep pixelsWide], [rep pixelsHigh], 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
[rep bitmapData]);
glBindTexture(GL_TEXTURE_2D, texID);
glBegin (GL_QUADS);
glTexCoord2f (0.0f,0.0f); /* lower left corner of image */
glVertex3f (-10.0f, -10.0f, 0.0f);
glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */
glVertex3f (10.0f, -10.0f, 0.0f);
glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */
glVertex3f (10.0f, 10.0f, 0.0f);
glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */
glVertex3f (-10.0f, 10.0f, 0.0f);
glEnd ();
glDisable (GL_TEXTURE_2D); /* disable texture mapping */
}
You need to call glBindTexture *before* you do anything to it (that is, immediately after glGenTextures).
Also, you shouldn't be using NSBitmapImageRep in that way. It's asking for trouble. Search the boards for a longer explanation.
Also, you shouldn't be using NSBitmapImageRep in that way. It's asking for trouble. Search the boards for a longer explanation.

