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
Surface.MakeCurrent
surface.DrawInto(canvas1.Backdrop.Graphics,0,0)

for x as integer = 1 to 300
for y as integer = 1 to 300
Canvas1.Backdrop.Graphics.Pixel(x,y)=opengl.glReadPixels(x,y)

next

next[/quote]

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)
else
p = new Picture(w, h)
end

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
next
offset = offset + pad //skip per line
next

return p //store picture

End Function[/code]