SlideShare a Scribd company logo
The Titanium OpenGL Module:
  Sophisticated Graphics for the Ti Programmer




               Richard Salter
Richard M. Salter
Logical Labs
—  What   is OpenGL?
  ◦  An API for managing a 3D graphics
     environment.
   –  not OO
   –  OpenGL “pipeline”
—    Getting Ti/Javascript and OpenGL to play nicely
      together
      ◦  “Objectify” the OpenGL API with respect to a
         drawing surface
        –  Create a natural extension to the Titanium object model.
        –  Ti.OpenGL.View

      ◦  Compensate for inefficiencies introduced by moving
         programming level to Javascript.
        –  Cope with the large volume of data associated with a given
            OpenGL model.
        –  Ti.OpenGL.DataBuffer
Richard Salter: Using the Titanium OpenGL Module
var Ti.Opengl = require('Ti.OpenGL');	

            var view = Ti.Opengl.createView({	
              	backgroundColor:"#aaa",	
              	top:0,	
              	left:0	
              	width:’100%’,	
              	height:’100%’,	
            }),	


—    Creates OpenGL context and view
—    Initializes Framebuffers and Renderbuffers
—    Optionally: can specify
      ◦  depthbuffer
      ◦  multisampling
var squareVertices = [	                  (5, 33)
                           (-.5, .33)
  	-0.5, -0.33,	
  	 0.5, -0.33,	
  	-0.5, 0.33,	
  	 0.5, 0.33,	            (-.5, -.33)   (5, -.33)
],	

var squareColors = [	
   	255, 255,   0, 255,	
   	0,   255, 255, 255,	
   	0,     0,   0,   0,	
   	255,   0, 255, 255,	
],
view.setFrameBuffer();	
view.clear();	
view.glVertexPointer(2, Ti.Opengl.GL_FLOAT, 0, squareVertices);	
view.glColorPointer(4, Ti.Opengl.GL_UNSIGNED_BYTE, 	
   	  	   	   	   	  	0, squareColors);	
view.glEnableClientState(Ti.Opengl.GL_VERTEX_ARRAY);	
view.glEnableClientState(Ti.Opengl.GL_COLOR_ARRAY);	
view.glDrawArrays(Ti.Opengl.GL_TRIANGLE_STRIP, 0, 4);	
view.presentFrameBuffer()	


   —    OpenGL convenience instructions
         ◦  setFrameBuffer/clear initialize framebuffer
         ◦  presentFrameBuffer submits framebuffer for
            rendering
setInterval(	
         	function(e){	
         	   	drawframe(view, new Date().getTime());	
         	}, 	
         	interval	
      );

var drawframe = function(view, timestamp) { 	
   	view.setFrameBuffer();	
   	view.clear();	
   	view.glLoadIdentity();	
   	view.glTranslatef(0.0, 	
   	   	  	Math.sin(mover.iterate(timestamp))/2.0, 	
   	   	  	0.0);	
   	view.glDrawArrays(Ti.Opengl.GL_TRIANGLE_STRIP, 0, 4); 	
   	view.presentFrameBuffer();	
};
var vertexDB = Ti.Opengl.createDataBuffer({	
        	data : Demo.data.squareVertices,	
        	type : Ti.Opengl.GL_FLOAT	
      });	

      var colorDB = Ti.Opengl.createDataBuffer({	
        	data : Demo.data.squareColors,	
        	type : Ti.Opengl.GL_UNSIGNED_BYTE	
      });

—    A databuffer is a compact opaque representation of an array of data
—    Databuffer properties
      ◦  data
      ◦  type
      ◦  size
view.glVertexPointer(2, Ti.Opengl.GL_FLOAT, 	
  	 	 	 	 	 	 	0, vertexDB);	
view.glColorPointer(4, Ti.Opengl.GL_UNSIGNED_BYTE, 	
  	 	 	 	 	 	 	0, colorDB);	



 —  Vertex   Buffers
   ◦  Databuffers are also used as a bridge to
      facilitating greater efficiency through using
      OpenGL vertex buffers directly.
