hedgewars/uLandTexture.pas
changeset 1806 3c4f0886c123
child 1807 795f97007833
equal deleted inserted replaced
1805:dd9fb4b13fd8 1806:3c4f0886c123
       
     1 (*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2009 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  *)
       
    18 
       
    19 unit uLandTexture;
       
    20 interface
       
    21 uses SDLh, uLandTemplates, uFloat, GL, uConsts;
       
    22 
       
    23 procedure UpdateLandTexture(Y, Height: LongInt);
       
    24 procedure DrawLand (X, Y: LongInt);
       
    25 
       
    26 implementation
       
    27 uses uMisc, uLand, uStore;
       
    28 
       
    29 var LandTexture: PTexture = nil;
       
    30     updTopY: LongInt = LAND_HEIGHT;
       
    31     updBottomY: LongInt = 0;
       
    32 
       
    33 
       
    34 procedure UpdateLandTexture(Y, Height: LongInt);
       
    35 begin
       
    36 if (Height <= 0) then exit;
       
    37 
       
    38 TryDo((Y >= 0) and (Y < LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true);
       
    39 TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true);
       
    40 
       
    41 if Y < updTopY then updTopY:= Y;
       
    42 if Y + Height > updBottomY then updBottomY:= Y + Height
       
    43 end;
       
    44 
       
    45 procedure RealLandTexUpdate;
       
    46 begin
       
    47 if updBottomY = 0 then exit;
       
    48 
       
    49 if LandTexture = nil then
       
    50 	LandTexture:= NewTexture(LAND_WIDTH, LAND_HEIGHT, @LandPixels)
       
    51 else
       
    52 	begin
       
    53 	glBindTexture(GL_TEXTURE_2D, LandTexture^.id);
       
    54 	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, updTopY, LAND_WIDTH, updBottomY - updTopY, GL_RGBA, GL_UNSIGNED_BYTE, @LandPixels[updTopY, 0]);
       
    55 	end;
       
    56 
       
    57 updTopY:= LAND_HEIGHT + 1;
       
    58 updBottomY:= 0
       
    59 end;
       
    60 
       
    61 procedure DrawLand(X, Y: LongInt);
       
    62 begin
       
    63 RealLandTexUpdate;
       
    64 DrawTexture(X, Y, LandTexture)
       
    65 end;
       
    66 
       
    67 end.