aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-04-25 16:45:48 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-04-25 16:45:48 +0000
commit666189bdf771731b25ade3eaf4db82dac2343a64 (patch)
tree3bd958a7edb6fe8337b20fde145c52cb762331ec
parent1b294eb6cf1faaea874d5521f1d93f8d870180e6 (diff)
downloadusdx-666189bdf771731b25ade3eaf4db82dac2343a64.tar.gz
usdx-666189bdf771731b25ade3eaf4db82dac2343a64.tar.xz
usdx-666189bdf771731b25ade3eaf4db82dac2343a64.zip
- fix: fade texture needs to be resized if the window was resized
- Previously the texture could have been too small (window initialized with 800x600 pixels -> fadeTex size 1024x1024. Then resize window to 1400x1050 and the texture will be too small) and an opengl error at glCopyTexSubImage2D() will occur. Due to the error fading was disabled then. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2308 b956fd51-792f-4845-bead-9b4dfca2ff2c
-rw-r--r--src/menu/UDisplay.pas54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/menu/UDisplay.pas b/src/menu/UDisplay.pas
index 02fda099..0b32c6cd 100644
--- a/src/menu/UDisplay.pas
+++ b/src/menu/UDisplay.pas
@@ -59,7 +59,7 @@ type
FadeTime: cardinal; // time when fading starts, 0 means that the fade texture must be initialized
DoneOnShow: boolean; // true if passed onShow after fading
- FadeTex: array[1..2] of GLuint;
+ FadeTex: array[0..1] of GLuint;
TexW, TexH: Cardinal;
FPSCounter: cardinal;
@@ -97,6 +97,8 @@ type
constructor Create;
destructor Destroy; override;
+ procedure InitFadeTextures();
+
procedure SaveScreenShot;
function Draw: boolean;
@@ -151,8 +153,6 @@ uses
UPathUtils;
constructor TDisplay.Create;
-var
- i: integer;
begin
inherited Create;
@@ -172,18 +172,8 @@ begin
FadeFailed := false;
DoneOnShow := false;
- for i := 1 to 2 do
- begin
- TexW := Round(Power(2, Ceil(Log2(ScreenW div Screens))));
- TexH := Round(Power(2, Ceil(Log2(ScreenH))));
-
- glGenTextures(1, PglUint(@FadeTex[i]));
- glBindTexture(GL_TEXTURE_2D, FadeTex[i]);
- glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, TexW, TexH, 0, GL_RGB, GL_UNSIGNED_BYTE, nil);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- end;
+ glGenTextures(2, PGLuint(@FadeTex));
+ InitFadeTextures();
//Set LastError for OSD to No Error
OSD_LastError := 'No Errors';
@@ -200,15 +190,33 @@ end;
destructor TDisplay.Destroy;
begin
- glDeleteTextures(2, @FadeTex);
+ glDeleteTextures(2, @FadeTex);
inherited Destroy;
end;
+procedure TDisplay.InitFadeTextures();
+var
+ i: integer;
+begin
+ TexW := Round(Power(2, Ceil(Log2(ScreenW div Screens))));
+ TexH := Round(Power(2, Ceil(Log2(ScreenH))));
+
+ for i := 0 to 1 do
+ begin
+ glBindTexture(GL_TEXTURE_2D, FadeTex[i]);
+ //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, TexW, TexH, 0, GL_RGB, GL_UNSIGNED_BYTE, nil);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ end;
+end;
+
function TDisplay.Draw: boolean;
var
S: integer;
FadeStateSquare: real;
FadeW, FadeH: real;
+ FadeCopyW, FadeCopyH: integer;
currentTime: cardinal;
glError: glEnum;
@@ -292,10 +300,18 @@ begin
// older errors in previous OpenGL calls.
glGetError();
+ FadeCopyW := ScreenW div Screens;
+ FadeCopyH := ScreenH;
+
+ // it is possible that our fade textures are too small after a window
+ // resize. In that case resize the fade texture to fit the requirements.
+ if (TexW < FadeCopyW) or (TexH < FadeCopyH) then
+ InitFadeTextures();
+
// copy screen to texture
- glBindTexture(GL_TEXTURE_2D, FadeTex[S]);
+ glBindTexture(GL_TEXTURE_2D, FadeTex[S-1]);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (S-1) * ScreenW div Screens, 0,
- ScreenW div Screens, ScreenH);
+ FadeCopyW, FadeCopyH);
glError := glGetError();
if (glError <> GL_NO_ERROR) then
@@ -349,7 +365,7 @@ begin
FadeW := (ScreenW div Screens)/TexW;
FadeH := ScreenH/TexH;
- glBindTexture(GL_TEXTURE_2D, FadeTex[S]);
+ glBindTexture(GL_TEXTURE_2D, FadeTex[S-1]);
glColor4f(1, 1, 1, 1-FadeStateSquare);
glEnable(GL_TEXTURE_2D);