Skip to content

Commit

Permalink
Feature/screenshot (#9)
Browse files Browse the repository at this point in the history
* Added takeScreenshot

* Added log
  • Loading branch information
gogoprog authored Oct 7, 2017
1 parent a58a171 commit 3962520
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ debug.log
generated
/test/packed-*
/test/index.*

/test/screenshot.png
/doc/pages

callgrind*
valgrind*
vgcore*

/dist
tags
tags
11 changes: 11 additions & 0 deletions src/application/application_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <fstream>
#include <sstream>

#define URHO3D_LOGGING

#include <Urho3D/IO/Log.h>
#include <Urho3D/Core/CoreEvents.h>
#include <Urho3D/Core/Timer.h>
#include <Urho3D/Core/Thread.h>
Expand Down Expand Up @@ -145,6 +148,14 @@ void App::exit()
engine_->Exit();
}

void App::takeScreenshot(const Urho3D::String & filename)
{
URHO3D_LOGDEBUG("Saving screenshot " + filename);
Image screenshot(context_);
GetSubsystem<Graphics>()->TakeScreenShot(screenshot);
screenshot.SavePNG(filename);
}

void App::setGuiFilename(const Urho3D::String & filename)
{
guiFilename = filename;
Expand Down
1 change: 1 addition & 0 deletions src/application/application_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class App : public Urho3D::Application
void runFrame();
void stop();
void exit();
void takeScreenshot(const Urho3D::String & filename);
void setGuiFilename(const Urho3D::String & filename);


Expand Down
1 change: 1 addition & 0 deletions src/bindings/bindings_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ EMBINDCEFV8_BINDINGS(application)
.method("getAudio", &App::getAudio)
.method("isRunning", &App::isRunning)
.method("setWindowTitle", &App::setWindowTitle)
.method("takeScreenshot", &App::takeScreenshot)
.method("setGuiFilename", &App::setGuiFilename)
.method("setWindowSize", &App::setWindowSize)
;
Expand Down
3 changes: 2 additions & 1 deletion src/haxe/gengine/Gengine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extern class Gengine
static public function setWindowSize(size:IntVector2):Void;
static public function setWindowTitle(title:String):Void;

static public function setGuiFilename(title:String):Void;
static public function takeScreenshot(filename:String):Void;
static public function setGuiFilename(filename:String):Void;

static public function exit():Void;
}
1 change: 1 addition & 0 deletions test/Application.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class GameSystem extends System
{
var p = Gengine.getInput().getMousePosition();
trace('Mouse position : ' + p.x + ', ' + p.y);
Gengine.takeScreenshot("screenshot.png");
}

if(Gengine.getInput().getMouseButtonPress(1))
Expand Down

0 comments on commit 3962520

Please sign in to comment.