You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
Hey Gophers!
My first time posting here or on any mailing list, so please go gentle on me.
I'm writing a small project using OpenGL and I am trying to create a function to make a screenshot, I've done this before in C and C++ with no problem, but I'm struggling here. The bindings I use (https://github.com/go-gl/glow) have the pixels returned in the format of unsafe.Pointer, rather than a byte array. That's an useless format for me and I'm trying to convert the unsafe.Pointer to a []byte.
// Read in the pixels gl.ReadPixels(0,0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, pixels)
Which results in the following error:
video\renderer.go:94: cannot use pixels (type []byte) as type unsafe.Pointer in argument gl.ReadPixels
That makes sense of course, but I have no idea how unsafe.Pointer works and I'm struggling to find a good example on the internet. I've tried a couple of things (storing the result in var buf unsafe.Pointer) and then converting that to a []byte, but that doesn't work.
Anyone care to show me how it's done? Just to note: I'm using the result with the image package to write an .png to disk.
Thanks!
--Jesse
Nick Craig-Wood
unread,
Dec 4, 2014, 11:55:48 AM12/4/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jesse....@gmail.com, golan...@googlegroups.com
On 04/12/14 13:50, jesse....@gmail.com wrote:
> width, height := r.window.GetSize()
> m := image.NewRGBA(image.Rect(0, 0, width, height))
> pixels := make([]byte, len(m.Pix))
> // Read in the pixels
> gl.ReadPixels(0,0,int32(width),int32(height),gl.RGBA,gl.UNSIGNED_BYTE,pixels)
> |
>
> Which results in the following error:
> video\renderer.go:94: cannot use pixels (type []byte) as type
> unsafe.Pointer in argument gl.ReadPixels
Try unsafe.Pointer(&pixels[0]) that should be what you want.