Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new examples testing webgl texturing #53

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6eb225b
add new examples testing webgl texturing
brupelo Mar 30, 2016
61f14e1
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Mar 31, 2016
28771c3
ignore several image file formats on examples
brupelo Mar 31, 2016
b01ef4a
fix standardjs errors
brupelo Mar 31, 2016
45275ec
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Mar 31, 2016
13863ed
adds setDebugMethod to native addon, it needs to be refactored proper…
brupelo Mar 31, 2016
e62d286
fix issues with stride on saving images
brupelo Mar 31, 2016
d9bbd9c
uses gl-conformance 2.0.3 explicitely
brupelo Mar 31, 2016
27371c9
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Apr 1, 2016
d0fca55
decrease verbosity on debug mode
brupelo Apr 1, 2016
4126c58
save ppm with same orientation than other image file formats (jpg, pn…
brupelo Apr 1, 2016
d9e9f99
set quality to 100 if options are not specified when saving to image
brupelo Apr 1, 2016
7309144
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Apr 1, 2016
3fb9955
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Apr 1, 2016
890020d
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Apr 1, 2016
f147071
avoid people pushing jscs files in the root
brupelo Apr 1, 2016
2de74bb
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Apr 2, 2016
305618d
new example taken from learningwebgl website
brupelo Apr 2, 2016
789ed90
flip jpg,gif,png image on bufferToFile
brupelo Apr 2, 2016
102c4b4
add new example taken from learningwebgl website
brupelo Apr 2, 2016
fa3027e
flip ppm image on bufferToFile
brupelo Apr 2, 2016
432e58f
fix linter errors
brupelo Apr 2, 2016
fb7f86c
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Apr 5, 2016
bfd8473
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo Apr 6, 2016
a180d78
add get-pixels and save-pixels dependencies
brupelo Apr 6, 2016
73a9a05
update angle submodule
brupelo Apr 6, 2016
b0184ba
build and use directly the angle submodule instead of relying on outd…
brupelo Apr 6, 2016
14ec3d1
lesson02.js dumps a jpg by default
brupelo Apr 6, 2016
ad2a095
replace hardcoded variables in binding.gyp windows configuration
brupelo Apr 6, 2016
b9898a9
Fix test3.js to display lena
brupelo Apr 22, 2016
1fc1e93
Merge branch 'master' of https://github.com/stackgl/headless-gl
brupelo May 28, 2016
fdee293
upgrade angle subproject commit and dependencies
brupelo May 28, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
build/*
.lock-wscript
npm-debug.log
*.log
.idea
.jscsrc
.lock-wscript
angle/build/*
build/*
Debug
*.log
example/**/*.gif
example/**/*.jpg
example/**/*.png
example/**/*.ppm
!example/data
node_modules
npm-debug.log
prebuilds/*
angle/build/*
example/**/*.ppm
23 changes: 9 additions & 14 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,23 @@
'library_dirs': [
'<(module_root_dir)/deps/<(platform)'
],
'dependencies':
[
'angle/src/angle.gyp:libEGL',
'angle/src/angle.gyp:libGLESv2'
],
'conditions': [
['OS=="mac"', {
'dependencies':
[
'angle/src/angle.gyp:libEGL',
'angle/src/angle.gyp:libGLESv2'
],
'libraries': [
'-framework QuartzCore',
'-framework Quartz'
],
]
}],
['OS=="linux"', {
'dependencies':
[
'angle/src/angle.gyp:libEGL',
'angle/src/angle.gyp:libGLESv2'
]
}],
['OS=="win"', {
'library_dirs': [
'<(module_root_dir)/deps/windows/lib/<(target_arch)',
'<(module_root_dir)/build/$(Configuration)_$(Platform)/lib',
],
'libraries': [
'libEGL.lib',
Expand Down Expand Up @@ -92,8 +87,8 @@
{
'destination': '$(SolutionDir)$(ConfigurationName)',
'files': [
'<(module_root_dir)/deps/windows/dll/<(target_arch)/libEGL.dll',
'<(module_root_dir)/deps/windows/dll/<(target_arch)/libGLESv2.dll'
'<(module_root_dir)/build/$(Configuration)_$(Platform)/libEGL.dll',
'<(module_root_dir)/build/$(Configuration)_$(Platform)/libGLESv2.dll'
]
}
]
Expand Down
Binary file removed deps/windows/dll/x64/d3dcompiler_47.dll
Binary file not shown.
Binary file removed deps/windows/dll/x64/libEGL.dll
Binary file not shown.
Binary file removed deps/windows/dll/x64/libGLESv2.dll
Binary file not shown.
Binary file removed deps/windows/lib/x64/libEGL.lib
Binary file not shown.
Binary file removed deps/windows/lib/x64/libGLESv2.lib
Binary file not shown.
87 changes: 62 additions & 25 deletions example/common/utils.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
var fs = require('fs')
var savePixels = require('save-pixels')
var ndarray = require('ndarray')
var path = require('path')

function bufferToStdout (gl, width, height) {
// Write output
var pixels = new Uint8Array(width * height * 4)
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
process.stdout.write(['P3\n# gl.ppm\n', width, ' ', height, '\n255\n'].join(''))
for (var i = 0; i < pixels.length; i += 4) {
process.stdout.write(pixels[i] + ' ' + pixels[i + 1] + ' ' + pixels[i + 2] + ' ')
}
function writePixels (array, filepath, format, options, cb) {
var out = fs.createWriteStream(filepath)
var pxstream = savePixels(array, format, options)
pxstream.pipe(out)
.on('error', cb)
.on('close', cb)
}

function bufferToFile (gl, width, height, filename) {
var file = fs.createWriteStream(filename)

// Write output
function bufferToFile (gl, width, height, filename, options) {
var extension = path.extname(filename)
var pixels = new Uint8Array(width * height * 4)

gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
file.write(['P3\n# gl.ppm\n', width, ' ', height, '\n255\n'].join(''))
for (var i = 0; i < pixels.length; i += 4) {
file.write(pixels[i] + ' ' + pixels[i + 1] + ' ' + pixels[i + 2] + ' ')

if (extension === '.ppm') {
// Special case, ppm file (TODO: Maybe adding ppm support into save-pixels)
var file = fs.createWriteStream(filename)

file.write(['P3\n# gl.ppm\n', width, ' ', height, '\n255\n'].join(''))
for (var y = 0; y < height; y++) {
var baseOffset = ((height - y) * width) << 2
for (var x = 0; x < width; x++) {
var offset = baseOffset + (x << 2)
file.write(pixels[offset] + ' ' + pixels[offset + 1] + ' ' + pixels[offset + 2] + ' ')
}
}
// for (var i = 0; i < pixels.length; i += 4) {
// file.write(pixels[i] + ' ' + pixels[i + 1] + ' ' + pixels[i + 2] + ' ')
// }
} else {
var ext = extension.substring(1, extension.length)
var buffer = ndarray(pixels, [width, height, 4], [4, 4 * width, 1], 0)

writePixels(buffer.step(1, -1), filename, ext, options || {'quality': 100}, function () {})
}
}

Expand Down Expand Up @@ -52,19 +70,11 @@ function loadShader (gl, shaderSource, shaderType) {
return shader
}

function createProgram (gl, shaders, opt_attribs, opt_locations) {
function createProgram (gl, shaders) {
var program = gl.createProgram()
shaders.forEach(function (shader) {
gl.attachShader(program, shader)
})
if (opt_attribs) {
opt_attribs.forEach(function (attrib, ndx) {
gl.bindAttribLocation(
program,
opt_locations ? opt_locations[ndx] : ndx,
attrib)
})
}
gl.linkProgram(program)

// Check the link status
Expand Down Expand Up @@ -93,9 +103,36 @@ function createProgramFromSources (gl, shaderSources, opt_attribs, opt_locations
return createProgram(gl, shaders, opt_attribs, opt_locations)
}

module.exports.bufferToStdout = bufferToStdout
// Returns a random integer from 0 to range - 1.
function randomInt (range) {
return Math.floor(Math.random() * range)
}

// Fills the buffer with the values that define a rectangle.
function setRectangle (gl, x, y, width, height) {
var x1 = x
var x2 = x + width
var y1 = y
var y2 = y + height
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
x1, y1,
x2, y1,
x1, y2,
x1, y2,
x2, y1,
x2, y2
]), gl.STATIC_DRAW)
}

function replaceExt (filename, ext) {
return filename.substr(0, filename.lastIndexOf('.')) + ext
}

module.exports.bufferToFile = bufferToFile
module.exports.drawTriangle = drawTriangle
module.exports.loadShader = loadShader
module.exports.createProgram = createProgram
module.exports.createProgramFromSources = createProgramFromSources
module.exports.randomInt = randomInt
module.exports.setRectangle = setRectangle
module.exports.replaceExt = replaceExt
Binary file added example/data/lena.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 35 additions & 22 deletions example/fractals/mandelbrot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,49 @@ function main () {
var gl = createContext(width, height)

var vertex_src = `
attribute vec2 a_position
attribute vec2 a_position;
void main() {
gl_Position = vec4(a_position,0,1)
gl_Position = vec4(a_position,0,1);
}
`

var fragment_src = `
precision mediump float
const int max_iterations = 255
precision mediump float;
const int max_iterations = 255;

vec2 complex_square( vec2 v ) {
return vec2(
v.x * v.x - v.y * v.y,
v.x * v.y * 2.0
)
);
}

void main()
{
vec2 uv = gl_FragCoord.xy - vec2(512.0,512.0) * 0.5
uv *= 2.5 / min( 512.0, 512.0 )
vec2 uv = gl_FragCoord.xy - vec2(512.0,512.0) * 0.5;
uv *= 2.5 / min( 512.0, 512.0 );

#if 0 // Mandelbrot
vec2 c = uv
vec2 v = vec2( 0.0 )
float scale = 0.06
vec2 c = uv;
vec2 v = vec2( 0.0 );
float scale = 0.06;
#else // Julia
vec2 c = vec2( 0.285, 0.01 )
vec2 v = uv
float scale = 0.01
vec2 c = vec2( 0.285, 0.01 );
vec2 v = uv;
float scale = 0.01;
#endif

int count = max_iterations
int count = max_iterations;

for ( int i = 0 ; i < max_iterations; i++ ) {
v = c + complex_square( v )
v = c + complex_square( v );
if ( dot( v, v ) > 4.0 ) {
count = i
break
count = i;
break;
}
}

gl_FragColor = vec4( float( count ) * scale )
gl_FragColor = vec4( float( count ) * scale );
}
`

Expand Down Expand Up @@ -89,10 +89,23 @@ function main () {
// draw
gl.drawArrays(gl.TRIANGLES, 0, 6)

var filename = __filename + '.ppm' // eslint-disable-line
log.info(__line, 'rendering ' + filename)
utils.bufferToFile(gl, width, height, filename)
log.info(__line, 'finished rendering ' + filename)
var frames = [
{ 'format': '.jpg', 'quality': 1 },
{ 'format': '.jpg', 'quality': 25 },
{ 'format': '.jpg', 'quality': 50 },
{ 'format': '.jpg', 'quality': 75 },
{ 'format': '.jpg', 'quality': 100 },
{ 'format': '.ppm', 'quality': 100 }
]

for (var i = 0; i < frames.length; i++) {
var filename = utils.replaceExt(__filename, '_' + frames[i]['quality'] + '_' + frames[i]['format'])
log.info(__line, 'rendering ' + filename)
utils.bufferToFile(gl, width, height, filename, {
quality: frames[i]['quality']
})
log.info(__line, 'finished rendering ' + filename)
}

gl.destroy()
}
Expand Down
Loading