[英]OpenGL texture from SDL Surface in Go
I'm using go-sdl2 and go-gl and I'm trying to create a gl texture from sdl surface.我正在使用go-sdl2和go-gl ,我正在尝试从 sdl 表面创建 gl 纹理。 In CI would do that by calling
glTexImage2D
with surface->pixels
as the last argument.在 CI 中,通过调用
glTexImage2D
并使用surface->pixels
作为最后一个参数来做到这一点。 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
.但是,在
go-sdl
中, pixels
是一个私有字段,并且Pixels()
(我应该用来访问它)返回[]byte
,这与期望最后一个参数unsafe.Pointer
的gl.TexImage2D
不兼容。 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
不能在 gl.TexImage2D 的参数中使用 image.Pixels()([]byte 类型的值)作为 unsafe.Pointer 类型
So what would be the proper way of creating gl texture from sdl surface in go?那么在go中从sdl表面创建gl纹理的正确方法是什么?
事实证明,有Surface.Data函数返回实际指针。
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.W, image.H, 0, gl.RGBA, gl.UNSIGNED_BYTE, image.Data())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.