Text Drawing & Playing Sound

Slides:



Advertisements
Similar presentations
Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
Advertisements

Sound Engine Evaluation for Computer Games Case Study: fmod Jyun-Ming Chen.
Creating Games For Windows, Xbox 360, and Windows Phone 7 Ryan Plemons
CSC1016 Coursework Clarification Derek Mortimer March 2010.
Homework Any Questions?. Statements / Blocks, Section 3.1 An expression becomes a statement when it is followed by a semicolon x = 0; Braces are used.
1 CS 177 Week 15 Recitation Slides Review. Announcements Final Exam on Sat. May 8th  PHY 112 from 8-10 AM Complete your online review of your classes.
Implementing 3D Digital Sound In “Virtual Table Tennis” By Alexander Stevenson.
Introduction to a Programming Environment
Computer Programming For Musical Applications II Tutorial 08 Recording in SuperCollider 21st November, 2008.
Week71 APCS-AB: Java Control Structures October 17, 2005.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
Text and Graphics September 26, Unit 3.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Ahmed Saker Indie Game Developer
Useful Tools for Making Video Games Part II An overview of.
1 Homework / Exam Finishing K&R Chapter 5 today –Skipping sections for now –Not covering section 5.12 Starting K&R Chapter 6 next Continue HW5.
Processing Hardware, Software. Hardware Hardware Processing is performed by a computer ’ s central processing unit and is measured by the clock speed.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Starting Out with Games & Graphics in C++ Tony Gaddis Chapter 8 The.
Programming Fundamentals. Today’s Lecture Array Fundamentals Arrays as Class Member Data Arrays of Objects C-Strings The Standard C++ string Class.
Chapter 7 Continued Arrays & Strings. Arrays of Structures Arrays can contain structures as well as simple data types. Let’s look at an example of this,
 Keep it simple and precise  Use bold titles for important messages  Use pictures that convey messages effectively  Make it easy to read at a glance.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Animations & Multimedia LESSON 9 #2.09 USING ANIMATION AND MULTIMEDIA.
Arrays and Strings. Arrays in PHP Arrays are made up of multiple memory blocks, each with the same name and differentiated by an index number Each block.
Using FlexTraining.
Flash Session 4: Importing Assets
2D Graphics Optimizations
CSC 533: Programming Languages Spring 2016
UNIT - IV SORTING By B.Venkateswarlu Dept of CSE.
SLC/VER1.0/OS CONCEPTS/OCT'99
Sound Music & Sound Effects.
CSC 533: Programming Languages Spring 2015
The Desktop Screen image displayed when a PC starts up A metaphor
Week 3 - Friday CS222.
CS 134 More Graphics.
Frame Update, Level Representation & Graphics
Arrays in PHP are quite versatile
Immediate Mode GUI – Theory and Example
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
Graphical Output Graphical Text.
Reading Netpbm Images.
Introduction to Gobbit Programming
Creating and Modifying Text part 2
Guide to Photostory 3.
Engineering Innovation Center
Computation as an Expressive Medium
EEL 3705 / 3705L Digital Logic Design
CS 177 Week 15 Recitation Slides
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Some Basics for Problem Analysis
Bases and Representations, Memory, Pointers, Arrays, For-Loops
Technology ICT Core: PowerPoint.
Fundamentals of Data Structures
File Input and Output.
Game Loop Update & Draw.
Pointers The C programming language gives us the ability to directly manipulate the contents of memory addresses via pointers. Unfortunately, this power.
Homework Any Questions?.
Explaining issues with DCremoval( )
Lecture 9 Announcements.
CHAPTER 21 LOOPS 1.
Homework Continue with K&R Chapter 5 Skipping sections for now
Game Programming Algorithms and Techniques
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Using Animation and Multimedia
02 | What DirectX Can Do and Creating the Main Game Loop
File Input and Output.
EECS 110: Lec 12: Mutable Data
Networks & I/O Devices July 10, 2019.
CSC 533: Programming Languages Spring 2019
Dynamic Array: Implementation of Stack
Presentation transcript:

Text Drawing & Playing Sound CS 134 Text Drawing & Playing Sound

Today in Video Games

Any questions about the homework? Homework Questions Any questions about the homework?

Text Drawing Text drawing is actually pretty simple, and just uses things you are already familiar with If you find a tutorial online and you don't understand it, don't use it!

Text Drawing Often, you don't need to actually support full text drawing. Logos, HUD, etc. can be plain old textures Here, Last of Us logo, the word “Exit”, “Sonic” can be drawn with glDrawSprite()

However, for other situations... Text Drawing However, for other situations...

Text Drawing Most APIs provide a dedicated text drawing routine. Java: Graphics.drawString(str, x, y) Graphics.setFont(font) Win32: DrawText(dc, str, count, rect, align) Commonly, you need a “font”, a “string”, and a position

