Practical Course SS07 Global Illumination Effects / C# Introduction computer graphics & visualization Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group Organizational… • everybody here, who is supposed to be here? • who else is here? • Schedule: - Tue. 11:30 – 12.30 - Question time (Thursday 10:30-12:00 )? • If - you have a question: forum question time Email appear in person Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization .NET Framework: Objectives To provide: • Consistent object-oriented programming environment no matter how the locally stored object code is executed: (locally, locally but Internet-distributed, or remotely). • Code-execution environment that: − minimizes software deployment and versioning conflicts, − promotes safe execution of code, − eliminates the performance problems of scripted/interpreted environments. To ensure : • Integrability of the .NET Framework code with any other code according to industry standards. Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization .NET Framework in context Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization DotNet, CLR, MSIL, C# … etc. VB.NET Quellcode C# Quellcode Andere .NET-fächige Sprache VB.NET Compiler C# Compiler Compiler Andere nicht .NET-fächige Sprache C++ Quellcode VC++ Compiler 7.0 Unmanaged code Compiler Managed code Managed code Managed code Managed code MSIL-code Microsoft Intermediate Language (MSIL) [DATEI] Just-In-Time-Compiler (JIT) (Teil der Common Language Runtime) Native Code (NativeImage) [Datei] Native Code [RAM] Native Code [Datei] Betriebssystem See http://www.dotnetframework.de/default2.aspx?start=http://www.dotnetframework.de/dotnet/DOTNET_Framework_Einfuehrung.asp Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Java (J2EE) vs. .NET: Performance Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Java (J2EE) vs. .NET: Portability • Java – Multi platform (available for every OS) – „Not really“ multi language • .NET – „Not really“ multi platform ( ROTOR, MONO) – Multi Language (C++, C#, J#, Basic, Delphi …) Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Java (J2EE) vs. .NET: Future • Java – well established – a lot of applications already exist (including Applets) • .NET – Microsoft's choice for Windows Longhorn (XP) – a lot of applications are ported to .NET Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Native Code vs. .NET: Performance • Native Code, the compiler – usually compiles everything only once – has much time to optimize code – has no idea of the target machine – can’t do runtime optimization on it’s own • .NET, the JIT … – compiles every USED method ONCE per program execution – needs to be fast – knows the target machine well – knows the program’s behavior See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetperftechs.asp Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Let‘s get started … • you need: – Windows XP/2003 (Windows ME/98/2000 not supported) – .NET Framework 1.1 (SDK not needed) – Visual Studio 2003, 2005 Use the systems in our lab!!! Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization C#... • C# is a type-safe object-oriented language. • Curly-brace syntax is very similar to C, C++ or Java. • C# syntax simplifies many of the complexities of C++. • C# provides powerful features: - nullable value types, enumerations, delegates, anonymous methods and direct memory access. - supports generic methods and types, and iterators. • C# supports encapsulation, inheritance and polymorphism. • A class may inherit directly from one parent class, but it may implement any number of interfaces. • In C#, a struct is a „lightweight class“, which can implement interfaces but does not support inheritance. Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization C#... • Use process "Interop." to interact with other Windows software (e.g. COM objects, native Win32 DLLs). • „Interop.“ enables C# programs to do just about anything that a native C++ application can do. • C# supports pointers and the concept of "unsafe" code (for those cases in which direct memory access is absolutely critical). • C# build process is simple (vs. C, C++), flexible (vs. Java). • There are no separate header files, and no strict order for methods and types. • A C# source file may define any number of classes, structs, interfaces, and events. Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization C#: new constructs • Encapsulated method signatures called delegates, which enable type-safe event notifications. • Properties, which serve as accessors for private member variables (set/get). • Attributes, which provide declarative metadata about types at run time. • Inline XML documentation comments. Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Hello World using System; namespace HelloWorldApplication { /// <summary> /// This class is really boring since it only prints „Hello World“ /// </summary> class HelloWorld { /// <summary> /// The Main Method is the entry point for the app /// </summary> [STAThread] static void Main(string[] args) { Console.WriteLine("Hello World"); } } } Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Hello World Form using using using using using using System; System.Drawing; System.Collections; System.ComponentModel; System.Windows.Forms; System.Data; namespace HelloWorldForm { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); label1.Text = "Hello World"; } protected override void Dispose( bool disposing ) { if( disposing ) if (components != null) components.Dispose(); base.Dispose( disposing ); } Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Hello World Form (cont.) private void InitializeComponent() { label1 = new System.Windows.Forms.Label(); SuspendLayout(); label1.Location = new System.Drawing.Point(164, 68); label1.Name = "label1"; label1.TabIndex = 0; label1.Text = "label1"; AutoScaleBaseSize = new System.Drawing.Size(5, 13); ClientSize = new System.Drawing.Size(420, 158); Controls.Add(label1); Name = "Form1"; Text = "Hello Application"; ResumeLayout(false); } [STAThread] static void Main() { Application.Run(new Form1()); } } } Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization Java (J2EE) vs. .NET: Code words C# Keyword Java Keyword Base super Bool boolean Is instanceof lock synchronized namespace package readonly const sealed final using import internal private : extends : implements Not Supported by C# native transient ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/dncenet/html/tchCJavaComparingProgrammingLanguages.htm#tchCJavaKeywordComparison Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization References — http://www.dotnetframework.de/default2.aspx?start=http://www.dotnetfra mework.de/dotnet/DOTNET_Framework_Einfuehrung.asp — E. Schanzer, Performance Considerations for Run-Time Technologies in the .NET Framework, Microsoft Corporation, August 2001. — S. T. Kachru, On the Relative Advantages of Teaching Web Services in .NET vs. J2EE, Master Thesis, North Carolina State University, Aug. 2003. — J2EE and .NET Application Server and Web Services Benchmark, Middleware company, Oct. 2002. — J2EE and .NET (Reloaded) Yet Another Performance Case Study, Middleware company, Jun. 2003. — H. Mössenböck, Introduction to C#, University of Linz, Austria. — H. Mössenböck, Advanced C#, University of Linz, Austria. — D. Marshall, Visual C# 2005: The Language, Microsoft Press, 2006. — Microsoft Visual Studio 2005 Documentation — ... Kai Bürger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization