]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Mouse texture, and screenshots
authordrumsetmonkey <abelleisle@roadrunner.com>
Wed, 3 Feb 2016 23:08:40 +0000 (18:08 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Wed, 3 Feb 2016 23:08:40 +0000 (18:08 -0500)
1  2 
assets/mouse.png
include/ui.h
main.cpp
src/config.cpp
src/entities.cpp
src/gameplay.cpp
src/ui.cpp

index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..9614317ae7f52f046f90e42b0d60a787066e2769
new file mode 100644 (file)
Binary files differ
diff --cc include/ui.h
index ade5850987e523b5c3558633bca9251b73834347,ade5850987e523b5c3558633bca9251b73834347..b9b9c24171209954dbff25de59774ac5d2fdc345
@@@ -12,6 -12,6 +12,7 @@@
  #include <world.h>
  #include <ft2build.h>
  #include <SDL2/SDL_opengl.h>
++#include <fstream>
  #include FT_FREETYPE_H
  
  #define DEBUG
@@@ -54,6 -54,6 +55,30 @@@ public
        void gotoParent();
  };
  
++typedef unsigned long DWORD;
++typedef unsigned short WORD;
++
++typedef struct{
++      WORD    bfType;
++      DWORD   bfSize;
++      WORD    bfReserved1, bfReserved2;
++      DWORD   bfOffBits; //how many bytes before the image data
++} __attribute__ ((packed)) BITMAPFILEHEADER;
++
++typedef struct{
++      DWORD   biSize; //size of header in bytes
++      long    biWidth;
++      long    biHeight;
++      WORD    biPlanes;
++      WORD    biBitCount; //how many bits are in a pixel
++      DWORD   biCompression;
++      DWORD   biSizeImage; //size of image in bytes
++      long    biXPelsPerMeter;
++      long    biYPelsPerMeter;
++      DWORD   biClrUsed; //how many colors there are
++      DWORD   biClrImportant; //important colors
++} __attribute__ ((packed)) BITMAPINFOHEADER;
++
  namespace ui {
        menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f);
        menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t);
diff --cc main.cpp
index 5fcd65e1d1bedb623a65f2b86a01ea4b835a8473,9038cc9caf39adb197a30acc6fb7e7a8927c7b3d..a85cd4d1827b51472526387c242ea5fdb55967ff
+++ b/main.cpp
@@@ -300,21 -295,19 +296,19 @@@ int main(/*int argc, char *argv[]*/)
        }       
        
        /*
-        *      Initialize the FreeType libraries and select what font to use using functions from the ui
-        *      namespace, defined in include/ui.h and src/ui.cpp. These functions should abort with errors
-        *      if they have error.
-        * 
-       */
+        * Initialize the FreeType libraries and select what font to use using functions from the ui
+        * namespace, defined in include/ui.h and src/ui.cpp. These functions should abort with errors
+        * if they have error.
+        */
        
        ui::initFonts();
 -      ui::setFontFace("ttf/Perfect DOS VGA 437.ttf");         // as in gamedev/ttf/<font>
 +      ui::setFontFace("ttf/VCR_OSD_MONO_1.001.ttf");          // as in gamedev/ttf/<font>
        
        /*
-        *      Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
-        *      srand, and its partner getRand points to rand. This is because having our own random number
-        *      generator may be favorable in the future, but at the moment is not implemented.
-        * 
-       */
+        * Initialize the random number generator. At the moment, initRand is a macro pointing to libc's
+        * srand, and its partner getRand points to rand. This is because having our own random number
+        * generator may be favorable in the future, but at the moment is not implemented.
+        */
        
        initRand(millis());
  
        }
  
        /*
-        *      Load sprites used in the inventory menu. See src/inventory.cpp
-       */
+        * Load sprites used in the inventory menu. See src/inventory.cpp
+        */
  
        invUI = Texture::loadTexture("assets/invUI.png" );
 +      mouseTex = Texture::loadTexture("assets/mouse.png");
        
        initInventorySprites();
        
@@@ -471,11 -459,12 +461,11 @@@ void mainLoop(void)
        currentTime = millis();
        deltaTime       = currentTime - prevTime;
  
 -      if(currentMenu != NULL)
 -              goto MENU;
 +      if(currentMenu)goto MENU;
  
        /*
-        *      Run the logic handler if MSEC_PER_TICK milliseconds have passed.
-       */
+        * Run the logic handler if MSEC_PER_TICK milliseconds have passed.
+        */
  
        prev = currentWorld;
        ui::handleEvents();
