Book Image

Lua Game Development Cookbook

By : Mario Kasuba, Mário Kašuba
Book Image

Lua Game Development Cookbook

By: Mario Kasuba, Mário Kašuba

Overview of this book

Table of Contents (16 chapters)
Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Writing a vertex shader


Vertex shaders are programs that operate on vertices and their attributes. This stage is also used to apply matrix transformations as well. GLSL shader programs use input and output variables. In the case of a vertex shader, input variables are either uniforms or vertex buffer data. Output variables are passed to the next stage of rendering the pipeline. There are also special built-in variables such as gl_Position, gl_PointSize, and others. These are mostly used with fixed functionality and may not be redeclared.

All shaders use the entry point function—main. This function is applied on each element—vertex.

Getting ready

This recipe will use the GLSL shading language with version 3.3. It assumes that all the vertices are stored in Vertex Buffer Object (VBO). The vertex shader program is applied on every vertex that is contained within VBO.

To prepare the vertex shader, you'll need to create the shader object first:

local shader_stage = gl_enum.GL_VERTEX_SHADER
local shader_object...