indexing description: "[ A simple GLSL scene ]" date: "$Date$" revision: "$Revision$" class MAIN_SCENE inherit EM_GL_SCENE EMGL_VIEW export {NONE} all end EMGL_BASIC_RENDERER export {NONE} all end GLEW_FUNCTIONS export {NONE} all end CG_FUNCTIONS_EXTERNAL export {NONE} all end CGENUM_ENUM_EXTERNAL rename is_valid_enum as cg_is_valid_enum export {NONE} all end CGGL_FUNCTIONS_EXTERNAL export {NONE} all end CGGLENUM_ENUM_EXTERNAL rename is_valid_enum as cg_gl_is_valid_enum export {NONE} all end create make feature {NONE} -- Initialisation CgContext: POINTER CgVertexProfile: INTEGER CgProgram: POINTER make is -- Initialise default values. local filename: STRING file: PLAIN_TEXT_FILE file_string: ANY main: ANY args: ANY error: INTEGER error_string: STRING -- Handle to the vertex and fragment shader do make_scene -- Initialise normalized speed for rotation of pyramid cgcontext := cg_create_context_external if cgcontext = 0x0 then io.put_string ("Failed to create cg context") end CgVertexProfile := cg_glget_latest_profile_external (cg_gl_vertex) if cgvertexprofile = cg_unknown then io.put_string("Invalid profile type") end cg_glset_optimal_options_external (cgvertexprofile) filename := "Cg/Wave.cg" main := (create {STRING}.make_from_string ("main")).to_c args := (create {STRING}.make_from_string ("")).to_c create file.make (filename) file.open_read file.read_stream (file.count) file_string := (create {STRING}.make_from_string (file.last_string)).to_c CgProgram := cg_create_program_external (cgcontext, cg_source, $file_string, cgvertexprofile, $main, $args) if CgProgram = 0x0 then error := cg_get_error_external create error_string.make_from_c (cg_get_error_string_external (error)) io.put_string ("Cg Error: " + error_string + "%N") end cg_glload_program_external (CgProgram) ensure speed_not_void: speed /= Void end feature -- Access program: EMGL_SHADER_PROGRAM -- Handle to the program object angle: DOUBLE -- Rotation angle in degrees speed: EM_NORMALIZED_SPEED -- Rotation speed for pyramid feature -- Drawing quadric_renderer: EMGLU_QUADRIC is -- Quadric renderer do create result end draw is -- Draw scene. do if program/=void then program.use program.uniform1f ( "time", time.ticks ) end -- Move the pyramid into the screen and rotate it emgl_translatef (0, 0, -9) emgl_rotatef (angle, 0, 1, 0) emgl_begin (Em_gl_triangles) -- Front emgl_color3f(1, 0, 0) -- Red emgl_vertex3d (0, 1, 0) emgl_vertex3d (-1, -1, 1) emgl_vertex3d (1, -1, 1) -- Right emgl_color3f(0, 1, 0) -- Green emgl_vertex3d (0, 1, 0) emgl_vertex3d (1, -1, 1) emgl_vertex3d (1, -1, -1) -- Back emgl_color3f (0, 0, 1) -- Blue emgl_vertex3d (0, 1, 0) emgl_vertex3d (1, -1, -1) emgl_vertex3d (-1, -1, -1) -- Left emgl_color3f (1, 1, 0) -- Yellow emgl_vertex3d (0, 1, 0) emgl_vertex3d (-1, -1, -1) emgl_vertex3d (-1, -1, 1) emgl_end emgl_color3f (1, 0, 1) emgl_translatef (0, 3, 0) quadric_renderer.sphere (2, 20, 10) if program/=void then program.unuse end -- Increment the angle if angle < 360 then angle := angle + speed.get_delta else angle := 0 end end invariant speed_not_void: speed /= Void end