diff options
-rw-r--r-- | demos/viewport/screen_capture/engine.cfg | 8 | ||||
-rw-r--r-- | demos/viewport/screen_capture/mountains.png | bin | 0 -> 927435 bytes | |||
-rw-r--r-- | demos/viewport/screen_capture/screen_capture.gd | 27 | ||||
-rw-r--r-- | demos/viewport/screen_capture/screen_capture.scn | bin | 0 -> 1977 bytes | |||
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 20 |
5 files changed, 47 insertions, 8 deletions
diff --git a/demos/viewport/screen_capture/engine.cfg b/demos/viewport/screen_capture/engine.cfg new file mode 100644 index 0000000000..b25ed8258e --- /dev/null +++ b/demos/viewport/screen_capture/engine.cfg @@ -0,0 +1,8 @@ +[application] + +name="Screen Capturing" +main_scene="res://screen_capture.scn" + +[display] + +stretch_mode="2d" diff --git a/demos/viewport/screen_capture/mountains.png b/demos/viewport/screen_capture/mountains.png Binary files differnew file mode 100644 index 0000000000..b8435bb1a8 --- /dev/null +++ b/demos/viewport/screen_capture/mountains.png diff --git a/demos/viewport/screen_capture/screen_capture.gd b/demos/viewport/screen_capture/screen_capture.gd new file mode 100644 index 0000000000..69f16fa498 --- /dev/null +++ b/demos/viewport/screen_capture/screen_capture.gd @@ -0,0 +1,27 @@ + +extends Control + +# member variables here, example: +# var a=2 +# var b="textvar" + +func _ready(): + # Initialization here + pass + + + + +func _on_button_pressed(): + get_viewport().queue_screen_capture() + #let two frames pass to make sure the screen was aptured + yield(get_tree(),"idle_frame") + yield(get_tree(),"idle_frame") + #retrieve the captured image + var img = get_viewport().get_screen_capture() + #create a texture for it + var tex = ImageTexture.new() + tex.create_from_image(img) + #set it to the capture node + get_node("capture").set_texture(tex) + pass # replace with function body diff --git a/demos/viewport/screen_capture/screen_capture.scn b/demos/viewport/screen_capture/screen_capture.scn Binary files differnew file mode 100644 index 0000000000..d204e3b67e --- /dev/null +++ b/demos/viewport/screen_capture/screen_capture.scn diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 3c7026daf1..412def40ff 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4270,17 +4270,21 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) { glReadPixels( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height,GL_RGBA,GL_UNSIGNED_BYTE,w.ptr()); } - uint32_t *imgptr = (uint32_t*)w.ptr(); - for(int y=0;y<(viewport.height/2);y++) { + bool flip = current_rt==NULL; - uint32_t *ptr1 = &imgptr[y*viewport.width]; - uint32_t *ptr2 = &imgptr[(viewport.height-y-1)*viewport.width]; + if (flip) { + uint32_t *imgptr = (uint32_t*)w.ptr(); + for(int y=0;y<(viewport.height/2);y++) { - for(int x=0;x<viewport.width;x++) { + uint32_t *ptr1 = &imgptr[y*viewport.width]; + uint32_t *ptr2 = &imgptr[(viewport.height-y-1)*viewport.width]; - uint32_t tmp = ptr1[x]; - ptr1[x]=ptr2[x]; - ptr2[x]=tmp; + for(int x=0;x<viewport.width;x++) { + + uint32_t tmp = ptr1[x]; + ptr1[x]=ptr2[x]; + ptr2[x]=tmp; + } } } |