Developing Graphics Frameworks with Python and OpenGL
eBook - ePub

Developing Graphics Frameworks with Python and OpenGL

Lee Stemkoski, Michael Pascale

Share book
  1. 334 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Developing Graphics Frameworks with Python and OpenGL

Lee Stemkoski, Michael Pascale

Book details
Book preview
Table of contents
Citations

About This Book

Developing Graphics Frameworks with Python and OpenGL shows you how to create software for rendering complete three-dimensional scenes. The authors explain the foundational theoretical concepts as well as the practical programming techniques that will enable you to create your own animated and interactive computer-generated worlds.

You will learn how to combine the power of OpenGL, the most widely adopted cross-platform API for GPU programming, with the accessibility and versatility of the Python programming language. Topics you will explore include generating geometric shapes, transforming objects with matrices, applying image-based textures to surfaces, and lighting your scene. Advanced sections explain how to implement procedurally generated textures, postprocessing effects, and shadow mapping. In addition to the sophisticated graphics framework you will develop throughout this book, with the foundational knowledge you will gain, you will be able to adapt and extend the framework to achieve even more spectacular graphical results.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Developing Graphics Frameworks with Python and OpenGL an online PDF/ePUB?
Yes, you can access Developing Graphics Frameworks with Python and OpenGL by Lee Stemkoski, Michael Pascale in PDF and/or ePUB format, as well as other popular books in Informatica & Grafica per computer. We have over one million books available in our catalogue for you to explore.

Information

Publisher
CRC Press
Year
2021
ISBN
9781000407976

CHAPTER 1

Introduction to Computer Graphics
DOI: 10.1201/9781003181378-1
The importance of computer graphics in modern society is illustrated by the great quantity and variety of applications and their impact on our daily lives. Computer graphics can be two-dimensional (2D) or three-dimensional (3D), animated, and interactive. They are used in data visualization to identify patterns and relationships, and also in scientific visualization, enabling researchers to model, explore, and understand natural phenomena. Computer graphics are used for medical applications, such as magnetic resonance imaging (MRI) and computed tomography (CT) scans, and architectural applications, such as creating blueprints or virtual models. They enable the creation of tools such as training simulators and software for computer-aided engineering and design. Many aspects of the entertainment industry make use of computer graphics to some extent: movies may use them for creating special effects, generating photorealistic characters, or rendering entire films, while video games are primarily interactive graphics-based experiences. Recent advances in computer graphics hardware and software have even helped virtual reality and augmented reality technology enter the consumer market.
The field of computer graphics is continuously advancing, finding new applications, and increasing in importance. For all these reasons, combined with the inherent appeal of working in a highly visual medium, the field of computer graphics is an exciting area to learn about, experiment with, and work in. In this book, you’ll learn how to create a robust framework capable of rendering and animating interactive three-dimensional scenes using modern graphics programming techniques.
Before diving into programming and code, you’ll first need to learn about the core concepts and vocabulary in computer graphics. These ideas will be revisited repeatedly throughout this book, and so it may help to periodically review parts of this chapter to keep the overall process in mind. In the second half of this chapter, you’ll learn how to install the necessary software and set up your development environment.

1.1 Core Concepts and Vocabulary

