Results 1 to 10 of 13

Thread: More opengl and a sample :)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Re: More opengl and a sample :)

    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.

  2. #2
    Your demo works here too.

    I don't have the time to dive into the source. Nevertheless, I have a tip for you. Your terrain seems very pixelated. This is caused by the high-contrast of the texture and maybe by the fact that you didn't turn mipmapping on. You could have a look at that and improve the quality of your terrain.

    Good luck!
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •