You can speed up terrain rendering by using triangle strips instead of quads. It is a bit tricky because you have to draw odd rows of terrain in one direction and event in opposite one. Here is sample code. (This code is from some old project of mine and it should work).
Code:
procedure TTerrainRenderer.Render;
var
x,z,w,h : integer;
grid : single;
switchSides : boolean;
begin
if not Assigned(fTerrainData) then exit;
w := fTerrainData.Width;
h := fTerrainData.Height;
grid := fTerrainData.GridSize;
switchSides := false;
fTerrainData.Texture.Apply;
glBegin(GL_TRIANGLE_STRIP);
for x := 0 to w-2 do begin
if switchSides then begin
for z := h-1 downto 0 do begin
glTexCoord2f(x/w,z/h);
glVertex3f(x*grid,fTerrainData.Heights[x,z],z*grid);
glTexCoord2f((x+1)/w,z/h);
glvertex3f((x+1)*grid,fTerrainData.Heights[x+1,z],z*grid);
end;
end else begin
for z := 0 to h-1 do begin
glTexCoord2f((x+1)/w,z/h);
glvertex3f((x+1)*grid,fTerrainData.Heights[x+1,z],z*grid);
glTexCoord2f(x/W,z/H);
glVertex3f(x*grid,fTerrainData.Heights[x,z],z*grid);
end;
end;
switchSides := not SwitchSides;
end;
glEnd;
end;
Triangle strips nay help but for large terrains you should use frustum culling.
I also noticed that you put calls to glEnable/Disable into display lists. I do not think is a good idea since state changes in OpenGL are quite expensive. It may not matter in this demo, but if you had many small objects rendered with display lists, it might hurt performance.
Always try to organise your rendering code so there is as little as possible state changes.
Bookmarks