diff --git a/include/render.h b/include/render.h index d456eac..c456380 100644 --- a/include/render.h +++ b/include/render.h @@ -128,7 +128,7 @@ void R_RenderView (void); // must set r_refdef first void R_ViewChanged (vrect_t *pvrect, int lineadj, float aspect); // called whenever r_refdef or vid change void R_InitSky (struct texture_s *mt); // called at level load -void R_InitSky_32 (byte *src); // called at level load +void R_InitSky_32 (byte *src, int bytesperpixel); void R_AddEfrags (entity_t *ent); void R_RemoveEfrags (entity_t *ent); diff --git a/source/gl_warp.c b/source/gl_warp.c index 3400b88..fcc0932 100644 --- a/source/gl_warp.c +++ b/source/gl_warp.c @@ -1070,32 +1070,67 @@ R_InitSky_32 A sky texture is 256*128, with the right side being a masked overlay ============== */ -void R_InitSky_32 (byte *src) +void R_InitSky_32 (byte *src, int bytesperpixel) { - int i, j; + int i, j, p; unsigned trans[128*128]; + unsigned transpix; + int r, g, b; + unsigned *rgba; + extern int skytexturenum; - for (i = 0;i < 128;i++) - for (j = 0;j < 128;j++) - trans[(i*128) + j] = src[i*256+j+128]; + if (bytesperpixel == 4) { + for (i = 0;i < 128;i++) + for (j = 0;j < 128;j++) + trans[(i*128) + j] = src[i*256+j+128]; + } else { + // make an average value for the back to avoid + // a fringe on the top level + r = g = b = 0; + for (i=0 ; i<128 ; i++) + for (j=0 ; j<128 ; j++) { + p = src[i*256 + j + 128]; + rgba = &d_8to24table[p]; + trans[(i*128) + j] = *rgba; + r += ((byte *)rgba)[0]; + g += ((byte *)rgba)[1]; + b += ((byte *)rgba)[2]; + } + + ((byte *)&transpix)[0] = r/(128*128); + ((byte *)&transpix)[1] = g/(128*128); + ((byte *)&transpix)[2] = b/(128*128); + ((byte *)&transpix)[3] = 0; + } if (!solidskytexture) solidskytexture = texture_extension_number++; - GL_Bind (solidskytexture ); - glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + GL_Bind (solidskytexture ); + glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - for (i = 0;i < 128;i++) - for (j = 0;j < 128;j++) - trans[(i*128) + j] = src[i*256+j]; + if (bytesperpixel == 4) { + for (i = 0;i < 128;i++) + for (j = 0;j < 128;j++) + trans[(i*128) + j] = src[i*256+j]; + } else { + for (i=0 ; i<128 ; i++) + for (j=0 ; j<128 ; j++) { + p = src[i*256 + j]; + if (p == 0) + trans[(i*128) + j] = transpix; + else + trans[(i*128) + j] = d_8to24table[p]; + } + } if (!alphaskytexture) alphaskytexture = texture_extension_number++; - GL_Bind(alphaskytexture); - glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + GL_Bind(alphaskytexture); + glTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } diff --git a/source/hl_bsp.c b/source/hl_bsp.c index 1dcea91..8fbafbc 100644 --- a/source/hl_bsp.c +++ b/source/hl_bsp.c @@ -238,7 +238,7 @@ void HL_Mod_LoadTextures (lump_t *l) if (!strncmp(mt->name,"sky",3)) { tx->transparent = false; - R_InitSky_32 (data); + R_InitSky_32 (data, bytesperpixel); } else { diff --git a/source/hl_wad.c b/source/hl_wad.c index c6dbc13..74743cb 100644 --- a/source/hl_wad.c +++ b/source/hl_wad.c @@ -137,9 +137,9 @@ byte *W_GetTexture(char *name, int matchwidth, int matchheight) { file = texwadlump[i].file; if (fseek(file, texwadlump[i].position, SEEK_SET)) - {Con_Printf("W_GetTexture: corrupt WAD3 file");return false;} + {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} if (fread(&t, sizeof(t), 1, file) != 1) - {Con_Printf("W_GetTexture: corrupt WAD3 file");return false;} + {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} image_width = LittleLong(t.width); image_height = LittleLong(t.height); if (matchwidth && image_width != matchwidth) @@ -147,26 +147,26 @@ byte *W_GetTexture(char *name, int matchwidth, int matchheight) if (matchheight && image_height != matchheight) continue; if (image_width & 15 || image_height & 15) - {Con_Printf("W_GetTexture: corrupt WAD3 file");return false;} + {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} // allocate space for expanded image, // and load incoming image into upper area (overwritten as it expands) if (!(data = outdata = malloc(image_width*image_height*4))) - {Con_Printf("W_GetTexture: out of memory");return false;} + {Con_Printf("W_GetTexture: out of memory");return NULL;} indata = outdata + image_width*image_height*3; datasize = image_width*image_height*85/64; // read the image data if (fseek(file, texwadlump[i].position + sizeof(t), SEEK_SET)) - {Con_Printf("W_GetTexture: corrupt WAD3 file");return false;} + {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} if (fread(indata, 1, image_width*image_height, file) != image_width*image_height) - {Con_Printf("W_GetTexture: corrupt WAD3 file");return false;} + {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} // read the number of colors used (always 256) if (fseek(file, texwadlump[i].position + sizeof(t) + datasize, SEEK_SET)) - {Con_Printf("W_GetTexture: corrupt WAD3 file");return false;} + {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} if (fread(&colorcount, 2, 1, file) != 1) - {Con_Printf("W_GetTexture: corrupt WAD3 file");return false;} + {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} colorcount = LittleShort(colorcount); // sanity checking @@ -175,7 +175,7 @@ byte *W_GetTexture(char *name, int matchwidth, int matchheight) // read the palette if (fread(&pal, 3, colorcount, file) != colorcount) - {Con_Printf("W_GetTexture: corrupt WAD3 file");return false;} + {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;} // expand the image to 32bit RGBA for (i = 0;i < image_width*image_height;i++) diff --git a/source/makefile.winc b/source/makefile.winc index 4c534d3..2624558 100644 --- a/source/makefile.winc +++ b/source/makefile.winc @@ -35,6 +35,8 @@ COM_sources=\ fnmatch.obj \ dirent.obj \ buildnum.obj \ + hl_wad.obj \ + hl_bsp.obj \ model.obj CL_SW_sources=\