—  Loading    from files
  ◦  Easiest
    –  Use the pvrtc file format with
        glCompressedTexImage2D and a Ti.Filesystem.File
        argument
  ◦  Alternatively
    –  Use jpg, png, etc. with convenience function
        texImage2D and a Ti.Filesystem.File argument.
—    Using a blob
           var txtr = Ti.Opengl.createTexture({	
              	filter : Ti.Opengl.GL_LINEAR,	
              	view : opengl,	
              	image : blob	
           })


  —    To bind this texture:

view.glBindTexture(Ti.Opengl.GL_TEXTURE_2D, txtr.name);
—  Shaders
  ◦  Creating shader programs using Javascript
    –  reproduce Objective C template
  ◦  Matrix operations
    –  Build Javascript library
    –  Core animation matrix operations (Phase 3)
—  Building   reusable OpenGL abstractions
  ◦  VBBuffers : function(view, dataBufs)
    –  Returns 1 or 2 vertex buffers built from
        DataBuffers contained in dataBufs
  ◦  Shaders : function(vpath, fpath)
    –  Load and compile vertex and fragment shaders
        from files found at vpath and fpath
  ◦  defaultInit : function(view)
    –  Initializes view with a default orthographic
        projection, etc.
—  (As   many as we have time for)

More Related Content

PDF
OpenGL L07-Skybox and Terrian
ODP
LOFAR - finding transients in the radio spectrum
KEY
Cocos2d実践編 1.0.0rc
PDF
Bitcoin:Next
PDF
Single qubit-gates operations
PDF
OpenGL L06-Performance
KEY
W3C HTML5 KIG-How to write low garbage real-time javascript
DOCX
Vtk point cloud important
OpenGL L07-Skybox and Terrian
LOFAR - finding transients in the radio spectrum
Cocos2d実践編 1.0.0rc
Bitcoin:Next
Single qubit-gates operations
OpenGL L06-Performance
W3C HTML5 KIG-How to write low garbage real-time javascript
Vtk point cloud important

What's hot (20)

PPTX
실시간 인벤트 처리
PDF
Kapacitor Alert Topic handlers
PDF
Inc decsourcefile
DOC
vbscript-reference book
PPT
Measuring SGX Texturing Performance
PDF
OpenGL L03-Utilities
PDF
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
PDF
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
PPTX
RedisConf17 - Distributed Java Map Structures and Services with Redisson
PDF
201801 CSE240 Lecture 12
PDF
Multi qubit entanglement
PDF
Openstack taskflow 簡介
PPTX
The State of JavaScript
PDF
What they don't tell you about JavaScript
PDF
Reactive x
PPTX
Nicety of java 8 multithreading for advanced, Max Voronoy
PPT
Full-Stack JavaScript with Node.js
PPTX
Synapse india dotnet development overloading operater part 4
DOCX
PDF
OpenGL Starter L02
실시간 인벤트 처리
Kapacitor Alert Topic handlers
Inc decsourcefile
vbscript-reference book
Measuring SGX Texturing Performance
OpenGL L03-Utilities
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
RedisConf17 - Distributed Java Map Structures and Services with Redisson
201801 CSE240 Lecture 12
Multi qubit entanglement
Openstack taskflow 簡介
The State of JavaScript
What they don't tell you about JavaScript
Reactive x
Nicety of java 8 multithreading for advanced, Max Voronoy
Full-Stack JavaScript with Node.js
Synapse india dotnet development overloading operater part 4
OpenGL Starter L02
Ad

Similar to Richard Salter: Using the Titanium OpenGL Module (20)

