diff --git a/source/src/console.cpp b/source/src/console.cpp index fb6ade08..517f3b1d 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -40,7 +40,7 @@ void conline(const char *sf, bool highlight) // add a line to the console } } -const int CONSPAD = FONTH/3; +#define CONSPAD (FONTH/3) void conoutf(const char *s, ...) { @@ -50,7 +50,7 @@ void conoutf(const char *s, ...) puts(sp); s = sf; vector lines; - text_block(s, VIRTW*2-2*CONSPAD-2*FONTH/3, lines); + text_block(s, curfont ? VIRTW*2-2*CONSPAD-2*FONTH/3 : 0, lines); loopv(lines) conline(lines[i], i!=0); lines.deletecontentsa(); } diff --git a/source/src/cube.h b/source/src/cube.h index c3add4b8..a72a7f50 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -88,11 +88,6 @@ extern int maxclients; extern hashtable mapinfo; extern bool hasTE, hasMT, hasMDA; -extern int VIRTW; // virtual screen size for text & HUD -#define VIRTH 1800 -#define FONTH 64 -#define PIXELTAB (VIRTW/12) - #include "protos.h" // external function decls #define AC_VERSION 930 diff --git a/source/src/main.cpp b/source/src/main.cpp index 312ee1ab..ec293068 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -42,7 +42,6 @@ void fatal(char *s, char *o) // failure exit } SDL_Surface *screen = NULL; -int VIRTW; static bool initing = false, restoredinits = false; bool initwarning() @@ -327,16 +326,16 @@ int main(int argc, char **argv) keyrepeat(false); SDL_ShowCursor(0); + initlog("gl"); + gl_init(scr_w, scr_h, colorbits, depthbits, fsaa); + + crosshair = textureload("packages/misc/crosshairs/default.png"); + if(!crosshair) fatal("could not find core textures (hint: run AssaultCube from the parent of the bin directory)"); + initlog("console"); if(!execfile("config/font.cfg")) fatal("cannot find font definitions"); if(!setfont("default")) fatal("no default font specified"); - initlog("gl"); - gl_init(scr_w, scr_h, colorbits, depthbits, fsaa); - - crosshair = textureload("packages/misc/crosshairs/default.png"); - if(!crosshair) fatal("could not find core textures (hint: run AssaultCube from the parent of the bin directory)"); - loadingscreen(); particleinit(); diff --git a/source/src/protos.h b/source/src/protos.h index c4ec500a..d361f474 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -193,6 +193,27 @@ extern void keyrepeat(bool on); extern bool initwarning(); // rendertext +struct font +{ + struct charinfo + { + short x, y, w, h; + }; + + char *name; + Texture *tex; + vector chars; + short defaultw, defaulth; + short offsetx, offsety, offsetw, offseth; +}; + +#define VIRTH 1800 +#define FONTH (curfont->defaulth) +#define PIXELTAB (VIRTW/12) + +extern int VIRTW; // virtual screen size for text & HUD +extern font *curfont; + extern bool setfont(char *name); extern void draw_text(const char *str, int left, int top); extern void draw_textf(const char *fstr, int left, int top, ...); diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 0e296c89..b88e4fe8 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -331,8 +331,9 @@ void drawreflection(float hf, int w, int h, float changelod, bool refract) reflecting = true; refracting = refract; - int size = 1< w || size > h) size /= 2; + extern int hwtexsize; + int size = 1< sizelimit) size /= 2; if(size!=reflectlastsize) { if(reflecttex) glDeleteTextures(1, &reflecttex); diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 5f943619..fd806576 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -2,22 +2,12 @@ #include "cube.h" -struct font -{ - struct charinfo - { - short x, y, w, h; - }; - - char *name; - Texture *tex; - vector chars; - short defaultw, defaulth; - short offsetx, offsety, offsetw, offseth; -}; +int VIRTW; static hashtable fonts; -static font *fontdef = NULL, *curfont = NULL; +static font *fontdef = NULL; + +font *curfont = NULL; void newfont(char *name, char *tex, char *defaultw, char *defaulth, char *offsetx, char *offsety, char *offsetw, char *offseth) { @@ -144,7 +134,7 @@ void text_block(const char *str, int max, vector &lines) { if(!str) return; int visible; - while((visible = text_visible(str, max))) + while((visible = max ? text_visible(str, max) : strlen(str))) { const char *newline = (const char *)memchr(str, '\n', visible); if(newline) visible = newline+1-str; diff --git a/source/src/texture.cpp b/source/src/texture.cpp index a61cdc7c..c2194d04 100644 --- a/source/src/texture.cpp +++ b/source/src/texture.cpp @@ -5,7 +5,8 @@ Texture *crosshair = NULL; hashtable textures; -VAR(maxtexsize, 0, -1, 4096); +VAR(hwtexsize, 1, 0, 0); +VARP(maxtexsize, 0, 0, 4096); void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, GLenum format) { @@ -17,14 +18,17 @@ void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); int tw = w, th = h; - if(maxtexsize<0) glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&maxtexsize); - if(maxtexsize) while(tw>maxtexsize || th>maxtexsize) { tw /= 2; th /= 2; } - if(tw!=w || th!=h) + if(pixels) { - if(gluScaleImage(format, w, h, GL_UNSIGNED_BYTE, pixels, tw, th, GL_UNSIGNED_BYTE, pixels)) + int sizelimit = maxtexsize ? min(maxtexsize, hwtexsize) : hwtexsize; + while(tw>sizelimit || th>sizelimit) { tw /= 2; th /= 2; } + if(tw!=w || th!=h) { - tw = w; - th = h; + if(gluScaleImage(format, w, h, GL_UNSIGNED_BYTE, pixels, tw, th, GL_UNSIGNED_BYTE, pixels)) + { + tw = w; + th = h; + } } } if(mipmap) @@ -34,11 +38,22 @@ void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, else glTexImage2D(GL_TEXTURE_2D, 0, format, tw, th, 0, format, GL_UNSIGNED_BYTE, pixels); } +GLenum texformat(int bpp) +{ + switch(bpp) + { + case 24: return GL_RGB; + case 32: return GL_RGBA; + default: return 0; + } +} + GLuint loadsurface(const char *texname, int &xs, int &ys, int clamp) { SDL_Surface *s = IMG_Load(findfile(texname, "rb")); if(!s) { conoutf("couldn't load texture %s", texname); return 0; } - if(s->format->BitsPerPixel!=24 && s->format->BitsPerPixel!=32) + GLenum format = texformat(s->format->BitsPerPixel); + if(!format) { SDL_FreeSurface(s); conoutf("texture must be 24bpp or 32bpp: %s", texname); @@ -46,7 +61,7 @@ GLuint loadsurface(const char *texname, int &xs, int &ys, int clamp) } GLuint tnum; glGenTextures(1, &tnum); - createtexture(tnum, s->w, s->h, s->pixels, clamp, true, s->format->BitsPerPixel==24 ? GL_RGB : GL_RGBA); + createtexture(tnum, s->w, s->h, s->pixels, clamp, true, format); xs = s->w; ys = s->h; SDL_FreeSurface(s); @@ -314,6 +329,8 @@ void setuptmu(int n, const char *rgbfunc, const char *alphafunc) void inittmus() { + glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&hwtexsize); + if(hasTE && !hasMT) maxtmus = 1; else if(hasTE && hasMT) {