Permalink
Browse files

Correctly handle interface image texture pages which are not 256x256.

Game logo now appears full size.
  • Loading branch information...
1 parent 74c153c commit f879b83605a601080e3bdd902996e50575ca9706 @Cyp Cyp committed Aug 5, 2012
@@ -1,4 +1,4 @@
-0,0,0,492,223,0,0,"IMAGE FE LOGO"
+0,15,5,483,228,0,0,"IMAGE FE LOGO"
2,0,219,37,24,0,0,"IMAGE COM1"
2,38,219,37,24,0,0,"IMAGE COM2"
2,76,219,37,24,0,0,"IMAGE COM3"
@@ -26,7 +26,7 @@
#include "tex.h"
-static unsigned short LoadTextureFile(const char *FileName)
+static unsigned short LoadTextureFile(const char *FileName, int *imageSize)
{
iV_Image *pSprite;
unsigned int i;
@@ -37,6 +37,8 @@ static unsigned short LoadTextureFile(const char *FileName)
debug(LOG_TEXTURE, "Load texture from resource cache: %s (%d, %d)",
FileName, pSprite->width, pSprite->height);
+ *imageSize = pSprite->width;
+
/* Have we already uploaded this one? */
for (i = 0; i < _TEX_INDEX; ++i)
{
@@ -70,14 +72,14 @@ IMAGEFILE *iV_LoadImageFile(const char *fileName)
numImages += (*ptr == '\n') ? 1 : 0;
ptr++;
}
- ImageFile = (IMAGEFILE *)malloc(sizeof(IMAGEFILE) + sizeof(IMAGEDEF) * numImages);
- ImageFile->ImageDefs = (IMAGEDEF*)(ImageFile + 1); // we allocated extra space for it
+ ImageFile = new IMAGEFILE;
+ ImageFile->imageDefs.resize(numImages);
ptr = pFileData;
numImages = 0;
while (ptr < pFileData + pFileSize)
{
int temp, retval;
- IMAGEDEF *ImageDef = &ImageFile->ImageDefs[numImages];
+ ImageDef *ImageDef = &ImageFile->imageDefs[numImages];
retval = sscanf(ptr, "%u,%u,%u,%u,%u,%d,%d%n", &ImageDef->TPageID, &ImageDef->Tu, &ImageDef->Tv, &ImageDef->Width,
&ImageDef->Height, &ImageDef->XOffset, &ImageDef->YOffset, &temp);
@@ -94,6 +96,7 @@ IMAGEFILE *iV_LoadImageFile(const char *fileName)
}
while (ptr < pFileData + pFileSize && *ptr++ != '\n') {} // skip rest of line
}
+ ImageFile->pages.resize(tPages + 1);
dot = (char *)strrchr(fileName, '/'); // go to last path character
dot++; // skip it
@@ -106,15 +109,14 @@ IMAGEFILE *iV_LoadImageFile(const char *fileName)
char path[PATH_MAX];
snprintf(path, PATH_MAX, "%s%u.png", texFileName, i);
- ImageFile->TPageIDs[i] = LoadTextureFile(path);
+ ImageFile->pages[i].id = LoadTextureFile(path, &ImageFile->pages[i].size);
}
- ImageFile->NumImages = numImages;
free(pFileData);
return ImageFile;
}
void iV_FreeImageFile(IMAGEFILE *ImageFile)
{
- free(ImageFile);
+ delete ImageFile;
}
View
@@ -24,43 +24,43 @@
static inline WZ_DECL_PURE unsigned short iV_GetImageWidth(const IMAGEFILE *ImageFile, const unsigned short ID)
{
- assert(ID < ImageFile->NumImages);
- return ImageFile->ImageDefs[ID].Width;
+ assert(ID < ImageFile->imageDefs.size());
+ return ImageFile->imageDefs[ID].Width;
}
static inline WZ_DECL_PURE unsigned short iV_GetImageHeight(const IMAGEFILE *ImageFile, const unsigned short ID)
{
- assert(ID < ImageFile->NumImages);
- return ImageFile->ImageDefs[ID].Height;
+ assert(ID < ImageFile->imageDefs.size());
+ return ImageFile->imageDefs[ID].Height;
}
static inline WZ_DECL_PURE short iV_GetImageXOffset(const IMAGEFILE *ImageFile, const unsigned short ID)
{
- assert(ID < ImageFile->NumImages);
- return ImageFile->ImageDefs[ID].XOffset;
+ assert(ID < ImageFile->imageDefs.size());
+ return ImageFile->imageDefs[ID].XOffset;
}
static inline WZ_DECL_PURE short iV_GetImageYOffset(const IMAGEFILE *ImageFile, const unsigned short ID)
{
- assert(ID < ImageFile->NumImages);
- return ImageFile->ImageDefs[ID].YOffset;
+ assert(ID < ImageFile->imageDefs.size());
+ return ImageFile->imageDefs[ID].YOffset;
}
static inline WZ_DECL_PURE unsigned short iV_GetImageCenterX(const IMAGEFILE *ImageFile, const unsigned short ID)
{
- assert(ID < ImageFile->NumImages);
- return ImageFile->ImageDefs[ID].XOffset + ImageFile->ImageDefs[ID].Width/2;
+ assert(ID < ImageFile->imageDefs.size());
+ return ImageFile->imageDefs[ID].XOffset + ImageFile->imageDefs[ID].Width/2;
}
static inline WZ_DECL_PURE unsigned short iV_GetImageCenterY(const IMAGEFILE *ImageFile, const unsigned short ID)
{
- assert(ID < ImageFile->NumImages);
- return ImageFile->ImageDefs[ID].YOffset + ImageFile->ImageDefs[ID].Height/2;
+ assert(ID < ImageFile->imageDefs.size());
+ return ImageFile->imageDefs[ID].YOffset + ImageFile->imageDefs[ID].Height/2;
}
View
@@ -32,6 +32,8 @@
#include "lib/framework/frame.h"
#include "pietypes.h"
+#include <vector>
+
//*************************************************************************
//
// screen surface structure
@@ -112,7 +114,7 @@ struct iIMDShape
//
//*************************************************************************
-struct IMAGEDEF
+struct ImageDef
{
unsigned int TPageID; /**< Which associated file to read our info from */
unsigned int Tu; /**< First vertex coordinate */
@@ -123,12 +125,16 @@ struct IMAGEDEF
int YOffset; /**< Y offset into source position */
};
-#define MAX_NUM_TPAGEIDS 16
struct IMAGEFILE
{
- int NumImages; /**< Number of images contained here */
- int TPageIDs[MAX_NUM_TPAGEIDS]; /**< OpenGL Texture IDs */
- IMAGEDEF *ImageDefs; /**< Stored images */
+ struct Page
+ {
+ int id; /// OpenGL texture ID.
+ int size; /// Size of texture in pixels. (Should be square.)
+ };
+
+ std::vector<Page> pages; /// Texture pages.
+ std::vector<ImageDef> imageDefs; /// Stored images.
};
#endif // _ivisdef_h
@@ -158,16 +158,17 @@ void pie_UniTransBoxFill(float x0, float y0, float x1, float y1, PIELIGHT light)
bool assertValidImage(IMAGEFILE *imageFile, unsigned id)
{
- ASSERT_OR_RETURN(false, id < (unsigned)imageFile->NumImages, "Out of range 1: %u/%d", id, imageFile->NumImages);
- ASSERT_OR_RETURN(false, imageFile->ImageDefs[id].TPageID < MAX_NUM_TPAGEIDS, "Out of range 2: %u", imageFile->ImageDefs[id].TPageID);
+ ASSERT_OR_RETURN(false, id < imageFile->imageDefs.size(), "Out of range 1: %u/%d", id, (int)imageFile->imageDefs.size());
+ ASSERT_OR_RETURN(false, imageFile->imageDefs[id].TPageID < imageFile->pages.size(), "Out of range 2: %u", imageFile->imageDefs[id].TPageID);
return true;
}
static PIEIMAGE makePieImage(IMAGEFILE *imageFile, unsigned id, PIERECT *dest = NULL, int x = 0, int y = 0)
{
- IMAGEDEF const &image = imageFile->ImageDefs[id];
+ ImageDef const &image = imageFile->imageDefs[id];
PIEIMAGE pieImage;
- pieImage.texPage = imageFile->TPageIDs[image.TPageID];
+ pieImage.texPage = imageFile->pages[image.TPageID].id;
+ pieImage.invTextureSize = 1.f / imageFile->pages[image.TPageID].size;
pieImage.tu = image.Tu;
pieImage.tv = image.Tv;
pieImage.tw = image.Width;
@@ -218,28 +219,16 @@ void iV_DrawImageTc(IMAGEFILE *imageFile, unsigned id, unsigned idTc, int x, int
void iV_DrawImageRect(IMAGEFILE *ImageFile, UWORD ID, int x, int y, int Width, int Height)
{
- IMAGEDEF *Image;
SDWORD hRep, hRemainder, vRep, vRemainder;
- PIEIMAGE pieImage;
- PIERECT dest;
- ASSERT_OR_RETURN(, ID < ImageFile->NumImages, "Out of range 1: %d", (int)ID);
- Image = &ImageFile->ImageDefs[ID];
+ assertValidImage(ImageFile, ID);
+ ImageDef *Image = &ImageFile->imageDefs[ID];
- ASSERT_OR_RETURN(, Image->TPageID < MAX_NUM_TPAGEIDS, "Out of range 2: %d", (int)Image->TPageID);
pie_SetRendMode(REND_OPAQUE);
pie_SetAlphaTest(true);
- pieImage.texPage = ImageFile->TPageIDs[Image->TPageID];
- pieImage.tu = Image->Tu;
- pieImage.tv = Image->Tv;
- pieImage.tw = Image->Width;
- pieImage.th = Image->Height;
-
- dest.x = x + Image->XOffset;
- dest.y = y + Image->YOffset;
- dest.w = Image->Width;
- dest.h = Image->Height;
+ PIERECT dest;
+ PIEIMAGE pieImage = makePieImage(ImageFile, ID, &dest, x, y);
vRemainder = Height % Image->Height;
hRemainder = Width % Image->Width;
View
@@ -63,6 +63,7 @@ struct PIEIMAGE ///< An area of texture.
{
SDWORD texPage;
SWORD tu, tv, tw, th;
+ float invTextureSize;
};
/***************************************************************************/
@@ -651,16 +651,16 @@ void pie_DrawImage(const PIEIMAGE *image, const PIERECT *dest, PIELIGHT colour)
glBegin(GL_TRIANGLE_STRIP);
//set up 4 pie verts
- glTexCoord2f(image->tu / OLD_TEXTURE_SIZE_FIX, image->tv / OLD_TEXTURE_SIZE_FIX);
+ glTexCoord2f(image->tu * image->invTextureSize, image->tv * image->invTextureSize);
glVertex2f(dest->x, dest->y);
- glTexCoord2f((image->tu + image->tw) / OLD_TEXTURE_SIZE_FIX, image->tv / OLD_TEXTURE_SIZE_FIX);
+ glTexCoord2f((image->tu + image->tw) * image->invTextureSize, image->tv * image->invTextureSize);
glVertex2f(dest->x + dest->w, dest->y);
- glTexCoord2f(image->tu / OLD_TEXTURE_SIZE_FIX, (image->tv + image->th) / OLD_TEXTURE_SIZE_FIX);
+ glTexCoord2f(image->tu * image->invTextureSize, (image->tv + image->th) * image->invTextureSize);
glVertex2f(dest->x, dest->y + dest->h);
- glTexCoord2f((image->tu + image->tw) / OLD_TEXTURE_SIZE_FIX, (image->tv + image->th) / OLD_TEXTURE_SIZE_FIX);
+ glTexCoord2f((image->tu + image->tw) * image->invTextureSize, (image->tv + image->th) * image->invTextureSize);
glVertex2f(dest->x + dest->w, dest->y + dest->h);
glEnd();
}
View
@@ -1494,7 +1494,7 @@ static void displayTitleBitmap(WZ_DECL_UNUSED WIDGET *psWidget, WZ_DECL_UNUSED U
// show warzone logo
static void displayLogo(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours)
{
- iV_DrawImage(FrontImages,IMAGE_FE_LOGO,xOffset+psWidget->x,yOffset+psWidget->y);
+ iV_DrawImage(FrontImages, IMAGE_FE_LOGO, xOffset + psWidget->x, std::max<int>(yOffset + psWidget->y, 0));
}
@@ -1678,10 +1678,10 @@ void addTopForm(void)
sFormInit.formID= FRONTEND_TOPFORM;
sFormInit.id = FRONTEND_LOGO;
- sFormInit.x = (short)((sFormInit.width/2)-(FRONTEND_LOGOW/2)); //115;
- sFormInit.y = (short)((sFormInit.height/2)-(FRONTEND_LOGOH/2));//18;
- sFormInit.width = FRONTEND_LOGOW;
- sFormInit.height= FRONTEND_LOGOH;
+ sFormInit.x = sFormInit.width/2 - iV_GetImageWidth(FrontImages, IMAGE_FE_LOGO)/2;
+ sFormInit.y = sFormInit.height/2 - iV_GetImageHeight(FrontImages, IMAGE_FE_LOGO)/2;
+ sFormInit.width = iV_GetImageWidth(FrontImages, IMAGE_FE_LOGO);
+ sFormInit.height= iV_GetImageHeight(FrontImages, IMAGE_FE_LOGO);
sFormInit.pDisplay= displayLogo;
widgAddForm(psWScreen, &sFormInit);
}
View
@@ -145,8 +145,6 @@ bool CancelPressed(void);
#define FRONTEND_SIDEX 24
#define FRONTEND_SIDEY FRONTEND_BOTFORMY
-#define FRONTEND_LOGOW 248
-#define FRONTEND_LOGOH 118
enum
{
View
@@ -27,6 +27,7 @@
#include "lib/ivis_opengl/piepalette.h"
#include "lib/ivis_opengl/piestate.h"
#include "lib/ivis_opengl/piefunc.h"
+#include "lib/ivis_opengl/bitimage.h"
#include "lib/gamelib/gtime.h"
#include "advvis.h"
#include "objects.h"
@@ -326,7 +327,7 @@ void drawRadar(void)
static void DrawNorth(void)
{
- iV_DrawImage(IntImages, RADAR_NORTH, -((radarWidth / 2.0) + (IntImages->ImageDefs[RADAR_NORTH].Width) + 1) , -(radarHeight / 2.0));
+ iV_DrawImage(IntImages, RADAR_NORTH, -((radarWidth / 2.0) + iV_GetImageWidth(IntImages, RADAR_NORTH) + 1), -(radarHeight / 2.0));
}
static PIELIGHT appliedRadarColour(RADAR_DRAW_MODE radarDrawMode, MAPTILE *WTile)

0 comments on commit f879b83

Please sign in to comment.