Text Drawing How is text represented? String An array of bytes, that encode a sequence of codepoints, commonly using ASCII, UTF-8, or UTF-16 Codepoint A number that represents a character. s 115 ☃ 9731

Text Drawing How are fonts represented? Font A collection of codepoint → glyph mappings Glyph A picture, in typography speak. Usually represented as a texture

Text Drawing Text drawing APIs usually provide the following two functions at the lowest level: int DrawText(font, str, x, y) Returns width of the text Can only draw a single line! int MeasureText(font, str) Same as DrawText, but does not do any drawing How are these implemented?

Text Drawing int DrawText(font, str, x, y) { foreach (codept in str ) { glyph = font[codept]; DrawGlyph(glyph, x, y); x += GlyphWidth( glyph ); }

Text Drawing What do the data structures look like? class Font class Glyph

Text Drawing What do the data/def structures look like? class FontDef int lineHeight Hashtable / Array glyph def class GlyphDef string texName Becomes an int glTexture for data int width

Write your own glDrawText() function, based on the previous slides. Text Drawing Write your own glDrawText() function, based on the previous slides.

Text Drawing Making font textures sounds very tedious, right? 96 different textures to create for just ASCII support! There are many tools that can help you out there FontBuilder is pretty good, easy to use. Spits out a single texture, but you can cut that up in Gimp. https://github.com/andryblack/fontbuilder

<Example using FontBuilder> Text Drawing <Example using FontBuilder>

Text Drawing Questions?

Sound Hardware Not much is done in hardware (unlike Graphics) Decompression Mixing 3D DSPs (“shaders”) Hasn't really changed for over 10 years.

Sound Hardware HW has dedicated memory block it plays audio from. A “Ring Buffer” You must write the memory to the buffer before the HW reads from it.

Sound Features 2D / 3D Sounds A “2D” sound will play what was recorded exactly. A “3D” sound will play as if it was playing in a specific position. Sounds / Streams A “sound” is always fully uncompressed in memory A “stream” is loaded into memory bit by bit, as needed

Sound Features 2D / 3D Sounds Use 2D sounds unless you want positioning to be dynamic Sounds / Streams Use “sounds” for short bursts of audio (< 10 seconds) Use “streams” for background music (> 10 seconds)

Sound Features DSPs are like shaders for sound Echos, Pitch Shifting, Reverb, Volume fadeoff, etc.

Using FMOD FMOD does most of the heavy lifting for you! http://fmod.org FMOD_System_Create() FMOD_System_Init() FMOD_System_CreateSound() FMOD_System_CreateStream() FMOD_System_PlaySound() FMOD_Channel_SetLoopCount()

Using FMOD – Initialization FMOD_System_Create() Load the FMOD library FMOD_System_Init() Initalize the FMOD library FMOD_SYSTEM* fmod; // Load jump sound effect FMOD_System_Create(&fmod); // Initalize FMOD with up to 100 sounds playing at once FMOD_System_Init(fmod, 100, FMOD_INIT_NORMAL, 0);

Using FMOD – Loading Audio FMOD_System_CreateSound() Load audio from disk as a sound (fully decompressed into RAM) FMOD_System_CreateStream() Load audio from disk as a stream FMOD_SOUND* jump; FMOD_SOUND* bgMusic; FMOD_System_CreateSound( fmod, "mariojump.mp3", FMOD_DEFAULT, 0, &jump); FMOD_System_CreateStream( fmod, “level1_bg.mp3”, FMOD_DEFAULT, 0, &bgMusic);

Using FMOD – Playing Audio FMOD_System_PlaySound() Play a specified sound until it finishes. Optionally can take a “channel” to play on, replacing the currently playing thing // Play a “jump” sound FMOD_System_PlaySound(fmod, jump, 0, false, NULL); // Change the background music FMOD_System_PlaySound(fmod, bgMusic, 0, false, &bgChan);

Using FMOD – Playing Audio How did we get the bg channel? FMOD_CHANNEL* bgChan; // Play nothing on a BG channel, start it paused FMOD_System_PlaySound( fmod, NULL, NULL, true, &bgChan);

Using FMOD – Looping FMOD_Channel_SetLoopCount() Set how often this channel should loop FMOD_CHANNEL* bgChan; // Loop this channel forever. FMOD_Channel_SetLoopCount(bgChan, -1);

Using FMOD One more function FMOD_System_Update() Update the FMOD runtime in prep for a new graphics tick // Call this once per graphics frame FMOD_System_Update(fmod);

Best Practices Initialize FMOD and a background channel at startup. Load sounds and streams at level start. Play sounds when appropriate Error checking!

Java Equivalent I've created a Java equivalent using javax.sound.sampled Load via Sound.loadFromFile No distinction between streaming and sounds Play via sound.play / sound.playLooping Stop via clip.stop / clip.close

Audio Questions?