1. 4FipS.com
  2. Photos
  3. Videos
  4. Code
  5. Forums
  6. pfQuizzz
  7. About

4FipS.com Forums

Forums dedicated to the projects hosted at 4FipS.com

Skip to content

OpenGL ES 2.0 shader setup

> About coding, hacking, photography, and such...

OpenGL ES 2.0 shader setup

Postby FipS on Tue Aug 09, 2011 3:06 pm

As I've found myself not remembering all this stuff, I've decided to put together a piece of pseudo code showing a typical command sequence for OpenGL ES 2.0 shader initialization and drawing. (Note that there's an alternative way to obtain vertex attribute locations using glGetAttribLocation(), but I rather prefer explicit binding using glBindAttribLocation()).

---Init---
Code: Select all
glCreateShader() => vertShader
glShaderSource(vertShader, vertSource)
glCompileShader(vertShader)

glCreateShader() => fragShader
glShaderSource(fragShader, fragSource)
glCompileShader(fragShader)

glCreateProgram() => program

glAttachShader(program, vertShader)
glAttachShader(program, fragShader)

glBindAttribLocation(program, attribLoc0, attribName0)
...
glBindAttribLocation(program, attribLocN, attribNameN)

glLinkProgram(program)

glGetUniformLocation(program, unifName0) => unifLoc0
...
glGetUniformLocation(program, unifNameN) => unifLocN

---Draw---
Code: Select all
glBindBuffer(GL_ARRAY_BUFFER, vtxBuffer)
glVertexAttribPointer(attribLoc0, ...)
glEnableVertexAttribArray(attribLoc0)
...
glVertexAttribPointer(attribLocN, ...)
glEnableVertexAttribArray(attribLocN)

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idxBuffer)

glUseProgram(program)

glUniform*(unifLoc0, unifValue0)
...
glUniform*(unifLocN, unifValueN)

glDrawElements(...)

References:
OpenGL ES 2.0 API Reference (khronos.org)
Vertex Shader Attribute Mapping in GLSL (stackoverflow.com)
User avatar
FipS
Site Admin
 
Posts: 146
Joined: Wed Nov 12, 2008 9:49 pm
Location: Prague

OpenGL ES 2.0 shader setup

Sponsor

Sponsor
 

Return to 4FipS.com General Discussion & Blog

Who is online

Users browsing this forum: Bing [Bot] and 1 guest