Giter Site home page Giter Site logo

kutuluk / js13k-2d Goto Github PK

View Code? Open in Web Editor NEW
118.0 11.0 6.0 616 KB

A 2kb webgl 2d sprite renderer, designed for Js13kGames

Home Page: https://kutuluk.github.io/js13k-2d

License: MIT License

JavaScript 96.03% HTML 3.97%
webgl 2d sprites js13k js13kgames gamedev rendering renderer

js13k-2d's People

Contributors

erjanmx avatar kutuluk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js13k-2d's Issues

Hardcoded OpenGL constants?

What is the point of using plain integers for representing some if not all of the used OpenGL constants such as GL_TEXTURE_WRAP_S ?

Example: https://github.com/kutuluk/js13k-2d/blob/master/src/renderer.js#L123

I don't know much about WebGL, but if there's a chance that they might not be defined on some weird browsers or something, I think the right thing to do would maybe be to inject the values manually to the gl object in that case?

Using plain integers like that is very confusing.

Texture size must always be power of 2

Code sample:

    import Renderer from 'js13k-2d'

    const scene = Renderer(canvas, { alpha: true })

    scene.background(0, 1, 0, 0.2)
    const atlas = scene.texture(createImageTexture(img), 0)
    const frame = atlas.frame(Renderer.Point(), atlas.size, Renderer.Point(0.5, 0.5))
    const sprites = []
    for (let i = 0; i < 0; i++) {
      const sprite = Renderer.Sprite(frame)
      sprite.rotation = Math.random() * 2 * Math.PI
      sprite.tint = Math.random() * 0xff0000
      scene.add(sprite)
      sprites.push(sprite)
    }
    scene.resize()
    scene.render()

Actual img size is (125px, 81px), so I need to use helper function createImageTexture

const createImageTexture = (img) => {
  const canvas = document.createElement('canvas')
  canvas.width = 1 << Math.ceil(Math.log2(img.width)) // eslint-disable-line
  canvas.height = 1 << Math.ceil(Math.log2(img.height)) // eslint-disable-line
  canvas.getContext('2d').drawImage(img, 0, 0)

  return canvas
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.