mirror of
https://github.com/Kugelschieber/vk-experiments.git
synced 2026-01-18 06:40:27 +00:00
Basic GLFW setup and started setting up Vulkan.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.idea/
|
||||||
83
01_Simple_Sprite/main.go
Normal file
83
01_Simple_Sprite/main.go
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-gl/glfw/v3.3/glfw"
|
||||||
|
vk "github.com/vulkan-go/vulkan"
|
||||||
|
"log"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
vkInstance vk.Instance
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
}
|
||||||
|
|
||||||
|
func createWindow(title string, width, height int) (*glfw.Window, error) {
|
||||||
|
if err := glfw.Init(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
window, err := glfw.CreateWindow(width, height, title, nil, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
window.MakeContextCurrent()
|
||||||
|
|
||||||
|
for !window.ShouldClose() {
|
||||||
|
window.SwapBuffers()
|
||||||
|
glfw.PollEvents()
|
||||||
|
}
|
||||||
|
|
||||||
|
return window, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func initVk() error {
|
||||||
|
vk.SetGetInstanceProcAddr(glfw.GetVulkanGetInstanceProcAddress())
|
||||||
|
|
||||||
|
if err := vk.Init(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func load() {
|
||||||
|
vk.CreateInstance(&vk.InstanceCreateInfo{
|
||||||
|
EnabledLayerCount: 0,
|
||||||
|
}, nil, &vkInstance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanup() {
|
||||||
|
vk.DestroyInstance(vkInstance, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loop(window *glfw.Window) {
|
||||||
|
for !window.ShouldClose() {
|
||||||
|
// ...
|
||||||
|
window.SwapBuffers()
|
||||||
|
glfw.PollEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
window, err := createWindow("01 Simple Sprite", 640, 480)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error creating window: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer glfw.Terminate()
|
||||||
|
|
||||||
|
if err := initVk(); err != nil {
|
||||||
|
log.Fatalf("error initializing Vulkan: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
load()
|
||||||
|
defer cleanup()
|
||||||
|
loop(window)
|
||||||
|
}
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Golang Vulkan Experiments
|
||||||
|
|
||||||
|
Learning and experimenting with Vulkan using Golang.
|
||||||
8
go.mod
Normal file
8
go.mod
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module github.com/Kugelschieber/vk-experiments
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb // indirect
|
||||||
|
github.com/vulkan-go/vulkan v0.0.0-20210402152248-956e3850d8f9 // indirect
|
||||||
|
)
|
||||||
4
go.sum
Normal file
4
go.sum
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw=
|
||||||
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
|
github.com/vulkan-go/vulkan v0.0.0-20210402152248-956e3850d8f9 h1:WFujQpkMAAd8dqccEm10n8dly4yQ/R5d2+Us7GutowA=
|
||||||
|
github.com/vulkan-go/vulkan v0.0.0-20210402152248-956e3850d8f9/go.mod h1:Y5Ti1uUBdKDsb0W8aPtIo9krs+29Y7p6Bc9yyy4AM6g=
|
||||||
Reference in New Issue
Block a user