removed libGLU dependency

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3280 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-10-27 07:41:46 +00:00
parent f55ead1812
commit 95cad2c3d1
10 changed files with 273 additions and 31 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ INCLUDES=-I/usr/X11R6/include -I../enet/include -I../src `sdl-config --cflags`
CXXFLAGS=$(CXXOPTFLAGS) $(INCLUDES) -fsigned-char -Wall -Wno-deprecated -rdynamic
PLATFORM_PREFIX=native
CLIENT_LIBS=-L/usr/X11R6/lib -L../enet -lenet `sdl-config --libs` -lSDL_image -lz -lGL -lGLU -lopenal -lvorbisfile
CLIENT_LIBS=-L/usr/X11R6/lib -L../enet -lenet `sdl-config --libs` -lSDL_image -lz -lGL -lopenal -lvorbisfile
CLIENT_OBJS= \
client.o \
clientgame.o \
+3 -1
View File
@@ -171,7 +171,9 @@ struct md2 : vertmodel
void begingenshadow()
{
glRotatef(180, 0, 0, 1);
matrixpos = 0;
matrixstack[0].identity();
matrixstack[0].rotate_around_z(180*RAD);
}
};
+3 -1
View File
@@ -147,7 +147,9 @@ struct md3 : vertmodel
void begingenshadow()
{
glRotatef(180, 0, 0, 1);
matrixpos = 0;
matrixstack[0].identity();
matrixstack[0].rotate_around_z(180*RAD);
}
};
+2
View File
@@ -223,6 +223,7 @@ extern void blendbox(int x1, int y1, int x2, int y2, bool border, int tex = -1,
extern void quad(GLuint tex, float x, float y, float s, float tx, float ty, float tsx, float tsy = 0);
extern void quad(GLuint tex, vec &c1, vec &c2, float tx, float ty, float tsx, float tsy);
extern void circle(GLuint tex, float x, float y, float r, float tx, float ty, float tr, int subdiv = 32);
extern void setperspective(float fovy, float aspect, float nearplane, float farplane);
extern void sethudgunperspective(bool on);
extern void gl_drawframe(int w, int h, float changelod, float curfps);
extern void clearminimap();
@@ -245,6 +246,7 @@ struct Texture
};
extern Texture *notexture, *noworldtexture;
extern void scaletexture(uchar *src, uint sw, uint sh, uint bpp, uchar *dst, uint dw, uint dh);
extern void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, GLenum format);
extern Texture *textureload(const char *name, int clamp = 0);
extern Texture *lookuptexture(int tex, Texture *failtex = notexture);
+9 -3
View File
@@ -782,6 +782,12 @@ int xtraverts;
VARP(hudgun, 0, 1, 1);
void setperspective(float fovy, float aspect, float nearplane, float farplane)
{
GLdouble ydist = nearplane * tan(fovy/2*RAD), xdist = ydist * aspect;
glFrustum(-xdist, xdist, -ydist, ydist, nearplane, farplane);
}
void sethudgunperspective(bool on)
{
glMatrixMode(GL_PROJECTION);
@@ -789,9 +795,9 @@ void sethudgunperspective(bool on)
if(on)
{
glScalef(1, 1, 0.5f); // fix hudugns colliding with map geometry
gluPerspective(75.0f, aspect, 0.3f, farplane); // y fov fixed at 75°
setperspective(75.0f, aspect, 0.3f, farplane); // y fov fixed at 75°
}
else gluPerspective(fovy, aspect, 0.15f, farplane);
else setperspective(fovy, aspect, 0.15f, farplane);
glMatrixMode(GL_MODELVIEW);
}
@@ -890,7 +896,7 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
}
farplane = fog*5/2;
gluPerspective(fovy, aspect, 0.15f, farplane);
setperspective(fovy, aspect, 0.15f, farplane);
glMatrixMode(GL_MODELVIEW);
transplayer();
+131
View File
@@ -0,0 +1,131 @@
static void FUNCNAME(halvetexture)(uchar *src, uint sw, uint sh, uchar *dst)
{
uint stride = sw*BPP;
for(uchar *yend = &src[sh*stride]; src < yend;)
{
for(uchar *xend = &src[stride]; src < xend; src += 2*BPP, dst += BPP)
{
#define OP(c, n) dst[n] = (uint(src[n]) + uint(src[n+BPP]) + uint(src[stride+n]) + uint(src[stride+n+BPP]))>>2
PIXELOP
#undef OP
}
src += stride;
}
}
static void FUNCNAME(shifttexture)(uchar *src, uint sw, uint sh, uchar *dst, uint dw, uint dh)
{
uint stride = sw*BPP, wfrac = sw/dw, hfrac = sh/dh, wshift = 0, hshift = 0;
while(dw<<wshift < sw) wshift++;
while(dh<<hshift < sh) hshift++;
uint tshift = wshift + hshift;
for(uchar *yend = &src[sh*stride]; src < yend;)
{
for(uchar *xend = &src[stride]; src < xend; src += wfrac*BPP, dst += BPP)
{
#define OP(c, n) c##t = 0
DEFPIXEL
#undef OP
for(uchar *ycur = src, *xend = &ycur[wfrac*BPP], *yend = &src[hfrac*stride];
ycur < yend;
ycur += stride, xend += stride)
{
for(uchar *xcur = ycur; xcur < xend; xcur += BPP)
{
#define OP(c, n) c##t += xcur[n]
PIXELOP
#undef OP
}
}
#define OP(c, n) dst[n] = (c##t)>>tshift
PIXELOP
#undef OP
}
src += (hfrac-1)*stride;
}
}
static void FUNCNAME(scaletexture)(uchar *src, uint sw, uint sh, uchar *dst, uint dw, uint dh)
{
uint stride = sw*BPP, wfrac = (sw<<12)/dw, hfrac = (sh<<12)/dh;
for(uint dy = 0, y = 0, yi = 0; dy < dh; dy++)
{
uint y2 = y + hfrac, yi2 = y2>>12,
h = y2 - y, ih = yi2 - yi,
ylow, yhigh;
if(yi < yi2) { ylow = 0x1000U - (y&0xFFFU); yhigh = y2&0xFFFU; }
else { ylow = y2 - y; yhigh = 0; }
for(uint dx = 0, x = 0, xi = 0; dx < dw; dx++)
{
uint x2 = x + wfrac, xi2 = x2>>12,
w = x2 - x, iw = xi2 - xi, iy = 0,
xlow, xhigh;
if(xi < xi2) { xlow = 0x1000U - (x&0xFFFU); xhigh = x2&0xFFFU; }
else { xlow = x2 - x; xhigh = 0; }
#define OP(c, n) c##t = 0
DEFPIXEL
#undef OP
for(uchar *ycur = &src[xi*BPP], *xend = &ycur[max(iw, 1U)*BPP], *yend = &ycur[stride*(max(ih, 1U) + (yhigh ? 1 : 0))];
ycur < yend;
ycur += stride, xend += stride, iy++)
{
#define OP(c, n) c = (ycur[n]*xlow)>>12
DEFPIXEL
#undef OP
for(uchar *xcur = &ycur[BPP]; xcur < xend; xcur += BPP)
{
#define OP(c, n) c += xcur[n]
PIXELOP
#undef OP
}
if(xhigh)
{
#define OP(c, n) c += (xend[n]*xhigh)>>12
PIXELOP
#undef OP
}
#define OP(c, n) c = (c<<12)/w
PIXELOP
#undef OP
if(!iy)
{
#define OP(c, n) c##t += (c*ylow)>>12
PIXELOP
#undef OP
}
else if(iy==ih)
{
#define OP(c, n) c##t += (c*yhigh)>>12
PIXELOP
#undef OP
}
else
{
#define OP(c, n) c##t += c
PIXELOP
#undef OP
}
}
#define OP(c, n) dst[n] = ((c##t)<<12)/h
PIXELOP
#undef OP
dst += BPP;
x = x2;
xi = xi2;
}
src += ih*stride;
y = y2;
yi = yi2;
}
}
#undef FUNCNAME
#undef DEFPIXEL
#undef PIXELOP
#undef BPP
+1 -1
View File
@@ -437,7 +437,7 @@ void drawstencilshadows()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovy, aspect, 0.15f, farplane);
setperspective(fovy, aspect, 0.15f, farplane);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
+117 -18
View File
@@ -3,6 +3,64 @@
#include "pch.h"
#include "cube.h"
#define FUNCNAME(name) name##1
#define DEFPIXEL uint OP(r, 0);
#define PIXELOP OP(r, 0);
#define BPP 1
#include "scale.h"
#define FUNCNAME(name) name##2
#define DEFPIXEL uint OP(r, 0), OP(g, 1);
#define PIXELOP OP(r, 0); OP(g, 1);
#define BPP 2
#include "scale.h"
#define FUNCNAME(name) name##3
#define DEFPIXEL uint OP(r, 0), OP(g, 1), OP(b, 2);
#define PIXELOP OP(r, 0); OP(g, 1); OP(b, 2);
#define BPP 3
#include "scale.h"
#define FUNCNAME(name) name##4
#define DEFPIXEL uint OP(r, 0), OP(g, 1), OP(b, 2), OP(a, 3);
#define PIXELOP OP(r, 0); OP(g, 1); OP(b, 2); OP(a, 3);
#define BPP 4
#include "scale.h"
void scaletexture(uchar *src, uint sw, uint sh, uint bpp, uchar *dst, uint dw, uint dh)
{
if(sw == dw*2 && sh == dh*2)
{
switch(bpp)
{
case 1: return halvetexture1(src, sw, sh, dst);
case 2: return halvetexture2(src, sw, sh, dst);
case 3: return halvetexture3(src, sw, sh, dst);
case 4: return halvetexture4(src, sw, sh, dst);
}
}
else if(sw < dw || sh < dh || sw&(sw-1) || sh&(sh-1))
{
switch(bpp)
{
case 1: return scaletexture1(src, sw, sh, dst, dw, dh);
case 2: return scaletexture2(src, sw, sh, dst, dw, dh);
case 3: return scaletexture3(src, sw, sh, dst, dw, dh);
case 4: return scaletexture4(src, sw, sh, dst, dw, dh);
}
}
else
{
switch(bpp)
{
case 1: return shifttexture1(src, sw, sh, dst, dw, dh);
case 2: return shifttexture2(src, sw, sh, dst, dw, dh);
case 3: return shifttexture3(src, sw, sh, dst, dw, dh);
case 4: return shifttexture4(src, sw, sh, dst, dw, dh);
}
}
}
Texture *notexture = NULL, *noworldtexture = NULL;
hashtable<char *, Texture> textures;
@@ -12,6 +70,63 @@ VARFP(maxtexsize, 0, 0, 1<<12, initwarning("texture quality", INIT_LOAD));
VARFP(trilinear, 0, 1, 1, initwarning("texture filtering", INIT_LOAD));
VARFP(bilinear, 0, 1, 1, initwarning("texture filtering", INIT_LOAD));
int formatsize(GLenum format)
{
switch(format)
{
case GL_LUMINANCE:
case GL_ALPHA: return 1;
case GL_LUMINANCE_ALPHA: return 2;
case GL_RGB: return 3;
case GL_RGBA: return 4;
default: return 4;
}
}
void resizetexture(int w, int h, bool mipmap, GLenum target, int &tw, int &th)
{
int hwlimit = hwtexsize,
sizelimit = mipmap && maxtexsize ? min(maxtexsize, hwlimit) : hwlimit;
w = min(w, sizelimit);
h = min(h, sizelimit);
if(mipmap || w&(w-1) || h&(h-1))
{
tw = th = 1;
while(tw < w) tw *= 2;
while(th < h) th *= 2;
if(w < tw - tw/2) tw /= 2;
if(h < th - th/2) th /= 2;
}
else
{
tw = w;
th = h;
}
}
void uploadtexture(GLenum target, GLenum internal, int tw, int th, GLenum format, GLenum type, void *pixels, int pw, int ph, bool mipmap)
{
int bpp = formatsize(format);
uchar *buf = NULL;
if(pw!=tw || ph!=th)
{
buf = new uchar[tw*th*bpp];
scaletexture((uchar *)pixels, pw, ph, bpp, buf, tw, th);
}
for(int level = 0;; level++)
{
uchar *src = buf ? buf : (uchar *)pixels;
glTexImage2D(target, level, internal, tw, th, 0, format, type, src);
if(!mipmap || max(tw, th) <= 1) break;
int srcw = tw, srch = th;
if(tw > 1) tw /= 2;
if(th > 1) th /= 2;
if(!buf) buf = new uchar[tw*th*bpp];
scaletexture(src, srcw, srch, bpp, buf, tw, th);
}
if(buf) delete[] buf;
}
void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap, GLenum format)
{
glBindTexture(GL_TEXTURE_2D, tnum);
@@ -27,24 +142,8 @@ void createtexture(int tnum, int w, int h, void *pixels, int clamp, bool mipmap,
(bilinear ? GL_LINEAR : GL_NEAREST));
int tw = w, th = h;
if(pixels)
{
int sizelimit = maxtexsize ? min(maxtexsize, hwtexsize) : hwtexsize;
while(tw>sizelimit || th>sizelimit) { tw /= 2; th /= 2; }
if(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)
{
if(gluBuild2DMipmaps(GL_TEXTURE_2D, format, tw, th, format, GL_UNSIGNED_BYTE, pixels)) fatal("could not build mipmaps");
}
else glTexImage2D(GL_TEXTURE_2D, 0, format, tw, th, 0, format, GL_UNSIGNED_BYTE, pixels);
if(pixels) resizetexture(w, h, mipmap, GL_TEXTURE_2D, tw, th);
uploadtexture(GL_TEXTURE_2D, format, tw, th, format, GL_UNSIGNED_BYTE, pixels, w, h, mipmap);
}
GLenum texformat(int bpp)
+1 -1
View File
@@ -1006,7 +1006,7 @@ struct vertmodel : model
SDL_FreeSurface(img);
#endif
if(aasize > 1<<dynshadowsize)
gluScaleImage(GL_ALPHA, aasize, aasize, GL_UNSIGNED_BYTE, pixels, 1<<dynshadowsize, 1<<dynshadowsize, GL_UNSIGNED_BYTE, pixels);
scaletexture(pixels, aasize, aasize, 1, pixels, 1<<dynshadowsize, 1<<dynshadowsize);
int texsize = min(aasize, 1<<dynshadowsize);
blurshadow(pixels, &pixels[texsize*texsize], texsize);
+5 -5
View File
@@ -83,7 +83,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ogg.lib libvorbisfile.lib openal32.lib efx-util.lib odbc32.lib odbccp32.lib zdll.lib opengl32.lib glu32.lib msvcrt.lib SDLmain.lib SDL.lib SDL_image.lib ws2_32.lib winmm.lib Dbghelp.lib"
AdditionalDependencies="ogg.lib libvorbisfile.lib openal32.lib efx-util.lib odbc32.lib odbccp32.lib zdll.lib opengl32.lib msvcrt.lib SDLmain.lib SDL.lib SDL_image.lib ws2_32.lib winmm.lib Dbghelp.lib"
OutputFile="../../bin_win32/ac_client.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
@@ -187,7 +187,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ogg.lib libvorbisfile.lib openal32.lib zdll.lib opengl32.lib glu32.lib SDLmain.lib SDL.lib SDL_image.lib ws2_32.lib winmm.lib Dbghelp.lib"
AdditionalDependencies="ogg.lib libvorbisfile.lib openal32.lib zdll.lib opengl32.lib SDLmain.lib SDL.lib SDL_image.lib ws2_32.lib winmm.lib Dbghelp.lib"
OutputFile="../../bin_win32/ac_client.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
@@ -295,7 +295,7 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/PROFILE"
AdditionalDependencies="msvcrt.lib zdll.lib opengl32.lib glu32.lib SDLmain.lib SDL.lib SDL_image.lib ws2_32.lib SDL_mixer.lib winmm.lib"
AdditionalDependencies="msvcrt.lib zdll.lib opengl32.lib SDLmain.lib SDL.lib SDL_image.lib ws2_32.lib SDL_mixer.lib winmm.lib"
OutputFile="..\..\bin_win32\ac_client.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
@@ -400,7 +400,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib zdll.lib opengl32.lib glu32.lib msvcrt.lib SDLmain.lib SDL.lib ws2_32.lib winmm.lib Dbghelp.lib LIBCPMT.LIB"
AdditionalDependencies="odbc32.lib odbccp32.lib zdll.lib opengl32.lib msvcrt.lib SDLmain.lib SDL.lib ws2_32.lib winmm.lib Dbghelp.lib LIBCPMT.LIB"
OutputFile="../../bin_win32/ac_server.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
@@ -497,7 +497,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib zdll.lib opengl32.lib glu32.lib msvcrtd.lib SDLmain.lib SDL.lib ws2_32.lib winmm.lib Dbghelp.lib"
AdditionalDependencies="odbc32.lib odbccp32.lib zdll.lib opengl32.lib msvcrtd.lib SDLmain.lib SDL.lib ws2_32.lib winmm.lib Dbghelp.lib"
OutputFile="../../bin_win32/ac_server.exe"
LinkIncremental="2"
SuppressStartupBanner="true"