Graphical Interfaces for C#*
Total Page:16
File Type:pdf, Size:1020Kb
Graphical Interfaces for C#* Milan FrankF, Ivo HanákH, Tomáš SmlsalS, Václav Skala@ Department of Computer Science and Engineering University of West Bohemia Plzeň, Czech Republic Abstract 1.1 The Basic Idea The .NET Framework seemed to be very interesting for A new environment called .NET was recently introduced people from the area of computer graphics that we to wide public. However, this environment does not decided to implement some of the well-known graphical contain libraries for advanced graphical output. interfaces in it. The VTK, OpenGL and DirectX have Therefore it is necessary to make such libraries available been taken into account. These interfaces are widespread to .NET. This paper describes our implementation of and having them prepared in the .NET Framework, it is graphical library interfaces. The implementation allows easy to extend our old working algorithms with new cooperation of graphical interfaces with .NET. We have features and functionality. For example, a developer used dealt with interfaces of libraries such as OpenGL, to write a code for OpenGL can simply continue with a DirectX, and Visualization Toolkit (also known as VTK). development with it, build it in .NET Framework and A short description of libraries is included as well as a easily add whatever other network functionality he short introduction to .NET environment. We also present wants. results, advantages, and disadvantages of our We have implemented the VTK, OpenGL and implementation. This paper contains neither comparison DirectX interfaces for use within the .NET Framework. It of the graphical libraries nor comparison of .NET fulfills well our objectives given at the early beginning. environment and other environments. Now, graphics developers can also work with the fully Keywords: .NET, OpenGL, DirectX, Direct3D, VTK, object oriented programming (OOP) language C#. It C++ Managed Extension, C# allows more inheritance, deriving and polymorphism into the computer graphics. 1 Introduction 1.2 The .NET Framework This paper is focused on a pure implementation task The .NET Framework is something like a (Java) rather than in explanation of a general theory or specific virtual machine. It allows runtime environment graphical algorithms. However, the described solution functionality to any .NET application on whatever seems to be interesting and useful to people within a hardware platform or operating system, where the .NET computer graphics community. The reason is simple: Framework is implemented. The .NET is based on there are many people using the OpenGL, Visualization Common Language Infrastructure (CLI) technology, Toolkit [1] (VTK) or DirectX, who want to benefit from which ensures a right communication between .NET Framework features. Simply, it is a runtime independent application and specific hardware or environment, which hides the operating system layer to operating system. The CLI is used by many libraries, the application and unifies single machine and network which are extending it. These libraries are referred to as environments into one (see [2]). Later, we will describe frameworks. For example, they provide application what a .NET Framework stands for in more detail. interfaces (APIs) or programming abstractions. Some beginners to the .NET have problems with correct understanding of language interoperability.It may seem that C# is the basic programming language of * Project supported by the Ministry of Education of a whole .NET and that other languages are only the Czech Republic: Project MSM 235200005 and something as extensions. Actually, C# is really the native Microsoft Research Ltd.: Project ROTOR. language of the .NET. However, .NET applications can F [email protected] H be written in any language, which meets some [email protected] S [email protected] requirements given by specifications (concretely the @ [email protected] Common Language Specification). The language interoperability is conditioned by some mechanisms as common data types system (CTS), data marshalling, etc. values of pixels inside a specified area (rectangle) at the All the .NET languages at the same way share the CTS. target frame buffer. Unfortunately, these functions do not It has to be noted that a source code is compiled into have good hardware support and their capabilities are not something similar to byte-code and additional type sufficient enough. E.g., they use nearest-neighbor information is included as metadata. approach when scaling due to which the visual result is The result is mixture of intermediate code and not good. Due to that it is better to use simple 3D objects metadata, which are still carrying a description of which with texture mapping instead of these functions. types will be available at the runtime. In other words, the Interface is the most important part of a library. It is intermediate code contains complete information to be the only part visible to a user. In the case of OpenGL this compiled into a native code of a used processor. Let us interface consists of a group of functions and constants. mention at least one advantage of the previously stated These functions are not grouped into classes so it is also principle. It is possible for execution engine to verify the possible to use the library in a non-object-oriented type safety and code correctness just before the execution languages (e.g., C). is done. Interface structure (i.e., contained functions and It is important to understand this background constants) is defined by specifications, which are open to information to be able to read the documentation the public. This specification also describes behavior and provided by the Microsoft Company. prescribed reaction of the library to calls of its interface functions. Important advantage of OpenGL interface is 2 Graphical Interfaces its full backward compatibility. Each new version neither adds a complete set of functions nor modifies existing ones. It just enlarges the existing set of functions by new 2.1 OpenGL ones. These additions usually follow features, which are implemented in the available hardware. OpenGL is a graphic library based on commercial From inside view behavior of OpenGL is similar to a graphical system by SGI [3]. It is used in many state machine. Each function (excluding function used to applications including games and industry. It offers an retrieve data and state) modifies the current state of the interface and facilities for projecting 3D objects on 2D machine. This state then influences the result of the screen (or into image), but just the projection is not the rendering. only purpose of the library. Interface functionality and behavior are described by This library provides complete rendering pipeline, standardized specification. However, a real which handles lighting, texturing and transformations. implementation is something a little bit different. It The result of 3D world projection is then rendered to the follows behavior described in the specification but in given frame buffer or window of current (underlying) some cases (usually error handling) it slightly differs. GUI (window system). Some implementations provide robust and very The object geometry can be specified using few basic stable background so they are able to absorb user's render primitives, such as points, lines, triangles and mistakes without any visible feedback while others quads. It includes support for triangle fans and strips. The strictly follow the specifications and in the case of such library as a standard part of the rendering pipeline also mistake they provide an unpredictable output. provides light and lighting computation. It is possible to This depends also on the used graphical hardware and choose from common light types, such as point light, sometimes on the used version of the device drivers. It directional light and reflector and to set up their can lead to difficulties while debugging when user parameters. These light types are often supported by the develops his/her application using robust implementation hardware. and then get strange output using another, less robust. It is also possible to cover surface of every rendered OpenGL provides functionality for rendering of basic primitive with user defined 2D or 1D texture. This primitives with defined properties (e.g., lights, texture, includes support for multi-texturing and mip-mapping as etc.). Unfortunately, this functionality is sometimes not a standard facility of the library. sufficient enough or its use is too difficult. Therefore Support for transformations is provided by together with OpenGL there exist several libraries (GLU, composition of particular transformations, which are GLUT) or add-ons (GL Extensions). specified by matrices. These particular transformations One of these is the GLU library. This library can be set either by a user (e.g. in the form of matrix) or provides facilities for rendering and tessellation of by standard library functions. Such functions offer a parametric surfaces as well as useful functions for setting possibility to parameterize basic transformations, such as projection. rotation around given axis, translation by a given vector Another case of such library is the GLUT library.It and scaling by given coefficients. aims at simplification and unification of OpenGL OpenGL is aimed at visualization of 3D objects. It is initialization and its cooperation with currently available also possible to use OpenGL for 2D output because the GUI. This is because OpenGL interface itself is interface contains functions