Friday, February 25, 2011

OpenGL ES Shading Language

Coming from an OpenGL 1.5 + Nvidia Cg environment there are some noticable differences when migrating over to OpenGL ES 2.0. This post is like a cheat sheet for myself and others to use as a quick reference to look up some major keypoints of the Opengl ES Shading Language.

Precision & range of variables

The OpenGL ES Shading Language, used in e.g. IPhone OpenGL ES 2.0, lets you decide upon the range and precision used to represent integer or floating point variables.

Precision qualifiers:

  • highp (e.g. highp mat4 myMatrix)
  • mediump (e.g. varying mediump vec2 myTexCoord)
  • lowp (e.g. lowp float myColor)

Minimum ranges and precision

Bits FP Range FP Precision Int Range
highp 16 (-262, 262) Relative 2-16 (-216, 216)
mediump 10 (-214, 214) Relative 2-10 (-210, 210)
lowp 8 (-2, 2) Absolute 2-8 (-28, 28)

default vertex shader precisions

  • precision highp float
  • precision highp int
  • precision lowp sampler2D
  • precision lowp samplerCube

default FRAGMENT shader precisions

  • precision mediump int
  • precision lowp sampler2D
  • precision lowp samplerCube

Notice the fragment shader is missing a default precision for float. This means you must include precision qualifier for floats.

Built-in Variables

Vertex shader

Type Precision
gl_Position vec4 highp
gl_PointSize float mediump

Fragment shader

Type Precision
gl_FragCoord vec4 mediump
gl_FrontFacing bool
gl_FragColor vec4 mediump
gl_FragData[gl_MaxDrawBuffers] vec4 mediump
gl_PointCoord vec2 mediump

Thursday, February 24, 2011

IPhone Development Reference Post

  3G 3GS 4 IPad
Resolution 480x320 480x320 960x640 1024x768
Ratio (*) 3:2 (1.5) 3:2 (1.5) 3:2 (1.5) 4:3 (1.33)
OpenGL ES 1.1 2.0 2.0 2.0

(*) The bigger the ratio the more “widescreen” the display is. Eg: 16:9 = 1.78, 16:10 = 1.6

Wednesday, February 16, 2011

Doom Classic Iphone Source Code

The Doom source code for IPhone can be downloaded from this site http://www.idsoftware.com/doom-classic/.

At the bottom of that page there is a broken link to the actual zip file: ftp://www.idsoftware.com/idstuff/doom/doomclassic_iphone_v1.0_source.zip

I could not find a mirror site which hosted this file, but after a closer look at the link I was able to find the source at the correct link here:
ftp://ftp.idsoftware.com/idstuff/doom/doomclassic_iphone_v1.0_source.zip

Friday, February 11, 2011

From Visual Studio to XCode – Lessons Learned #1

In Visual Studio I use HOME/END to jump back and forth on rows, extensively. Using those keys in XCode results in the cursor jumping to the beginning/end of the document instead of the current row. There is a simple way to fix this:

Open:

XCode->Preferences->Key Bindings->Text Key Bindings

xcode

  1. First, duplicate “Xcode Default” Key Binding Set, by clicking on Duplicate…
  2. Name your new Key Binding Set
  3. Assign “Home” to “Move to Beginning of Line”
  4. Assign “End” to “Move to End of Line”
  5. Remove the previous bindings for Home/End from “Scroll to Beginning of Document/Scroll to End of Document” (if necessary. Xcode might remove these automatically).