indexing description: "Two dimensional texture" date: "$Date$" revision: "$Revision$" class EMGL_TEXTURE_2D[F -> EMGL_FORMAT create default_create end] inherit EMGL_TEXTURE[F] EMGLU_FUNCTIONS export {NONE} all undefine default_create end EM_CONSTANTS export {NONE} all undefine default_create end EM_SHARED_BITMAP_FACTORY export {NONE} all undefine default_create end EM_SHARED_ERROR_HANDLER export {NONE} all undefine default_create end create make_empty, make_from_surface, make_from_surface_stretched feature {NONE} -- Initialization make_empty( width, height: INTEGER ) is -- Create a new EMGL_TEXTURE_2D object. do default_create bind_and_save_old tex_image2d( 0, width, height, 0, em_gl_rgb, em_gl_unsigned_byte, default_pointer ) set_texture_min_filter_internal( em_gl_linear ) set_texture_mag_filter_internal( em_gl_linear ) bind_old_id end make_from_surface( a_surface: EM_SURFACE ) is -- Create a new EMGL_TEXTURE_2D object from a bitmap -- This creation procedure does NOT stretch a texture -- that is too small require valid_bitmap: a_surface/=void local tmp_surface: EM_SURFACE height, width: INTEGER error: INTEGER do default_create width := next_power_of_two( a_surface.width ) height := next_power_of_two( a_surface.height ) bitmap_factory.create_empty_open_gl_bitmap (width, height) tmp_surface := bitmap_factory.last_bitmap -- Transparent texture fix if a_surface.is_alpha_transparency_enabled then a_surface.disable_alpha_transparency tmp_surface.blit_surface (a_surface, 0, 0) a_surface.enable_alpha_transparency else tmp_surface.blit_surface (a_surface, 0, 0) end -- clear any opengl error from until gl_get_error_external = 0 loop end bind_and_save_old set_texture_min_filter_internal( em_gl_linear ) set_texture_mag_filter_internal( em_gl_linear ) gl_tex_image2d_external ( target, 0, internal_format, width, height, 0, em_gl_rgba, em_gl_unsigned_byte, tmp_surface.pixels ) error := gl_get_error_external if error /= 0 then Error_handler.raise_warning (Error_handler.Em_error_generate_texture, [emglu_error_string( error )]) end bind_old_id end make_from_surface_stretched( a_surface: EM_SURFACE ) is -- Create a new EMGL_TEXTURE_2D object from a bitmap require valid_bitmap: a_surface/=void local tmp_surface: EM_SURFACE height, width: INTEGER error: INTEGER do default_create width := next_power_of_two( a_surface.width ) height := next_power_of_two( a_surface.height ) bitmap_factory.create_stretched_bitmap ( a_surface, (width+0.001)/a_surface.width, (height+0.001)/a_surface.height) tmp_surface := Bitmap_factory.last_bitmap bitmap_factory.create_empty_open_gl_bitmap (width, height) -- Transparent texture fix tmp_surface.disable_alpha_transparency bitmap_factory.last_bitmap.blit_surface (tmp_surface, 0, 0) tmp_surface := bitmap_factory.last_bitmap -- clear any opengl error from until gl_get_error_external = 0 loop end bind_and_save_old set_texture_min_filter_internal( em_gl_linear ) set_texture_mag_filter_internal( em_gl_linear ) gl_tex_image2d_external ( target, 0, internal_format, width, height, 0, em_gl_rgba, em_gl_unsigned_byte, tmp_surface.pixels ) error := gl_get_error_external if error /= 0 then Error_handler.raise_warning (Error_handler.Em_error_generate_texture, [emglu_error_string( error )]) end bind_old_id end target: INTEGER is once result:=em_gl_texture_2d end binding_target: INTEGER is once result:=em_gl_texture_binding_2d; end feature -- Status texture_bitmap: EM_BITMAP is -- Returns a Bitmap created from the current texture pixels local error: INTEGER do Bitmap_factory.create_empty_open_gl_bitmap (texture_width, texture_height) result := Bitmap_factory.last_bitmap bind_and_save_old gl_get_tex_image_external ( target, 0, em_gl_rgba, em_gl_unsigned_byte, result.pixels ) error := gl_get_error_external if error /= 0 then Error_handler.raise_warning (Error_handler.Em_error_generate_texture, [emglu_error_string( error )]) end bind_old_id end end -- class EMGL_TEXTURE_2D