Our primary goal is to generate two-dimensional images of three-dimensional scenes; this process is called rendering the scene. Scenes may contain two- and three-dimensional objects, from simple geometric shapes such as boxes and spheres, to complex models representing real-world or imaginary objects such as teapots or alien lifeforms. These objects may simply appear to be a single color, or their appearance may be affected by textures (images applied to surfaces), light sources that result in shading (the darkness of an object not in direct light) and shadows (the silhouette of one object's shape on the surface of another object), or environmental properties such as fog. Scenes are rendered from the point of view of a virtual camera, whose relative position and orientation in the scene, together with its intrinsic properties such as angle of view and depth of field, determine which objects will be visible or partially obscured by other objects when the scene is rendered. A 3D scene containing multiple shaded objects and a virtual camera is illustrated in Figure 1.1. The region contained within the truncated pyramid shape outlined in white (called a frustum) indicates the space visible to the camera. In Figure 1.1, this region completely contains the red and green cubes, but only contains part of the blue sphere, and the yellow cylinder lies completely outside of this region. The results of rendering the scene in Figure 1.1 are shown in Figure 1.2.
FIGURE 1.1 Three-dimensional scene with geometric objects, viewing region (white outline) and virtual camera (lower right).
FIGURE 1.2 Results of rendering the scene from Figure 1.1
From a more technical, lower-level perspective, rendering a scene produces a raster—an array of pixels (picture elements) which will be displayed on a screen, arranged in a two-dimensional grid. Pixels are typically extremely small; zooming in on an image can illustrate the presence of individual pixels, as shown in Figure 1.3.
FIGURE 1.3 Zooming in on an image to illustrate individual pixels.
On modern computer systems, pixels specify colors using triples of floating-point numbers between 0 and 1 to represent the amount of red, green, and blue light present in a color; a value of 0 represents no amount of that color is present, while a value of 1 represents that color is displayed at full (100%) intensity. These three colors are typically used since photoreceptors in the human eye take in those particular colors. The triple (1, 0, 0) represents red, (0, 1, 0) represents green, and (0, 0, 1) represents blue. Black and white are represented by (0, 0, 0) and (1, 1, 1), respectively. Additional colors and their corresponding triples of values specifying the amounts of red, green, and blue (often called RGB values) are illustrated in Figure 1.4.
FIGURE 1.4 Various colors and their corresponding (R, G, B) values.
The quality of an image depends in part on its resolution (the number of pixels in the raster) and precision (the number of bits used for each pixel). As each bit has two possible values (0 or 1), the number of colors that can be expressed with N-bit precision is 2N. For example, early video game consoles with 8-bit graphics were able to display 28=256 different colors. Monochrome displays could be said to have 1-bit graphics, while modern displays often feature “high color” (16-bit, 65,536 color) or “true color” (24-bit, more than 16 million colors) graphics. Figure 1.5 illustrates the same image rendered with high precision but different resolutions, while Figure 1.6 illustrates the same image rendered with high resolution but different precision levels.
FIGURE 1.5 A single image rendered with different resolutions.
FIGURE 1.6 A single image rendered with different precisions.
In computer science, a buffer (or data buffer, or buffer memory) is a part of a computer's memory that serves as temporary storage for data while it is being moved from one location to another. Pixel data is stored in a region of memory called the framebuffer. A framebuffer may contain multiple buffers that store different types of data for each pixel. At a minimum, the framebuffer must contain a color buffer, which stores RGB values. When rendering a 3D scene, the framebuffer must also contain a depth buffer, which stores distances from points on scene objects to the virtual camera. Depth values are used to determine whether the various points on each object are in front of or behind other objects (from the camera’s perspective), and thus whether they will be visiblewhen the scene is rendered. If one scene object obscures another and a transparency effect is desired, the renderer makes use of alpha values: floating-point numbers between 0 and 1 that specifies how overlapping colors should be blended together; the value 0 indicates a fully transparent color, while the value 1 indicates a fully opaque color. Alpha values are also stored in the color buffer along with RGB color values; the combined data is often referred to as RGBA color values. Finally, framebuffers may contain a buffer called a stencil buffer, which may be used to store values used in generating advanced effects, such as shadows, reflections, or portal rendering.
In addition to rendering three-dimensional scenes, another goal in computer graphics is to create animated scenes. Animations consist of a sequence of images displayed in quick enough succession that the viewer interprets the objects in the images to be continuously moving or changing in appearance. Each image that is displayed is called a frame. The speed at which these images appear is called the frame rate and is measured in frames per second (FPS). The standard frame rate for movies and television is 24 FPS. Computer monitors typically display graphics at 60 FPS. For virtual reality simulations, developers aim to attain 90 FPS, as lower frame rates may cause disorientation and other negative side effects in users. Since computer graphics must render these images in real time, often in response to user interaction, it is vital that computers be able to do so quickly.
In the early 1990s, computers relied on the central processing unit (CPU) circuitry to perform the calculations needed for graphics. As real-time 3D graphics became increasingly common in video game platforms (inc...

Table of contents