@@@ -610,7 -600,11 +601,9 @@@ void render()
  
        currentWorld->draw(player);
  
--
+       /*
+        * Calculate the player's hand angle.
+        */
 -
        handAngle = atan((ui::mouse.y - (player->loc.y + player->height/2)) / (ui::mouse.x - player->loc.x + player->width/2))*180/PI;
        if(ui::mouse.x < player->loc.x){
                if(handAngle <= 0)
        player->inv->draw();
  
        /*
++<<<<<<< HEAD
 +       *      Here we draw a black overlay if it's been requested.
 +      */
++
++       /*
+        * Here we draw a black overlay if it's been requested.
+        */
        
        if(fadeIntensity){
                if(fadeWhite)
        }
  
        /*
-        *      Draw a white triangle as a replacement for the mouse's cursor.
-       */
+        * Draw a white triangle as a replacement for the mouse's cursor.
+        */
  
 -      glColor3ub(255,200,255);
 -
 -      glBegin(GL_TRIANGLES);
 -              glVertex2i(ui::mouse.x                  ,ui::mouse.y              );
 -              glVertex2i(ui::mouse.x+HLINE*3.5,ui::mouse.y              );
 -              glVertex2i(ui::mouse.x                  ,ui::mouse.y-HLINE*3.5);
 +      glColor3ub(255,255,255);
 +      glEnable(GL_TEXTURE_2D);
 +      glBindTexture(GL_TEXTURE_2D, mouseTex);
 +      glBegin(GL_QUADS);
 +              glTexCoord2f(0,0);glVertex2i(ui::mouse.x                        ,ui::mouse.y                    );
 +              glTexCoord2f(1,0);glVertex2i(ui::mouse.x+HLINE*5        ,ui::mouse.y                    );
 +              glTexCoord2f(1,1);glVertex2i(ui::mouse.x+HLINE*5        ,ui::mouse.y-HLINE*5    );
 +              glTexCoord2f(0,1);glVertex2i(ui::mouse.x                        ,ui::mouse.y-HLINE*5    );
        glEnd();
 +      glDisable(GL_TEXTURE_2D);
        
        /**************************
        ****  END RENDERING   ****
diff --cc src/config.cpp
index 87d0f98ce85a427366739361f6172eeb49c21941,9f9b05e11b0ba460e3994a9684b31308252224c3..3ef1a3e7942146b14aabd97049a63350e7c0c972
@@@ -11,16 -11,35 +11,33 @@@ extern float                VOLUME_MASTER
  extern float           VOLUME_MUSIC;
  
  XMLDocument xml;
 +XMLElement *scr;
 +XMLElement *vol;
  
 -void readConfig(void){
 -      XMLElement *scr;
 -      XMLElement *vol;
 -      
 +void readConfig(){
+       unsigned int uval;
+       bool bval;
 -      //float fval;
 -      
++
        xml.LoadFile("config/settings.xml");
        scr = xml.FirstChildElement("screen");
-       SCREEN_WIDTH  = scr->UnsignedAttribute("width");
+       
+       if(scr->QueryUnsignedAttribute("width",&uval) == XML_NO_ERROR)
+               SCREEN_WIDTH = uval;
+       else SCREEN_WIDTH = 1280;
+       if(scr->QueryUnsignedAttribute("height",&uval) == XML_NO_ERROR)
+               SCREEN_HEIGHT = uval;
+       else SCREEN_HEIGHT = 800;
+       if(scr->QueryBoolAttribute("fullscreen",&bval) == XML_NO_ERROR)
+               FULLSCREEN = bval;
+       else FULLSCREEN = false;
+       if(xml.FirstChildElement("hline")->QueryUnsignedAttribute("size",&uval) == XML_NO_ERROR)
+               HLINE = uval;
+       else HLINE = 3;
+       
+       /*SCREEN_WIDTH  = scr->UnsignedAttribute("width");
        SCREEN_HEIGHT = scr->UnsignedAttribute("height");
        FULLSCREEN    = scr->BoolAttribute("fullscreen");
-       HLINE         = xml.FirstChildElement("hline")->UnsignedAttribute("size");
+       HLINE         = xml.FirstChildElement("hline")->UnsignedAttribute("size");*/
  
        vol = xml.FirstChildElement("volume");
        VOLUME_MASTER = vol->FirstChildElement("master")->FloatAttribute("volume");
Simple merge
Simple merge
diff --cc src/ui.cpp
index 8e6d8e30f27a5897195c483a70a603ee6625fdc5,65e1673c2ecb8c885caf3c92e8ac560686ad214a..a0750378ae2cce6150f48bd7c3e76da3de71d55e
@@@ -227,7 -227,7 +227,8 @@@ namespace ui 
                                buf[j*4  ]=fontColor[0];
                                buf[j*4+1]=fontColor[1];
                                buf[j*4+2]=fontColor[2];
 -                              buf[j*4+3]=ftf->glyph->bitmap.buffer[j] ? 255 : 0;
++                              //buf[j*4+3]=ftf->glyph->bitmap.buffer[j] == 255 ? 255 : 0;
 +                              buf[j*4+3]=ftf->glyph->bitmap.buffer[j];
                        }
                        
                        ftexwh[i-33].x=ftf->glyph->bitmap.width;
                                }
                        }
                }
 +              setFontSize(16);
        }
