def initSkybox(self, width, height, location):
        faces = ['front', 'left', 'back', 'right', 'top', 'bottom']
        paths = ['beach', 'clouds', 'water']

        self.fileLength = len(faces)

        self.myVBO = vbo.VBO(array(self.data, 'f'))

        self.boxes = len(paths)
        self.textureList = []

        for path in paths:

            textureIDs = glGenTextures(self.fileLength)

            for c, pic in enumerate(faces):
                im = Image.open(os.path.join(location, path, pic + ".png"))
                width, height = im.size
                #image = array(im)[::-1, :].tostring()  # mirror image on y-axis
                image = array(im).tostring()  # mirror image on y-axis

                glBindTexture(GL_TEXTURE_2D, textureIDs[c])
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                                GL_LINEAR)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                                GL_LINEAR)
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0,
                             GL_RGB, GL_UNSIGNED_BYTE, image)
                glGenerateMipmap(GL_TEXTURE_2D)

            self.textureList.append(textureIDs)
 def initHelicopter(self):
    
     self.objectVertices, self.objectTextures, self.objectNormals, self.objectFaces = self.objLoader.loadObjFile(self.filename)
     self.data, self.heli_vbo = self.objLoader.createDataFromObj()
     
     # Create BoundingBox
     self.boundingBox = [map(min, zip(*self.objectVertices)), map(max, zip(*self.objectVertices))]
     self.center = [(x[0]+x[1])/2.0 for x in zip(*self.boundingBox)]
     self.scaleFactor = 2.0/max([(x[1]-x[0]) for x in zip(*self.boundingBox)])
     
     # Scale, Center
     self.handler.pushModelMatrix(geo.scaleMatrix(self.scaleFactor, self.scaleFactor, self.scaleFactor))
     self.handler.pushModelMatrix(geo.translationMatrix(-self.center[0], -self.center[1], -self.center[2]))
     
     im = Image.open("./heli_data/500DLINE.JPG")
     width, height = im.size
     image = array(im)[::-1,:].tostring()
     self.textureIDs = glGenTextures(1)
     
     glBindTexture(GL_TEXTURE_2D, self.textureIDs)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image)
     glGenerateMipmap(GL_TEXTURE_2D)
    def initSkybox(self, width, height, location):
        faces = ['front', 'left', 'back', 'right', 'top', 'bottom']
        paths = ['beach', 'clouds', 'water']

        self.fileLength = len(faces)

        self.myVBO = vbo.VBO(array(self.data, 'f'))

        self.boxes = len(paths)
        self.textureList = []

        for path in paths:

            textureIDs = glGenTextures(self.fileLength)

            for c, pic in enumerate(faces):
                im = Image.open(os.path.join(location, path, pic + ".png"))
                width, height = im.size
                #image = array(im)[::-1, :].tostring()  # mirror image on y-axis
                image = array(im).tostring()  # mirror image on y-axis

                glBindTexture(GL_TEXTURE_2D, textureIDs[c])
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
                             GL_UNSIGNED_BYTE, image)
                glGenerateMipmap(GL_TEXTURE_2D)

            self.textureList.append(textureIDs)
Exemplo n.º 4
0
    def load(self,create_mipmap = True):

        if self.tex_file == None:
            print "Error: No texture file image set"
            return False

        self.location = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D,self.location)

        # glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,wrap_s)
        # glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,wrap_t)

        # glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,mag_filter)
        # glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,min_filter)
        # glTexParameterf( GL_TEXTURE_2D,  GL_TEXTURE_MAX_ANISOTROPY_EXT,
        #                  max_anisotropy)

        try:
            im = ImageOps.flip(Image.open(self.tex_file).convert('RGB'))
        except IOError:
            print "Error opening file", self.tex_file
            exit(-1)

        texdata = im.getdata()
        buf = numpy.array(texdata,dtype='uint8',order='C')
        buf_shape = (im.size[0],im.size[1],3)
        data = numpy.reshape(buf,buf_shape,order='C')

        glTexImage2Dub(GL_TEXTURE_2D, 0, 3, 0, GL_RGB, data)
        
        if self.create_mipmap:
            glGenerateMipmap(GL_TEXTURE_2D)

        glBindTexture(GL_TEXTURE_2D,0)
        return True
Exemplo n.º 5
0
    def load_default(self):
        self.name = 'default'
        self.location = glGenTextures(1)
        glBindTexture(GL_TEXTURE_CUBE_MAP, self.location)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,
                        self.mag_filter)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
                        self.min_filter)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,
                        GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,
                        GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R,
                        GL_CLAMP_TO_EDGE)

        targets = [
            GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
            GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
            GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
        ]
        for trg in targets:
            data = numpy.zeros((1, 1, 3), dtype='uint8', order='C')
            glTexImage2Dub(trg, 0, 3, 0, GL_RGB, data)

        print 'Created default cubemap texture'
        glGenerateMipmap(GL_TEXTURE_CUBE_MAP)