PPT
Opengl (1)
PPTX
BYO3D 2011: Rendering
PPT
Open gles
PPT
openGL basics for sample program (1).ppt
PPT
openGL basics for sample program.ppt
PPT
CS 354 Viewing Stuff
DOCX
Lab Practices and Works Documentation / Report on Computer Graphics
PPTX
UNIT 1 OPENGL_UPDATED .pptx
PDF
The Ring programming language version 1.5.1 book - Part 7 of 180
PPTX
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
PDF
The Ring programming language version 1.5.3 book - Part 8 of 184
PDF
The Ring programming language version 1.5.4 book - Part 8 of 185
PDF
18csl67 vtu lab manual
PDF
Computer Graphics - Lecture 01 - 3D Programming I
PDF
Opengl basics
PDF
OpenGL Introduction.
PPTX
Chapter02 graphics-programming
PPTX
COLLADA & WebGL
PDF
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Opengl (1)
BYO3D 2011: Rendering
Open gles
openGL basics for sample program (1).ppt
openGL basics for sample program.ppt
CS 354 Viewing Stuff
Lab Practices and Works Documentation / Report on Computer Graphics
UNIT 1 OPENGL_UPDATED .pptx
The Ring programming language version 1.5.1 book - Part 7 of 180
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
The Ring programming language version 1.5.3 book - Part 8 of 184
The Ring programming language version 1.5.4 book - Part 8 of 185
18csl67 vtu lab manual
Computer Graphics - Lecture 01 - 3D Programming I
Opengl basics
OpenGL Introduction.
Chapter02 graphics-programming
COLLADA & WebGL
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Ad

More from Axway Appcelerator (20)