++
++      void takeScreenshot(GLubyte* pixels){
++              GLubyte bgr[SCREEN_WIDTH*SCREEN_HEIGHT*3];
++              for(uint x = 0; x < SCREEN_WIDTH*SCREEN_HEIGHT*3; x+=3){
++                      bgr[x] = pixels[x+2];
++                      bgr[x+1] = pixels[x+1];
++                      bgr[x+2] = pixels[x];
++              }
++
++              time_t epoch = time(NULL);
++              struct tm* timen = localtime(&epoch);
++
++              std::string name = "screenshots/";
++              name += std::to_string(1900 + timen->tm_year) += "-";
++              name += std::to_string(timen->tm_mon + 1) += "-";
++              name += std::to_string(timen->tm_mday) += "_";
++              name += std::to_string(timen->tm_hour) += "-";
++              name += std::to_string(timen->tm_min) += "-";
++              name += std::to_string(timen->tm_sec);
++              name += ".bmp";
++              FILE* bmp = fopen(name.c_str(), "w+");
++
++              unsigned long header_size = sizeof(BITMAPFILEHEADER) +
++                                                                      sizeof(BITMAPINFOHEADER);
++
++              BITMAPFILEHEADER bmfh;
++              BITMAPINFOHEADER bmih;
++
++              memset(&bmfh, 0, sizeof(BITMAPFILEHEADER));
++              memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
++
++              bmfh.bfType = 0x4d42;
++
++              bmfh.bfOffBits = 0x36;
++              bmfh.bfSize = header_size;
++              bmfh.bfReserved1 = 0;
++              bmfh.bfReserved2 = 0;
++
++
++              bmih.biSize = sizeof(BITMAPINFOHEADER);
++              bmih.biBitCount = 24;
++
++              bmih.biClrImportant = 0;
++              bmih.biClrUsed = 0;
++
++              bmih.biCompression = 0;
++
++              bmih.biWidth = SCREEN_WIDTH;
++              bmih.biHeight = SCREEN_HEIGHT;
++
++              bmih.biPlanes = 1;
++              bmih.biSizeImage = 0;
++
++              bmih.biXPelsPerMeter = 0x0ec4;
++              bmih.biYPelsPerMeter = 0x0ec4;
++
++              fwrite(&bmfh, 1,sizeof(BITMAPFILEHEADER),bmp);
++              fwrite(&bmih, 1,sizeof(BITMAPINFOHEADER),bmp);
++              fwrite(&bgr, 1,3*SCREEN_WIDTH*SCREEN_HEIGHT,bmp);
++
++      }
++
        void dialogAdvance(void){
                unsigned char i;
                if(!typeOutDone){
@@@ -1125,11 -1123,11 +1190,12 @@@ DONE
                                        currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
                                        break;
                                case SDLK_F12:
--                                      std::cout << "Took screenshot" << std::endl;
                                        // Make the BYTE array, factor of 3 because it's RBG.
                                        static GLubyte* pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT];
                                        glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  
++                                      takeScreenshot(pixels);
++                                      std::cout << "Took screenshot" << std::endl;
                                        break;
                                default:
                                        break;