Exemplo n.º 6
0
    def load(self, create_mipmap=True):

        if self.tex_file == None:
            print "Error: No texture file image set"
            return False

        self.location = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D, self.location)

        # glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,wrap_s)
        # glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,wrap_t)

        # glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,mag_filter)
        # glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,min_filter)
        # glTexParameterf( GL_TEXTURE_2D,  GL_TEXTURE_MAX_ANISOTROPY_EXT,
        #                  max_anisotropy)

        try:
            im = ImageOps.flip(Image.open(self.tex_file).convert('RGB'))
        except IOError:
            print "Error opening file", self.tex_file
            exit(-1)

        texdata = im.getdata()
        buf = numpy.array(texdata, dtype='uint8', order='C')
        buf_shape = (im.size[0], im.size[1], 3)
        data = numpy.reshape(buf, buf_shape, order='C')

        glTexImage2Dub(GL_TEXTURE_2D, 0, 3, 0, GL_RGB, data)

        if self.create_mipmap:
            glGenerateMipmap(GL_TEXTURE_2D)

        glBindTexture(GL_TEXTURE_2D, 0)
        return True
    def initSkybox(self, location):
        """
        lade Bilder der Skybox in OpenGL
        @param location: Pfad zu Skybox-Bildern
        """
        faces = ["front", "left", "back", "right", "top", "bottom"]
        paths = ["water", "beach", "clouds", "sky_hell_512"]

        self.fileLength = len(faces)

        self.pillar = vbo.VBO(array(self.data, "f"))

        self.boxes = len(paths)
        self.textureList = []

        for path in paths:

            textureIDs = glGenTextures(self.fileLength)

            for c, pic in enumerate(faces):
                im = Image.open(os.path.join(location, path, pic + ".png"))
                width, height = im.size
                image = array(im).tostring()  # mirror image on y-axis

                glBindTexture(GL_TEXTURE_2D, textureIDs[c])
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image)
                glGenerateMipmap(GL_TEXTURE_2D)

            self.textureList.append(textureIDs)
Exemplo n.º 8
0
    def load(self, debug=False):
        self.location = glGenTextures(1)
        glBindTexture(GL_TEXTURE_CUBE_MAP, self.location)

        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,
                        self.mag_filter)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
                        self.min_filter)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,
                        GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,
                        GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R,
                        GL_CLAMP_TO_EDGE)
        glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT,
                        self.max_anisotropy)

        if self.tex_xpos == None or \
           self.tex_ypos == None or \
           self.tex_zpos == None or \
           self.tex_xneg == None or \
           self.tex_yneg == None or \
           self.tex_zneg == None:
            print 'Error: Cubemap textures not set'
            return False

        files = [
            self.tex_xpos, self.tex_xneg, self.tex_ypos, self.tex_yneg,
            self.tex_zpos, self.tex_zneg
        ]
        targets = [
            GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
            GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
            GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
        ]

        for tex_file, trg in zip(files, targets):

            # try:
            #     Image.open(self.tex_file).verify()
            # except a:
            #     print 'Error loading cubemap images', a
            #     return False

            img = Image.open(tex_file).convert('RGB')

            texdata = img.getdata()
            buf = numpy.array(texdata, dtype='uint8', order='C')
            buf_shape = (img.size[0], img.size[1], 3)
            data = numpy.reshape(buf, buf_shape, order='C')
            glTexImage2Dub(trg, 0, 3, 0, GL_RGB, data)

            print 'Loaded cubemap texture [' + tex_file + ']'

        if self.create_mipmaps:
            glGenerateMipmap(GL_TEXTURE_CUBE_MAP)
            if debug: print "Generated cubemap mipmaps"

        return True
Exemplo n.º 9
0
    def load(self,debug = False):
        self.location = glGenTextures(1)
        glBindTexture(GL_TEXTURE_CUBE_MAP,self.location)

        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,self.mag_filter)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,self.min_filter)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);
        glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_ANISOTROPY_EXT,
                        self.max_anisotropy)

        if self.tex_xpos == None or \
           self.tex_ypos == None or \
           self.tex_zpos == None or \
           self.tex_xneg == None or \
           self.tex_yneg == None or \
           self.tex_zneg == None:
            print 'Error: Cubemap textures not set' 
            return False
        
        files = [self.tex_xpos,self.tex_xneg,self.tex_ypos,
                 self.tex_yneg,self.tex_zpos,self.tex_zneg]
        targets =  [GL_TEXTURE_CUBE_MAP_POSITIVE_X,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
                    GL_TEXTURE_CUBE_MAP_POSITIVE_Y,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
                    GL_TEXTURE_CUBE_MAP_POSITIVE_Z,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z]
        
        for tex_file,trg in zip(files,targets):

            # try:
            #     Image.open(self.tex_file).verify()
            # except a:
            #     print 'Error loading cubemap images', a
            #     return False

            img = Image.open(tex_file).convert('RGB') 

            texdata = img.getdata()
            buf = numpy.array(texdata,dtype='uint8',order='C')
            buf_shape = (img.size[0],img.size[1],3)
            data = numpy.reshape(buf,buf_shape,order='C')
            glTexImage2Dub(trg, 0, 3, 0, GL_RGB, data)

            print 'Loaded cubemap texture [' + tex_file + ']'

        if self.create_mipmaps:
            glGenerateMipmap(GL_TEXTURE_CUBE_MAP)
            if debug: print "Generated cubemap mipmaps"
    
        return True
