SlideShare une entreprise Scribd logo
1  sur  27
WebGL
Is it a game changer for web
based game development?
Iker Jamardo
HTML5 Developers Conference
2013/10/23
About Ludei...
• San Francisco based company.
• Started developing native iOS and
Android games.
• More than 18M users have
downloaded a game by Ludei.
• Developers of CocoonJS platform to
push HTML5 game and app
development.
• 10K+ developers, 500+ games
About me...
Iker Jamardo Zugaza
@judax
• I run engineering @ Ludei.
• Passionate about software architecture. A C/C++ and
Java lover (refurbished to JavaScript).
• Former University Professor and Researcher.
• Designed and implemented the core of Ludei’s crossplatform technology.
What is WebGL?
• Stands for Web Graphics Library.
• Maintained by the non-profit Khronos Group
http://www.khronos.org
• A Web Standard JavaScript API for accessing the
underlying graphics hardware without the need of
plugins.
• WebGL 1.0 is based on OpenGL ES 2.0
• Available in the major desktop browsers:
Advantages of WebGL
• Allows low level access to the graphics hardware
while still being in a web based environment, with all
it’s advantages:
» Cross-platform
» Rapid prototyping: JavaScript.
» Execute and update anytime and anywhere.
» Integration with document level content.
» There are ways to access native features without
leaving the JavaScript + HTML space.
» Great communication environment.
Let’s see WebGL in action!
• For commercial purposes:
» http://carvisualizer.plus360degrees.com/threejs/
• For Games:
» http://www.webgl.com/category/webgl-games/
» http://playtankworld.com/
» https://triggerrally.com/
» http://www.goodboydigital.com/runpixierun/
» https://turbulenz.com/games/save-the-day/
Is WebGL just for 3D
content?
• WebGL is not for 3D visualization only. 2D
apps/games can benefit from access to the graphics
hardware.
• Canvas 2D Vs WebGL contexts APIs:
» The 2D context provides a high level graphics API:
» Primitives, complex paths, gradients, ...
» The WebGL context is a low level graphics
hardware management API similar to OpenGL.
» Some program level code + GPU shader code.
What does WebGL look
like?
• Accessing the WebGL context in the application code:
// WebGL is bound to an HTML5 canvas.
// Either get it from the document or create a new one.
var canvas = document.createElement(“canvas”);

// Get the WebGL context from the canvas.
// Depending on the browser, there are different context
// names:
// “experimental-webgl”: Chrome, Opera, IE11

// “moz-webgl”: Mozilla Firefox
// “webkit-3d”: Safari
var gl = canvas.getContext(“experimental-webgl”);
What does WebGL look
like?
• The simplest vertex shader:
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
void main(void) {
gl_Position = uPMatrix * uMVMatrix *
vec4(aVertexPosition, 1.0);
}
</script>
What does WebGL look
like?
• The simplest fragment shader:

<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
void main(void) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

</script>
What does WebGL look
like?
• Basic steps to setup a WebGL application:
» Initialization phase:
» Retrieve the WebGL context.
» Setup WebGL data: array buffers, textures, lights, ...
» Load shader programs and get the connections to the
shader code variables (attributes and uniforms).

» Update and render loop phase:
» Update your app/game logic.

» Render you app/game.
» Pass information to the shaders.
» Execute the shaders: vertex -> fragment
What does WebGL look
like?
gl = canvas.getContext("experimental-webgl");

<html>

gl.viewportWidth = canvas.width;

<head>

shader = gl.createShader(gl.VERTEX_SHADER);

} catch (e) {

<meta http-equiv="content-type" content="text/html; charset=ISO-88591">

} else {

}

return null;

if (!gl) {

<script type="text/javascript" src="glMatrix-0.9.5.min.js"></script>

}

alert("Could not initialise WebGL, sorry :-(");

<script id="shader-fs" type="x-shader/x-fragment">

gl.shaderSource(shader, str);

}

precision mediump float;

gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);

} else if (shaderScript.type == "x-shader/x-vertex") {

gl.viewportHeight = canvas.height;

<title>Learning WebGL &mdash; lesson 1</title>

void main(void) {

shader = gl.createShader(gl.FRAGMENT_SHADER);

gl.compileShader(shader);

}

if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {

function getShader(gl, id) {

alert(gl.getShaderInfoLog(shader));

var shaderScript = document.getElementById(id);

}

</script>

return null;

if (!shaderScript) {

}

return null;

<script id="shader-vs" type="x-shader/x-vertex">

return shader;

}

}

var str = "";

var shaderProgram;

uniform mat4 uPMatrix;

var k = shaderScript.firstChild;

function initShaders() {

void main(void) {

while (k) {

attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;

if (k.nodeType == 3) {

gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);

var fragmentShader = getShader(gl, "shader-fs");
var vertexShader = getShader(gl, "shader-vs");

str += k.textContent;

}
}

<script type="text/javascript">

shaderProgram = gl.createProgram();

k = k.nextSibling;

</script>

gl.attachShader(shaderProgram, vertexShader);

var gl;

}

gl.attachShader(shaderProgram, fragmentShader);

function initGL(canvas) {

var shader;

gl.linkProgram(shaderProgram);

try {

if (shaderScript.type == "x-shader/x-fragment") {
What does WebGL look
like?

if (!gl.getProgramParameter(shaderProgram,
gl.LINK_STATUS)) {

1.0, -1.0, 0.0

];
alert("Could not initialise shaders");
}

gl.bufferData(gl.ARRAY_BUFFER, new
Float32Array(vertices), gl.STATIC_DRAW);

gl.useProgram(shaderProgram);

shaderProgram.vertexPositionAttribute =
gl.getAttribLocation(shaderProgram, "aVertexPosition");
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute
);
shaderProgram.pMatrixUniform =
gl.getUniformLocation(shaderProgram, "uPMatrix");

triangleVertexPositionBuffer.itemSize = 3;

mat4.translate(mvMatrix, [-1.5, 0.0, -7.0]);

gl.bindBuffer(gl.ARRAY_BUFFER,
triangleVertexPositionBuffer);
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute,
triangleVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);

triangleVertexPositionBuffer.numItems = 3;
setMatrixUniforms();
squareVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,
squareVertexPositionBuffer);

gl.drawArrays(gl.TRIANGLES, 0,
triangleVertexPositionBuffer.numItems);
mat4.translate(mvMatrix, [3.0, 0.0, 0.0]);

vertices = [

shaderProgram.mvMatrixUniform =
gl.getUniformLocation(shaderProgram, "uMVMatrix");

1.0, 1.0, 0.0,

}

-1.0, 1.0, 0.0,

var mvMatrix = mat4.create();

1.0, -1.0, 0.0,

var pMatrix = mat4.create();

gl.bindBuffer(gl.ARRAY_BUFFER,
squareVertexPositionBuffer);

-1.0, -1.0, 0.0
];

function setMatrixUniforms() {
gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false,
pMatrix);

gl.bufferData(gl.ARRAY_BUFFER, new
Float32Array(vertices), gl.STATIC_DRAW);
squareVertexPositionBuffer.itemSize = 3;

gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false,
mvMatrix);
}

squareVertexPositionBuffer.numItems = 4;

gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute,
squareVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);
setMatrixUniforms();
gl.drawArrays(gl.TRIANGLE_STRIP, 0,
squareVertexPositionBuffer.numItems);
}
function webGLStart() {
var canvas = document.getElementById("lesson01-canvas");

}

