gpt4 book ai didi

go - 不需要模块提供包 SDL2

转载 作者:行者123 更新时间:2023-12-03 10:08:02 24 4
gpt4 key购买 nike

我正在尝试从 https://github.com/veandco/go-sdl2 导入 sdl2 包.我遵循了 readme.md for Windows 上出现的所有步骤。安装mingw64并在cmd上执行:

go get -v github.com/veandco/go-sdl2/sdl
它工作正常,但是当我尝试这样做时:
go run .\sdl2.go
我收到了这个错误:
sdl2.go:4:2: no required module provides package github.com/veandco/go-sdl2/sdl: working directory is not part of a module
在我的另一台计算机上运行完美,但是当我克隆这个存储库并将软件包安装到另一台笔记本电脑上时,我遇到了很多问题。要获取有关此案例的更多信息,我将我的测试源放在这里以提供更多信息:
package main

import (
"github.com/veandco/go-sdl2/sdl"
"fmt"
)

const winWidth, winHeight int = 800, 600



type color struct {
r, g, b byte
}

func setPixel(x, y int, c color, pixels []byte) {
index := (y * winWidth + x) * 4

if index < len(pixels)-4 && index >= 0 {
pixels[index] = c.r
pixels[index+1] = c.g
pixels[index+2] = c.b
}
}

func main() {
winWidth := 800
winHeight := 600

window,err := sdl.CreateWindow("Testing SDL2", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
int32(winWidth) ,int32(winHeight), sdl.WINDOW_SHOWN)
if err != nil {
fmt.Println(err)
return
}
defer window.Destroy()

renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if err != nil {
fmt.Println(err)
return
}
defer renderer.Destroy()

tex, err := renderer.CreateTexture(sdl.PIXELFORMAT_ABGR8888, sdl.TEXTUREACCESS_STREAMING, int32(winWidth), int32(winHeight))
if err != nil {
fmt.Println(err)
return
}
defer tex.Destroy()

pixels := make([]byte, winWidth*winHeight*4)

for y := 0; y < winHeight; y++ {
for x := 0; x < winWidth; x++ {
setPixel(x,y, color{byte(x % 255),byte(y % 255), 0}, pixels)
}
}
tex.Update(nil,pixels,winWidth*4)
renderer.Copy(tex,nil,nil)
renderer.Present()

sdl.Delay(2000)

}

最佳答案

根据New module changes in Go 1.16博客

The go command now builds packages in module-aware mode by default, even when no go.mod is present. This is a big step toward using modules in all projects.


按照博客中的建议,将 GO111MODULE 的值更改为 auto go env -w GO111MODULE=auto会解决这个问题。

关于go - 不需要模块提供包 SDL2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66267267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com