Lua Game Development Cookbook
eBook - ePub

Lua Game Development Cookbook

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

Lua Game Development Cookbook

About this book

This book is for all programmers and game enthusiasts who want to stop dreaming about creating a game, and actually create one from scratch. The reader should know the basics of programming and using the Lua language. Knowledge of the C/C++ programming language is not necessary, but it's strongly recommended in order to write custom Lua modules extending game engine capabilities or to rewrite parts of the Lua code into a more efficient form.

Algebra and matrix operations are required in order to understand advanced topics in Chapter 4, Graphics – Legacy Method with OpenGL 1.x-2.1 and Chapter 5, Graphics – Modern Method with OpenGL 3.0+.

Sample demonstrations are coupled with binary libraries for Windows and Linux operating systems for convenience.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
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.
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.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Lua Game Development Cookbook by Mario Kasuba in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming. We have over one million books available in our catalogue for you to explore.

Information

Lua Game Development Cookbook


Table of Contents

Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Basics of the Game Engine
Introduction
Preparing a basic file structure for the game engine
Getting ready
How to do it…
How it works…
Making a stack
Getting ready
How to do it…
How it works…
Making a queue
Getting ready
How to do it…
How it works…
Making a prioritized queue
Getting ready
How to do it…
How it works…
Extending ipairs for use in sparse arrays
Getting ready
How to do it…
How it works…
Creating Lua modules
Getting ready
How to do it…
A module that returns a table as an interface
A module in the form of an object
A module in the form of a singleton object
How it works…
Handling errors with pcall, xpcall, and assert
Getting ready
How to do it…
How it works…
Using Lua with existing projects written in C/C++
Getting ready
How to do it…
Initializing the Lua state
Creating a Lua module in C/C++
Passing variables from C/C++ into the Lua environment
Passing variables from the Lua environment to C/C++
Making the C++ class accessible from Lua with Lutok2
How it works…
Getting LuaSDL for libSDL 1.2
Getting ready
How to do it…
There's more…
Designing the main application loop with LuaSDL
Getting ready
How to do it…
How it works…
2. Events
Introduction
Processing input events with LuaSDL
Getting ready
How to do it…
Event handling with the if-then-else chain
Event handling with an associative array
How it works…
See also
Using the keyboard input
Getting ready
How to do it…
Normal keys
Modifier keys
How it works…
See also
Using the relative mouse position
Getting ready
How to do it…
There's more…
Using the absolute mouse position
How to do it…
Using timers
Getting ready
How to do it…
How it works…
There's more…
3. Graphics – Common Methods
Introduction
Creating a window in libSDL
Getting ready
How to do it…
How it works…
Creating surfaces
Getting ready
How to do it…
How it works…
There's more…
Surfaces manipulation
Getting ready
How to do it…
How it works…
Using colors
Getting ready
How to do it…
How it works…
Cursor manipulation
Getting ready
How to do it…
How it works…
See also
Initializing the graphics mode with OpenGL
Getting ready
How to do it…
How it works…
Getting OpenGL information
Getting ready
How to do it…
Getting the OpenGL version
Getting the graphic card vendor
Getting the graphic card name
Getting the extensions list
How it works…
Using OpenGL extensions with GLEW and Lua
Getting ready
How to do it…
How it works…
Loading images with SDL_image
Getting ready
How to do it…
How it works…
Creating textures
Getting ready
How to do it…
How it works…
There's more…
Loading and using bitmap fonts
Getting ready
How to do it…
How it works…
There's more…
See also
Loading and using TrueType fonts
Getting ready
How to do it…
How it works…
See also
Displaying the text
Getting ready
How to do it…
How it works…
See also
Creating texture atlas with the rover-design pattern
Getting ready
How to do it…
How it works…
Using tiles and tilesets in the game
Getting ready
How to do it…
How it works…
See also
4. Graphics – Legacy Method with OpenGL 1.x–2.1
Introduction
Drawing primitives in immediate mode
Getting ready
How to do it…
Drawing points
Drawing lines
Drawing line strips
Drawing line loops
Drawing triangles
Drawing triangle strips
Drawing triangle fans
Drawing quads
Drawing quad strips
Drawing polygons
How it works…
See also
Setting up blending
Getting ready
How to do it…
Additive blending
Subtractive blending
Alpha blending
How it works…
Moving, rotating, and scaling objects
Getting ready
How to do it…
How it works…
The identity matrix
The translation matrix
The scale matrix
The rotation matrix
There's more…
See also
Setting up the orthogonal and perspective cameras
Getting ready
How to do it…
The orthogonal mode
The perspective mode
How it works…
There's more…
See also
Setting up materials
Getting ready
How to do it…
How it works…
There's more…
See also
Setting up lighting
Getting ready
How to do it…
How it works…
There's more…
See also
Using display lists
Getting ready
How to do it…
How it works…
See also
Setting up the vertex buffer
Getting ready
How to do it…
How it works…
There's more…
5. Graphics – Modern Method with OpenGL 3.0+
Introduction
Loading and using GLSL shaders
Getting ready
How to do it…
How it works…
See also
Using uniform variables with shaders
Getting ready
How to do it…
Writing into uniform variables
Reading from uniform variables
How it works…
Writing a vertex shader
Getting ready
How to do it…
How it works…
There's more…
See also
Writing a fragment (pixel) shader
Getting ready
How to do it…
How it works…
There's more…
See also
Drawing primitives using vertex buffers
Getting ready
How to do it…
Vertex positions
Vertex colors
Vertex texture coordinates
How it works…
There's more…
See also
Rendering to texture
Getting ready
How to do it…
The render buffer with the color attachment
The render buffer with the depth attachment
How it works…
See also
Applying highlights and shadows to the scene
Getting ready
How to do it…
Vertex shader
Fragment shader
How it works…
See also
Bumpmapping
Getting ready
How to do it…
Vertex shader
Fragment shader
Ho...

Table of contents

  1. Lua Game Development Cookbook