var triangleVertexPositionBuffer;
var squareVertexPositionBuffer;
function initBuffers() {
triangleVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER,
triangleVertexPositionBuffer);
var vertices = [

initGL(canvas);

function drawScene() {

initShaders();

gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);

initBuffers();

gl.clear(gl.COLOR_BUFFER_BIT |
gl.DEPTH_BUFFER_BIT);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
mat4.perspective(45, gl.viewportWidth / gl.viewportHeight,
0.1, 100.0, pMatrix);

gl.enable(gl.DEPTH_TEST);
What does WebGL look
like?
The awesome result!
</script>
</head>
<body onload="webGLStart();">
<a href="http://learningwebgl.com/blog/?p=28">&lt;&lt; Back to
Lesson 1</a><br />
<canvas id="lesson01-canvas" style="border: none;"
width="500" height="500"></canvas>

<br/>
<a href="http://learningwebgl.com/blog/?p=28">&lt;&lt; Back to
Lesson 1</a><br />
</body>
</html>
Learn WebGL!
• Some resources to start playing around with WebGL:
» http://learningwebgl.com/
» http://www.khronos.org/webgl/ and it‘s wiki.
» https://developer.mozilla.org/enUS/docs/Web/WebGL/Getting_started_with_WebGL
» http://www.html5rocks.com/en/tutorials/webgl/webgl_funda
mentals/
WebGL Game Engines
• Working in WebGL from scratch in a professional
project is challenging.
• This is when Game Engines come handy:
» High level APIs and tools that speed up and
simplify the app/game development process.
» http://html5gameengine.com/
» ThreeJS: http://threejs.org/
» Goo: http://www.gooengine.com/

» PlayCanvas: http://playcanvas.com/
» Construct2: https://www.scirra.com/construct2
» PixiJS: http://www.pixijs.com/
WebGL Game Engines
WebGL Game Engines
Tips to select the best
Game Engine
• The project must guide the selection (not all the way
around).
• 2D or 3D (or both)? Fallback to canvas 2D?
• Does it have an editor (or tools)?
• Is it open source (or easily extensible)?
• What games/apps have been developed using it?
• Does it have a pipeline defined? From design to code.
• Does it have the option to export cross-platform
(specially mobile) apps?
Cross-platform WebGL
(specially mobile)
• In order to say that WebGL is truly cross-platform, it
must be supported on mobile:

4.0
+
Options for WebGL on
mobile
• No one wants to play on a browser on mobile.
» Users: We want apps!
» Developers: We want to monetize!
• Options to deploy a native app that runs WebGL.
» EjectaGL: Only iOS support.
» Ludei: Both iOS and Android support.
Ludei
• An optimized JSVM for canvas 2D and WebGL.
» Same environment across all devices/OS-s.
» Hardware accelerated: No bounds as a browser.
• An easy to use environment:
» The CocoonJS Launcher App for testing
(debugging/profiling).
» The Ludei cloud to configure and compile the
bundles for different platforms.
• Extensions to access native features/services.
» IAPs, Ads, Push Notifications, Social Networks, ...
Ludei
Ludei

Let see some WebGL running
on both iOS and Android!
Tips for WebGL on mobile
• Understand that mobile is not a desktop system:
» Limited processing power.
» Limited memory.
» Different resolutions.
» Different input.
• Pack your textures: Less fottprint and more
performance.
• Do not load what is not necessary.
• Keep calls to the GPU as low as possible for better
performance.
Conclusions
• HTML5 + WebGL is an amazing technology for
developing Rich Internet Applications with no plugins.
• There are options (engines/tools) to simplify the
process of building these apps and games.
• There are options to run your apps and games on
mobile.
THANK YOU!
ANY QUESTIONS?
Visit our booth at the conference expo for demo showcase and more info.

Contenu connexe

Tendances

[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
Christopher Schmitt
 

Tendances (20)

2013 04-02-server-side-backbone
2013 04-02-server-side-backbone2013 04-02-server-side-backbone
2013 04-02-server-side-backbone
 
Dojo (QCon 2007 Slides)
Dojo (QCon 2007 Slides)Dojo (QCon 2007 Slides)
Dojo (QCon 2007 Slides)
 
React JS Belgium Touch Base - React, Flux, React Native
React JS Belgium Touch Base - React, Flux, React NativeReact JS Belgium Touch Base - React, Flux, React Native
React JS Belgium Touch Base - React, Flux, React Native
 
Using Features
Using FeaturesUsing Features
Using Features
 
Korea linuxforum2014 html5game-sangseoklim
Korea linuxforum2014 html5game-sangseoklimKorea linuxforum2014 html5game-sangseoklim
Korea linuxforum2014 html5game-sangseoklim
 
Next generation Graphics: SVG
Next generation Graphics: SVGNext generation Graphics: SVG
Next generation Graphics: SVG
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start)
 
Webpack
Webpack Webpack
Webpack
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
Webpack slides
Webpack slidesWebpack slides
Webpack slides
 
HTML 5 - Overview
HTML 5 - OverviewHTML 5 - Overview
HTML 5 - Overview
 
Lecture: Webpack 4
Lecture: Webpack 4Lecture: Webpack 4
Lecture: Webpack 4
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
BreizhBeans - Web components
BreizhBeans - Web componentsBreizhBeans - Web components
BreizhBeans - Web components
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
 
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
 
Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
 
[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 

Similaire à HTML5DevConf 2013 (October): WebGL is a game changer!

Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012
philogb
 
New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011
philogb
 
The Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG FilesThe Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG Files
Mario Heiderich
 

Similaire à HTML5DevConf 2013 (October): WebGL is a game changer! (20)

Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012
 
New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011New Tools for Visualization in JavaScript - Sept. 2011
New Tools for Visualization in JavaScript - Sept. 2011
 
WebGL Awesomeness
WebGL AwesomenessWebGL Awesomeness
WebGL Awesomeness
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
Academy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphicsAcademy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphics
 
Introduction to html5 game programming with ImpactJs
Introduction to html5 game programming with ImpactJsIntroduction to html5 game programming with ImpactJs
Introduction to html5 game programming with ImpactJs
 
Apache Flex and the imperfect Web
Apache Flex and the imperfect WebApache Flex and the imperfect Web
Apache Flex and the imperfect Web
 
Html5 Game Development with Canvas
Html5 Game Development with CanvasHtml5 Game Development with Canvas
Html5 Game Development with Canvas
 
JavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkJavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web framework
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
Using Javascript in today's world
Using Javascript in today's worldUsing Javascript in today's world
Using Javascript in today's world
 
VizEx View HTML5 Workshop
VizEx View HTML5 WorkshopVizEx View HTML5 Workshop
VizEx View HTML5 Workshop
 
VizEx View HTML5 Workshop
VizEx View HTML5 WorkshopVizEx View HTML5 Workshop
VizEx View HTML5 Workshop
 
Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5
 
The Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG FilesThe Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG Files
 
Installing Games Sucks, Learn WebGL
Installing Games Sucks, Learn WebGLInstalling Games Sucks, Learn WebGL
Installing Games Sucks, Learn WebGL
 
HTML5 and Other Modern Browser Game Tech
HTML5 and Other Modern Browser Game TechHTML5 and Other Modern Browser Game Tech
HTML5 and Other Modern Browser Game Tech
 
Node azure
Node azureNode azure
Node azure
 
GWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO ToolsGWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO Tools
 
WebGL For Game Development Spring 2013
WebGL For Game Development Spring 2013WebGL For Game Development Spring 2013
WebGL For Game Development Spring 2013
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

HTML5DevConf 2013 (October): WebGL is a game changer!

  • 1. WebGL Is it a game changer for web based game development? Iker Jamardo HTML5 Developers Conference 2013/10/23
  • 2. About Ludei... • San Francisco based company. • Started developing native iOS and Android games. • More than 18M users have downloaded a game by Ludei. • Developers of CocoonJS platform to push HTML5 game and app development. • 10K+ developers, 500+ games
  • 3. About me... Iker Jamardo Zugaza @judax • I run engineering @ Ludei. • Passionate about software architecture. A C/C++ and Java lover (refurbished to JavaScript). • Former University Professor and Researcher. • Designed and implemented the core of Ludei’s crossplatform technology.
  • 4. What is WebGL? • Stands for Web Graphics Library. • Maintained by the non-profit Khronos Group http://www.khronos.org • A Web Standard JavaScript API for accessing the underlying graphics hardware without the need of plugins. • WebGL 1.0 is based on OpenGL ES 2.0 • Available in the major desktop browsers:
  • 5. Advantages of WebGL • Allows low level access to the graphics hardware while still being in a web based environment, with all it’s advantages: » Cross-platform » Rapid prototyping: JavaScript. » Execute and update anytime and anywhere. » Integration with document level content. » There are ways to access native features without leaving the JavaScript + HTML space. » Great communication environment.
  • 6. Let’s see WebGL in action! • For commercial purposes: » http://carvisualizer.plus360degrees.com/threejs/ • For Games: » http://www.webgl.com/category/webgl-games/ » http://playtankworld.com/ » https://triggerrally.com/ » http://www.goodboydigital.com/runpixierun/ » https://turbulenz.com/games/save-the-day/
  • 7. Is WebGL just for 3D content? • WebGL is not for 3D visualization only. 2D apps/games can benefit from access to the graphics hardware. • Canvas 2D Vs WebGL contexts APIs: » The 2D context provides a high level graphics API: » Primitives, complex paths, gradients, ... » The WebGL context is a low level graphics hardware management API similar to OpenGL. » Some program level code + GPU shader code.
  • 8. What does WebGL look like? • Accessing the WebGL context in the application code: // WebGL is bound to an HTML5 canvas. // Either get it from the document or create a new one. var canvas = document.createElement(“canvas”); // Get the WebGL context from the canvas. // Depending on the browser, there are different context // names: // “experimental-webgl”: Chrome, Opera, IE11 // “moz-webgl”: Mozilla Firefox // “webkit-3d”: Safari var gl = canvas.getContext(“experimental-webgl”);
  • 9. What does WebGL look like? • The simplest vertex shader: <script id="shader-vs" type="x-shader/x-vertex"> attribute vec3 aVertexPosition; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; void main(void) { gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); } </script>
  • 10. What does WebGL look like? • The simplest fragment shader: <script id="shader-fs" type="x-shader/x-fragment"> precision mediump float; void main(void) { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } </script>
  • 11. What does WebGL look like? • Basic steps to setup a WebGL application: » Initialization phase: » Retrieve the WebGL context. » Setup WebGL data: array buffers, textures, lights, ... » Load shader programs and get the connections to the shader code variables (attributes and uniforms). » Update and render loop phase: » Update your app/game logic. » Render you app/game. » Pass information to the shaders. » Execute the shaders: vertex -> fragment
  • 12. What does WebGL look like? gl = canvas.getContext("experimental-webgl"); <html> gl.viewportWidth = canvas.width; <head> shader = gl.createShader(gl.VERTEX_SHADER); } catch (e) { <meta http-equiv="content-type" content="text/html; charset=ISO-88591"> } else { } return null; if (!gl) { <script type="text/javascript" src="glMatrix-0.9.5.min.js"></script> } alert("Could not initialise WebGL, sorry :-("); <script id="shader-fs" type="x-shader/x-fragment"> gl.shaderSource(shader, str); } precision mediump float; gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } else if (shaderScript.type == "x-shader/x-vertex") { gl.viewportHeight = canvas.height; <title>Learning WebGL &mdash; lesson 1</title> void main(void) { shader = gl.createShader(gl.FRAGMENT_SHADER); gl.compileShader(shader); } if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { function getShader(gl, id) { alert(gl.getShaderInfoLog(shader)); var shaderScript = document.getElementById(id); } </script> return null; if (!shaderScript) { } return null; <script id="shader-vs" type="x-shader/x-vertex"> return shader; } } var str = ""; var shaderProgram; uniform mat4 uPMatrix; var k = shaderScript.firstChild; function initShaders() { void main(void) { while (k) { attribute vec3 aVertexPosition; uniform mat4 uMVMatrix; if (k.nodeType == 3) { gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); var fragmentShader = getShader(gl, "shader-fs"); var vertexShader = getShader(gl, "shader-vs"); str += k.textContent; } } <script type="text/javascript"> shaderProgram = gl.createProgram(); k = k.nextSibling; </script> gl.attachShader(shaderProgram, vertexShader); var gl; } gl.attachShader(shaderProgram, fragmentShader); function initGL(canvas) { var shader; gl.linkProgram(shaderProgram); try { if (shaderScript.type == "x-shader/x-fragment") {
  • 13. What does WebGL look like? if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { 1.0, -1.0, 0.0 ]; alert("Could not initialise shaders"); } gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); gl.useProgram(shaderProgram); shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute ); shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix"); triangleVertexPositionBuffer.itemSize = 3; mat4.translate(mvMatrix, [-1.5, 0.0, -7.0]); gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexPositionBuffer); gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, triangleVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0); triangleVertexPositionBuffer.numItems = 3; setMatrixUniforms(); squareVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, squareVertexPositionBuffer); gl.drawArrays(gl.TRIANGLES, 0, triangleVertexPositionBuffer.numItems); mat4.translate(mvMatrix, [3.0, 0.0, 0.0]); vertices = [ shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); 1.0, 1.0, 0.0, } -1.0, 1.0, 0.0, var mvMatrix = mat4.create(); 1.0, -1.0, 0.0, var pMatrix = mat4.create(); gl.bindBuffer(gl.ARRAY_BUFFER, squareVertexPositionBuffer); -1.0, -1.0, 0.0 ]; function setMatrixUniforms() { gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, pMatrix); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); squareVertexPositionBuffer.itemSize = 3; gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix); } squareVertexPositionBuffer.numItems = 4; gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, squareVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0); setMatrixUniforms(); gl.drawArrays(gl.TRIANGLE_STRIP, 0, squareVertexPositionBuffer.numItems); } function webGLStart() { var canvas = document.getElementById("lesson01-canvas"); } var triangleVertexPositionBuffer; var squareVertexPositionBuffer; function initBuffers() { triangleVertexPositionBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexPositionBuffer); var vertices = [ initGL(canvas); function drawScene() { initShaders(); gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight); initBuffers(); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); gl.clearColor(0.0, 0.0, 0.0, 1.0); mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix); gl.enable(gl.DEPTH_TEST);
  • 14. What does WebGL look like? The awesome result! </script> </head> <body onload="webGLStart();"> <a href="http://learningwebgl.com/blog/?p=28">&lt;&lt; Back to Lesson 1</a><br /> <canvas id="lesson01-canvas" style="border: none;" width="500" height="500"></canvas> <br/> <a href="http://learningwebgl.com/blog/?p=28">&lt;&lt; Back to Lesson 1</a><br /> </body> </html>
  • 15. Learn WebGL! • Some resources to start playing around with WebGL: » http://learningwebgl.com/ » http://www.khronos.org/webgl/ and it‘s wiki. » https://developer.mozilla.org/enUS/docs/Web/WebGL/Getting_started_with_WebGL » http://www.html5rocks.com/en/tutorials/webgl/webgl_funda mentals/
  • 16. WebGL Game Engines • Working in WebGL from scratch in a professional project is challenging. • This is when Game Engines come handy: » High level APIs and tools that speed up and simplify the app/game development process. » http://html5gameengine.com/ » ThreeJS: http://threejs.org/ » Goo: http://www.gooengine.com/ » PlayCanvas: http://playcanvas.com/ » Construct2: https://www.scirra.com/construct2 » PixiJS: http://www.pixijs.com/
  • 19. Tips to select the best Game Engine • The project must guide the selection (not all the way around). • 2D or 3D (or both)? Fallback to canvas 2D? • Does it have an editor (or tools)? • Is it open source (or easily extensible)? • What games/apps have been developed using it? • Does it have a pipeline defined? From design to code. • Does it have the option to export cross-platform (specially mobile) apps?
  • 20. Cross-platform WebGL (specially mobile) • In order to say that WebGL is truly cross-platform, it must be supported on mobile: 4.0 +
  • 21. Options for WebGL on mobile • No one wants to play on a browser on mobile. » Users: We want apps! » Developers: We want to monetize! • Options to deploy a native app that runs WebGL. » EjectaGL: Only iOS support. » Ludei: Both iOS and Android support.
  • 22. Ludei • An optimized JSVM for canvas 2D and WebGL. » Same environment across all devices/OS-s. » Hardware accelerated: No bounds as a browser. • An easy to use environment: » The CocoonJS Launcher App for testing (debugging/profiling). » The Ludei cloud to configure and compile the bundles for different platforms. • Extensions to access native features/services. » IAPs, Ads, Push Notifications, Social Networks, ...
  • 23. Ludei
  • 24. Ludei Let see some WebGL running on both iOS and Android!
  • 25. Tips for WebGL on mobile • Understand that mobile is not a desktop system: » Limited processing power. » Limited memory. » Different resolutions. » Different input. • Pack your textures: Less fottprint and more performance. • Do not load what is not necessary. • Keep calls to the GPU as low as possible for better performance.
  • 26. Conclusions • HTML5 + WebGL is an amazing technology for developing Rich Internet Applications with no plugins. • There are options (engines/tools) to simplify the process of building these apps and games. • There are options to run your apps and games on mobile.
  • 27. THANK YOU! ANY QUESTIONS? Visit our booth at the conference expo for demo showcase and more info.