Permalink
Browse files

Added basic screenshot taking and background alpha channel support fo…

…r taking transparent images.

bloom.tga now has an alpha channel.
  • Loading branch information...
1 parent c999976 commit 5434ed1e1bfe6031958a9cedd1df859396c87fa8 @acaudwell committed Mar 21, 2010
Showing with 70 additions and 12 deletions.
  1. +2 −0 ChangeLog
  2. +2 −2 README
  3. BIN data/bloom.tga
  4. +2 −2 data/gource.1
  5. +6 −2 src/core/display.cpp
  6. +2 −1 src/core/display.h
  7. +38 −0 src/gource.cpp
  8. +3 −0 src/gource.h
  9. +9 −4 src/gource_settings.cpp
  10. +1 −1 src/gource_settings.h
  11. +5 −0 src/main.cpp
View
@@ -1,4 +1,6 @@
0.27:
+ * --background-colour can now be used to set the alpha channel (eg FFFFFF00).
+ * Added take screenshot button (F12). Screenshots respect the alpha channel.
* Added ini style config file support.
* Added demo mode for showing multiple projects in a loop.
* Added --logo and --background-image options.
View
4 README
@@ -81,8 +81,8 @@ options:
-e, --elasticity FLOAT
Elasticity of nodes.
- -b, --background-colour FFFFFF
- Background colour in hex.
+ -b, --background-colour FFFFFF[FF]
+ Background colour in hex. Alpha channel optional.
--background-image IMAGE
Set a background image.
View
Binary file not shown.
View
@@ -55,8 +55,8 @@ Time in seconds files remain idle before they are removed.
\fB\-e, \-\-elasticity FLOAT\fR
Elasticity of nodes.
.TP
-\fB\-b, \-\-background-colour FFFFFF\fR
-Background colour in hex.
+\fB\-b, \-\-background-colour FFFFFF[FF]\fR
+Background colour in hex. Alpha channel optional.
.TP
\fB\-\-background\-image IMAGE\fR
Set a background image.
View
@@ -32,7 +32,7 @@
SDLAppDisplay display;
SDLAppDisplay::SDLAppDisplay() {
- clearColour = vec3f(0.0f,0.0f,0.0f);
+ clearColour = vec4f(0.0f,0.0f,0.0f,1.0f);
enable_shaders=false;
enable_alpha=false;
vsync=false;
@@ -43,6 +43,10 @@ SDLAppDisplay::~SDLAppDisplay() {
}
void SDLAppDisplay::setClearColour(vec3f colour) {
+ //setClearColour(vec4f(colour,1.0f));
+}
+
+void SDLAppDisplay::setClearColour(vec4f colour) {
clearColour = colour;
}
@@ -133,7 +137,7 @@ void SDLAppDisplay::update() {
}
void SDLAppDisplay::clear() {
- glClearColor(clearColour.x, clearColour.y, clearColour.z, 1.0f);
+ glClearColor(clearColour.x, clearColour.y, clearColour.z, clearColour.w);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
View
@@ -67,7 +67,7 @@ class SDLAppDisplay {
public:
int width, height;
bool fullscreen;
- vec3f clearColour;
+ vec4f clearColour;
SDLAppDisplay();
~SDLAppDisplay();
@@ -80,6 +80,7 @@ class SDLAppDisplay {
void clear();
void enableVsync(bool vsync);
void setClearColour(vec3f colour);
+ void setClearColour(vec4f colour);
#ifdef SDLAPP_SHADER_SUPPORT
void enableShaders(bool enable);
View
@@ -573,6 +573,10 @@ void Gource::keyPress(SDL_KeyboardEvent *e) {
if(commitlog==0) return;
+ if(e->keysym.sym == SDLK_F12) {
+ screenshot();
+ }
+
if (e->keysym.sym == SDLK_q) {
debug = !debug;
}
@@ -1626,11 +1630,45 @@ void Gource::drawBloom(Frustum &frustum, float dt) {
//draw 'gourceian blur' around dirnodes
glBindTexture(GL_TEXTURE_2D, bloomtex->textureid);
glBlendFunc (GL_ONE, GL_ONE);
+
root->drawBloom(frustum, dt);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
+void Gource::screenshot() {
+
+ char* screenbuff = new char[display.width * display.height * 4];
+
+ glReadPixels(0, 0, display.width, display.height,
+ GL_RGBA, GL_UNSIGNED_BYTE, screenbuff);
+
+ const char tga_header[12] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ short width = display.width;
+ short height = display.height;
+ char bitsperpixel = 32;
+ char imagedescriptor = 8;
+
+ //write tga
+ std::string filename("gource-screenshot.tga");
+
+ std::ofstream tga;
+ tga.open(filename.c_str(), std::ios::out | std::ios::binary );
+
+ if(!tga.is_open()) return;
+
+ tga.write(tga_header, 12);
+ tga.write((char*)&width, sizeof(short));
+ tga.write((char*)&height, sizeof(short));
+ tga.write(&bitsperpixel, 1);
+ tga.write(&imagedescriptor, 1);
+
+ tga.write(screenbuff, display.width * display.height * 4);
+ tga.close();
+
+ delete[] screenbuff;
+}
+
void Gource::draw(float t, float dt) {
display.mode2D();
View
@@ -24,6 +24,7 @@
#include <deque>
#include <dirent.h>
+#include <fstream>
#include "core/display.h"
#include "core/sdlapp.h"
@@ -182,6 +183,8 @@ class Gource : public SDLApp {
void drawActions(float dt);
void drawTree(Frustum &frustum, float dt);
void drawBloom(Frustum &frustum, float dt);
+
+ void screenshot();
public:
Gource(FrameExporter* frameExporter);
~Gource();
View
@@ -255,7 +255,7 @@ void GourceSettings::setGourceDefaults() {
bloom_multiplier = 1.0f;
bloom_intensity = 0.75f;
- background_colour = vec3f(0.1f, 0.1f, 0.1f);
+ background_colour = vec4f(0.1f, 0.1f, 0.1f, 1.0f);
background_image = "";
elasticity = 0.0f;
@@ -542,12 +542,17 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc
if(!entry->hasValue()) conffile.entryException(entry, "specify background colour (FFFFFF)");
- int r,g,b;
+ int r,g,b,a;
std::string colstring = entry->getString();
- if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) {
- background_colour = vec3f(r,g,b);
+ if(colstring.size()==8 && sscanf(colstring.c_str(), "%02x%02x%02x%02x", &r, &g, &b, &a) == 4) {
+ background_colour = vec4f(r,g,b,a);
background_colour /= 255.0f;
+ if(a==255) background_colour.w = 1.0f;
+ } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) {
+ background_colour = vec4f(r,g,b,1.0f);
+ background_colour /= 255.0f;
+ background_colour.w = 1.0f;
} else {
conffile.invalidValueException(entry);
}
View
@@ -78,7 +78,7 @@ class GourceSettings : public SDLAppSettings {
float bloom_multiplier;
float bloom_intensity;
- vec3f background_colour;
+ vec4f background_colour;
std::string background_image;
float elasticity;
View
@@ -75,6 +75,11 @@ int main(int argc, char *argv[]) {
display.multiSample(4);
}
+ //background needs alpha channel
+ if(gGourceSettings.background_colour.w < 1.0f) {
+ display.enableAlpha(true);
+ }
+
//enable vsync
display.enableVsync(true);

0 comments on commit 5434ed1

Please sign in to comment.