class render_texture :
?depht_buffer:bool -> int -> int ->
OcsfmlGraphics.render_texture is the little brother of OcsfmlGraphics.render_window.
It implements the same 2D drawing and OpenGL-related functions (see their base class OcsfmlGraphics.render_target for more details), the difference is that the result is stored in an off-screen texture rather than being show in a window.
Rendering to a texture can be useful in a variety of situations:
(* Create a new render-window *)
let window = new render_window
(OcsfmlWindow.VideoMode.create ~w:800 ~h:600 ())
(* Create a new render-texture *)
let texture =
try new OcsfmlGraphics.render_texture 500 500
with OcsfmlGraphics.CreateFailure ->
failwith "Could not create the render texture"
let main_loop () =
(* Event processing *)
(* ... *)
(* Clear the whole texture with red color *)
texture#clear ~color:OcsfmlGraphics.Color.red ();
(* Draw stuff to the texture *)
texture#draw sprite ; (* sprite is an Ocsfml.sprite *)
texture#draw shape ; (* shape is an Ocsfml.shape *)
texture#draw text ; (* text is an Ocsfml.text *)
(* We're done drawing to the texture *)
(* Now we start rendering to the window, clear it first *)
(* Draw the texture *)
let sprite = new sprite ~texture:(texture#get_texture) () in
window#draw sprite ;
(* End the current frame and display its contents on screen *)
then main_loop ()
method create :
?depht_buffer:bool -> int -> int -> bool
Before calling this function, the render-texture is in an
invalid state, thus it is mandatory to call it before doing
anything with the render-texture. The optional parameter,
depthBfr, is useful if you want to use the render-texture for 3D
OpenGL rendering that requires a depth-buffer. Otherwise it is
unnecessary, and you should leave this parameter to false (which
is its default value).
Returns True if creation has been successful.
method destroy :
method display :
This function updates the target texture with what has been
drawn so far. Like for windows, calling this function is
mandatory at the end of rendering. Not calling it may leave the
texture in an undefined state.
method get_texture :
After drawing to the render-texture and calling display, you can
retrieve the updated texture using this function, and draw it
using a sprite (for example). The internal texture of a
render-texture is always the same instance, so that it is
possible to call this function once and keep a reference to the
texture even after it is modified.
Returns Const reference to the texture.
method is_smooth :
method set_active :
?active:bool -> unit -> bool
This function makes the render-texture's context current for
future OpenGL rendering operations (so you shouldn't care about
it if you're not doing direct OpenGL stuff). Only one context
can be current in a thread, so if you want to draw OpenGL
geometry to another render target (like a render_window) don't
forget to activate it again.
Returns True if operation was successful, false otherwise.
method set_smooth :
bool -> unit
This function is similar to Ocsfml.texture.set_smooth. This
parameter is disabled by default.