Exemplo n.º 10
0
    def load_default(self):
        self.name = 'default'
        self.location = glGenTextures(1)
        glBindTexture(GL_TEXTURE_CUBE_MAP,self.location)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,self.mag_filter)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,self.min_filter)
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);

        targets =  [GL_TEXTURE_CUBE_MAP_POSITIVE_X,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
                    GL_TEXTURE_CUBE_MAP_POSITIVE_Y,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
                    GL_TEXTURE_CUBE_MAP_POSITIVE_Z,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z]
        for trg in targets:
            data = numpy.zeros((1,1,3),dtype='uint8',order='C')
            glTexImage2Dub(trg, 0, 3, 0, GL_RGB, data)
            
        print 'Created default cubemap texture'
        glGenerateMipmap(GL_TEXTURE_CUBE_MAP)
Exemplo n.º 11
0
    def initHelicopter(self):

        self.objectVertices, self.objectTextures, self.objectNormals, self.objectFaces = self.objLoader.loadObjFile(
            self.filename)
        self.data, self.heli_vbo = self.objLoader.createDataFromObj()

        # Create BoundingBox
        self.boundingBox = [
            map(min, zip(*self.objectVertices)),
            map(max, zip(*self.objectVertices))
        ]
        self.center = [(x[0] + x[1]) / 2.0 for x in zip(*self.boundingBox)]
        self.scaleFactor = 2.0 / max([(x[1] - x[0])
                                      for x in zip(*self.boundingBox)])

        # Scale, Center
        self.handler.pushModelMatrix(
            geo.scaleMatrix(self.scaleFactor, self.scaleFactor,
                            self.scaleFactor))
        self.handler.pushModelMatrix(
            geo.translationMatrix(-self.center[0], -self.center[1],
                                  -self.center[2]))

        im = Image.open("./heli_data/500DLINE.JPG")
        width, height = im.size
        image = array(im)[::-1, :].tostring()
        self.textureIDs = glGenTextures(1)

        glBindTexture(GL_TEXTURE_2D, self.textureIDs)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
                     GL_UNSIGNED_BYTE, image)
        glGenerateMipmap(GL_TEXTURE_2D)
    def initHeliPad(self):
        """
        berechne den Umfang der Saeule fuer das Helipad
        und erstelle Rechteck fuer die Landeplattform
        """
        images = ['pillar', 'top']

        texCoords = [[0, 0], [1, 0], [0, 1], [1, 1]]

        r = self.faces / 2.

        points = []
        for i in range(self.faces + 1):
            x, z = math.cos(i * math.pi / r) * 1.5, math.sin(i * math.pi / r) * 1.5
            points.append([x, 0, z])
            points.append([x, self.height, z])

        dataList = []
        for i in range(0, self.faces * 2, 2):
            for e in range(4):
                dataList.append(points[i + e] + texCoords[e])

        self.len = len(dataList)

        self.pillar = vbo.VBO(array(dataList, 'f'))

        ### plattform

        r = self.radius * 1.5
        s = self.height
        size = self.height * 0.001
        p = [[-r, s, r], [r, s, r], [-r, s - size, r], [r, s - size, r],
             [-r, s, -r], [r, s, -r], [-r, s - size, -r], [r, s - size, -r]]

        top = [p[5] + [0, 0], p[4] + [1, 0], p[0] + [1, 1], p[1] + [0, 1],  # top
               p[1] + [0, 0], p[0] + [1, 0], p[2] + [1, 1], p[3] + [0, 1],  # front
               p[0] + [0, 0], p[4] + [1, 0], p[6] + [1, 1], p[2] + [0, 1],  # left
               p[4] + [0, 0], p[5] + [1, 0], p[7] + [1, 1], p[6] + [0, 1],  # back
               p[5] + [0, 0], p[1] + [1, 0], p[3] + [1, 1], p[7] + [0, 1],  # right  
               p[3] + [0, 0], p[2] + [1, 0], p[6] + [1, 1], p[7] + [0, 1]]  # bottom

        self.top = vbo.VBO(array(top, 'f'))
        self.bb = [(-r + self.x, -self.gamesize, -r + self.z),
                   (r + self.x, self.height - self.gamesize, r + self.z)]
        self.textureID = glGenTextures(2)

        # load image
        for c, im in enumerate(images):
            image = Image.open(os.path.join("textures/helipad", im + '.png'))
            width, height = image.size
            imagedata = array(image)
            imagedata = imagedata[::-1, :]
            imagedata = imagedata.tostring()

            glBindTexture(GL_TEXTURE_2D, self.textureID[c])

            glBindTexture(GL_TEXTURE_2D, self.textureID[c])
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
                                 GL_UNSIGNED_BYTE, imagedata)
            glGenerateMipmap(GL_TEXTURE_2D)