indexing description: "[ A component which displays OpenGL content. Create a subclass of EM_3D_COMPONENT and put the OpenGL code in the feature `draw'. If you need custom initialisation of OpenGL overwrite `prepare_drawing' but make sure to either call the original version or to set the OpenGL viewport yourself. Make sure to enable OpenGL in the `video_subsystem'. Subclasses should call `make_3d_component' at creation. For an example 3D component see SIERPINSKY_DISPLAY in the `widget_browser' example. See EM_COMPONENT ]" date: "$Date$" revision: "$Revision$" deferred class EM_3D_COMPONENT inherit EM_COMPONENT EM_CONSTANTS export {NONE} all end EMGL_DRAW export {NONE} all end EMGL_SETTINGS export {NONE} all end EMGL_VIEW export {NONE} all end EMGLU_VIEW export {NONE} all end feature {NONE} -- Initialisation make_3d_component is -- Initialise default values. require opengl_enabled: Video_subsystem.opengl_enabled do make_component min_view_distance := 0.1 max_view_distance := 100.0 field_of_view := 45.0 end feature -- Access min_view_distance: DOUBLE -- Minimal viewing distance max_view_distance: DOUBLE -- Maximum viewing distance field_of_view: DOUBLE -- Field of view in degrees feature -- Element change set_min_view_distance (a_distance: like min_view_distance) is -- Set `min_view_distance' to `a_distance'. require a_distance_positive: a_distance > 0 a_distance_smaller_max: a_distance < max_view_distance do min_view_distance := a_distance ensure min_view_distance_set: min_view_distance = a_distance end set_max_view_distance (a_distance: like max_view_distance) is -- Set `max_view_distance' to `a_distance'. require a_distance_positive: a_distance > 0 a_distance_bigger_min: a_distance > min_view_distance do max_view_distance := a_distance ensure max_view_distance_set: max_view_distance = a_distance end set_field_of_view (a_fov: like field_of_view) is -- Set `field_of_view' to `a_fov'. do field_of_view := a_fov ensure field_of_view_set: field_of_view = a_fov end feature -- Drawing prepare_drawing is -- Prepare for drawing `Current'. do if Video_subsystem.video_surface.is_opengl_blitting_enabled then Video_subsystem.video_surface.disable_opengl_blitting emgl_tex_envi (Em_gl_texture_env_mode, Em_gl_modulate) end emgl_viewport (x, Video_subsystem.video_surface.height - height - y, width, height) if width > 0 and height > 0 then -- Reset depth buffer emgl_clear (Em_gl_depth_buffer_bit) -- Opengl settings emgl_enable (Em_gl_depth_test) -- Enable antialiasing emgl_enable (Em_gl_line_smooth) emgl_hint (Em_gl_line_smooth, Em_gl_nicest) -- Setup the projection matrix emgl_matrix_mode (Em_gl_projection) emgl_load_identity emglu_perspective (field_of_view, width/height, min_view_distance, max_view_distance) -- Setup the model view matrix emgl_matrix_mode (Em_gl_modelview) emgl_load_identity end end finish_drawing is -- Finish drawing `Current'. do end invariant min_view_distance_positive: min_view_distance > 0 max_view_distance_positive: max_view_distance > 0 min_smaller_max: min_view_distance < max_view_distance end