class Globe(QOpenGLWidget):
def __init__(self):
super(Globe, self).__init__()
array_coords = [
'x', 'y', 'z',
'cx', 'cy', 'cz',
'rx', 'ry', 'rz'
]
for coord in array_coords:
if coord == 'z':
setattr(self, coord, 50)
else:
setattr(self, coord, 0)
self.img = Image.open("/path/to/image.tiff")
self.mapWidth, self.mapHeight = self.img.size
pgImData = numpy.asarray(self.img)
self.inputMapFile = numpy.flipud(pgImData)
def initializeGL(self):
glShadeModel(GL_SMOOTH)
glEnable(GL_DEPTH_TEST)
glEnable(GL_CULL_FACE)
glEnable(GL_LIGHTING)
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [0.9, 0.9, 0.9, 1.0])
glEnable(GL_COLOR_MATERIAL)
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)
glActiveTexture(GL_TEXTURE0)
self.text_obj = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, self.text_obj)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, self.mapWidth, self.mapHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, self.inputMapFile.tobytes())
glPixelStorei(GL_UNPACK_ALIGNMENT, 4)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
def paintGL(self):
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glFrustum(-1, 1, -1, 1, 5, 1000)
glMatrixMode(GL_MODELVIEW)
glEnable(GL_DEPTH_TEST)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glPushMatrix()
glRotated(self.rx / 16, 1, 0, 0)
glRotated(self.ry / 16, 0, 1, 0)
GlobeDraw().create_earth() # это метод рисования глобуса
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, self.text_obj)
glPopMatrix()
glLoadIdentity()
gluLookAt(self.x, self.y, self.z, self.cx, self.cy, self.cz, 0, 1, 0)
self.update()