def initializeGL(self, gls: 'GLShared') -> None: self.gls = gls assert self.gls is not None # Basic solid-color program self.prog = self.gls.shader_cache.get("vert2", "frag1") self.mat_loc = GL.glGetUniformLocation(self.prog.program, "mat") self.col_loc = GL.glGetUniformLocation(self.prog.program, "color") # Build a VBO for rendering square "drag-handles" self.vbo_handles_ar = numpy.ndarray((4, ), dtype=[("vertex", numpy.float32, 2)]) self.vbo_handles_ar["vertex"] = numpy.array(corners) * HANDLE_HALF_SIZE self.vbo_handles = VBO(self.vbo_handles_ar, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER) self.vao_handles = VAO() with self.vbo_handles, self.vao_handles: VBOBind(self.prog.program, self.vbo_handles_ar.dtype, "vertex").assign() # Build a VBO/VAO for the perimeter # We don't initialize it here because it is updated every render # 4 verticies for outside perimeter # 6 verticies for each dim self.vbo_per_dim_ar = numpy.zeros(16, dtype=[("vertex", numpy.float32, 2)]) self.vbo_per_dim = VBO(self.vbo_per_dim_ar, GL.GL_DYNAMIC_DRAW, GL.GL_ARRAY_BUFFER) self.vao_per_dim = VAO() with self.vao_per_dim, self.vbo_per_dim: VBOBind(self.prog.program, self.vbo_per_dim_ar.dtype, "vertex").assign()
def __init__(self, draw_type=GL_QUADS): self.count = 0 self.color_data = [] self.position_data = [] self.color_buffer = VBO(np.array([])) self.position_buffer = VBO(np.array([])) self.draw_type = draw_type
def _initializeGL(self): self.initialized = True self.__filled_vao = VAO() self.__outline_vao = VAO() with self.__filled_vao, self.parent._sq_vbo: vbobind(self.parent._filled_shader, self.parent._sq_vbo.data.dtype, "vertex").assign() # Use a fake array to get a zero-length VBO for initial binding filled_instance_array = numpy.ndarray( 0, dtype=self.parent._filled_instance_dtype) self.filled_instance_vbo = VBO(filled_instance_array) with self.__filled_vao, self.filled_instance_vbo: vbobind(self.parent._filled_shader, self.parent._filled_instance_dtype, "pos", div=1).assign() vbobind(self.parent._filled_shader, self.parent._filled_instance_dtype, "r", div=1).assign() vbobind(self.parent._filled_shader, self.parent._filled_instance_dtype, "r_inside_frac_sq", div=1).assign() vbobind(self.parent._filled_shader, self.parent._filled_instance_dtype, "color", div=1).assign() with self.__outline_vao, self.parent._outline_vbo: vbobind(self.parent._outline_shader, self.parent._outline_vbo.data.dtype, "vertex").assign() # Build instance for outline rendering # We don't have an inner 'r' for this because we just do two instances per vertex # Use a fake array to get a zero-length VBO for initial binding outline_instance_array = numpy.ndarray( 0, dtype=self.parent._outline_instance_dtype) self.outline_instance_vbo = VBO(outline_instance_array) with self.__outline_vao, self.outline_instance_vbo: vbobind(self.parent._outline_shader, self.parent._outline_instance_dtype, "pos", div=1).assign() vbobind(self.parent._outline_shader, self.parent._outline_instance_dtype, "r", div=1).assign() vbobind(self.parent._outline_shader, self.parent._outline_instance_dtype, "color", div=1).assign()
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 prepareColor(self): """Prepare the colors for the shader.""" # # This should probably be moved to Actor # if self.highlight: # we set single highlight color in shader # Currently do everything in Formex model # And we always need this one self.avbo = VBO(self.fcoords) self.useObjectColor = 1 self.objectColor = np.array(colors.red) elif self.color is not None: #print("COLOR",self.color) if self.color.ndim == 1: # here we only accept a single color for front and back # different colors should have been handled before self.useObjectColor = 1 self.objectColor = self.color elif self.color.ndim == 2: self.useObjectColor = 0 self.vertexColor = at.multiplex(self.color, self.object.nplex()) #pf.debug("Multiplexing colors: %s -> %s " % (self.color.shape, self.vertexColor.shape),pf.DEBUG.OPENGL2) elif self.color.ndim == 3: self.useObjectColor = 0 self.vertexColor = self.color if self.vertexColor is not None: #print("Shader suffix:[%s]" % pf.options.shader) if pf.options.shader == 'alpha': self.alpha = 0.5 if self.vertexColor.shape[-1] == 3: # Expand to 4 !!! self.vertexColor = at.growAxis(self.vertexColor, 1, fill=0.5) self.cbo = VBO(self.vertexColor.astype(float32)) if pf.options.shader == 'alpha': size_report("Created cbo VBO", self.cbo) self.rgbamode = self.useObjectColor == 0 and self.vertexColor.shape[ -1] == 4 #### TODO: should we make this configurable ?? # # !!!!!!!!!!!! Fix a bug with AMD cards !!!!!!!!!!!!!!! # # it turns out that some? AMD? cards do not like an unbound cbo # even if that attribute is not used in the shader. # Creating a dummy color buffer seems to solve that problem # if self.cbo is None: self.cbo = VBO(np.array(colors.red))
def init(self): """ Create vertex buffer objects (VBOs). """ self.vertex_buffer = VBO(self.vertices, 'GL_STATIC_DRAW') if self.normal_data_empty(): logging.info('STL model has no normal data') self.normals = self.calculate_normals() self.normal_buffer = VBO(self.normals, 'GL_STATIC_DRAW') self.initialized = True
def __init__(self, width, height): vertices = [-1, -1, 0, 1, -1, 0, 1, 1, 0, 1, 1, 0, -1, 1, 0, -1, -1, 0] self.num_vertices = len(vertices) // 3 self.vbo = VBO(np.array(vertices, dtype=np.float32), GL_STATIC_DRAW, GL_ARRAY_BUFFER) self.vao = glGenVertexArrays(1) glBindVertexArray(self.vao) self.vbo.bind() glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * 4, self.vbo) glEnableVertexAttribArray(0) glBindVertexArray(0) self.shader = compile_shader(self.vs_source, self.fs_source) self.texture = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, self.texture) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, width, height)
def initializeGL(self, gls: 'GLShared', width: int, height: int) -> None: self.__width = width self.__height = height # Initialize (but don't fill) the Color LUT self.__texture_colors = Texture(debug_name="Layer Color LUT") with self.__texture_colors.on(GL.GL_TEXTURE_1D): GL.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST) GL.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) GL.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) GL.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE) # Compositing shader and geometry self.__composite_shader = gls.shader_cache.get( "layer_composite_vert", "layer_composite_frag", fragment_bindings={"final_color": 0}) ar = self.__get_vbo_data() self.__composite_vao = VAO(debug_name="Compositor Quad VAO") self.__composite_vbo = VBO(ar, GL.GL_STATIC_DRAW) GL.glObjectLabel(GL.GL_BUFFER, int(self.__composite_vbo), -1, "Compositor Quad VBO") with self.__composite_vao: self.__composite_vbo.bind() VBOBind(self.__composite_shader.program, ar.dtype, "vertex").assign() VBOBind(self.__composite_shader.program, ar.dtype, "texpos").assign()
def points_random_3d(count, range_x=(-10.0, 10.0), range_y=(-10.0, 10.0), range_z=(-10.0, 10.0), seed=None): """ Generates random positions :param count: Number of points :param range_x: min-max range for x axis :param range_y: min-max range for y axis :param range_z: min-max range for z axis :param seed: The random seed to be used """ random.seed(seed) def gen(): for i in range(count): yield random.uniform(*range_x) yield random.uniform(*range_y) yield random.uniform(*range_z) data = numpy.fromiter(gen(), count=count * 3, dtype=numpy.float32) pos = VBO(data) vao = VAO("geometry:points_random_3d", mode=GL.GL_POINTS) vao.add_array_buffer(GL.GL_FLOAT, pos) vao.map_buffer(pos, "in_position", 3) vao.build() return vao
def __init__(self, src, actor=None): Component.__init__(self, actor) # TODO Include a mesh name (e.g. 'Dragon') as ID as well as src (e.g. '../res/models/Dragon.obj') self.src = src self.filepath = Context.getInstance().getResourcePath('models', src) # OpenGL version-dependent code (NOTE assumes major version = 3) self.vao = None if Context.getInstance().GL_version_minor > 0: # 3.1 (or greater?) self.vao = glGenVertexArrays(1) else: # 3.0 (or less?) self.vao = GLuint(0) glGenVertexArrays(1, self.vao) glBindVertexArray(self.vao) self.loadModel(self.filepath) self.vbo = VBO(self.meshData, GL_STATIC_DRAW) self.vbo.bind() glEnableVertexAttribArray(0) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * 4, self.vbo + 0) glEnableVertexAttribArray(1) glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * 4, self.vbo + 12) self.ebo = glGenBuffers(1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.ebo) glBufferData(GL_ELEMENT_ARRAY_BUFFER, len(self.elements) * 4, self.elements, GL_STATIC_DRAW)
def test_gl(): glClearColor(1, 0, 0, 0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) print("Error before compilation?", glGetError()) shader = shaders.compileProgram( shaders.compileShader( """#version 130 attribute vec3 position; void main() { gl_Position = vec4(position, 0); }""", GL_VERTEX_SHADER), shaders.compileShader( """#version 130 void main() { gl_FragColor = vec4(0,1,0,.5); }""", GL_FRAGMENT_SHADER), ) vbo = VBO(array([ (0, 1, 0), (1, -1, 0), (-1, -1, 0), ], dtype="f")) position_location = glGetAttribLocation(shader, "position") stride = 3 * 4 with vbo: with shader: glEnableVertexAttribArray(position_location) stride = 3 * 4 glVertexAttribPointer(position_location, 3, GL_FLOAT, False, stride, vbo) glDrawArrays(GL_TRIANGLES, 0, 3)
def initializeGL(self): self.vbo = VBO(numpy.ndarray(0, dtype=self.__text_render.buffer_dtype), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER) self.vao = VAO() with self.vao, self.vbo: self.__text_render.b1.assign() self.__text_render.b2.assign()
def __init__(self, data, parent=None, **kw): """ Constructor, initialization """ QGLWidget.__init__(self, parent) self.setFormat(QGLFormat(QGL.SampleBuffers)) self.setMinimumSize(500, 300) #300 self.setMouseTracking(True) self.setFocusPolicy(Qt.StrongFocus) self.data = data vertexes = [] colors = [] from utils.misc import IceAndFire maxY = max(map(max, [log10(el.y_data) for el in data])) maxX = max(map(max, [el.x_data for el in data])) rtmax = max([z.rtmin for z in data]) for el in data: for i, x in enumerate(el.x_data): c = IceAndFire.getQColor(log10(el.y_data[i]) / maxY) colors.append(c) vertexes.append([(x * 2 * self.corner_) / maxX, (el.rt * 2 * self.corner_) / rtmax]) from OpenGL.arrays.vbo import VBO self.vertexes = VBO(array(vertexes, 'f')) self.colors = VBO(array(colors, 'f')) self.mode = "None" # "ZOOMING", "PANNING", "NONE" self.lastpos = QPoint() self.counter_trans_x = 0 self.counter_trans_y = 0 self.defaultColors = { 'ticks': (0., 0., 0., 0.), 'axes': (0., 0., 0., 0.), 'curves': (0., 0., 1., 0.), 'backgroundColor': (1., 1., 1., 1.) } #self.axes=self.drawAxes() self.transformationMatrix = self.setupTransformationMatrix( self.width(), self.height())
def prepareSubelems(self): """Create an index buffer to draw subelements This is always used for nplex > 3, but also to draw the edges for nplex=3. """ if self.ibo is None and self.subelems is not None: self.ibo = VBO(self.subelems.astype(int32), target=GL.GL_ELEMENT_ARRAY_BUFFER)
def texturesCalc(self): from OpenGL.arrays.vbo import VBO basis = [[0., 0.], [0., 1.]] hola = [] length = len(self.vertexes) for i in range(length / 2): hola += basis return VBO(array(hola))
def initializeGL(self): # Working VBO that will contain glyph data self.vbo = VBO(numpy.ndarray(0, dtype=self.text_render.buffer_dtype), GL.GL_DYNAMIC_DRAW, GL.GL_ARRAY_BUFFER) self.vao = VAO() with self.vao, self.vbo: self.text_render.b1.assign() self.text_render.b2.assign() self.__vbo_needs_update = True
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 __init__(self, dtype, shader, glhint): self.__dtype = dtype self.vao = VAO() self.batch_vbo = VBO(numpy.array([], dtype=dtype), glhint) with self.vao, self.batch_vbo: vbobind(shader, dtype, "vertex").assign() self.clear()
def initializeGL(self): self.__vao = VAO() # Lookup for vertex positions self.__vert_vbo_dtype = numpy.dtype([("vertex", numpy.float32, 2)]) self.__vert_vbo = VBO(numpy.ndarray(0, dtype=self.__vert_vbo_dtype), GL.GL_DYNAMIC_DRAW) self.__vert_vbo_current = False self.__index_vbo_dtype = numpy.uint32 self.__index_vbo = VBO(numpy.ndarray(0, dtype=self.__index_vbo_dtype), GL.GL_DYNAMIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER) self.__index_vbo_current = False self.__shader = self.__gls.shader_cache.get("vert2", "frag1") with self.__vao, self.__vert_vbo: vbobind(self.__shader, self.__vert_vbo_dtype, "vertex").assign() self.__index_vbo.bind()
def initializeGL(self, gls, width, height): # Get shader self.__shader = gls.shader_cache.get("basic_fill_vert", "basic_fill_frag") self.__vbo = VBO(numpy.ndarray(0, dtype=self.__vbo_dtype), GL.GL_STATIC_DRAW) self.__vao = VAO() # Create array of lines sufficient to fill screen self.resize(width, height)
def initializeGL(self, glshared): self._filled_shader = glshared.shader_cache.get( "via_filled_vertex_shader", "via_filled_fragment_shader") self._outline_shader = glshared.shader_cache.get( "via_outline_vertex_shader", "frag1") # Build geometry for filled rendering using the frag shader for circle borders filled_points = [ ((-1, -1), ), ((1, -1), ), ((-1, 1), ), ((1, 1), ), ] ar = numpy.array(filled_points, dtype=[("vertex", numpy.float32, 2)]) self._sq_vbo = VBO(ar, GL.GL_STATIC_DRAW) # Build geometry for outline rendering outline_points = [] for i in numpy.linspace(0, math.pi * 2, N_OUTLINE_SEGMENTS, False): outline_points.append(((math.cos(i), math.sin(i)), )) outline_points_array = numpy.array(outline_points, dtype=[("vertex", numpy.float32, 2) ]) self._outline_vbo = VBO(outline_points_array, GL.GL_STATIC_DRAW) self._filled_instance_dtype = numpy.dtype([ ("pos", numpy.float32, 2), ("r", numpy.float32, 1), ("r_inside_frac_sq", numpy.float32, 1), ("color", numpy.float32, 4) ]) self._outline_instance_dtype = numpy.dtype([("pos", numpy.float32, 2), ("r", numpy.float32, 1), ("color", numpy.float32, 4) ]) for i in self.__batches: i._initializeGL()
def prepareTexture(self): """Prepare texture and texture coords""" if self.useTexture == 1: if self.texcoords.ndim == 2: #curshape = self.texcoords.shape self.texcoords = at.multiplex(self.texcoords, self.object.nelems(), axis=-2) #print("Multiplexing texture coords: %s -> %s " % (curshape, self.texcoords.shape)) self.tbo = VBO(self.texcoords.astype(float32)) self.texture.activate()
def initializeGL(self) -> None: self.__dtype = numpy.dtype([('vertex', numpy.float32, 2)]) self.__shader = self.__view.gls.shader_cache.get( "basic_fill_vert", "basic_fill_frag") self._va_vao = VAO() self._va_batch_vbo = VBO(numpy.array([], dtype=self.__dtype), GL.GL_STREAM_DRAW) GL.glObjectLabel(GL.GL_BUFFER, int(self._va_batch_vbo), -1, "Hairline VA batch VBO") with self._va_vao, self._va_batch_vbo: VBOBind(self.__shader.program, self.__dtype, "vertex").assign()
def initializeGL(self, gls: 'GLShared') -> None: self.gls = gls # zap the cached text on GL reinitialize (VBO handles / etc are likely invalid) self.textCached = {} # basic solid-color shader self.prog = gls.shader_cache.get("vert2", "frag1") # Construct a VBO containing all the points we need for rendering dtype = numpy.dtype([("vertex", numpy.float32, 2)]) points = numpy.ndarray((16, ), dtype=dtype) # keypoint display: edge half-dimension in pixels self.d1 = d1 = 20 # keypoint display: text-area "flag" height in pixels th = 16 # keypoint display: right-edge offset of text flag in pixels tw = 6 points["vertex"] = [ # Lines making up keypoint cross (rendered with GL_LINES) (-d1, -d1), (-d1, d1), (-d1, d1), (d1, d1), (d1, d1), (d1, -d1), (d1, -d1), (-d1, -d1), (0, -d1), (0, d1), (-d1, 0), (d1, 0), # flag (rendered with GL_TRIANGLE_STRIP) (-d1, -d1), (-d1, -d1 - th), (-tw, -d1), (-tw, -d1 - th) ] # Pack it all into a VBO self.handle_vbo = VBO(points, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER) # and bind the program for rendering self.handle_vao = VAO() with self.handle_vao, self.handle_vbo: VBOBind(self.prog.program, dtype, "vertex").assign()
def initGL(self, gls: 'GLShared') -> None: self._tex = Texture() # Setup the basic texture parameters with self._tex.on(GL.GL_TEXTURE_2D): GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE) GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE) # numpy packs data tightly, whereas the openGL default is 4-byte-aligned # fix line alignment to 1 byte so odd-sized textures load right GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) # Download the data to the buffer. cv2 stores data in BGR format GL.glTexImage2D( GL.GL_TEXTURE_2D, 0, GL.GL_RGB, self.im.shape[1], self.im.shape[0], 0, GL.GL_BGR, GL.GL_UNSIGNED_BYTE, self.im.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))) self.prog = gls.shader_cache.get("image_vert", "image_frag") ar = numpy.ndarray( (4, ), dtype=[("vertex", numpy.float32, 2), ("texpos", numpy.float32, 2)]) # type: ignore sca = max(self.im.shape[0], self.im.shape[1]) x = self.im.shape[1] / float(sca) y = self.im.shape[0] / float(sca) ar["vertex"] = [(-x, -y), (-x, y), (x, -y), (x, y)] ar["texpos"] = [(0, 0), (0, 1), (1, 0), (1, 1)] self.b1 = VBOBind(self.prog.program, ar.dtype, "vertex") self.b2 = VBOBind(self.prog.program, ar.dtype, "texpos") self.vbo = VBO(ar, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER) self.mat_loc = GL.glGetUniformLocation(self.prog.program, "mat") self.tex1_loc = GL.glGetUniformLocation(self.prog.program, "tex1") self.vao = VAO() with self.vbo, self.vao: self.b1.assign() self.b2.assign()
def _prepareNormals(self, canvas): """Prepare the normals buffer object for the actor. The normals buffer object depends on the renderer settings: lighting, avgnormals """ #if renderer.canvas.settings.lighting: if True: if canvas.settings.avgnormals: normals = self.b_avgnormals else: normals = self.b_normals # Normals are always full fcoords size #print("SIZE OF NORMALS: %s; COORDS: %s" % (normals.size,self.fcoords.size)) self.nbo = VBO(normals)
def addHighlightPoints(self, sel=None): """Add a highlight for the selected points. Default is all.""" self.removeHighlight() vbo = VBO(self.object.points()) self._highlight = Drawable(self, vbo=vbo, subelems=sel.reshape(-1, 1), name=self.name + "_highlight", linewidth=10, lighting=False, color=np.array(colors.yellow), opak=True, pointsize=10, offset=1.0) # Put at the front to make visible self.drawable.insert(0, self._highlight)
def initializeGL(self, gls: 'GLShared') -> None: self.shader = gls.shader_cache.get("vert2", "frag1") self.vao = VAO() self.vbo = VBO(bytes(), usage=GL.GL_STREAM_DRAW) # bind the shader with self.vao, self.vbo: loc = GL.glGetAttribLocation(self.shader.program, "vertex") assert loc != -1 GL.glEnableVertexAttribArray(loc) # TODO - HACK. AttribPointer is dependent on ABI data layout. # Should be common on all sane archs, but this should be fetched on demand GL.glVertexAttribPointer(loc, 2, GL.GL_FLOAT, False, 8, ctypes.c_void_p(0)) GL.glVertexAttribDivisor(loc, 0)
def __init__(self): self.face = None self.stroker = None self.foreTextures = dict() self.backTextures = dict() # compile rendering program self.renderProgram = GLProgram(_textVertexShaderSource, _textFragmentShaderSource) self.renderProgram.compile_and_link() # make projection uniform self.projectionUniform = GLUniform(self.renderProgram.get_program_id(), 'projection', 'mat4f') self.textColorUniform = GLUniform(self.renderProgram.get_program_id(), 'textColor', 'vec3f') self.textureSizeUniform = GLUniform( self.renderProgram.get_program_id(), 'textureSize', 'vec2f') # create rendering buffer self.vbo = VBO(_get_rendering_buffer(0, 0, 0, 0)) self.vbo.create_buffers() self.vboId = glGenBuffers(1) # initialize VAO self.vao = glGenVertexArrays(1) glBindVertexArray(self.vao) glBindBuffer(GL_ARRAY_BUFFER, self.vboId) self.vbo.bind() self.vbo.copy_data() glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * ctypes.sizeof(ctypes.c_float), ctypes.c_void_p(0)) glEnableVertexAttribArray(0) glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 5 * ctypes.sizeof(ctypes.c_float), ctypes.c_void_p(3 * ctypes.sizeof(ctypes.c_float))) glEnableVertexAttribArray(1) # self.vbo.unbind() glBindVertexArray(0) self.zNear = -1.0 self.zFar = 1.0
def compile_VBO(self, force=False): "Compiles the verticies of all faces into a VBO and saves the ref." if self._VBO_is_compiled and not force: return vbos = [] try: self._VBO_format = self.shapes[0].compile_VBO(force=True) except IndexError: raise ValueError("Shape3D tried to compile to VBO, but it didn't\ have any shapes.") for s in self.shapes: fmt = s.compile_VBO() if fmt != self._VBO_format and fmt is not None: # TODO figure out a good way of filling in the blanks? raise ValueError("While compiling a Shape3D to VBO, a Shape2D\ format mismatched with the format for the other shapes.") vbos.append(s._VBO) self._VBO = VBO(np.concatenate(vbos)) self._VBO_is_compiled = True