Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added basic screenshot taking and background alpha channel support fo…

…r taking transparent images.

bloom.tga now has an alpha channel.
  • Loading branch information...
commit 5434ed1e1bfe6031958a9cedd1df859396c87fa8 1 parent c999976
Andrew Caudwell authored March 21, 2010
2  ChangeLog
... ...
@@ -1,4 +1,6 @@
1 1
 0.27:
  2
+ * --background-colour can now be used to set the alpha channel (eg FFFFFF00).
  3
+ * Added take screenshot button (F12). Screenshots respect the alpha channel.
2 4
  * Added ini style config file support.
3 5
  * Added demo mode for showing multiple projects in a loop.
4 6
  * Added --logo and --background-image options.
4  README
@@ -81,8 +81,8 @@ options:
81 81
     -e, --elasticity FLOAT
82 82
             Elasticity of nodes.
83 83
 
84  
-    -b, --background-colour FFFFFF
85  
-            Background colour in hex.
  84
+    -b, --background-colour FFFFFF[FF]
  85
+            Background colour in hex. Alpha channel optional. 
86 86
 
87 87
     --background-image IMAGE
88 88
         Set a background image.
BIN  data/bloom.tga
Binary file not shown
4  data/gource.1
@@ -55,8 +55,8 @@ Time in seconds files remain idle before they are removed.
55 55
 \fB\-e, \-\-elasticity FLOAT\fR
56 56
 Elasticity of nodes.
57 57
 .TP
58  
-\fB\-b, \-\-background-colour FFFFFF\fR
59  
-Background colour in hex.
  58
+\fB\-b, \-\-background-colour FFFFFF[FF]\fR
  59
+Background colour in hex. Alpha channel optional.
60 60
 .TP
61 61
 \fB\-\-background\-image IMAGE\fR
62 62
 Set a background image.
8  src/core/display.cpp
@@ -32,7 +32,7 @@
32 32
 SDLAppDisplay display;
33 33
 
