I'm using go-sdl2 and go-gl and I'm trying to create a gl texture from sdl surface. In C I would do that by calling glTexImage2D
with surface->pixels
as the last argument. In go-sdl
, however, pixels
is a private field and Pixels()
(that I'm supposed to use to access it) returns []byte
, which is incompatible with gl.TexImage2D
that expects the last argument to be an unsafe.Pointer
.
image, err := img.Load("img.png")
if err != nil {
//...
}
var texture uint32
gl.GenTextures(1, &texture)
gl.BindTexture(gl.TEXTURE_2D, texture)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.W, image.H, 0, gl.RGBA, gl.UNSIGNED_BYTE, image.Pixels())
cannot use image.Pixels() (value of type []byte) as type unsafe.Pointer in argument to gl.TexImage2D
So what would be the proper way of creating gl texture from sdl surface in go?
It turns out that there is Surface.Data function that returns the actual pointer.
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.W, image.H, 0, gl.RGBA, gl.UNSIGNED_BYTE, image.Data())