git repos / blockattack-game

commit 269c4c3f

sago007 · 2019-04-27 19:31
269c4c3fe1f87a0b84b72349a07015ea209006e9 patch · browse files
parent dddcbb9c141fd912eb8a51c98e031c4c7dfde270

Changed the 16:9 resolution to be 1364 wide instead of 1366 pixels (relative).
Write screenshot feature now works with Software render (still not hardware!)

Changed files

M source/code/global.hpp before
M source/code/main.cpp before
diff --git a/source/code/global.hpp b/source/code/global.hpp index 3674db5..351cbfb 100644 --- a/source/code/global.hpp +++ b/source/code/global.hpp
@@ -49,6 +49,10 @@ void DrawIMG_Bounded(const sago::SagoSprite& sprite, SDL_Renderer* target, int x
void sagoTextSetHelpFont(sago::SagoTextField& field);
void sagoTextSetBlueFont(sago::SagoTextField& field);
+const int SIXTEEN_NINE_WIDTH = 1364;
+const int FOUR_THREE_WIDTH = 1024;
+const int SCREEN_HIGHT = 768;
+
struct GlobalData {
sago::SagoSprite bHighScore;
sago::SagoSprite bBack;
@@ -74,8 +78,8 @@ struct GlobalData {
TextManager theTextManager;
- int xsize = 1024;
- int ysize = 768;
+ int xsize = FOUR_THREE_WIDTH;
+ int ysize = SCREEN_HIGHT;
int mousex = 0;
int mousey = 0;
};
diff --git a/source/code/main.cpp b/source/code/main.cpp index 157b179..8cbfb6d 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -249,23 +249,23 @@ void ResetFullscreen() {
Mix_HaltMusic(); //We need to reload all data in case the screen type changes. Music must be stopped before unload.
if (globalData.bFullscreen) {
SDL_DisplayMode dm;
- globalData.xsize = 1366;
- globalData.ysize = 768;
+ globalData.xsize = SIXTEEN_NINE_WIDTH;
+ globalData.ysize = SCREEN_HIGHT;
if (SDL_GetDesktopDisplayMode(0, &dm) == 0) {
globalData.xsize = globalData.ysize*dm.w/(double)dm.h;
}
SDL_SetWindowFullscreen(sdlWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
}
else {
- globalData.xsize = 1024;
- globalData.ysize = 768;
+ globalData.xsize = FOUR_THREE_WIDTH;
+ globalData.ysize = SCREEN_HIGHT;
SDL_SetWindowFullscreen(sdlWindow, 0);
}
- if (globalData.alwaysSixteenNine || globalData.xsize > 1366) {
- globalData.xsize = 1366;
+ if (globalData.alwaysSixteenNine || globalData.xsize > SIXTEEN_NINE_WIDTH) {
+ globalData.xsize = SIXTEEN_NINE_WIDTH;
}
- if (globalData.xsize < 1024) {
- globalData.xsize = 1024;
+ if (globalData.xsize < FOUR_THREE_WIDTH) {
+ globalData.xsize = FOUR_THREE_WIDTH;
}
SDL_RenderSetLogicalSize(globalData.screen, globalData.xsize, globalData.ysize);
dataHolder.invalidateAll(globalData.screen);
@@ -325,7 +325,6 @@ static ExplosionManager theExplosionManager;
#include "ReplayPlayer.hpp"
-
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
void writeScreenShot() {
if (globalData.verboseLevel) {
@@ -333,8 +332,24 @@ void writeScreenShot() {
}
int rightNow = (int)time(nullptr);
string buf = getPathToSaveFiles() + "/screenshots/screenshot"+std::to_string(rightNow)+".bmp";
- SDL_Surface* sreenshotSurface = SDL_CreateRGBSurface(0, 1024, 768, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
- SDL_RenderReadPixels(globalData.screen, NULL, SDL_PIXELFORMAT_ARGB8888, sreenshotSurface->pixels, sreenshotSurface->pitch);
+ SDL_Surface* infoSurface = SDL_GetWindowSurface(sdlWindow);
+ if (!infoSurface) {
+ std::cerr << "Could not get infoSurface. No screenshot written. Be aware that the screenshot feature only works with software render\n";
+ return;
+ }
+ std::vector<char> pixels(infoSurface->w * infoSurface->h * infoSurface->format->BytesPerPixel);
+ int errorCode = SDL_RenderReadPixels(globalData.screen, &infoSurface->clip_rect, infoSurface->format->format, static_cast<void*>(pixels.data()), infoSurface->w * infoSurface->format->BytesPerPixel);
+ if (errorCode) {
+ SDL_FreeSurface(infoSurface);
+ std::cerr << "Could not do SDL_RenderReadPixels. Error code: " << errorCode << ". No screenshot written\n";
+ return;
+ }
+ SDL_Surface* sreenshotSurface = SDL_CreateRGBSurfaceFrom(static_cast<void*>(pixels.data()), infoSurface->w, infoSurface->h, infoSurface->format->BitsPerPixel, infoSurface->w * infoSurface->format->BytesPerPixel, infoSurface->format->Rmask, infoSurface->format->Gmask, infoSurface->format->Bmask, infoSurface->format->Amask);
+ SDL_FreeSurface(infoSurface);
+ if (!sreenshotSurface) {
+ std::cerr << "Could not get sreenshotSurface. No screenshot written\n";
+ return;
+ }
SDL_SaveBMP(sreenshotSurface, buf.c_str());
SDL_FreeSurface(sreenshotSurface);
if (!globalData.NoSound) {
@@ -1109,11 +1124,11 @@ int main(int argc, char* argv[]) {
if (config.allowResize) {
createWindowParams |= SDL_WINDOW_RESIZABLE;
}
- globalData.xsize = 1024;
+ globalData.xsize = FOUR_THREE_WIDTH;
if (globalData.alwaysSixteenNine) {
- globalData.xsize = 1366;
+ globalData.xsize = SIXTEEN_NINE_WIDTH;
}
- globalData.ysize = 768;
+ globalData.ysize = SCREEN_HIGHT;
sdlWindow = SDL_CreateWindow("Block Attack - Rise of the Blocks " VERSION_NUMBER,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,