34 34
 SDLAppDisplay::SDLAppDisplay() {
35  
-    clearColour = vec3f(0.0f,0.0f,0.0f);
  35
+    clearColour = vec4f(0.0f,0.0f,0.0f,1.0f);
36 36
     enable_shaders=false;
37 37
     enable_alpha=false;
38 38
     vsync=false;
@@ -43,6 +43,10 @@ SDLAppDisplay::~SDLAppDisplay() {
43 43
 }
44 44
 
45 45
 void SDLAppDisplay::setClearColour(vec3f colour) {
  46
+    //setClearColour(vec4f(colour,1.0f));
  47
+}
  48
+
  49
+void SDLAppDisplay::setClearColour(vec4f colour) {
46 50
     clearColour = colour;
47 51
 }
48 52
 
@@ -133,7 +137,7 @@ void SDLAppDisplay::update() {
133 137
 }
134 138
 
135 139
 void SDLAppDisplay::clear() {
136  
-    glClearColor(clearColour.x, clearColour.y, clearColour.z, 1.0f);
  140
+    glClearColor(clearColour.x, clearColour.y, clearColour.z, clearColour.w);
137 141
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
138 142
 }
139 143
 
3  src/core/display.h
@@ -67,7 +67,7 @@ class SDLAppDisplay {
67 67
 public:
68 68
     int width, height;
69 69
     bool fullscreen;
70  
-    vec3f clearColour;
  70
+    vec4f clearColour;
71 71
 
72 72
     SDLAppDisplay();
73 73
     ~SDLAppDisplay();
@@ -80,6 +80,7 @@ class SDLAppDisplay {
80 80
     void   clear();
81 81
     void   enableVsync(bool vsync);
82 82
     void   setClearColour(vec3f colour);
  83
+    void   setClearColour(vec4f colour);
83 84
 
84 85
 #ifdef SDLAPP_SHADER_SUPPORT
85 86
     void   enableShaders(bool enable);
38  src/gource.cpp
@@ -573,6 +573,10 @@ void Gource::keyPress(SDL_KeyboardEvent *e) {
573 573
 
574 574
         if(commitlog==0) return;
575 575
 
  576
+        if(e->keysym.sym == SDLK_F12) {
  577
+            screenshot();
  578
+        }
  579
+
576 580
         if (e->keysym.sym == SDLK_q) {
577 581
             debug = !debug;
578 582
         }
@@ -1626,11 +1630,45 @@ void Gource::drawBloom(Frustum &frustum, float dt) {
1626 1630
     //draw 'gourceian blur' around dirnodes
1627 1631
     glBindTexture(GL_TEXTURE_2D, bloomtex->textureid);
1628 1632
     glBlendFunc (GL_ONE, GL_ONE);
  1633
+
1629 1634
     root->drawBloom(frustum, dt);
1630 1635
 
1631 1636
     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1632 1637
 }
1633 1638
 
  1639
+void Gource::screenshot() {
  1640
+
  1641
+    char* screenbuff = new char[display.width * display.height * 4];
  1642
+
  1643
+    glReadPixels(0, 0, display.width, display.height,
  1644
+                 GL_RGBA, GL_UNSIGNED_BYTE, screenbuff);
  1645
+
  1646
+    const char tga_header[12] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  1647
+    short width           = display.width;
  1648
+    short height          = display.height;
  1649
+    char  bitsperpixel    = 32;
  1650
+    char  imagedescriptor = 8;
  1651
+
  1652
+    //write tga
  1653
+    std::string filename("gource-screenshot.tga");
  1654
+
  1655
+    std::ofstream tga;
  1656
+    tga.open(filename.c_str(), std::ios::out | std::ios::binary );
  1657
+
  1658
+    if(!tga.is_open()) return;
  1659
+
  1660
+    tga.write(tga_header, 12);
  1661
+    tga.write((char*)&width, sizeof(short));
  1662
+    tga.write((char*)&height, sizeof(short));
  1663
+    tga.write(&bitsperpixel, 1);
  1664
+    tga.write(&imagedescriptor, 1);
  1665
+
  1666
+    tga.write(screenbuff, display.width * display.height * 4);
  1667
+    tga.close();
  1668
+
  1669
+    delete[] screenbuff;
  1670
+}
  1671
+
1634 1672
 void Gource::draw(float t, float dt) {
1635 1673
 
1636 1674
     display.mode2D();
3  src/gource.h
@@ -24,6 +24,7 @@
24 24
 
25 25
 #include <deque>
26 26
 #include <dirent.h>
  27
+#include <fstream>
27 28
 
28 29
 #include "core/display.h"
29 30
 #include "core/sdlapp.h"
@@ -182,6 +183,8 @@ class Gource : public SDLApp {
182 183
     void drawActions(float dt);
183 184
     void drawTree(Frustum &frustum, float dt);
184 185
     void drawBloom(Frustum &frustum, float dt);
  186
+
  187
+    void screenshot();
185 188
 public:
186 189
     Gource(FrameExporter* frameExporter);
187 190
     ~Gource();
13  src/gource_settings.cpp
@@ -255,7 +255,7 @@ void GourceSettings::setGourceDefaults() {
255 255
     bloom_multiplier = 1.0f;
256 256
     bloom_intensity  = 0.75f;
257 257
 
258  
-    background_colour = vec3f(0.1f, 0.1f, 0.1f);
  258
+    background_colour = vec4f(0.1f, 0.1f, 0.1f, 1.0f);
259 259
     background_image  = "";
260 260
 
261 261
     elasticity = 0.0f;
@@ -542,12 +542,17 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc
542 542
 
543 543
         if(!entry->hasValue()) conffile.entryException(entry, "specify background colour (FFFFFF)");
544 544
 
545  
-        int r,g,b;
  545
+        int r,g,b,a;
546 546
         std::string colstring = entry->getString();
547 547
 
548  
-        if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) {
549  
-            background_colour = vec3f(r,g,b);
  548
+        if(colstring.size()==8 && sscanf(colstring.c_str(), "%02x%02x%02x%02x", &r, &g, &b, &a) == 4) {
  549
+            background_colour = vec4f(r,g,b,a);
550 550
             background_colour /= 255.0f;
  551
+            if(a==255) background_colour.w = 1.0f;
  552
+        } else if(colstring.size()==6 && sscanf(colstring.c_str(), "%02x%02x%02x", &r, &g, &b) == 3) {
  553
+            background_colour = vec4f(r,g,b,1.0f);
  554
+            background_colour /= 255.0f;
  555
+            background_colour.w = 1.0f;
551 556
         } else {
552 557
             conffile.invalidValueException(entry);
553 558
         }
2  src/gource_settings.h
@@ -78,7 +78,7 @@ class GourceSettings : public SDLAppSettings {
78 78
     float bloom_multiplier;
79 79
     float bloom_intensity;
80 80
 
81  
-    vec3f background_colour;
  81
+    vec4f background_colour;
82 82
     std::string background_image;
83 83
 
84 84
     float elasticity;
5  src/main.cpp
@@ -75,6 +75,11 @@ int main(int argc, char *argv[]) {
75 75
         display.multiSample(4);
76 76
     }
77 77
 
  78
+    //background needs alpha channel
  79
+    if(gGourceSettings.background_colour.w < 1.0f) {
  80
+        display.enableAlpha(true);
  81
+    }
  82
+
78 83
     //enable vsync
79 84
     display.enableVsync(true);
80 85
 

0 notes on commit 5434ed1

Please sign in to comment.
Something went wrong with that request. Please try again.