GRAPHICS PROGRAMMING THEN and NOW How the Ways of Showing Pixels on Screen Have Changed
Total Page:16
File Type:pdf, Size:1020Kb
Aatu Mikkonen GRAPHICS PROGRAMMING THEN AND NOW How the ways of showing pixels on screen have changed GRAPHICS PROGRAMMING THEN AND NOW How the ways of showing pixels on screen have changed Aatu Mikkonen Bachelor’s Thesis Spring 2021 Bachelor’s Degree of Information Tech- nology Oulu University of Applied Sciences ABSTRACT Oulu University of Applied Sciences Bachelor’s degree of Information technology Author(s): Aatu Mikkonen Title of the thesis: Graphics Programming Then and Now Thesis examiner(s): Kari Laitinen Term and year of thesis completion: Spring 2021 Pages: 20 Graphics programming is relatively unknown form of programming even though everyone uses its capabilities every day, e.g., writing documents, creating art on a computer and playing or creating video games. Graphics programming, at least in Finland, does not have much literature written for it. The purpose of this report is to examine how the graphics programming has evolved from the old times to modern times, and examine how the tools for writing graphics programming has changed. The author applied background knowledge learned in school and in free time about the research. The work was carried out by using the internet with search engines and online documentation searches. A variety of books, videos, articles and documentation pages were used as materials. The main results are a brief overview on the differences in graphics programming from the old times to modern times, descriptions on the areas graphics programming handles and a small example on the implementation of graphics program. Keywords: graphics, graphics programming, graphics history, api CONTENTS TERMINOLOGY AND ABBREVIATIONS ...................................................................................... 5 1 INTRODUCTION ................................................................................................................... 6 2 GRAPHICS PROGRAMMING ............................................................................................... 7 2.1 Graphics in the 1980s ................................................................................................ 7 2.1.1 Character sets and sprite sheets ................................................................. 8 2.2 Modern time graphics ................................................................................................. 9 2.2.1 Software rendering ....................................................................................... 9 2.2.2 Hardware rendering ................................................................................... 10 3 APPLICATION PROGRAMMING INTERFACES FOR GRAPHICS .................................... 11 3.1 Comparison of Graphics APIs .................................................................................. 11 3.1.1 OpenGL ..................................................................................................... 11 3.1.2 Vulkan ........................................................................................................ 12 3.1.3 DirectX ....................................................................................................... 12 3.1.4 Metal .......................................................................................................... 13 3.1.5 WebGL ....................................................................................................... 13 3.2 Graphics API comparison results ............................................................................. 14 4 GRAPHICS PROGRAM IMPLEMENTATION ...................................................................... 15 4.1 Initialization............................................................................................................... 15 4.2 Shaders .................................................................................................................... 15 4.2.1 Fragment shaders ...................................................................................... 16 4.2.2 Vertex Shaders .......................................................................................... 17 5 CONCLUSIONS .................................................................................................................. 18 REFERENCES ............................................................................................................................ 19 4 TERMINOLOGY AND ABBREVIATIONS AMD Advanced Micro Devices API Application Programming Interface C64 Commodore 64 GLSL OpenGL Shading Language GLUT OpenGL Utility Toolkit GPU Graphics Processing Unit HLSL High-Level Shading Language MSL Metal Shading Language NES Nintendo Entertainment System OS Operating System ROM Read-only Memory 5 1 INTRODUCTION This thesis is an explanation about graphics programming in game development in the old times and about the development of a simple graphics program without the need of a game engine, using modern technology and tools. There is no client for the project. The author’s objective is to learn about graphics programming and improve general programming knowledge. This thesis is going to cover topics on how the graphics programming in game development has changed from circa 1980 to modern days, also the development and implementation of a graphics program written from the ground up. The reason for the author to write graphics programming with game development in mind is that the author feels that graphics programming is more prevalent in game development than in desktop application on web application development in general. The program’s source code will be hosted on web via git. The program is going to display two simple textures, where both will be fading in and out using a shader program. The author wrote the program in conjunction to a tutorial on the Internet to learn about how to draw a shape and how to apply a texture to it. The language of the program used is C. OpenGL and its shader language was used to display a texture on the program window. 6 2 GRAPHICS PROGRAMMING Graphics programming is a form of programming where the developer implements everything that is visually shown on the screen. Graphics programming could be considered a fairly low level pro- gramming language for front-end developers, even though in modern times and depending on the dimensions the developer works on, the requirements of graphics programming more relate to dis- playing 3D and shading correctly then and project them to the camera of the 3D scene. As the programming language goes lower level, the involvement from the developer rises as there are less abstractions which help the programmer to write the code more safely and make the code more readable. Every modern language is considered high level as basically the only low-level programming language is assembly where each line resembles a machine code instruction. In as- sembly there can be unique instructions on each different processor architecture, though there can be similarities. FIGURE 1. Hierarchy of programming language levels 2.1 Graphics in the 1980s Graphics in the years late 1970s to early 1980 was primitive as the computers, especially commer- cial ones, were simple, where the most common microprocessor was an 8-bit microprocessor. The most famous example of early computers, and which used an 8-bit microprocessor was the Com- 7 modore 64, C64 [1]. The microprocessor that the C64 ran on was a variation of an 8-bit micropro- cessor called “MOS 6502”, which had variations for other well-known computers and consoles such as the Atari 2600 and the original NES. Writing any sort of software to old hardware such as the MOS 6502 required the developer to write the code in assembly language. There were made some high-level programming languages for the processors of that time, such as the BASIC language, which depended on the platform, their own modifications and possibly were not compatible with each other. Even though there were higher level languages to help the programmer, they were not applicable to write anything else, but a simple program. If the software needed speed, talking machine code via the help of assembly was required as it could be highly optimized. 2.1.1 Character sets and sprite sheets The most common way to draw graphics was to print the characters written to a character ROM, or overwritten to a character set in C64’s case. Consoles such as the original NES generally had the sprite sheets flashed to a character ROM chip on the game cartridge. FIGURE 2. A .chr file containing a very simple tileset for the NES In the case of NES, the character ROM consists of two individual sprite sheets, one for foreground sprites and the other for background elements. Each sprite can be made of 4 different colors and the colors can be changed to a specific palette to make the colors different. There could be up to 8 four unique palettes, where each of them could hold up to three unique colors taken from a fixed palette like in FIGURE 3, with one shared background color [2]. FIGURE 3. An example range of available colors for the NES NES sprite sheets could hold 256 sprites each, 16 sprites horizontally and 16 sprites vertically as seen in FIGURE 2. Each sprite sheet took four kilobytes of space and generally there was eight kilobytes of character ROM available, enough for a foreground and background sprite sheet. A NES cartridge can hold up to 40 kilobytes of ROM in total without modifications, so that makes the game logic have 32 kilobytes of space [3]. Even though in modern times as the technology has evolved and the