PDF
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
PPTX
2014 Dublin Web Summit by Jeff Haynie
PPTX
Making the Mobile Mind Shift
PPTX
Stop Debating, Start Measuring
PPTX
Mobile & The New Experience Economy (And What it Means for IT)
PPTX
Apps, APIs & Analytics: What "Mobile First" Really Means
PPTX
Appcelerator Presentation Template
PPTX
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
PPTX
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
PPTX
Codestrong 2012 keynote how to build a top ten app
PPTX
Codestrong 2012 breakout session at&t api platform and trends
PPTX
Codestrong 2012 breakout session what's new in titanium studio
PPTX
Codestrong 2012 breakout session using appcelerator cloud services in your ...
PPTX
Codestrong 2012 breakout session the role of cloud services in your next ge...
PPTX
Codestrong 2012 breakout session new device platform support for titanium
PPTX
Codestrong 2012 breakout session mobile platform and infrastructure
PPTX
Codestrong 2012 breakout session making money on appcelerator's marketplace
PDF
Codestrong 2012 breakout session live multi-platform testing
PPTX
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
PPTX
Codestrong 2012 breakout session i os internals and best practices
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
2014 Dublin Web Summit by Jeff Haynie
Making the Mobile Mind Shift
Stop Debating, Start Measuring
Mobile & The New Experience Economy (And What it Means for IT)
Apps, APIs & Analytics: What "Mobile First" Really Means
Appcelerator Presentation Template
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
Codestrong 2012 keynote how to build a top ten app
Codestrong 2012 breakout session at&t api platform and trends
Codestrong 2012 breakout session what's new in titanium studio
Codestrong 2012 breakout session using appcelerator cloud services in your ...
Codestrong 2012 breakout session the role of cloud services in your next ge...
Codestrong 2012 breakout session new device platform support for titanium
Codestrong 2012 breakout session mobile platform and infrastructure
Codestrong 2012 breakout session making money on appcelerator's marketplace
Codestrong 2012 breakout session live multi-platform testing
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
Codestrong 2012 breakout session i os internals and best practices

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
Spectral efficient network and resource selection model in 5G networks
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
20250228 LYD VKU AI Blended-Learning.pptx
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A Presentation on Artificial Intelligence
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 3 Spatial Domain Image Processing.pdf
Electronic commerce courselecture one. Pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Richard Salter: Using the Titanium OpenGL Module

  • 1. The Titanium OpenGL Module: Sophisticated Graphics for the Ti Programmer Richard Salter
  • 3. —  What is OpenGL? ◦  An API for managing a 3D graphics environment. –  not OO –  OpenGL “pipeline”
  • 4. —  Getting Ti/Javascript and OpenGL to play nicely together ◦  “Objectify” the OpenGL API with respect to a drawing surface –  Create a natural extension to the Titanium object model. –  Ti.OpenGL.View ◦  Compensate for inefficiencies introduced by moving programming level to Javascript. –  Cope with the large volume of data associated with a given OpenGL model. –  Ti.OpenGL.DataBuffer
  • 6. var Ti.Opengl = require('Ti.OpenGL'); var view = Ti.Opengl.createView({ backgroundColor:"#aaa", top:0, left:0 width:’100%’, height:’100%’, }), —  Creates OpenGL context and view —  Initializes Framebuffers and Renderbuffers —  Optionally: can specify ◦  depthbuffer ◦  multisampling
  • 7. var squareVertices = [ (5, 33) (-.5, .33) -0.5, -0.33, 0.5, -0.33, -0.5, 0.33, 0.5, 0.33, (-.5, -.33) (5, -.33) ], var squareColors = [ 255, 255, 0, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 255, 255, ],
  • 8. view.setFrameBuffer(); view.clear(); view.glVertexPointer(2, Ti.Opengl.GL_FLOAT, 0, squareVertices); view.glColorPointer(4, Ti.Opengl.GL_UNSIGNED_BYTE, 0, squareColors); view.glEnableClientState(Ti.Opengl.GL_VERTEX_ARRAY); view.glEnableClientState(Ti.Opengl.GL_COLOR_ARRAY); view.glDrawArrays(Ti.Opengl.GL_TRIANGLE_STRIP, 0, 4); view.presentFrameBuffer() —  OpenGL convenience instructions ◦  setFrameBuffer/clear initialize framebuffer ◦  presentFrameBuffer submits framebuffer for rendering
  • 9. setInterval( function(e){ drawframe(view, new Date().getTime()); }, interval ); var drawframe = function(view, timestamp) { view.setFrameBuffer(); view.clear(); view.glLoadIdentity(); view.glTranslatef(0.0, Math.sin(mover.iterate(timestamp))/2.0, 0.0); view.glDrawArrays(Ti.Opengl.GL_TRIANGLE_STRIP, 0, 4); view.presentFrameBuffer(); };
  • 10. var vertexDB = Ti.Opengl.createDataBuffer({ data : Demo.data.squareVertices, type : Ti.Opengl.GL_FLOAT }); var colorDB = Ti.Opengl.createDataBuffer({ data : Demo.data.squareColors, type : Ti.Opengl.GL_UNSIGNED_BYTE }); —  A databuffer is a compact opaque representation of an array of data —  Databuffer properties ◦  data ◦  type ◦  size
  • 11. view.glVertexPointer(2, Ti.Opengl.GL_FLOAT, 0, vertexDB); view.glColorPointer(4, Ti.Opengl.GL_UNSIGNED_BYTE, 0, colorDB); —  Vertex Buffers ◦  Databuffers are also used as a bridge to facilitating greater efficiency through using OpenGL vertex buffers directly.
  • 12. —  Loading from files ◦  Easiest –  Use the pvrtc file format with glCompressedTexImage2D and a Ti.Filesystem.File argument ◦  Alternatively –  Use jpg, png, etc. with convenience function texImage2D and a Ti.Filesystem.File argument.
  • 13. —  Using a blob var txtr = Ti.Opengl.createTexture({ filter : Ti.Opengl.GL_LINEAR, view : opengl, image : blob }) —  To bind this texture: view.glBindTexture(Ti.Opengl.GL_TEXTURE_2D, txtr.name);
  • 14. —  Shaders ◦  Creating shader programs using Javascript –  reproduce Objective C template ◦  Matrix operations –  Build Javascript library –  Core animation matrix operations (Phase 3)
  • 15. —  Building reusable OpenGL abstractions ◦  VBBuffers : function(view, dataBufs) –  Returns 1 or 2 vertex buffers built from DataBuffers contained in dataBufs ◦  Shaders : function(vpath, fpath) –  Load and compile vertex and fragment shaders from files found at vpath and fpath ◦  defaultInit : function(view) –  Initializes view with a default orthographic projection, etc.
  • 16. —  (As many as we have time for)