Skip to content

Instantly share code, notes, and snippets.

@akinncar
Last active October 19, 2020 00:51
Show Gist options
  • Save akinncar/4aba1f4bc92bc9fc35f2aaaf05912fac to your computer and use it in GitHub Desktop.
Save akinncar/4aba1f4bc92bc9fc35f2aaaf05912fac to your computer and use it in GitHub Desktop.
GLView Expo 3D Game Example
<GLView
style={{ flex: 1 }}
onContextCreate={async (gl) => {
// GL Parameter disruption
const { drawingBufferWidth: width, drawingBufferHeight: height } = gl;
// Renderer declaration and set properties
const renderer = new Renderer({ gl });
renderer.setSize(width, height);
renderer.setClearColor("#fff");
// Scene declaration, add a fog, and a grid helper to see axes dimensions
const scene = new Scene();
scene.fog = new Fog("#3A96C4", 1, 10000);
scene.add(new GridHelper(10, 10));
// Add all necessary lights
const ambientLight = new AmbientLight(0x101010);
scene.add(ambientLight);
const pointLight = new PointLight(0xffffff, 2, 1000, 1);
pointLight.position.set(0, 200, 200);
scene.add(pointLight);
const spotLight = new SpotLight(0xffffff, 0.5);
spotLight.position.set(0, 500, 100);
spotLight.lookAt(scene.position);
scene.add(spotLight);
// Add sphere object instance to our scene
scene.add(sphere);
// Set camera position and look to sphere
camera.position.set(
cameraInitialPositionX,
cameraInitialPositionY,
cameraInitialPositionZ
);
camera.lookAt(sphere.position);
// Render function
const render = () => {
requestAnimationFrame(render);
renderer.render(scene, camera);
gl.endFrameEXP();
};
render();
}}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment