当前位置: 首页>>代码示例>>Python>>正文


Python VBO.unbind方法代码示例

本文整理汇总了Python中OpenGL.arrays.vbo.VBO.unbind方法的典型用法代码示例。如果您正苦于以下问题:Python VBO.unbind方法的具体用法?Python VBO.unbind怎么用?Python VBO.unbind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenGL.arrays.vbo.VBO的用法示例。


在下文中一共展示了VBO.unbind方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: StlModel

# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import unbind [as 别名]

#.........这里部分代码省略.........
        glShadeModel(GL_SMOOTH)

        # material properties (white plastic)
        glMaterial(GL_FRONT, GL_AMBIENT, (0.0, 0.0, 0.0, 1.0))
        glMaterial(GL_FRONT, GL_DIFFUSE, (0.55, 0.55, 0.55, 1.0))
        glMaterial(GL_FRONT, GL_SPECULAR, (0.7, 0.7, 0.7, 1.0))
        glMaterial(GL_FRONT, GL_SHININESS, 32.0)

        # lights properties
        glLight(GL_LIGHT0, GL_AMBIENT, (0.3, 0.3, 0.3, 1.0))
        glLight(GL_LIGHT0, GL_DIFFUSE, (0.3, 0.3, 0.3, 1.0))
        glLight(GL_LIGHT1, GL_DIFFUSE, (0.3, 0.3, 0.3, 1.0))

        # lights position
        glLightfv(GL_LIGHT0, GL_POSITION, self.light_position)
        glLightfv(GL_LIGHT1, GL_POSITION, (-20.0, -20.0, 20.0))

        glColor(1.0, 1.0, 1.0)

        ### VBO stuff

        self.vertex_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)
        self.normal_buffer.bind()
        glNormalPointer(GL_FLOAT, 0, None)

        glEnableClientState(GL_VERTEX_ARRAY)
        glEnableClientState(GL_NORMAL_ARRAY)

        glDrawArrays(GL_TRIANGLES, 0, len(self.vertices))

        glDisableClientState(GL_NORMAL_ARRAY)
        glDisableClientState(GL_VERTEX_ARRAY)
        self.normal_buffer.unbind()
        self.vertex_buffer.unbind()

        ### end VBO stuff

        glDisable(GL_LIGHT1)
        glDisable(GL_LIGHT0)

        glPopMatrix()

    def display(self, mode_2d=False):
        glEnable(GL_LIGHTING)
        self.draw_facets()
        glDisable(GL_LIGHTING)

    # ------------------------------------------------------------------------
    # TRANSFORMATIONS
    # ------------------------------------------------------------------------

    def scale(self, factor):
        if factor != self.scaling_factor:
            logging.info('actually scaling vertices')
            self.vertices *= (factor / self.scaling_factor)
            self.scaling_factor = factor
            self.invalidate_bounding_box()
            self.modified = True

    def translate(self, x, y, z):
        self.vertices = vector.translate(self.vertices, x, y, z)
        self.invalidate_bounding_box()
        self.modified = True

    def rotate_rel(self, angle, axis):
开发者ID:kefir-,项目名称:tatlin,代码行数:70,代码来源:actors.py

示例2: instancingdemo

# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import unbind [as 别名]
class instancingdemo(df.demoplate):
    
    def init(self):
        print "OpenGL Information:"
        for prop in ["GL_VENDOR", "GL_RENDERER", "GL_VERSION", "GL_SHADING_LANGUAGE_VERSION"]:
            print "\t%s = %s" % (prop, glGetString(globals()[prop]))

        
        self.campos = np.array([2.5, 1.5, 1.5, 1], dtype = np.float32)
        self.center = np.array([0.0,0.0,0.0,1.0], dtype = np.float32)
        
        self.perspective_mat = None
        self.mvp = None
        # OpenGL Stuff
        glEnable(GL_DEPTH_TEST)
        #glEnable(GL_CULL_FACE)
        glClearColor(1, 1, 1, 0)
        glPointSize(5)
        # Shader Stuff.
        with open('shader.fs') as fs, open('shader.vs') as vs:            
            self.shader = su.Shader(list(vs), list(fs))
        
        self.shader.bindfragdata(0, 'fragcolor')
        self.mvploc = self.shader.uniformlocation('mvp')
        self.objploc = self.shader.uniformlocation('objp')
        self.objoffsetloc = self.shader.uniformlocation('objoffset')
        self.positionloc = self.shader.attributelocation('vs_position')
        self.normalloc = self.shader.attributelocation('vs_normal')
        
        self.loadsquirrel()
        self.buildobjoffsets()
        
    def buildobjoffsets(self):
        objoffset = np.zeros((5,5,5,4), dtype = np.float32)
        start = np.array([-1, -1, -1, 0], dtype = np.float32)
        steps = np.arange(0, 2.1, 0.5, dtype = np.float32)
        for x in range(5):
            for y in range(5):
                for z in range(5):
                    objoffset[x,y,z,] = start + np.array([steps[x], steps[y], steps[z], 0], dtype = np.float32)
        self.shader.use()
        glUniform4fv(self.objoffsetloc, 5 * 5 * 5, objoffset.flatten().tolist())
                
    def loadsquirrel(self):
        # When loading the data, pad the normals to 4 floats (16bytes) since GPUs hate unaligned memory.
        obj = wf.ObjFileParser("squirrel.obj", padnormals = 4)
        self.objscale = 1 / np.max(obj.scale / 2)
        self.objcenter = obj.minpos + (obj.scale / 2)
        
        self.obj_mat = hm.scale(hm.identity(),
                                [self.objscale * 0.2] * 3)
        self.obj_mat = hm.translation(self.obj_mat,
                                      -self.objcenter)

        # Generate a GL compatible indexed vertex buffer for the object
        self.vbdata, ibdata = obj.generateIndexedBuffer([0,1], np.uint16)
        vbdata = self.vbdata
        self.elementnum = np.shape(ibdata)[0]
        # VAO
        self.vertobj = glGenVertexArrays(1)
        glBindVertexArray(self.vertobj)
        # Setup the VBO for the vertex data.
        self.vertbuf = VBO(vbdata, GL_STATIC_DRAW, GL_ARRAY_BUFFER)
        self.vertbuf.bind()
        glVertexAttribPointer(self.positionloc, 4, GL_FLOAT, GL_TRUE, 8 * 4, ctypes.c_void_p(0))
        glVertexAttribPointer(self.normalloc, 4, GL_FLOAT, GL_TRUE, 8 * 4, ctypes.c_void_p(16))
        glEnableVertexAttribArray(self.positionloc)
        glEnableVertexAttribArray(self.normalloc)
        # Indexbuffer
        self.indexbuf = VBO(ibdata, GL_STATIC_DRAW, GL_ELEMENT_ARRAY_BUFFER)
        self.indexbuf.bind()
        
        glBindVertexArray(0)
        self.vertbuf.unbind()
        self.indexbuf.unbind()
        #Animation init...
        self.rotation = 0

                
    def resize(self, width, height):
        glViewport(0, 0, width, height)
        self.perspective_mat = hm.perspective(hm.identity(),
                                              60,
                                              float(width) / height,
                                              0.1,
                                              6.0)
        self.modelview_mat = hm.lookat(hm.identity(),
                                       self.campos,
                                       self.center)
        
        self.mvp = np.dot(self.perspective_mat, self.modelview_mat)
    
    def display(self, timediff):

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        self.shader.use()
        glUniformMatrix4fv(self.objploc, 1, GL_TRUE,
                           np.dot(hm.rotation(hm.identity(), self.rotation, [0,1,0]), self.obj_mat).tolist())
        glUniformMatrix4fv(self.mvploc, 1, GL_TRUE,
                           hm.rotation(self.mvp, self.rotation / 4, [0.577350269189626] * 3).tolist())
#.........这里部分代码省略.........
开发者ID:rpls,项目名称:instancing,代码行数:103,代码来源:main.py

示例3: GcodeModel

# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import unbind [as 别名]

#.........这里部分代码省略.........
        # for every pair of vertices of the model, there are 3 vertices for the arrow
        assert len(self.arrows) == ((len(self.vertices) // 2) * 3), \
            'The 2:3 ratio of model vertices to arrow vertices does not hold.'

        self.max_layers         = len(self.layer_stops) - 1
        self.num_layers_to_draw = self.max_layers
        self.arrows_enabled     = True
        self.initialized        = False

        t_end = time.time()

        logging.info('Initialized Gcode model in %.2f seconds' % (t_end - t_start))
        logging.info('Vertex count: %d' % len(self.vertices))

    def movement_color(self, move):
        """
        Return the color to use for particular type of movement.
        """
        # default movement color is gray
        color = [0.6, 0.6, 0.6, 0.6]

        extruder_on = (move.flags & Movement.FLAG_EXTRUDER_ON or
                       move.delta_e > 0)
        outer_perimeter = (move.flags & Movement.FLAG_PERIMETER and
                           move.flags & Movement.FLAG_PERIMETER_OUTER)

        if extruder_on and outer_perimeter:
            color = [0.0, 0.875, 0.875, 0.6] # cyan
        elif extruder_on and move.flags & Movement.FLAG_PERIMETER:
            color = [0.0, 1.0, 0.0, 0.6] # green
        elif extruder_on and move.flags & Movement.FLAG_LOOP:
            color = [1.0, 0.875, 0.0, 0.6] # yellow
        elif extruder_on:
            color = [1.0, 0.0, 0.0, 0.6] # red

        return color

    # ------------------------------------------------------------------------
    # DRAWING
    # ------------------------------------------------------------------------

    def init(self):
        self.vertex_buffer       = VBO(self.vertices, 'GL_STATIC_DRAW')
        self.vertex_color_buffer = VBO(self.colors.repeat(2, 0), 'GL_STATIC_DRAW') # each pair of vertices shares the color

        if self.arrows_enabled:
            self.arrow_buffer       = VBO(self.arrows, 'GL_STATIC_DRAW')
            self.arrow_color_buffer = VBO(self.colors.repeat(3, 0), 'GL_STATIC_DRAW') # each triplet of vertices shares the color

        self.initialized = True

    def display(self, mode_2d=False):
        glPushMatrix()
        glTranslate(self.offset_x, self.offset_y, 0)
        glEnableClientState(GL_VERTEX_ARRAY)
        glEnableClientState(GL_COLOR_ARRAY)

        self._display_movements(mode_2d)

        if self.arrows_enabled:
            self._display_arrows()

        glDisableClientState(GL_COLOR_ARRAY)
        glDisableClientState(GL_VERTEX_ARRAY)
        glPopMatrix()

    def _display_movements(self, mode_2d=False):
        self.vertex_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)

        self.vertex_color_buffer.bind()
        glColorPointer(4, GL_FLOAT, 0, None)

        if mode_2d:
            glScale(1.0, 1.0, 0.0) # discard z coordinates
            start = self.layer_stops[self.num_layers_to_draw - 1]
            end   = self.layer_stops[self.num_layers_to_draw] - start
        else: # 3d
            start = 0
            end   = self.layer_stops[self.num_layers_to_draw]

        glDrawArrays(GL_LINES, start, end)

        self.vertex_buffer.unbind()
        self.vertex_color_buffer.unbind()

    def _display_arrows(self):
        self.arrow_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)

        self.arrow_color_buffer.bind()
        glColorPointer(4, GL_FLOAT, 0, None)

        start = (self.layer_stops[self.num_layers_to_draw - 1] // 2) * 3
        end   = (self.layer_stops[self.num_layers_to_draw] // 2) * 3

        glDrawArrays(GL_TRIANGLES, start, end - start)

        self.arrow_buffer.unbind()
        self.arrow_color_buffer.unbind()
开发者ID:kefir-,项目名称:tatlin,代码行数:104,代码来源:actors.py

示例4: GcodeModel

# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import unbind [as 别名]

#.........这里部分代码省略.........

                arrow = self.arrow
                # position the arrow with respect to movement
                arrow = vector.rotate(arrow, movement.angle(), 0.0, 0.0, 1.0)
                arrow_list.extend(arrow)

                vertex_color = self.movement_color(movement)
                color_list.append(vertex_color)

            self.layer_stops.append(len(vertex_list))

        self.vertices = numpy.array(vertex_list, 'f')
        self.colors = numpy.array(color_list, 'f')
        self.arrows = numpy.array(arrow_list, 'f')
        # by translating the arrow vertices outside of the loop, we achieve a
        # significant performance gain thanks to numpy. it would be really nice
        # if we could rotate in a similar fashion...
        self.arrows = self.arrows + self.vertices[1::2].repeat(3, 0)

        # for every pair of vertices of the model, there are 3 vertices for the arrow
        assert len(self.arrows) == ((len(self.vertices) // 2) * 3), \
            'The 2:3 ratio of model vertices to arrow vertices does not hold.'

    def movement_color(self, movement):
        """
        Return the color to use for particular type of movement.
        """
        if not movement.extruder_on:
            color = self.color_map['gray']
        elif movement.is_loop:
            color = self.color_map['yellow']
        elif movement.is_perimeter and movement.is_perimeter_outer:
            color = self.color_map['cyan']
        elif movement.is_perimeter:
            color = self.color_map['green']
        else:
            color = self.color_map['red']

        return color

    # ------------------------------------------------------------------------
    # DRAWING
    # ------------------------------------------------------------------------

    def init(self):
        self.vertex_buffer       = VBO(self.vertices, 'GL_STATIC_DRAW')
        self.vertex_color_buffer = VBO(self.colors.repeat(2, 0), 'GL_STATIC_DRAW') # each pair of vertices shares the color

        if self.arrows_enabled:
            self.arrow_buffer       = VBO(self.arrows, 'GL_STATIC_DRAW')
            self.arrow_color_buffer = VBO(self.colors.repeat(3, 0), 'GL_STATIC_DRAW') # each triplet of vertices shares the color

        self.initialized = True

    def display(self, mode_2d=False):
        glEnableClientState(GL_VERTEX_ARRAY)
        glEnableClientState(GL_COLOR_ARRAY)

        self._display_movements(mode_2d)

        if self.arrows_enabled:
            self._display_arrows()

        glDisableClientState(GL_COLOR_ARRAY)
        glDisableClientState(GL_VERTEX_ARRAY)

    def _display_movements(self, mode_2d=False):
        self.vertex_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)

        self.vertex_color_buffer.bind()
        glColorPointer(4, GL_FLOAT, 0, None)

        if mode_2d:
            glScale(1.0, 1.0, 0.0) # discard z coordinates
            start = self.layer_stops[self.num_layers_to_draw - 1]
            end   = self.layer_stops[self.num_layers_to_draw] - start
        else: # 3d
            start = 0
            end   = self.layer_stops[self.num_layers_to_draw]

        glDrawArrays(GL_LINES, start, end)

        self.vertex_buffer.unbind()
        self.vertex_color_buffer.unbind()

    def _display_arrows(self):
        self.arrow_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)

        self.arrow_color_buffer.bind()
        glColorPointer(4, GL_FLOAT, 0, None)

        start = (self.layer_stops[self.num_layers_to_draw - 1] // 2) * 3
        end   = (self.layer_stops[self.num_layers_to_draw] // 2) * 3

        glDrawArrays(GL_TRIANGLES, start, end - start)

        self.arrow_buffer.unbind()
        self.arrow_color_buffer.unbind()
开发者ID:jmil,项目名称:tatlin,代码行数:104,代码来源:actors.py

示例5: GcodeModel

# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import unbind [as 别名]

#.........这里部分代码省略.........
        glDisableClientState(GL_COLOR_ARRAY)

        if self.arrows_enabled:
            self._display_layer_markers()

        glDisableClientState(GL_VERTEX_ARRAY)
        glPopMatrix()

    def _display_movements(self, elevation=0, eye_height=0, mode_ortho=False, mode_2d=False):
        self.vertex_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)

        self.vertex_color_buffer.bind()
        glColorPointer(4, GL_FLOAT, 0, None)

        if mode_2d:
            glScale(1.0, 1.0, 0.0) # discard z coordinates
            start = self.layer_stops[self.num_layers_to_draw - 1]
            end   = self.layer_stops[self.num_layers_to_draw]

            glDrawArrays(GL_LINES, start, end - start)

        elif mode_ortho:
            if elevation >= 0:
                # draw layers in normal order, bottom to top
                start = 0
                end   = self.layer_stops[self.num_layers_to_draw]

                glDrawArrays(GL_LINES, start, end - start)

            else:
                # draw layers in reverse order, top to bottom
                stop_idx = self.num_layers_to_draw - 1
                while stop_idx >= 0:
                    start = self.layer_stops[stop_idx]
                    end   = self.layer_stops[stop_idx + 1]

                    glDrawArrays(GL_LINES, start, end - start)

                    stop_idx -= 1

        else: # 3d projection mode
            reverse_threshold_layer = self._layer_up_to_height(eye_height - self.offset_z)

            if reverse_threshold_layer >= 0:
                # draw layers up to (and including) the threshold in normal order, bottom to top
                normal_layers_to_draw = min(self.num_layers_to_draw, reverse_threshold_layer + 1)
                start = 0
                end   = self.layer_stops[normal_layers_to_draw]

                glDrawArrays(GL_LINES, start, end - start)

            if reverse_threshold_layer + 1 < self.num_layers_to_draw:
                # draw layers from the threshold in reverse order, top to bottom
                stop_idx = self.num_layers_to_draw - 1
                while stop_idx > reverse_threshold_layer:
                    start = self.layer_stops[stop_idx]
                    end   = self.layer_stops[stop_idx + 1]

                    glDrawArrays(GL_LINES, start, end - start)

                    stop_idx -= 1

        self.vertex_buffer.unbind()
        self.vertex_color_buffer.unbind()

    def _layer_up_to_height(self, height):
        """Return the index of the last layer lower than height."""
        for idx in range(len(self.layer_heights) - 1, -1, -1):
            if self.layer_heights[idx] < height:
                return idx

        return 0

    def _display_arrows(self):
        self.arrow_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)

        self.arrow_color_buffer.bind()
        glColorPointer(4, GL_FLOAT, 0, None)

        start = (self.layer_stops[self.num_layers_to_draw - 1] // 2) * 3
        end   = (self.layer_stops[self.num_layers_to_draw] // 2) * 3

        glDrawArrays(GL_TRIANGLES, start, end - start)

        self.arrow_buffer.unbind()
        self.arrow_color_buffer.unbind()

    def _display_layer_markers(self):
        self.layer_marker_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)

        start = self.layer_marker_stops[self.num_layers_to_draw - 1]
        end   = self.layer_marker_stops[self.num_layers_to_draw]

        glColor4f(0.6, 0.6, 0.6, 0.6)
        glDrawArrays(GL_TRIANGLES, start, end - start)

        self.layer_marker_buffer.unbind()
开发者ID:SHINOTECH,项目名称:tatlin,代码行数:104,代码来源:actors.py

示例6: MSGLCanvas2D

# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import unbind [as 别名]

#.........这里部分代码省略.........
    
    
    def normalizeAngle(self,angle):
            while (angle < 0):
                    angle += 360 * 16
            while (angle > 360 * 16):
                    angle -= 360 * 16


########DRAWING METHODS##################################################

    def drawLine(self, point_, point):
        glBegin(GL_LINES)
        glVertex2d(point_.x(), point_.y())
        glVertex2d(point.x(), point.y())
        glEnd()
    
    def drawRect(self, p_1, p_2, p_3=None, p_4 = None):
        pass
    
    def drawOnePoint(self, point, colour= Qt.yellow):
        pass
    
    def scatterPlot(self):
        """ Draw Data (x, y)"""
        if self.vertexes is not None and self.colors is not None:
            self.vertexes.bind()
            glEnableClientState(GL_VERTEX_ARRAY)
            glVertexPointerf(self.vertexes)
            self.colors.bind()                  
            glEnableClientState(GL_COLOR_ARRAY)
            glColorPointerf(self.colors)
            glDrawArrays(GL_LINES, 0, len(self.vertexes))
            self.vertexes.unbind()
            self.colors.unbind()
            #self.textures.unbind()
            glDisableClientState(GL_VERTEX_ARRAY)
            glDisableClientState(GL_COLOR_ARRAY)
    
    def spectrumPlot(self, points):
        pass
    
    def histogramPlot(self, points, bin = 5.):
        pass
        
    def barPlot(points, width =2.):pass

    


########MOUSE AND KEYBOARDS EVENTS###########################################################################
    
    
    def wheelEvent(self, event):
        if event.delta() >0:
            self.zoom_ -= .05    
        else:
            self.zoom_ += .05
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(-self.corner_*self.zoom_, 
                   self.corner_*self.zoom_, 
                   -self.corner_*self.zoom_, 
                   self.corner_*self.zoom_)
        self.updateGL()
        glMatrixMode(GL_MODELVIEW)
开发者ID:jerkos,项目名称:metms,代码行数:70,代码来源:MetGLCanvas2D.py

示例7: glGetUniformLocation

# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import unbind [as 别名]
 prog = shaderutil.createProgram("./shader.vs", "./shader.fs")
 mvploc = glGetUniformLocation(prog, "mvp")
 positionloc = glGetAttribLocation(prog, "vs_position")
 colorloc = glGetAttribLocation(prog, "vs_color")    
 
 # Setup VAO
 vertobj = glGenVertexArrays(1)
 glBindVertexArray(vertobj)
 # Setup the VBO (using the fancy VBO Object from pyopengl, doing it "manually" would also be a possibility)
 vertbuf = VBO(cubedata, GL_STATIC_DRAW)
 vertbuf.bind()
 glEnableVertexAttribArray(positionloc)
 glEnableVertexAttribArray(colorloc)
 glVertexAttribPointer(positionloc, 4, GL_FLOAT, GL_TRUE, 8 * 4, vertbuf+0) # "+0" since we need to create an offset.
 glVertexAttribPointer(colorloc, 4, GL_FLOAT, GL_TRUE, 8 * 4, vertbuf+16) # 4 * 4 Bytes per float.
 vertbuf.unbind() # We can unbind the VBO, since it's linked to the VAO
 # glBindVertexArray(0)
 
 running = True
 t = time.time()
 rotation = 0.0
 while running:
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glUseProgram(prog)
     glUniformMatrix4fv(mvploc, 1, GL_TRUE, hm.rotation(mvp, rotation,[0,1,0]).tolist())
     # glBindVertexArray(vertobj)
     glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)
     glDrawArrays(GL_POINTS, 0, 14)
     glfwSwapBuffers()
     # glfwPollEvents() # This would poll for key/mouse events manually.
     # Do the rotation thing...
开发者ID:mkhoeini,项目名称:glfwexample,代码行数:33,代码来源:main.py

示例8: __init__

# 需要导入模块: from OpenGL.arrays.vbo import VBO [as 别名]
# 或者: from OpenGL.arrays.vbo.VBO import unbind [as 别名]
class model:

    ''' class for STL file / 3d model '''

    def __init__(self, stl_data, batchh=None):
        ''' initialise model data'''
        vert, norm = stl_data
        self.vertices = numpy.array(vert, dtype=GLfloat)
        self.normals = numpy.array(norm, dtype=GLfloat)
        self.vertex_buffer = VBO(self.vertices, 'GL_STATIC_DRAW')
        self.normal_buffer = VBO(self.normals, 'GL_STATIC_DRAW')

        # calculate model scale
        self.corner = self.vertices.transpose().min(1)
        self.corner2 = self.vertices.transpose().max(1)
        self.scale = abs(self.corner) + abs(self.corner2)
        self.scale = max(self.scale[0], self.scale[1], self.scale[2])
        print 'STL File loaded in: ', loadtime
        print 'Object information'
        print 'corner 1: ', self.corner
        print 'corner 2: ', self.corner2
        print 'object scale: ', self.scale

    def draw(self):
        ''' draw model on screen '''
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()

        # center the model
        glTranslate(window.width/2, window.height/2, -150)

        # scale the model
        glScale(150/self.scale, 150/self.scale, 150/self.scale)

        # draw grid and coordinate lines
        draw_grid()
        draw_xyz(0, 0, 0, -20, -20)

        # demo rotation
        glRotate(rot, 1, 0, 0)
        glRotate(rot2, 0, 1, 0)
        glRotate(rot3, 0, 0, 1)

        self.vertex_buffer.bind()
        glVertexPointer(3, GL_FLOAT, 0, None)
        self.normal_buffer.bind()
        glNormalPointer(GL_FLOAT, 0, None)

        glEnableClientState(GL_VERTEX_ARRAY)
        glEnableClientState(GL_NORMAL_ARRAY)

        glDrawArrays(GL_TRIANGLES, 0, len(self.vertices))

        glDisableClientState(GL_NORMAL_ARRAY)
        glDisableClientState(GL_VERTEX_ARRAY)

        self.normal_buffer.unbind()
        self.vertex_buffer.unbind()

        glPopMatrix()
开发者ID:vluttine,项目名称:3d-printer-robot,代码行数:63,代码来源:gui.py


注:本文中的OpenGL.arrays.vbo.VBO.unbind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。