62 SDLPrimSurface: PSDL_Surface = nil; |
62 SDLPrimSurface: PSDL_Surface = nil; |
63 PauseTexture, |
63 PauseTexture, |
64 SyncTexture, |
64 SyncTexture, |
65 ConfirmTexture: PTexture; |
65 ConfirmTexture: PTexture; |
66 cScaleFactor: GLfloat = 2.0; |
66 cScaleFactor: GLfloat = 2.0; |
|
67 SupportNPOTT: Boolean = false; |
67 |
68 |
68 implementation |
69 implementation |
69 uses uMisc, uConsole, uLand, uLocale, uWorld; |
70 uses uMisc, uConsole, uLand, uLocale, uWorld; |
70 |
71 |
71 var |
72 var |
345 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
346 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
346 var rr: TSDL_Rect; |
347 var rr: TSDL_Rect; |
347 _l, _r, _t, _b: real; |
348 _l, _r, _t, _b: real; |
348 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
349 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
349 begin |
350 begin |
350 if SourceTexture^.h = 0 then exit; |
351 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
351 rr.x:= X; |
352 rr.x:= X; |
352 rr.y:= Y; |
353 rr.y:= Y; |
353 rr.w:= r^.w; |
354 rr.w:= r^.w; |
354 rr.h:= r^.h; |
355 rr.h:= r^.h; |
355 |
356 |
965 {$ENDIF} |
966 {$ENDIF} |
966 |
967 |
967 LoadImage:= tmpsurf //Result |
968 LoadImage:= tmpsurf //Result |
968 end; |
969 end; |
969 |
970 |
|
971 function glLoadExtension(extension : string) : boolean; |
|
972 begin |
|
973 glLoadExtension:= glext_LoadExtension(extension); |
|
974 if not glLoadExtension then |
|
975 WriteLnToConsole('OpenGL: "' + extension + '" failed to load') |
|
976 else |
|
977 WriteLnToConsole('OpenGL: "' + extension + '" loaded'); |
|
978 end; |
|
979 |
970 procedure SetupOpenGL; |
980 procedure SetupOpenGL; |
971 begin |
981 begin |
972 SetScale(2.0); |
|
973 |
|
974 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
975 glMatrixMode(GL_MODELVIEW); |
|
976 |
|
977 glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
982 glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
978 {$IFDEF DEBUGFILE} |
983 {$IFDEF DEBUGFILE} |
979 AddFileLog('GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
984 AddFileLog('GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
980 {$ENDIF} |
985 {$ENDIF} |
981 |
986 |
|
987 {$IFNDEF GLES11} |
|
988 SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
|
989 {$ENDIF} |
|
990 |
|
991 // set view port to whole window |
|
992 glViewport(0, 0, cScreenWidth, cScreenHeight); |
|
993 |
|
994 glMatrixMode(GL_MODELVIEW); |
|
995 // prepare default translation/scaling |
|
996 glLoadIdentity; |
|
997 glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
|
998 glTranslatef(0, -cScreenHeight / 2, 0); |
|
999 |
|
1000 // enable alpha blending |
|
1001 glEnable(GL_BLEND); |
|
1002 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
982 end; |
1003 end; |
983 |
1004 |
984 procedure SetScale(f: GLfloat); |
1005 procedure SetScale(f: GLfloat); |
985 begin |
1006 begin |
|
1007 // leave immediately if scale factor didn't change |
|
1008 if f = cScaleFactor then exit; |
|
1009 |
|
1010 if f = 2.0 then // default scaling |
|
1011 glPopMatrix // "return" to default scaling |
|
1012 else // other scaling |
|
1013 begin |
|
1014 glPushMatrix; // save default scaling |
|
1015 glLoadIdentity; |
|
1016 glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
|
1017 glTranslatef(0, -cScreenHeight / 2, 0); |
|
1018 end; |
|
1019 |
986 cScaleFactor:= f; |
1020 cScaleFactor:= f; |
987 |
|
988 glLoadIdentity; |
|
989 glViewport(0, 0, cScreenWidth, cScreenHeight); |
|
990 glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
|
991 //glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
|
992 glTranslatef(0, -cScreenHeight / 2, 0); |
|
993 |
|
994 // glTranslatex(320, 0, 0); |
|
995 // glRotatef(90.0, 0.0, 0.0, 1.0); |
|
996 end; |
1021 end; |
997 |
1022 |
998 //////////////////////////////////////////////////////////////////////////////// |
1023 //////////////////////////////////////////////////////////////////////////////// |
999 var ProgrTex: PTexture = nil; |
1024 var ProgrTex: PTexture = nil; |
1000 Step: integer = 0; |
1025 Step: integer = 0; |