SlideShare ist ein Scribd-Unternehmen logo
1 von 32
WebGL 입문4
초미니? 2D엔진 만들기!
ProjectBS – WebGL 소모임
ProjectBS – WebGL 소모임
오늘의 목표!
Rect Base 2D 엔진
Color, Bitmap 재질
ProjectBS – WebGL 소모임
TODO LIST!
1. 초기화!
2. 쉐이더파서!
3. 버퍼생성기!
4. 텍스쳐생성기!
5. 메쉬구조체!
6. 재질구조체!
7. 루프관리!
8. 렌더러!
ProjectBS – WebGL 소모임
원하는 API
bsGL.init(
'canvas‘ , // ID or Canvas Object
function(){
console.log('초기화!')
// Host Code
},
‘쉐이더.js','확장.js‘
)
bsGL.init(
'canvas‘ , // ID or Canvas Object
function(){
console.log('초기화!')
// Host Code
},
‘쉐이더.js','확장.js‘
)
ProjectBS – WebGL 소모임
Gl객체 찾기
확장,
쉐이더.js
로딩 / 파싱
호스트 실행
초기화를 하면?
var bsGL = (function () {
var W = window, DOC = document, HEAD = DOC.getElementsByTagName('head')[0];
var API = {
gl: null, cvs: null,
VBOS: {}, UVBOS: {}, IBOS: {}, // 버퍼관리용 공간
PROGRAMS: {}, TEXTURES: {}, // 프로그램 텍스쳐 공간
LOOPS: {}, // 루프를 관리할 공간
SHADER_SOURCES: {}, // 파싱된 쉐이더를 관리할 공간
children: [], // 루트의 자식객체를 관리할 공간
init: function ($cvs, $func) {
// 먼가 실행
}
}
return API
})();
ProjectBS – WebGL 소모임
가볍게 엔진구조체 생각!
bsGL.init(~~~)
bsGL.children.push(~~~)
ProjectBS – WebGL 소모임
bsGL.init 구현!
init: function ($cvs, $func) {
var script, list = arguments, i = list.length - 1
load(list[i])
function load($src) {
script ? (script.onload = null, HEAD.removeChild(script)) : 0
script = DOC.createElement('script')
script.type = 'text/javascript', script.charset = 'utf-8', script.src = $src
if (i == 2) script.onload = function () {
script.onload = null, HEAD.removeChild(script)
// 호스트 실행 전 우리가 필요한 것들을 한다!
// context3d를 얻어야겠고…
// 엔진에 기본적으로 필요한 주요버퍼와 프로그램을 미리생성한다!
$func() // 호스트 실행!
}
else script.onload = function () {
load(list[i])
}
HEAD.appendChild(script)
i--
}
}
ProjectBS – WebGL 소모임
호스트 실행전 준비!
if (i == 2) script.onload = function () {
script.onload = null, HEAD.removeChild(script)
API.getGL($cvs)
API.setBase()
$func();
(function animloop() {
for (var k in API.LOOPS) API.LOOPS[k]()
API.render()
requestAnimFrame(animloop)
})()
}
var bsGL = (function () {
var API = {
…
…
render: function () {},
setBase: function () {}
}
return API
})();
ProjectBS – WebGL 소모임
getGL 구현
getGL: function ($cvs) {
var cvs = typeof $cvs == 'string' ? DOC.getElementById($cvs) : $cvs;
var keys = 'webgl,experimental-webgl,webkit-3d,moz-webgl'.split(','), i = keys.length
while (i--) if (gl = cvs.getContext(keys[i])) break
console.log(gl ? 'webgl 초기화 성공!' : console.log('webgl 초기화 실패!!'))
API.gl = gl, API.cvs = cvs
}
ProjectBS – WebGL 소모임
setBase 구현
1. Rect와 관련된 버퍼를 생성한다!
2. 쉐이더.js를 해석해서 쉐이더 & 프로그램을
만든다.
bsGL.setBase = function () {
var data = [-0.5, -0.5, 0.0, 0.5, -0.5, 0.0, -0.5, 0.5, 0.0, 0.5, 0.5, 0.0 ]
var index = [0, 1, 2, 1, 2, 3]
var uv = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0]
bsGL.makeBuffer('VBOS', 'rect', data, 3)
bsGL.makeBuffer('IBOS', 'rect', index, 1)
bsGL.makeBuffer('UVBOS', 'rect', uv, 2)
bsGL.makeBuffer('VBOS', 'null', [-0.5, -0.5, 0.0], 3)
bsGL.shaderParser()
}
ProjectBS – WebGL 소모임
makeBuffer 구현
bsGL.makeBuffer = function ($type, $name, $data, $itemSize, $drawType) {
var gl = bsGL.gl
// $type : IBOS….
var buffer = bsGL[$type][$name], bufferType, arrayType
if (buffer) return buffer
buffer = gl.createBuffer()
bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER
arrayType = $type == 'IBOS' ? Uint16Array : Float32Array
gl.bindBuffer(bufferType, buffer)
gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW)
buffer.name = $name, buffer.type = $type
buffer.itemSize = $itemSize
buffer.numItem = $data.length / $itemSize
bsGL[$type][$name] = buffer
console.log(bsGL[$type][$name])
}
Ex.js
ProjectBS – WebGL 소모임
Shader 소스 구조체!
bsGL.SHADER_SOURCES['color'] = {
vertex: "n",
fragment: "n",
attribs: 'aVertexPosition', // 사용한 버퍼
uniforms: 'uPixelMatrix,uRotation,uPosition,uScale,uColor' // 사용한 유니폼
}
shader.js
ProjectBS – WebGL 소모임
Shader Parser 구현!
bsGL.shaderParser = function () {
var gl = bsGL.gl, vShader, fShader, program
for (var k in bsGL.SHADER_SOURCES) {
var t = bsGL.SHADER_SOURCES[k]
vShader = gl.createShader(gl.VERTEX_SHADER)
gl.shaderSource(vShader, t.vertex), gl.compileShader(vShader)
fShader = gl.createShader(gl.FRAGMENT_SHADER)
gl.shaderSource(fShader, t.fragment), gl.compileShader(fShader)
program = gl.createProgram()
gl.attachShader(program, vShader), gl.attachShader(program, fShader)
gl.linkProgram(program)
vShader.name = k + '_vertex', fShader.name = k + '_fragment',
program.name = k
bsGL.PROGRAMS[k] = program
console.log(vShader), console.log(fShader), console.log(program)
}
} Ex.js
bsGL.shaderParser = function () {
var gl = bsGL.gl, vShader, fShader, program
for (var k in bsGL.SHADER_SOURCES) {
var t = bsGL.SHADER_SOURCES[k]
vShader = gl.createShader(gl.VERTEX_SHADER)
gl.shaderSource(vShader, t.vertex), gl.compileShader(vShader)
fShader = gl.createShader(gl.FRAGMENT_SHADER)
gl.shaderSource(fShader, t.fragment), gl.compileShader(fShader)
program = gl.createProgram()
gl.attachShader(program, vShader), gl.attachShader(program, fShader)
gl.linkProgram(program)
vShader.name = k + '_vertex', fShader.name = k + '_fragment',
program.name = k
bsGL.PROGRAMS[k] = program
console.log(vShader), console.log(fShader), console.log(program)
}
}
ProjectBS – WebGL 소모임
Shader Parser 구현!
var gl = bsGL.gl, vShader, fShader, program
for (var k in bsGL.SHADER_SOURCES) {
…
gl.useProgram(program)
var i = 0, list = t.attribs.split(','), max = list.length, key
for (i; i < max; i++) {
key = list[i]
program[key] = gl.getAttribLocation(program, key);
gl.bindBuffer(gl.ARRAY_BUFFER, bsGL.VBOS['null'])
gl.vertexAttribPointer(program[key], bsGL.VBOS['null'].itemSize, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(program[key]);
}
list = t.uniforms.split(','), max = list.length
for (i = 0; i < max; i++) {
key = list[i]
program[key] = gl.getUniformLocation(program, key);
}
bsGL.PROGRAMS[k] = program
}
ProjectBS – WebGL 소모임
Shader Parser 구현2!
Ex.js
bsGL.makeBuffer = function ($type, $name, $data, $itemSize, $drawType) {
var gl = bsGL.gl
// $type : IBOS, ....
var buffer = bsGL[$type][$name], bufferType, arrayType
if (buffer) return buffer
buffer = gl.createBuffer()
bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER
arrayType = $type == 'IBOS' ? Uint16Array : Float32Array
gl.bindBuffer(bufferType, buffer)
gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW)
buffer.name = $name, buffer.type = $type
buffer.itemSize = $itemSize, buffer.numItem = $data.length / $itemSize
bsGL[$type][$name] = buffer
}
ProjectBS – WebGL 소모임
bsGL.MakeBuffer() 구현
bsGL.makeBuffer = function ($type, $name, $data, $itemSize, $drawType) {
var gl = bsGL.gl
// $type : IBOS, ....
var buffer = bsGL[$type][$name], bufferType, arrayType
if (buffer) return buffer
buffer = gl.createBuffer()
bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER
arrayType = $type == 'IBOS' ? Uint16Array : Float32Array
gl.bindBuffer(bufferType, buffer)
gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW)
buffer.name = $name, buffer.type = $type
buffer.itemSize = $itemSize, buffer.numItem = $data.length / $itemSize
bsGL[$type][$name] = buffer
}
ProjectBS – WebGL 소모임
bsGL.MakeBuffer() 구현
ProjectBS – WebGL 소모임
더 필요한건?
1. 초기화! – 대충완료 -_-?
2. 쉐이더파서! - 대충완료
3. 버퍼생성기! - 대충완료
4. 텍스쳐생성기!
5. 메쉬구조체!
6. 재질구조체!
7. 렌더러!
bsGL.makeTexture = function ($src) {
var gl = bsGL.gl
var texture = bsGL.TEXTURES[$src]
if (texture) return texture
texture = gl.createTexture()
texture.img = new Image()
texture.img.src = $src
texture.loaded = 0
texture.img.onload = function () {
texture.loaded = 1
gl.bindTexture(gl.TEXTURE_2D, texture)
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.img);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.generateMipmap(gl.TEXTURE_2D)
gl.bindTexture(gl.TEXTURE_2D, null)
}
bsGL.TEXTURES[$src] = texture
return texture
}
ProjectBS – WebGL 소모임
bsGL.makeTexture() 구현
Ex.js
bsGL.Material = function ($type) {
var result
switch ($type) {
case 'color' :
result = new Float32Array([Math.random(), Math.random(), Math.random()])
result.program = bsGL.PROGRAMS['color']
break
case 'bitmap' :
result = bsGL.makeTexture(arguments[1])
result.program = bsGL.PROGRAMS['bitmap']
break
}
return result
}
ProjectBS – WebGL 소모임
bsGL.Material() 구현
bsGL.Material('bitmap','test.png')
Ex.js
bsGL.Mesh = function () {
var result = {
vbo: bsGL.VBOS['rect'],
ibo: bsGL.IBOS['rect'],
uvbo: bsGL.UVBOS['rect'],
position: new Float32Array([0, 0, 0]),
rotation: new Float32Array([0, 0, 0]),
scale: new Float32Array([100, 100, 1]),
alpha: 1,
material: new bsGL.Material('color'),
children: []
}
return result
}
ProjectBS – WebGL 소모임
bsGL.Mesh() 구현
Ex.js
ProjectBS – WebGL 소모임
드디어 렌더러!
가장 기초적인 렌더방식으로!
ProjectBS – WebGL 소모임
Draw(Root.children)
child1
child2
…
Draw(child1.children)
Draw(child2.children)
가장 기초적인 렌더방식으로! – 1Object
1DrawCall
ProjectBS – WebGL 소모임
bsGL.render = function () {
var gl = bsGL.gl
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.enable(gl.BLEND), gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
// 전체프로그램 공용 유니폼은 1번만 세팅한다!
for (var k in bsGL.PROGRAMS) {
var tProgram = bsGL.PROGRAMS[k]
gl.useProgram(tProgram)
gl.uniformMatrix4fv(tProgram.uPixelMatrix, false, bsGL.uPixelMatrix)
}
prevVBO = prevUVBO = prevIBO = render = 0
draw(bsGL.children)
}
bsGL.render() 변경!
ProjectBS – WebGL 소모임
bsGL.render = function () {
var gl = bsGL.gl
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.enable(gl.BLEND), gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
// 전체프로그램 공용 유니폼은 1번만 세팅한다!
for (var k in bsGL.PROGRAMS) {
var tProgram = bsGL.PROGRAMS[k]
gl.useProgram(tProgram)
gl.uniformMatrix4fv(tProgram.uPixelMatrix, false, bsGL.uPixelMatrix)
}
prevVBO = prevUVBO = prevIBO = render = 0
draw(bsGL.children)
}
bsGL.render() 변경!
ProjectBS – WebGL 소모임
function draw($list) {
var gl = bsGL.gl
var i = $list.length
var tObject, tProgram, tVBO, tIBO, tUVBO, tMaterial;
while (i--) {
render = 0,
tObject = $list[i],tMaterial=tObject.material
tVBO = tObject.vbo, tIBO = tObject.ibo, tUVBO = tObject.uvbo,
gl.useProgram(tProgram = tMaterial.program),
gl.uniform3fv(tProgram.uRotation, tObject.rotation),
gl.uniform3fv(tProgram.uPosition, tObject.position),
gl.uniform3fv(tProgram.uScale, tObject.scale)
gl.bindBuffer(gl.ARRAY_BUFFER, tVBO),
gl.vertexAttribPointer(tProgram.aVertexPosition, tVBO.itemSize, gl.FLOAT, false, 0, 0);
bsGL.draw() 구현
ProjectBS – WebGL 소모임
switch (tProgram.name) {
case 'bitmap' :
if (tMaterial.loaded) {
gl.bindBuffer(gl.ARRAY_BUFFER, tUVBO);
gl.vertexAttribPointer(tProgram.aUV, tUVBO.itemSize, gl.FLOAT, false, 0, 0);
gl.bindTexture(gl.TEXTURE_2D, tMaterial), gl.uniform1i(tProgram.uSampler, 0)
render = 1
}
break
case 'color' :
gl.uniform3fv(tProgram.uColor, tMaterial), render = 1
break
}
if (render) {
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, tIBO)
gl.drawElements(gl.TRIANGLES, tIBO.numItem, gl.UNSIGNED_SHORT, 0)
}
tObject.children.length > 0 ? draw(tObject.children) : 0
bsGL.draw() 구현
ProjectBS – WebGL 소모임
bsGL.init('canvas', function () {
for (var i = 0; i < 500; i++) {
var test = bsGL.Mesh()
bsGL.children.push(test)
test.position[0] = Math.random() * 1920 - 960
test.position[1] = Math.random() * 1920 - 960
var s = Math.random() * 100
test.scale = [s, s, 1]
if (i % 5 == 0) {
test.material = bsGL.Material('bitmap', 'test.png')
}
}
bsGL.LOOPS['loopTest'] = function () {
for (var i = 0; i < 500; i++) {
bsGL.children[i].rotation[2] += 0.1
}
}
}, 'shader.js', 'ex.js')
Host Code
ProjectBS – WebGL 소모임
http://ligo.kr/f81
ProjectBS – WebGL 소모임
http://ligo.kr/en9
ProjectBS – WebGL 소모임
다섯번째 모임에서는
1. 프레임버퍼
2. 마우스 Picking
3. Renderer에 대한 토론
End
www.Bswebgl.com – 런치프로젝트 webGL
https://github.com/projectBS/webGL
https://www.facebook.com/groups/bs5js/

Weitere ähnliche Inhalte

Was ist angesagt?

3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
JavaScript Meetup HCMC
 
Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意
Ryosuke IWANAGA
 

Was ist angesagt? (20)

Будь первым
Будь первымБудь первым
Будь первым
 
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門
 
Javascript is your (Auto)mate
Javascript is your (Auto)mateJavascript is your (Auto)mate
Javascript is your (Auto)mate
 
Jk rubyslava 25
Jk rubyslava 25Jk rubyslava 25
Jk rubyslava 25
 
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Devcast node.js e mongo db o casamento perfeito
Devcast   node.js e mongo db o casamento perfeitoDevcast   node.js e mongo db o casamento perfeito
Devcast node.js e mongo db o casamento perfeito
 
Memory leak in Javascript - Renan Bastos
Memory leak in Javascript - Renan BastosMemory leak in Javascript - Renan Bastos
Memory leak in Javascript - Renan Bastos
 
KEYNOTE: Node.js interactive 2017 - The case for node.js
KEYNOTE: Node.js interactive 2017 - The case for node.jsKEYNOTE: Node.js interactive 2017 - The case for node.js
KEYNOTE: Node.js interactive 2017 - The case for node.js
 
The jsdom
The jsdomThe jsdom
The jsdom
 
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
3D Web Programming [Thanh Loc Vo , CTO Epsilon Mobile ]
 
Introducing perf budgets on CI with puppeteer - perf.now()
Introducing perf budgets on CI with puppeteer - perf.now()Introducing perf budgets on CI with puppeteer - perf.now()
Introducing perf budgets on CI with puppeteer - perf.now()
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
 
JavaScript on the Desktop
JavaScript on the DesktopJavaScript on the Desktop
JavaScript on the Desktop
 
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsFwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 

Ähnlich wie Bs webgl소모임004

Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
gerbille
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
tamillarasan
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
Chihoon Byun
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
 

Ähnlich wie Bs webgl소모임004 (20)

Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
JS Experience 2017 - Animações simples com o three.js
JS Experience 2017 - Animações simples com o three.jsJS Experience 2017 - Animações simples com o three.js
JS Experience 2017 - Animações simples com o three.js
 
Developing Web Graphics with WebGL
Developing Web Graphics with WebGLDeveloping Web Graphics with WebGL
Developing Web Graphics with WebGL
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
 
Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
 
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Front End Development: The Important Parts
Front End Development: The Important PartsFront End Development: The Important Parts
Front End Development: The Important Parts
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
 
Single Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle StorySingle Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle Story
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Custom gutenberg block development in react
Custom gutenberg block development in reactCustom gutenberg block development in react
Custom gutenberg block development in react
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 

Kürzlich hochgeladen

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Kürzlich hochgeladen (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 

Bs webgl소모임004

  • 1. WebGL 입문4 초미니? 2D엔진 만들기! ProjectBS – WebGL 소모임
  • 2. ProjectBS – WebGL 소모임 오늘의 목표! Rect Base 2D 엔진 Color, Bitmap 재질
  • 3. ProjectBS – WebGL 소모임 TODO LIST! 1. 초기화! 2. 쉐이더파서! 3. 버퍼생성기! 4. 텍스쳐생성기! 5. 메쉬구조체! 6. 재질구조체! 7. 루프관리! 8. 렌더러!
  • 4. ProjectBS – WebGL 소모임 원하는 API bsGL.init( 'canvas‘ , // ID or Canvas Object function(){ console.log('초기화!') // Host Code }, ‘쉐이더.js','확장.js‘ )
  • 5. bsGL.init( 'canvas‘ , // ID or Canvas Object function(){ console.log('초기화!') // Host Code }, ‘쉐이더.js','확장.js‘ ) ProjectBS – WebGL 소모임 Gl객체 찾기 확장, 쉐이더.js 로딩 / 파싱 호스트 실행 초기화를 하면?
  • 6. var bsGL = (function () { var W = window, DOC = document, HEAD = DOC.getElementsByTagName('head')[0]; var API = { gl: null, cvs: null, VBOS: {}, UVBOS: {}, IBOS: {}, // 버퍼관리용 공간 PROGRAMS: {}, TEXTURES: {}, // 프로그램 텍스쳐 공간 LOOPS: {}, // 루프를 관리할 공간 SHADER_SOURCES: {}, // 파싱된 쉐이더를 관리할 공간 children: [], // 루트의 자식객체를 관리할 공간 init: function ($cvs, $func) { // 먼가 실행 } } return API })(); ProjectBS – WebGL 소모임 가볍게 엔진구조체 생각! bsGL.init(~~~) bsGL.children.push(~~~)
  • 7. ProjectBS – WebGL 소모임 bsGL.init 구현! init: function ($cvs, $func) { var script, list = arguments, i = list.length - 1 load(list[i]) function load($src) { script ? (script.onload = null, HEAD.removeChild(script)) : 0 script = DOC.createElement('script') script.type = 'text/javascript', script.charset = 'utf-8', script.src = $src if (i == 2) script.onload = function () { script.onload = null, HEAD.removeChild(script) // 호스트 실행 전 우리가 필요한 것들을 한다! // context3d를 얻어야겠고… // 엔진에 기본적으로 필요한 주요버퍼와 프로그램을 미리생성한다! $func() // 호스트 실행! } else script.onload = function () { load(list[i]) } HEAD.appendChild(script) i-- } }
  • 8. ProjectBS – WebGL 소모임 호스트 실행전 준비! if (i == 2) script.onload = function () { script.onload = null, HEAD.removeChild(script) API.getGL($cvs) API.setBase() $func(); (function animloop() { for (var k in API.LOOPS) API.LOOPS[k]() API.render() requestAnimFrame(animloop) })() } var bsGL = (function () { var API = { … … render: function () {}, setBase: function () {} } return API })();
  • 9. ProjectBS – WebGL 소모임 getGL 구현 getGL: function ($cvs) { var cvs = typeof $cvs == 'string' ? DOC.getElementById($cvs) : $cvs; var keys = 'webgl,experimental-webgl,webkit-3d,moz-webgl'.split(','), i = keys.length while (i--) if (gl = cvs.getContext(keys[i])) break console.log(gl ? 'webgl 초기화 성공!' : console.log('webgl 초기화 실패!!')) API.gl = gl, API.cvs = cvs }
  • 10. ProjectBS – WebGL 소모임 setBase 구현 1. Rect와 관련된 버퍼를 생성한다! 2. 쉐이더.js를 해석해서 쉐이더 & 프로그램을 만든다. bsGL.setBase = function () { var data = [-0.5, -0.5, 0.0, 0.5, -0.5, 0.0, -0.5, 0.5, 0.0, 0.5, 0.5, 0.0 ] var index = [0, 1, 2, 1, 2, 3] var uv = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0] bsGL.makeBuffer('VBOS', 'rect', data, 3) bsGL.makeBuffer('IBOS', 'rect', index, 1) bsGL.makeBuffer('UVBOS', 'rect', uv, 2) bsGL.makeBuffer('VBOS', 'null', [-0.5, -0.5, 0.0], 3) bsGL.shaderParser() }
  • 11. ProjectBS – WebGL 소모임 makeBuffer 구현 bsGL.makeBuffer = function ($type, $name, $data, $itemSize, $drawType) { var gl = bsGL.gl // $type : IBOS…. var buffer = bsGL[$type][$name], bufferType, arrayType if (buffer) return buffer buffer = gl.createBuffer() bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER arrayType = $type == 'IBOS' ? Uint16Array : Float32Array gl.bindBuffer(bufferType, buffer) gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW) buffer.name = $name, buffer.type = $type buffer.itemSize = $itemSize buffer.numItem = $data.length / $itemSize bsGL[$type][$name] = buffer console.log(bsGL[$type][$name]) } Ex.js
  • 12. ProjectBS – WebGL 소모임 Shader 소스 구조체! bsGL.SHADER_SOURCES['color'] = { vertex: "n", fragment: "n", attribs: 'aVertexPosition', // 사용한 버퍼 uniforms: 'uPixelMatrix,uRotation,uPosition,uScale,uColor' // 사용한 유니폼 } shader.js
  • 13. ProjectBS – WebGL 소모임 Shader Parser 구현! bsGL.shaderParser = function () { var gl = bsGL.gl, vShader, fShader, program for (var k in bsGL.SHADER_SOURCES) { var t = bsGL.SHADER_SOURCES[k] vShader = gl.createShader(gl.VERTEX_SHADER) gl.shaderSource(vShader, t.vertex), gl.compileShader(vShader) fShader = gl.createShader(gl.FRAGMENT_SHADER) gl.shaderSource(fShader, t.fragment), gl.compileShader(fShader) program = gl.createProgram() gl.attachShader(program, vShader), gl.attachShader(program, fShader) gl.linkProgram(program) vShader.name = k + '_vertex', fShader.name = k + '_fragment', program.name = k bsGL.PROGRAMS[k] = program console.log(vShader), console.log(fShader), console.log(program) } } Ex.js
  • 14. bsGL.shaderParser = function () { var gl = bsGL.gl, vShader, fShader, program for (var k in bsGL.SHADER_SOURCES) { var t = bsGL.SHADER_SOURCES[k] vShader = gl.createShader(gl.VERTEX_SHADER) gl.shaderSource(vShader, t.vertex), gl.compileShader(vShader) fShader = gl.createShader(gl.FRAGMENT_SHADER) gl.shaderSource(fShader, t.fragment), gl.compileShader(fShader) program = gl.createProgram() gl.attachShader(program, vShader), gl.attachShader(program, fShader) gl.linkProgram(program) vShader.name = k + '_vertex', fShader.name = k + '_fragment', program.name = k bsGL.PROGRAMS[k] = program console.log(vShader), console.log(fShader), console.log(program) } } ProjectBS – WebGL 소모임 Shader Parser 구현!
  • 15. var gl = bsGL.gl, vShader, fShader, program for (var k in bsGL.SHADER_SOURCES) { … gl.useProgram(program) var i = 0, list = t.attribs.split(','), max = list.length, key for (i; i < max; i++) { key = list[i] program[key] = gl.getAttribLocation(program, key); gl.bindBuffer(gl.ARRAY_BUFFER, bsGL.VBOS['null']) gl.vertexAttribPointer(program[key], bsGL.VBOS['null'].itemSize, gl.FLOAT, false, 0, 0); gl.enableVertexAttribArray(program[key]); } list = t.uniforms.split(','), max = list.length for (i = 0; i < max; i++) { key = list[i] program[key] = gl.getUniformLocation(program, key); } bsGL.PROGRAMS[k] = program } ProjectBS – WebGL 소모임 Shader Parser 구현2! Ex.js
  • 16. bsGL.makeBuffer = function ($type, $name, $data, $itemSize, $drawType) { var gl = bsGL.gl // $type : IBOS, .... var buffer = bsGL[$type][$name], bufferType, arrayType if (buffer) return buffer buffer = gl.createBuffer() bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER arrayType = $type == 'IBOS' ? Uint16Array : Float32Array gl.bindBuffer(bufferType, buffer) gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW) buffer.name = $name, buffer.type = $type buffer.itemSize = $itemSize, buffer.numItem = $data.length / $itemSize bsGL[$type][$name] = buffer } ProjectBS – WebGL 소모임 bsGL.MakeBuffer() 구현
  • 17. bsGL.makeBuffer = function ($type, $name, $data, $itemSize, $drawType) { var gl = bsGL.gl // $type : IBOS, .... var buffer = bsGL[$type][$name], bufferType, arrayType if (buffer) return buffer buffer = gl.createBuffer() bufferType = $type == 'IBOS' ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER arrayType = $type == 'IBOS' ? Uint16Array : Float32Array gl.bindBuffer(bufferType, buffer) gl.bufferData(bufferType, new arrayType($data), $drawType ? $drawType : gl.STATIC_DRAW) buffer.name = $name, buffer.type = $type buffer.itemSize = $itemSize, buffer.numItem = $data.length / $itemSize bsGL[$type][$name] = buffer } ProjectBS – WebGL 소모임 bsGL.MakeBuffer() 구현
  • 18. ProjectBS – WebGL 소모임 더 필요한건? 1. 초기화! – 대충완료 -_-? 2. 쉐이더파서! - 대충완료 3. 버퍼생성기! - 대충완료 4. 텍스쳐생성기! 5. 메쉬구조체! 6. 재질구조체! 7. 렌더러!
  • 19. bsGL.makeTexture = function ($src) { var gl = bsGL.gl var texture = bsGL.TEXTURES[$src] if (texture) return texture texture = gl.createTexture() texture.img = new Image() texture.img.src = $src texture.loaded = 0 texture.img.onload = function () { texture.loaded = 1 gl.bindTexture(gl.TEXTURE_2D, texture) gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.img); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.generateMipmap(gl.TEXTURE_2D) gl.bindTexture(gl.TEXTURE_2D, null) } bsGL.TEXTURES[$src] = texture return texture } ProjectBS – WebGL 소모임 bsGL.makeTexture() 구현 Ex.js
  • 20. bsGL.Material = function ($type) { var result switch ($type) { case 'color' : result = new Float32Array([Math.random(), Math.random(), Math.random()]) result.program = bsGL.PROGRAMS['color'] break case 'bitmap' : result = bsGL.makeTexture(arguments[1]) result.program = bsGL.PROGRAMS['bitmap'] break } return result } ProjectBS – WebGL 소모임 bsGL.Material() 구현 bsGL.Material('bitmap','test.png') Ex.js
  • 21. bsGL.Mesh = function () { var result = { vbo: bsGL.VBOS['rect'], ibo: bsGL.IBOS['rect'], uvbo: bsGL.UVBOS['rect'], position: new Float32Array([0, 0, 0]), rotation: new Float32Array([0, 0, 0]), scale: new Float32Array([100, 100, 1]), alpha: 1, material: new bsGL.Material('color'), children: [] } return result } ProjectBS – WebGL 소모임 bsGL.Mesh() 구현 Ex.js
  • 22. ProjectBS – WebGL 소모임 드디어 렌더러! 가장 기초적인 렌더방식으로!
  • 23. ProjectBS – WebGL 소모임 Draw(Root.children) child1 child2 … Draw(child1.children) Draw(child2.children) 가장 기초적인 렌더방식으로! – 1Object 1DrawCall
  • 24. ProjectBS – WebGL 소모임 bsGL.render = function () { var gl = bsGL.gl gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.enable(gl.BLEND), gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) // 전체프로그램 공용 유니폼은 1번만 세팅한다! for (var k in bsGL.PROGRAMS) { var tProgram = bsGL.PROGRAMS[k] gl.useProgram(tProgram) gl.uniformMatrix4fv(tProgram.uPixelMatrix, false, bsGL.uPixelMatrix) } prevVBO = prevUVBO = prevIBO = render = 0 draw(bsGL.children) } bsGL.render() 변경!
  • 25. ProjectBS – WebGL 소모임 bsGL.render = function () { var gl = bsGL.gl gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.enable(gl.BLEND), gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) // 전체프로그램 공용 유니폼은 1번만 세팅한다! for (var k in bsGL.PROGRAMS) { var tProgram = bsGL.PROGRAMS[k] gl.useProgram(tProgram) gl.uniformMatrix4fv(tProgram.uPixelMatrix, false, bsGL.uPixelMatrix) } prevVBO = prevUVBO = prevIBO = render = 0 draw(bsGL.children) } bsGL.render() 변경!
  • 26. ProjectBS – WebGL 소모임 function draw($list) { var gl = bsGL.gl var i = $list.length var tObject, tProgram, tVBO, tIBO, tUVBO, tMaterial; while (i--) { render = 0, tObject = $list[i],tMaterial=tObject.material tVBO = tObject.vbo, tIBO = tObject.ibo, tUVBO = tObject.uvbo, gl.useProgram(tProgram = tMaterial.program), gl.uniform3fv(tProgram.uRotation, tObject.rotation), gl.uniform3fv(tProgram.uPosition, tObject.position), gl.uniform3fv(tProgram.uScale, tObject.scale) gl.bindBuffer(gl.ARRAY_BUFFER, tVBO), gl.vertexAttribPointer(tProgram.aVertexPosition, tVBO.itemSize, gl.FLOAT, false, 0, 0); bsGL.draw() 구현
  • 27. ProjectBS – WebGL 소모임 switch (tProgram.name) { case 'bitmap' : if (tMaterial.loaded) { gl.bindBuffer(gl.ARRAY_BUFFER, tUVBO); gl.vertexAttribPointer(tProgram.aUV, tUVBO.itemSize, gl.FLOAT, false, 0, 0); gl.bindTexture(gl.TEXTURE_2D, tMaterial), gl.uniform1i(tProgram.uSampler, 0) render = 1 } break case 'color' : gl.uniform3fv(tProgram.uColor, tMaterial), render = 1 break } if (render) { gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, tIBO) gl.drawElements(gl.TRIANGLES, tIBO.numItem, gl.UNSIGNED_SHORT, 0) } tObject.children.length > 0 ? draw(tObject.children) : 0 bsGL.draw() 구현
  • 28. ProjectBS – WebGL 소모임 bsGL.init('canvas', function () { for (var i = 0; i < 500; i++) { var test = bsGL.Mesh() bsGL.children.push(test) test.position[0] = Math.random() * 1920 - 960 test.position[1] = Math.random() * 1920 - 960 var s = Math.random() * 100 test.scale = [s, s, 1] if (i % 5 == 0) { test.material = bsGL.Material('bitmap', 'test.png') } } bsGL.LOOPS['loopTest'] = function () { for (var i = 0; i < 500; i++) { bsGL.children[i].rotation[2] += 0.1 } } }, 'shader.js', 'ex.js') Host Code
  • 29. ProjectBS – WebGL 소모임 http://ligo.kr/f81
  • 30. ProjectBS – WebGL 소모임 http://ligo.kr/en9
  • 31. ProjectBS – WebGL 소모임 다섯번째 모임에서는 1. 프레임버퍼 2. 마우스 Picking 3. Renderer에 대한 토론
  • 32. End www.Bswebgl.com – 런치프로젝트 webGL https://github.com/projectBS/webGL https://www.facebook.com/groups/bs5js/