{"id":16807179,"url":"https://github.com/ryohey/webgl-react","last_synced_at":"2025-07-05T18:36:57.708Z","repository":{"id":40699347,"uuid":"498125303","full_name":"ryohey/webgl-react","owner":"ryohey","description":"webgl-react is a React library for 2D rendering in WebGL with screen coordinates.","archived":false,"fork":false,"pushed_at":"2024-11-02T05:51:23.000Z","size":15944,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T22:13:05.228Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryohey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-30T23:34:48.000Z","updated_at":"2024-11-04T07:18:35.000Z","dependencies_parsed_at":"2024-06-25T17:17:05.534Z","dependency_job_id":"bef01736-647e-444a-b327-aaae6b33aff4","html_url":"https://github.com/ryohey/webgl-react","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Fwebgl-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Fwebgl-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Fwebgl-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Fwebgl-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryohey","download_url":"https://codeload.github.com/ryohey/webgl-react/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244898185,"owners_count":20528331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T09:53:07.503Z","updated_at":"2025-03-22T02:31:36.354Z","avatar_url":"https://github.com/ryohey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webgl-react\n\nwebgl-react is a React library for 2D rendering in WebGL with screen coordinates.\n\n[![npm version](https://badge.fury.io/js/@ryohey%2Fwebgl-react.svg)](https://badge.fury.io/js/@ryohey%2Fwebgl-react)\n![Node.js CI](https://github.com/ryohey/webgl-react/workflows/Node.js%20CI/badge.svg)\n\n## Why?\n\nIn react, drawing large numbers of shapes with divs, etc. is a very heavy process. webgl-react provides a React component that uses WebGL to draw large numbers of shapes in a single draw call.\n\nwebgl-react uses different shaders for different shapes. If you do not find the shape you need, you can write your own shaders, please read the [Custom Shape](#custom-shape) section.\n\n## Example\n\n```ts\nimport { BorderedCircles, GLCanvas, Rectangles } from \"@ryohey/webgl-react\"\n\nexport const App = () =\u003e {\n  const rects = [\n    {\n      x: 100,\n      y: 200,\n      width: 30,\n      height: 50,\n    },\n  ]\n  const circleRects = [\n    {\n      x: 10,\n      y: 50,\n      width: 10,\n      height: 10,\n    },\n  ]\n  return (\n    \u003c\u003e\n      \u003ch1\u003eWebGL React\u003c/h1\u003e\n      \u003cGLCanvas\n        height={SIZE}\n        width={SIZE}\n        style={{ border: \"1px solid black\" }}\n      \u003e\n        \u003cRectangles rects={rects} color={[0.5, 1, 0.5, 1.0]} /\u003e\n        \u003cBorderedCircles\n          rects={circleRects}\n          fillColor={[0, 0, 0.5, 0.5]}\n          strokeColor={[0, 0, 0, 1]}\n          zIndex={0}\n        /\u003e\n      \u003c/GLCanvas\u003e\n    \u003c/\u003e\n  )\n}\n```\n\n## GLCanvas\n\nGLCanvas is a wrapper for the canvas component. You can use any of the canvas props.\n\n## Shapes\n\n- Rectangles\n- BorderedRectangles\n- BorderedCircles\n\n## [Custom Shape](custom-shape)\n\n1. Write a GLSL shader and pass it to `new Shader()`\n2. Create a subclass of `InstancedBuffer` that matches the shader attributes\n3. Create a wrapper for the `GLNode` component by passing them to `createShader` and `createBuffer`\n\n## Transform\n\nSpecifies the transformation matrix to be applied to the child component. The specified transformation matrix will be multiplied by the projection matrix provided by `useProjectionMatrix`.\n\n## Hooks\n\n### useProjectionMatrix\n\nGets the projection matrix that the figure component reads internally. GLCanvas provides by default a matrix of orthographic projections that translates to the screen coordinate system.\n\n### useRenderer (internal)\n\nGets the Renderer class responsible for WebGL rendering. Usually not used outside of the library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryohey%2Fwebgl-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryohey%2Fwebgl-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryohey%2Fwebgl-react/lists"}