I only need to render 2 dimensional text, but the examples (Text Rendering by MetalByExample.com) I found are in Objective-C, very messy, and probably have a lot of muck (code or steps that aren't necessary for full functionality). How should I go about rendering simple text in Metal? This is trivial in SwiftUI, but how do I do it in Metal? I know this question is kind of vague but there's very little useful resources on how to render simple text in Metal. How could I render a simple hello world text, given this starting code?
import Cocoa
import MetalKit
class ViewController: NSViewController {
private let Device = MTLCreateSystemDefaultDevice()!
private var CommandQue: MTLCommandQueue!, Pipeline: MTLRenderPipelineState!
private var View: MTKView {
return view as! MTKView
}
override func viewDidLoad() {
super.viewDidLoad()
View.delegate = self
View.device = Device
CommandQue = Device.makeCommandQueue()
let PipelineDescriptor = MTLRenderPipelineDescriptor()
let Library = Device.makeDefaultLibrary()!
PipelineDescriptor.vertexFunction = Library.makeFunction(name: "V")
PipelineDescriptor.fragmentFunction = Library.makeFunction(name: "T")
Pipeline = try? Device.makeRenderPipelineState(descriptor: PipelineDescriptor)
}
}
extension ViewController: MTKViewDelegate {
func mtkView(_ _: MTKView, drawableSizeWillChange Size: CGSize) {
View.draw()
}
func draw(in _: MTKView) {
let CommandBuffer = CommandQue.makeCommandBuffer()!, CommandEncoder = CommandBuffer.makeRenderCommandEncoder(descriptor: View.currentRenderPassDescriptor!)!
CommandEncoder.setRenderPipelineState(Pipeline!)
// Render
CommandEncoder.endEncoding()
CommandBuffer.present(View.currentDrawable!)
CommandBuffer.commit()
}
}
Basically how could I replicate this simple SwiftUI in Metal? I'm not asking for a 'code this for me' but I would like some pointers on where to start?
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}