mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-07-06 19:42:50 +00:00
save full texture images
This commit is contained in:
parent
977d35bc8d
commit
f7b5a1b44f
@ -3186,6 +3186,11 @@ int getSnakelevColor(cell *c, int i, int last, int fd, int wcol) {
|
|||||||
|
|
||||||
void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) {
|
void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) {
|
||||||
|
|
||||||
|
if(texture::saving) {
|
||||||
|
texture::apply(c, V, 0xFFFFFFFF);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qfi.shape = NULL; qfi.special = false;
|
qfi.shape = NULL; qfi.special = false;
|
||||||
ivoryz = isGravityLand(c->land);
|
ivoryz = isGravityLand(c->land);
|
||||||
|
|
||||||
@ -5082,7 +5087,7 @@ void calcparam() {
|
|||||||
|
|
||||||
int realradius = min(vid.xcenter, vid.ycenter);
|
int realradius = min(vid.xcenter, vid.ycenter);
|
||||||
|
|
||||||
vid.scrsize = vid.ycenter - (ISANDROID ? 2 : ISIOS ? 40 : 40);
|
vid.scrsize = vid.ycenter - (inHighQual ? 0 : ISANDROID ? 2 : ISIOS ? 40 : 40);
|
||||||
|
|
||||||
vid.radius = vid.scale * vid.scrsize;
|
vid.radius = vid.scale * vid.scrsize;
|
||||||
|
|
||||||
@ -5090,7 +5095,7 @@ void calcparam() {
|
|||||||
|
|
||||||
sidescreen = false;
|
sidescreen = false;
|
||||||
|
|
||||||
if(vid.xres < vid.yres) {
|
if(vid.xres < vid.yres && !inHighQual) {
|
||||||
vid.radius = int(vid.scale * vid.xcenter) - (ISIOS ? 10 : 2);
|
vid.radius = int(vid.scale * vid.xcenter) - (ISIOS ? 10 : 2);
|
||||||
vid.ycenter = vid.yres - realradius - vid.fsize - (ISIOS ? 10 : 0);
|
vid.ycenter = vid.yres - realradius - vid.fsize - (ISIOS ? 10 : 0);
|
||||||
}
|
}
|
||||||
|
2
hyper.h
2
hyper.h
@ -2386,6 +2386,8 @@ namespace texture {
|
|||||||
extern ld penwidth;
|
extern ld penwidth;
|
||||||
extern transmatrix itt;
|
extern transmatrix itt;
|
||||||
extern int twidth;
|
extern int twidth;
|
||||||
|
extern bool saving;
|
||||||
|
|
||||||
extern vector<unsigned> texture_pixels;
|
extern vector<unsigned> texture_pixels;
|
||||||
|
|
||||||
void showMenu();
|
void showMenu();
|
||||||
|
103
textures.cpp
103
textures.cpp
@ -42,8 +42,10 @@ unsigned paint_color = 0x000000FF;
|
|||||||
|
|
||||||
vector<unsigned> texture_pixels;
|
vector<unsigned> texture_pixels;
|
||||||
|
|
||||||
string texturename = "texture/hyperrogue-texture.png";
|
string texturename = "textures/hyperrogue-texture.png";
|
||||||
string configname = "texture/hyperrogue.txc";
|
string configname = "textures/hyperrogue.txc";
|
||||||
|
|
||||||
|
bool saving = false;
|
||||||
|
|
||||||
eTextureState tstate;
|
eTextureState tstate;
|
||||||
eTextureState tstate_max;
|
eTextureState tstate_max;
|
||||||
@ -97,6 +99,8 @@ bool whitetexture() {
|
|||||||
|
|
||||||
bool readtexture() {
|
bool readtexture() {
|
||||||
|
|
||||||
|
texture_pixels.resize(twidth * twidth);
|
||||||
|
|
||||||
#if CAP_SDL_IMG
|
#if CAP_SDL_IMG
|
||||||
SDL_Surface *txt = IMG_Load(texturename.c_str());
|
SDL_Surface *txt = IMG_Load(texturename.c_str());
|
||||||
if(!txt) {
|
if(!txt) {
|
||||||
@ -183,7 +187,6 @@ bool readtexture() {
|
|||||||
[&] (int x, int v) { half_expanded[twidth * y + x] = v; }
|
[&] (int x, int v) { half_expanded[twidth * y + x] = v; }
|
||||||
);
|
);
|
||||||
|
|
||||||
texture_pixels.resize(twidth * twidth);
|
|
||||||
for(int x=0; x<twidth; x++)
|
for(int x=0; x<twidth; x++)
|
||||||
scale_colorarray(origdim,
|
scale_colorarray(origdim,
|
||||||
[&] (int y) { return base_y+y < 0 || base_y+y >= ty ? 0 : half_expanded[x + (base_y + y) * twidth]; },
|
[&] (int y) { return base_y+y < 0 || base_y+y >= ty ? 0 : half_expanded[x + (base_y + y) * twidth]; },
|
||||||
@ -206,6 +209,7 @@ void saveRawTexture() {
|
|||||||
qpixel(sraw,x,y) = texture_pixels[y * twidth + x];
|
qpixel(sraw,x,y) = texture_pixels[y * twidth + x];
|
||||||
IMAGESAVE(sraw, texturename.c_str());
|
IMAGESAVE(sraw, texturename.c_str());
|
||||||
SDL_FreeSurface(sraw);
|
SDL_FreeSurface(sraw);
|
||||||
|
addMessage(XLAT("Saved the raw texture to %1", texturename));
|
||||||
}
|
}
|
||||||
|
|
||||||
transmatrix itt = Id;
|
transmatrix itt = Id;
|
||||||
@ -318,6 +322,28 @@ bool apply(cell *c, const transmatrix &V, int col) {
|
|||||||
lastptd().u.poly.outline = grid_color;
|
lastptd().u.poly.outline = grid_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(texture::saving) {
|
||||||
|
// create a nicer aura for saved texture
|
||||||
|
for(int i=0; i<size(mi.tvertices); i += 9) {
|
||||||
|
ld p[3];
|
||||||
|
while(true) {
|
||||||
|
p[0] = hrandf();
|
||||||
|
p[1] = hrandf();
|
||||||
|
p[2] = 1 - p[0] - p[1];
|
||||||
|
if(p[2] >= 0) break;
|
||||||
|
}
|
||||||
|
ld v[2] = {0,0};
|
||||||
|
for(int j=0; j<2; j++) for(int k=0; k<3; k++)
|
||||||
|
v[j] += mi.tvertices[3*k+j] * p[k];
|
||||||
|
|
||||||
|
int vi[2] = {int(v[0] * twidth), int(v[1] * twidth)};
|
||||||
|
|
||||||
|
col = texture_pixels[(vi[0] & (twidth-1)) + (vi[1] & (twidth-1)) * twidth];
|
||||||
|
hyperpoint h = hpxyz(mi.vertices[i], mi.vertices[i+1], mi.vertices[i+2]);
|
||||||
|
addaura(V*h, col, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(out_of_range) {
|
catch(out_of_range) {
|
||||||
@ -378,31 +404,25 @@ void perform_mapping() {
|
|||||||
orig_texture_parameters = current_texture_parameters;
|
orig_texture_parameters = current_texture_parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
int forgeArgs() {
|
void saveFullTexture() {
|
||||||
using namespace arg;
|
addMessage(XLAT("Saving full texture to %1...", texturename));
|
||||||
|
dynamicval<unsigned> dd(grid_color, 0);
|
||||||
|
dynamicval<unsigned> dm(mesh_color, 0);
|
||||||
|
texture::saving = true;
|
||||||
|
drawscreen();
|
||||||
|
|
||||||
if(0) ;
|
dynamicval<int> dv(pngres, twidth);
|
||||||
else if(argis("-txpic")) {
|
saveHighQualityShot(texturename.c_str());
|
||||||
shift(); texturename = args();
|
texture::saving = false;
|
||||||
}
|
|
||||||
|
|
||||||
else if(argis("-fsp")) {
|
drawscreen();
|
||||||
shift(); gsplits = argf();
|
itt = xyscale(Id, vid.scrsize * 1. / vid.radius);
|
||||||
}
|
readtexture();
|
||||||
|
perform_mapping();
|
||||||
else if(argis("-txc")) {
|
|
||||||
shift(); configname = args();
|
|
||||||
}
|
|
||||||
|
|
||||||
else return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool newmove = false;
|
bool newmove = false;
|
||||||
|
|
||||||
auto texture_hook =
|
|
||||||
addHook(hooks_args, 100, forgeArgs);
|
|
||||||
|
|
||||||
void drawRawTexture() {
|
void drawRawTexture() {
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
@ -690,7 +710,7 @@ void showMenu() {
|
|||||||
if(tstate == tsOff) {
|
if(tstate == tsOff) {
|
||||||
dialog::addItem(XLAT("select geometry/pattern"), 'r');
|
dialog::addItem(XLAT("select geometry/pattern"), 'r');
|
||||||
if(tstate_max == tsAdjusting)
|
if(tstate_max == tsAdjusting)
|
||||||
dialog::addItem(XLAT("readjust the texture"), 't');
|
dialog::addItem(XLAT("readjust/save raw texture"), 't');
|
||||||
if(tstate_max == tsActive)
|
if(tstate_max == tsActive)
|
||||||
dialog::addItem(XLAT("reactivate the texture"), 't');
|
dialog::addItem(XLAT("reactivate the texture"), 't');
|
||||||
dialog::addItem(XLAT("open PNG as texture"), 'o');
|
dialog::addItem(XLAT("open PNG as texture"), 'o');
|
||||||
@ -736,7 +756,7 @@ void showMenu() {
|
|||||||
dialog::addColorItem(XLAT("mesh color"), mesh_color, 'm');
|
dialog::addColorItem(XLAT("mesh color"), mesh_color, 'm');
|
||||||
dialog::addSelItem(XLAT("color alpha"), its(color_alpha), 'c');
|
dialog::addSelItem(XLAT("color alpha"), its(color_alpha), 'c');
|
||||||
dialog::addItem(XLAT("edit the texture"), 'e');
|
dialog::addItem(XLAT("edit the texture"), 'e');
|
||||||
dialog::addItem(XLAT("save the texture image"), 'S');
|
dialog::addItem(XLAT("save the full texture image"), 'S');
|
||||||
dialog::addItem(XLAT("save the texture config"), 's');
|
dialog::addItem(XLAT("save the texture config"), 's');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -884,6 +904,8 @@ void showMenu() {
|
|||||||
}
|
}
|
||||||
else if(uni == 'S' && tstate == tsAdjusting)
|
else if(uni == 'S' && tstate == tsAdjusting)
|
||||||
saveRawTexture();
|
saveRawTexture();
|
||||||
|
else if(uni == 'S' && tstate == tsActive)
|
||||||
|
saveFullTexture();
|
||||||
else if(doexiton(sym, uni))
|
else if(doexiton(sym, uni))
|
||||||
popScreen();
|
popScreen();
|
||||||
};
|
};
|
||||||
@ -1037,5 +1059,38 @@ void remap(eTextureState old_tstate, eTextureState old_tstate_max) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int textureArgs() {
|
||||||
|
using namespace arg;
|
||||||
|
|
||||||
|
if(0) ;
|
||||||
|
else if(argis("-txpic")) {
|
||||||
|
shift(); texturename = args();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(argis("-txp")) {
|
||||||
|
shift(); gsplits = argf();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(argis("-txc")) {
|
||||||
|
shift(); configname = args();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(argis("-txc")) {
|
||||||
|
shift(); configname = args();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(argis("-txcl")) {
|
||||||
|
PHASE(3); drawscreen();
|
||||||
|
load_textureconfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
else return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto texture_hook =
|
||||||
|
addHook(hooks_args, 100, textureArgs);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user