Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions _docs/starting/first-render.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ This tutorial assumes the [First Application](/docs/starting/first-application)
The initial setup of render seems a bit daunting in WebGPU, especially if we are coming from an OpenGL background. In reality, it isn't as bad as it seems. LittleKt takes care of a lot of the work for us but also keeps things low-level enough that we can build on top of it. Let's render something!

```kotlin
import com.littlekt.Context
import com.littlekt.ContextListener
import com.littlekt.file.vfs.readTexture
import com.littlekt.graphics.Color
import com.littlekt.graphics.webgpu.*
import com.littlekt.graphics.g2d.*
import com.littlekt.resources.Textures
import com.littlekt.util.viewport.ExtendViewport

class MyGame(context: Context) : ContextListener(context) {

override suspend fun Context.start() {
Expand All @@ -19,7 +28,7 @@ class MyGame(context: Context) : ContextListener(context) {

val device = graphics.device // LittleKt creates a WebGPU adapter & a device from it. It's as simple as referencing it.
val surfaceCapability = graphics.surfaceCapabilities // we grab the current graphics surface capabilities
val preferredFromat = graphics.preferredFormat // what TextureFormat the surface prefers
val preferredFormat = graphics.preferredFormat // what TextureFormat the surface prefers

// then we configure the surface
graphics.configureSurface(
Expand Down Expand Up @@ -54,7 +63,7 @@ class MyGame(context: Context) : ContextListener(context) {
val swapChainTexture: WebGPUTexture = checkNotNull(surfaceTexture.texture) // we need the underlying WebGPU texture, which may be null
val frame: TextureView = swapChainTexture.createView() // we create the view of the texture! We can now use it as a color attachment in a render pass!

val commandEncoder: CommandEncoder = device.createCommandEncoder // handles creating commands to present to the surface
val commandEncoder: CommandEncoder = device.createCommandEncoder() // handles creating commands to present to the surface
val renderPassEncoder =
commandEncoder.beginRenderPass(
desc =
Expand Down Expand Up @@ -96,4 +105,4 @@ class MyGame(context: Context) : ContextListener(context) {
}
}
}
```
```