OpenGL programming in Linux

Source: Internet
Author: User
Linux-based OpenGL programming-general Linux technology-Linux programming and kernel information. The following is a detailed description. OpenGL is an industrial standard 3D computer graphics software interface. It is released by SGI and widely used on Unix, OS/2, Windows/NT, and other platforms, including Linux. On Windows/NT platforms, general development tools such as VC, BC, and Fortran Powerstation support the development of direct OpenGL applications. on commercial Unix platforms, motif also supports OpenGL (after all, OpenGL was originally a workstation). What about Linux?
This article focuses not on OpenGL programming methods and techniques, but on how to develop OpenGL programs on the Linux platform. This section describes several tools that support OpenGL, supplemented by detailed examples.

1. Introduction to the OpenGL programming environment in Linux

OpenGL is not a free software. Its copyright and trademark (OpenGL) are all owned by SGI. But in Linux, there is a product replaced by OpenGL: Mesa. Mesa provides almost identical interfaces with OpenGL. For those who use OpenGL API programming, there is almost no difference. Mesa is a free software that complies with the GPL protocol (partially follows the LGPL Protocol). It is precisely because of Mesa's freedom that it outperforms OpenGL in terms of new hardware support. Mesa can be obtained from www.mesa3d.org. After obtaining Mesa, follow the instructions to generate the dynamic and static Connection Library and header files required for programming.
Anyone who knows about OpenGL knows that OpenGL only provides 3D graphic interfaces and does not have functions such as drawing windows, receiving responses, and processing messages. These functions must be provided by a third-party development environment, such as the VC mentioned above. Some people may think that since OpenGL can be developed under Motif, Lesstif in Linux should also be fine. Yes, indeed, but unfortunately, Lesstif in Linux is a very immature product and is not portable, so there are very few developers who use Lesstif. Below we will briefly introduce several commonly used toolkit.
The most common tool for developing OpenGL programs in Linux is GLUT (The OpenGL Utility Toolkit ). It can create one or more OpenGL windows, respond to and process user interaction operations, simple pop-up menus, and some built-in drawing and Font Processing functions. Like OpenGL, GLUT can be transplanted to multiple platforms. Thanks to its outstanding performance, it has now become one of the standard suites released by Mesa.
Another good development Kit is FLTK (Fast Light Tool Kit), a graphical interface development Tool written in C ++. Unlike GTK ++ and KDE, KDE focuses only on the graphic interface design and does not involve other practical applications. This feature makes it more concise and efficient than many other development tools. It is also a development tool with good portability. In fact, it is attracting more and more people's interest. Many commercial software (especially the software dedicated to developing embedded desktop systems) have chosen it as a graphical interface development tool. For more information, see the author's article FLTK-an excellent graphic interface development kit. There is a component in FLTK: Fl_Gl_Window is a specialized OpenGL window. It is quite convenient to use it to develop OpenGL programs.
GTK and KDE are the most widely used development tools in Linux. GTK itself does not directly support OpenGL (whether the new version supports OpenGL is not clear yet), but some people have developed widgets that support OpenGL, called GLAREA, you can search online or contact the author of this article. KDE provides support for OpenGL, but one of its drawbacks is that KDE only runs on Linux and is not portable. Here, I will mainly introduce the first two toolkit.

2. Use GLUT to develop OpenGL programs

2.1 How to obtain
GLUT can be obtained from Mesa. You can also download it from its homepage: http://reality.sgi.com/employees/mjk_asd/glu3/glu3.html. After installation, the GLUT header file glut. h will be installed under the GL directory of the OpenGL header file, and the library file libglut. a or libglut. so will also be installed. With them, you can use GLUT for programming.

2.2 A simple example
Next, let's take a look at a simple example. In this example, draw a three-dimensional ball.
/* Light. c
This program draws an OpenGL window using GLUT and displays a ball for illumination.
*/
/* Because the header file glut. h contains the gl. h and glu. h, you only need to include this file */
# Include <GL/glut. h>
# Include <stdlib. h>

/* Initialize the material attributes, light source attributes, and illumination model, and open the depth buffer */
QUOTE:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.