webgl_helper 0.4.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 44

webgl_helper

A small helper library to reduce boilerplate code when using the WebGL API.

Features

The development of this library has just started. Many features are not completely implemented yet or missing at all.

  • Reduces boilerplate code, e.g. connecting buffers to vertex attrib locations and draw in 1 call.
  • Makes the WebGL API more type safe by adding types for a number of WebGL constants.

This library is not a high level library like three.js.

Version 0.4.0

  • Added support for Dart 2.

Version 0.3.0

  • Added support for Dart strong mode.

example/main.dart

import 'dart:html';
import 'package:webgl_helper/webgl_helper.dart';

ShaderProgram program;
Buffer buffer;

main() {
  // query the canvas element
  var canvasElement = querySelector('#webgl-canvas');

  // init the webgl rendering context
  glInit(canvasElement);

  // set the color used to clear the color buffer
  glClearColor(0, 0, 0, 1);

  // enable blending and set the blend function
  glEnableBlend(true);
  glBlendFunc(BlendingCoefficient.SRC_ALPHA, BlendingCoefficient.ONE_MINUS_SRC_ALPHA);

  // create a shader program
  program = new ShaderProgram.fromSources(vertexShader, fragmentShader);

  // create a buffer that contains 2 types of per vertex data: positions and colors
  buffer = new Buffer(BufferTarget.ARRAY_BUFFER);
  buffer.data({
    'a_position': {
      Buffer.SIZE: 2, // 2 components per vertex (x, y)
      Buffer.DATA: [1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0]
    },
    'a_color': {
      Buffer.SIZE: 3, // 3 components per vertex (r, g, b)
      Buffer.DATA: [1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0]
    }
  });

  // start rendering
  window.requestAnimationFrame(render);
}

render(tick) {
  // clear the color buffer
  glClear([ClearMode.COLOR_BUFFER]);

  // draw the vertices using the given shader program and the vertex data stored in the buffer. additionally, set an
  // uniform.
  gluDrawArrays(program, buffer, uniformSetters: {
    'u_alpha': (uniform) => uniform.set1f(0.5)
  });

  // next frame
  window.requestAnimationFrame(render);
}

// the vertex shader...
final vertexShader = '''
#version 100

precision mediump float;

attribute vec2 a_position;
attribute vec3 a_color;
varying vec3 v_color;

void main() {
  v_color = a_color;
  gl_Position = vec4(a_position / 2.0, 0.0, 1.0);
}
''';

// ...and the fragment shader
final fragmentShader = '''
#version 100

precision mediump float;

uniform float u_alpha;
varying vec3 v_color;

void main() {
  gl_FragColor = vec4(v_color, u_alpha);
}
''';

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  webgl_helper: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:webgl_helper/webgl_helper.dart';
  
Version Uploaded Documentation Archive
0.4.0 Jul 25, 2018 Go to the documentation of webgl_helper 0.4.0 Download webgl_helper 0.4.0 archive
0.3.0 Oct 30, 2016 Go to the documentation of webgl_helper 0.3.0 Download webgl_helper 0.3.0 archive
0.2.0 Mar 28, 2016 Go to the documentation of webgl_helper 0.2.0 Download webgl_helper 0.2.0 archive
0.1.0 Mar 1, 2016 Go to the documentation of webgl_helper 0.1.0 Download webgl_helper 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
1
Health:
Code health derived from static analysis. [more]
90
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: web

Primary library: package:webgl_helper/webgl_helper.dart with components: html.

Health issues and suggestions

Document public APIs (-10 points)

137 out of 137 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Format lib/src/buffer.dart.

Run dartfmt to format lib/src/buffer.dart.

Format lib/src/constants.dart.

Run dartfmt to format lib/src/constants.dart.

Format lib/src/context.dart.

Run dartfmt to format lib/src/context.dart.

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/framebuffer.dart (Run dartfmt to format lib/src/framebuffer.dart.)
  • lib/src/shader.dart (Run dartfmt to format lib/src/shader.dart.)
  • lib/src/texture.dart (Run dartfmt to format lib/src/texture.dart.)
  • lib/src/uniform.dart (Run dartfmt to format lib/src/uniform.dart.)
  • lib/src/vertexattrib.dart (Run dartfmt to format lib/src/vertexattrib.dart.)
  • lib/webgl_helper.dart (Run dartfmt to format lib/webgl_helper.dart.)

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.69.0 <3.0.0
vector_math ^2.0.8 2.0.8
Dev dependencies
build_runner ^0.9.2
build_web_compilers ^0.4.1