Python bgl.GL_UNSIGNED_BYTE Examples
The following are 2
code examples of bgl.GL_UNSIGNED_BYTE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bgl
, or try the search function
.
Example #1
Source File: ui.py From addon_common with GNU General Public License v3.0 | 5 votes |
def buffer_image(self): if not self.loaded: return if self.buffered: return if self.deleted: return bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture_id) bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE) bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST) bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR) # texbuffer = bgl.Buffer(bgl.GL_BYTE, [self.width,self.height,self.depth], image_data) image_size = self.image_width*self.image_height*self.image_depth texbuffer = bgl.Buffer(bgl.GL_BYTE, [image_size], self.image_flat) bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, self.image_width, self.image_height, 0, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, texbuffer) del texbuffer bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) self.buffered = True
Example #2
Source File: opengl_utils.py From Blender-Addon-Photogrammetry-Importer with MIT License | 4 votes |
def render_opengl_image(image_name, cam, point_size): draw_manager = DrawManager.get_singleton() coords, colors = draw_manager.get_coords_and_colors() scene = bpy.context.scene render = bpy.context.scene.render width = render.resolution_x height = render.resolution_y # TODO Provide an option to render from the 3D view perspective # width = bpy.context.region.width # height = bpy.context.region.height offscreen = gpu.types.GPUOffScreen(width, height) with offscreen.bind(): bgl.glPointSize(point_size) #bgl.glClear(bgl.GL_COLOR_BUFFER_BIT) #bgl.glClear(bgl.GL_DEPTH_BUFFER_BIT) view_matrix = cam.matrix_world.inverted() projection_matrix = cam.calc_matrix_camera( bpy.context.evaluated_depsgraph_get(), x=width, y=height) perspective_matrix = projection_matrix @ view_matrix gpu.matrix.load_matrix(perspective_matrix) gpu.matrix.load_projection_matrix(Matrix.Identity(4)) shader = gpu.shader.from_builtin('3D_FLAT_COLOR') shader.bind() batch = batch_for_shader(shader, "POINTS", {"pos": coords, "color": colors}) batch.draw(shader) buffer = bgl.Buffer(bgl.GL_BYTE, width * height * 4) bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer) offscreen.free() image = create_image_lazy(image_name, width, height) copy_buffer_to_pixel(buffer, image)