I am trying to import sdl2 package from https://github.com/veandco/go-sdl2. I followed all the steps that appear on readme.md for Windows. Installing mingw64 and do on cmd:
go get -v github.com/veandco/go-sdl2/sdl
It works okay, but when I tried to do:
go run .\sdl2.go
I got this error:
sdl2.go:4:2: no required module provides package github.com/veandco/go-sdl2/sdl: working directory is not part of a module
In my other computer works perfect but when I clone this repository and install the package on the other laptop I had a lot of issues. To get more info about the case I put my test source here to brig more information:
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)
}
According to New module changes in Go 1.16 blog
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.
as suggested in the blog change the value for GO111MODULE to auto go env -w GO111MODULE=auto
would fix the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With