indexing description: "[ Main scene for the hello_cg_world example ]" date: "$Date$" revision: "$Revision$" class CG_SCENE inherit EM3D_TRACKBALL_SCENE redefine make_scene, predraw, draw end GL_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_scene feature -- Initialisation make_scene is -- create the scene do camera_distance := 45.0 Precursor {EM3D_TRACKBALL_SCENE} initialize_mesh initialize_cg end initialize_mesh is -- Initialize the scene local x, y: INTEGER do gl_polygon_mode (em_gl_front_and_back, em_gl_line) create mesh.make(0, size - 1) from x := 0 until x >= size loop mesh[x] := create {ARRAY[EM_VECTOR3D]}.make(0, size - 1) from y := 0 until y >= size loop (mesh[x])[y] := [ (size / 2) - x, (size / 2) - y , 0.0] y := y + 1 end x := x + 1 end end initialize_cg is -- initialize Cg local filename: STRING file: PLAIN_TEXT_FILE file_string: ANY main: ANY args: ANY tmp: ANY error: INTEGER error_string: STRING -- Handle to the vertex and fragment shader do 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) main := (create {STRING}.make_from_string ("main")).to_c args := (create {STRING}.make_from_string ("")).to_c filename := "Cg/Wave.cg" 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) tmp := (create {STRING}.make_from_string ("IN.position")).to_c position := cg_get_named_parameter_external (cgProgram, $tmp) tmp := (create {STRING}.make_from_string ("IN.color")).to_c color := cg_get_named_parameter_external (cgProgram, $tmp) tmp := (create {STRING}.make_from_string ("IN.wave")).to_c wave := cg_get_named_parameter_external (cgProgram, $tmp) tmp := (create {STRING}.make_from_string ("ModelViewProj")).to_c modelViewMatrix := cg_get_named_parameter_external (cgProgram, $tmp) end feature -- Drawing is_predraw: BOOLEAN predraw is -- Do the predraw things do is_predraw := true -- Reset the aspect gl_matrix_mode_external (Em_gl_projection) gl_pop_matrix gl_matrix_mode_external (Em_gl_modelview) is_predraw:=false end draw is -- Draw scene. local x, y: INTEGER do gl_rotatef(45, 1, 0, 0) cg_glset_state_matrix_parameter_external (modelviewmatrix, cg_gl_modelview_projection_matrix, cg_gl_matrix_identity) cg_glenable_profile_external (cgvertexprofile) cg_glbind_program_external (cgprogram) cg_glset_parameter4f_external (color, 1.0, 0.5, 0.5, 1.0) from x := 0 until x >= size - 1 loop gl_begin(em_gl_triangle_strip) from y := 0 until y >= size - 1 loop cg_glset_parameter3f_external (wave, wave_movement, 1.0, 1.0) gl_vertex3d((mesh[x])[y].x, (mesh[y])[y].y, (mesh[x])[y].z) gl_vertex3d((mesh[x + 1])[y].x, (mesh[x + 1])[y].y, (mesh[x + 1])[y].z) wave_movement := wave_movement + 0.00001 if wave_movement > 2 * 3.14 then wave_movement := 0.0 end y := y + 1 end gl_end x := x + 1 end end size: INTEGER is 32 mesh: ARRAY[ARRAY[EM_VECTOR3D]] wave_movement: DOUBLE feature {NONE} CgContext: POINTER CgVertexProfile: INTEGER CgProgram: POINTER position: POINTER color: POINTER wave: POINTER modelViewMatrix: POINTER end