openglsurface saving as jpg

Anyone know a way to save the image draw into an openglsurface. I cant seem to find the rendered image object.

Tried DrawInto and it does not work.

Capturing the screen image does work.

[quote=124249:@dave duke]tried all these

for x as integer = 1 to 300
for y as integer = 1 to 300



DrawInto does not work. All you will read is the blank picture. Although as your code stands, if you do place any picture as backdrop, it will trigger a nil exception.

You want to grab the screen picture with mac os x screencapture, MBS plugin or bitblt on Windows. Then crop it to the size of the OpenGLSurface control.

*Edit first line : if you do not place

This is what I use… (only tested on mac)

[code]Function getPicture(glSurf As OpenGLSurface) As Picture
//calculate sizes
dim w As integer = glSurf.Width
dim h As integer = glSurf.Height
dim pad As integer = w mod 4
dim totalBytes As integer = (w * h * 3) + (h * pad)

//create and fill memoryblock with pixel data
dim m As MemoryBlock = New MemoryBlock(totalBytes)
OpenGL.glReadPixels(0, 0, w, h, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, m)

//create output picture
dim p As Picture
if TargetCarbon then
p = new Picture(w, h, 32)
p = new Picture(w, h)

dim surf As RGBSurface = p.RGBSurface

//scan memoryblock into picture
h = h-1
w = w-1
dim x, y, offset As integer //offset starts at 0
for y = h downto 0
for x = 0 to w
surf.Pixel(x, y) = m.ColorValue(offset, 24)
offset = offset + 3
offset = offset + pad //skip per line

return p //store picture

End Function[/code]