[SDL] [OT]-Copy OpenGL Screen Buffer To Texture?

John Magnotti john.magnotti at gmail.com
Tue Nov 30 13:31:04 PST 2010


Hi,

Depending on the use case, you could also use a function like
SDL_SaveBMP (http://www.libsdl.org/docs/html/sdlsavebmp.html) and then
load the resulting image into a texture using normal means. Obviously
this isn't good if you are trying to create certain special effects,
but if you just want a quick way to do screen captures and reload
them, maybe it could be useful.


John

On Tue, Nov 30, 2010 at 3:16 PM, Christian Leger <chrism.leger at gmail.com> wrote:
> Hi,
>
> You're very welcome.
>
> The function call I gave has certain parameters set only for the example
> where I found it. The values 0, 0, 128, 128 are what they are only because
> that was the choice of the program writer. I'm not sure if powers of two are
> still a requirement with any modern hardware. It used to be a requirement,
> but sometime in the last 3-5 years (or even more) that requirement has
> disappeared in normal commodity graphics hardware.
>
> I suggest you try the above function with argument values suitable to your
> screen resolution.
> In short:
>     - define a texture buffer (like a char array) that can hold a 640X480
> image at your desired pixel format
>     - make a texture with this buffer, call it TB
>     - render a scene to your screen at 640x480
>     - bind TB as the active texture
>     - use the glCopyTexImage2D call, supplying appropriate parameters for
> your resolution
>     - now you should be able to use texture TB to texture-map anywhere you
> like.
>
> then let us know how it goes! Let me know if you'd like more clarification.
> I haven't tested the above as stated here, so if it doesn't work for you,
> maybe I'm making a mistake somewhere. A good place to start would be to
> download the NeHe lesson #36, and see if you can play around with the
> texture and viewport size used when the program renders and then copies to
> texture.
>
> Thanks,
>
> Christian
>
> On Tue, Nov 30, 2010 at 3:53 PM, Jesse Palser <SLNTHERO at aol.com> wrote:
>>
>> Hi,
>>
>> Thanks for the information.
>>
>> My game runs in a 640x480 window by default,
>> which means the window's dimensions are
>> not a power of 2 (a requirement of OGL?)...
>>
>> How would I copy screen buffer to texture
>> and then display texture onto screen
>> when dimensions are 640x480?
>>
>> Thanks...
>>
>> Jesse
>>
>>
>>
>> On 11/30/2010 03:40 PM, Christian Leger wrote:
>>
>> Howdy,
>>
>> Here is a tiny sample from the NeHe lesson #36:
>>
>>     // Copy Our ViewPort To The Blur Texture (From 0,0 To 128,128... No
>> Border)
>>     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, 128, 128, 0);
>>
>> This function is used after rendering a scene to a viewport of dimensions
>> [0,128]X[0,128]. A texture has to be bound before the operation is taken.
>>
>> Let us know if this is helpful!
>>
>> Thanks,
>>
>> Christian
>>
>> On Tue, Nov 30, 2010 at 3:20 PM, Jesse Palser <SLNTHERO at aol.com> wrote:
>>>
>>> [OT]-Copy OpenGL Screen Buffer To Texture?
>>>
>>> Hi,
>>>
>>> I wish to copy the current OpenGL screen buffer
>>> into an OpenGL texture to be displayed later.
>>>
>>> Whats the best method to do the above?
>>> Thanks...
>>>
>>> Jesse
>>> _______________________________________________
>>> SDL mailing list
>>> SDL at lists.libsdl.org
>>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>>
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>>
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>



More information about the SDL mailing list