# HG changeset patch # User unc0rr # Date 1201540279 0 # Node ID 86fbe8753a7c21ec12188187ec3eab53f9bc26b6 # Parent 0138f1b5a804936574cab1566491707ae162d9f3 - Enable back console (doesn't render yet) - Make texture size be of power of 2 diff -r 0138f1b5a804 -r 86fbe8753a7c hedgewars/hwengine.dpr --- a/hedgewars/hwengine.dpr Sun Jan 27 20:47:30 2008 +0000 +++ b/hedgewars/hwengine.dpr Mon Jan 28 17:11:19 2008 +0000 @@ -103,8 +103,8 @@ end; gsConsole: begin DoGameTick(Lag); -// DrawWorld(Lag, SDLPrimSurface); -// DrawConsole(SDLPrimSurface); + DrawWorld(Lag, SDLPrimSurface); + DrawConsole(SDLPrimSurface); end; gsExit : begin OnDestroy; diff -r 0138f1b5a804 -r 86fbe8753a7c hedgewars/uConsole.pas --- a/hedgewars/uConsole.pas Sun Jan 27 20:47:30 2008 +0000 +++ b/hedgewars/uConsole.pas Mon Jan 28 17:11:19 2008 +0000 @@ -112,13 +112,13 @@ w:= cScreenWidth; h:= 4; end; -SDL_FillRect(Surface, @r, cConsoleSplitterColor); +//SDL_FillRect(Surface, @r, cConsoleSplitterColor); for y:= 0 to cConsoleHeight div 256 + 1 do for x:= 0 to cScreenWidth div 256 + 1 do DrawSprite(sprConsoleBG, x * 256, cConsoleHeight - 256 - y * 256, 0, Surface); for y:= 0 to cConsoleHeight div Fontz[fnt16].Height do - DXOutText(4, cConsoleHeight - (y + 2) * (Fontz[fnt16].Height + 2), fnt16, ConsoleLines[(CurrLine - 1 - y + cLinesCount) mod cLinesCount], Surface); -DXOutText(4, cConsoleHeight - Fontz[fnt16].Height - 2, fnt16, '> '+InputStr, Surface); + //DXOutText(4, cConsoleHeight - (y + 2) * (Fontz[fnt16].Height + 2), fnt16, ConsoleLines[(CurrLine - 1 - y + cLinesCount) mod cLinesCount], Surface); +//DXOutText(4, cConsoleHeight - Fontz[fnt16].Height - 2, fnt16, '> '+InputStr, Surface); end; procedure WriteToConsole(s: shortstring); diff -r 0138f1b5a804 -r 86fbe8753a7c hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Sun Jan 27 20:47:30 2008 +0000 +++ b/hedgewars/uMisc.pas Mon Jan 28 17:11:19 2008 +0000 @@ -123,7 +123,7 @@ TargetPoint: TPoint = (X: NoPointX; Y: 0); implementation -uses uConsole, uStore, uIO, Math, uRandom; +uses uConsole, uStore, uIO, Math, uRandom, GLU; var KBnum: Longword = 0; {$IFDEF DEBUGFILE} var f: textfile; @@ -255,13 +255,25 @@ RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' end; +function isPowerOf2(i: Longword): boolean; +begin +if i = 0 then exit(true); +while (i and 1) = 0 do i:= i shr 1; +isPowerOf2:= (i = 1) +end; + +function toPowerOf2(i: Longword): Longword; +begin +toPowerOf2:= 1; +while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 +end; + function Surface2Tex(surf: PSDL_Surface): PTexture; var mode: LongInt; texId: GLuint; + tw, th: Longword; + tmpp: pointer; begin -if SDL_MustLock(surf) then - SDLTry(SDL_LockSurface(surf) >= 0, true); - new(Surface2Tex); Surface2Tex^.w:= surf^.w; Surface2Tex^.h:= surf^.h; @@ -269,7 +281,7 @@ if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else begin - TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', false); + TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4', false); Surface2Tex^.id:= 0; exit end; @@ -278,12 +290,30 @@ glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); -glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); +if SDL_MustLock(surf) then + SDLTry(SDL_LockSurface(surf) >= 0, true); + +if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then + begin + tw:= toPowerOf2(Surf^.w); + th:= toPowerOf2(Surf^.h); + + GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); + + gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, + Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, + tmpp); + + glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp); + + FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) + end else + glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); if SDL_MustLock(surf) then SDL_UnlockSurface(surf); -glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); +glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) end;