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