From 702371fec96535cf74eb94606056617e23d32acd Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Fri, 20 Feb 2026 10:56:24 +0100 Subject: [PATCH] docs: Triangle Tutorial --- apps/typegpu-docs/astro.config.mjs | 32 +++++----- .../tutorials/your-first-triangle/index.mdx | 58 +++++++++++++++++++ 2 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 apps/typegpu-docs/src/content/docs/tutorials/your-first-triangle/index.mdx diff --git a/apps/typegpu-docs/astro.config.mjs b/apps/typegpu-docs/astro.config.mjs index 7c6487dcd8..994209a7c0 100644 --- a/apps/typegpu-docs/astro.config.mjs +++ b/apps/typegpu-docs/astro.config.mjs @@ -124,6 +124,24 @@ export default defineConfig({ label: 'Getting Started', slug: 'getting-started', }, + DEV && { + label: 'Tutorials', + items: [ + { + label: 'Your First Triangle', + slug: 'tutorials/your-first-triangle', + }, + { + label: + 'From a Triangle to Simulating Boids: Step-by-step Tutorial', + slug: 'tutorials/triangle-to-boids', + }, + { + label: 'Game of life tutorial', + slug: 'tutorials/game-of-life', + }, + ], + }, { label: 'Fundamentals', items: stripFalsy([ @@ -267,20 +285,6 @@ export default defineConfig({ }, ]), }, - DEV && { - label: 'Tutorials', - items: [ - { - label: - 'From a Triangle to Simulating Boids: Step-by-step Tutorial', - slug: 'tutorials/triangle-to-boids', - }, - { - label: 'Game of life tutorial', - slug: 'tutorials/game-of-life', - }, - ], - }, { label: 'Reference', items: stripFalsy([ diff --git a/apps/typegpu-docs/src/content/docs/tutorials/your-first-triangle/index.mdx b/apps/typegpu-docs/src/content/docs/tutorials/your-first-triangle/index.mdx new file mode 100644 index 0000000000..dda4fd447e --- /dev/null +++ b/apps/typegpu-docs/src/content/docs/tutorials/your-first-triangle/index.mdx @@ -0,0 +1,58 @@ +--- +title: "Your First Triangle" +description: A tutorial that will guide you through the process of creating a simple triangle rendering program. +draft: true +--- + +Refer to [Getting Started](/TypeGPU/getting-started) on how to install TypeGPU. + +```ts twoslash +import tgpu from 'typegpu'; + +const root = await tgpu.init(); +const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); +``` + +```ts twoslash +import tgpu, { d, common } from 'typegpu'; +const root = await tgpu.init(); +const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); +// ---cut--- +const pipeline = root['~unstable'].createRenderPipeline({ + // This effect will span the whole canvas. + vertex: common.fullScreenTriangle, + // A function that returns a color for each pixel. + fragment: () => { + 'use gpu'; + // Returning a red color (red: 1, green: 0, blue: 0, alpha: 1) + return d.vec4f(1, 0, 0, 1); + }, + targets: { format: presentationFormat }, +}); +``` + +To draw the prepared pipeline, we need to create a canvas. + +```html + +``` + +```ts twoslash +import tgpu, { d, common } from 'typegpu'; +const root = await tgpu.init(); +const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); +const pipeline = root['~unstable'].createRenderPipeline({ + // This effect will span the whole canvas. + vertex: common.fullScreenTriangle, + // A function that returns a color for each pixel. + fragment: () => { + 'use gpu'; + // Returning a red color (red: 1, green: 0, blue: 0, alpha: 1) + return d.vec4f(1, 0, 0, 1); + }, + targets: { format: presentationFormat }, +}); +// ---cut--- +const canvas = document.getElementById('main-canvas') as HTMLCanvasElement; +const context = root.configureContext({ canvas }); +```