I wanted to render the image I had in memory with OpenGL. The image data are stored as
data without padding. The colors are represented by RGB (in this order). When I loaded the texture data with
1
2
3
4
5
6
7
8
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE,
imageData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE,
imageData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
the rendered image showed only a black and with image which was line-wise distorted. The reason for the distortion was that by image data was not correctly aligned. The
defines the alignment when uploading data. So, setting
1
| glPixelStorei(GL_UNPACK_ALIGNMENT, 1) |
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
solved my problem.
|