Class OcsfmlGraphics.render_texture

class render_texture : ?depht_buffer:bool -> int -> int -> object .. end
Target for off-screen 2D rendering into an texture.

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:

Usage example:
    (* Create a new render-window *)
    let window = new render_window 
                        (OcsfmlWindow.VideoMode.create ~w:800 ~h:600 ()) 
                        "SFML window" 
    (* 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 ();
      (* 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 *)
      texture#display ;

      (* Now we start rendering to the window, clear it first *)
      window#clear ()
      (* 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 *)
      window#display ;
      if window#is_open 
      then main_loop ()

    main_loop ()

method create : ?depht_buffer:bool -> int -> int -> bool
Create the render-texture.

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 : unit
method display : unit
Update the contents of the target texture.

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 : const_texture reference
Get a read-only reference to the target 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 : bool
Tell whether the smooth filtering is enabled or not.
Returns True if texture smoothing is enabled.
method set_active : ?active:bool -> unit -> bool
Activate of deactivate the render-texture for rendering.

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
Enable or disable texture smoothing.

This function is similar to Ocsfml.texture.set_smooth. This parameter is disabled by default.