diff --git a/hyper.h b/hyper.h index be981715..efae7a43 100644 --- a/hyper.h +++ b/hyper.h @@ -1967,7 +1967,7 @@ struct textureinfo { vector vertices; vector tvertices; cell *c; - vector matrices; + vector matrices; // these are required to adjust to geometry changes int current_geometry, current_type, symmetries, current_trunc; @@ -2380,6 +2380,8 @@ namespace texture { extern unsigned paint_color; extern ld penwidth; extern transmatrix itt; + extern int twidth; + extern vector texture_pixels; void showMenu(); diff --git a/polygons.cpp b/polygons.cpp index 6cfde383..3468f2b2 100644 --- a/polygons.cpp +++ b/polygons.cpp @@ -246,13 +246,40 @@ void polylineColor(SDL_Surface *s, int *x, int *y, int polyi, int col) { lineColor(s, x[i-1], y[i-1], x[i], y[i], col); } -void filledPolygonColorI(SDL_Surface *s, int* polyx, int *polyy, int polyi, int col) { - Sint16 spolyx[polyi], spolyy[polyi]; - for(int i=0; i= -1e-7 && h[1] >= -1e-7 && h[2] >= -1e-7) { + hyperpoint ht = target * h; + int x = int(ht[0] * texture::twidth) & (texture::twidth-1); + int y = int(ht[1] * texture::twidth) & (texture::twidth-1); + int c = texture::texture_pixels[y * texture::twidth + x]; + auto& pix = qpixel(s, mx, my); + for(int p=0; p<3; p++) { + int alpha = part(c, 3) * part(col, 0); + auto& v = part(pix, p); + v = ((255*255 - alpha) * 255 * v + alpha * part(col, p+1) * part(c, p) + 255 * 255 * 255/2 + 1) / (255 * 255 * 255); + } + } + } + } + #if CAP_GL void glcolor2(int color) { unsigned char *c = (unsigned char*) (&color); @@ -606,7 +633,12 @@ void drawpolyline(polytodraw& p) { for(int i=0; itvertices[i*3], p.col); + } + else if(poly_flags & POLY_INVERSE) { int i = polyi; if(true) { polyx[i] = 0; polyy[i] = 0; i++; diff --git a/textures.cpp b/textures.cpp index e26375e8..7ea49711 100644 --- a/textures.cpp +++ b/textures.cpp @@ -33,7 +33,7 @@ int twidth = 2048; unsigned paint_color = 0x000000FF; -vector expanded_data; +vector texture_pixels; string texturename = "hyperrogue-texture.png"; string configname = "hyperrogue.txc"; @@ -77,14 +77,14 @@ bool loadTextureGL() { glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, twidth, twidth, 0, GL_BGRA, GL_UNSIGNED_BYTE, - &expanded_data[0] ); + &texture_pixels[0] ); return true; } bool whitetexture() { - expanded_data.resize(0); - expanded_data.resize(twidth * twidth, 0xFFFFFFFF); + texture_pixels.resize(0); + texture_pixels.resize(twidth * twidth, 0xFFFFFFFF); return true; } @@ -102,7 +102,7 @@ bool readtexture() { SDL_FreeSurface(txt); vector half_expanded(twidth * ty); - expanded_data.resize(twidth * twidth); + texture_pixels.resize(twidth * twidth); int origdim = max(tx, ty); int base_x = tx/2 - origdim/2; @@ -112,12 +112,12 @@ bool readtexture() { /* for(int y=0; y= ty ? 0 : half_expanded[x + (base_y + y) * twidth]; }, - [&] (int y, int v) { expanded_data[twidth * y + x] = v; } + [&] (int y, int v) { texture_pixels[twidth * y + x] = v; } ); for(int y=0; y 9000) twidth = 256; + tstate_max = tsOff; + } + else if(uni == 'n' && tstate == tsOff) { addMessage("white"); if(whitetexture() && loadTextureGL()) { @@ -839,7 +847,7 @@ void filltriangle(const array& v, const array& p, int c if((d0 <= 1 && d1 <= 1 && d2 <= 1) || lev >= 20) { for(int i=0; i<3; i++) - expanded_data[((p[i].first) & (twidth-1)) + (p[i].second & (twidth-1)) * twidth] = col; + texture_pixels[((p[i].first) & (twidth-1)) + (p[i].second & (twidth-1)) * twidth] = col; return; } else if(d1 >= d0 && d1 >= d2) @@ -903,6 +911,5 @@ void drawPixel(cell *c, hyperpoint h, int col) { } -// todo texture editor // todo `three octagons` with two colors