Hi, I am learning opengl and have progressed onto texturing using pictures. I am trying to texture one face of a cube but the result is very weird.
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_POLYGON);
glTexCoord2f( 1.0, -1.0);
glVertex3f( 1.0, -1.0, 1);
glTexCoord2f( 1.0, -1.0);
glVertex3f( 1.0, -1.0, -1);
glTexCoord2f( 1.0, 1.0);
glVertex3f( 1.0, 1.0, -1);
glTexCoord2f( 1.0, 1.0);
glVertex3f( 1.0, 1.0, 1);
glEnd();
glDisable(GL_TEXTURE_2D);
The normals are applied correctly so its not that causing the issue. I then have a separate function to load the image:
QImage temp;
temp.load("./Example.ppm"); //load in image
QImage image = QGLWidget::convertToGLFormat(temp); //convert to correct format
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pic.width(), pic.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.bits());
glBindTexture(GL_TEXTURE_2D, texture);
where texture is a global unsigned int. Any ideas what may be causing this issue? I tried using:
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
but that didn’t change anything.