From: drumsetmonkey Date: Wed, 3 Feb 2016 23:08:40 +0000 (-0500) Subject: Mouse texture, and screenshots X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=b5598688432a0acd416be97ecf54576bbbf07eb6;p=clyne%2Fgamedev.git Mouse texture, and screenshots --- b5598688432a0acd416be97ecf54576bbbf07eb6 diff --cc assets/mouse.png index 0000000,0000000..9614317 new file mode 100644 Binary files differ diff --cc include/ui.h index ade5850,ade5850..b9b9c24 --- a/include/ui.h +++ b/include/ui.h @@@ -12,6 -12,6 +12,7 @@@ #include #include #include ++#include #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 5fcd65e,9038cc9..a85cd4d --- a/main.cpp +++ 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/ + ui::setFontFace("ttf/VCR_OSD_MONO_1.001.ttf"); // as in gamedev/ttf/ /* - * 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()); @@@ -402,11 -393,10 +394,11 @@@ } /* - * 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) @@@ -625,8 -625,8 +624,13 @@@ 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) @@@ -689,19 -691,16 +695,19 @@@ } /* - * 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 87d0f98,9f9b05e..3ef1a3e --- a/src/config.cpp +++ b/src/config.cpp @@@ -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"); diff --cc src/ui.cpp index 8e6d8e3,65e1673..a075037 --- a/src/ui.cpp +++ b/src/ui.cpp @@@ -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; @@@ -872,8 -871,7 +875,70 @@@ } } } + 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;