Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: More opengl and a sample :)

  1. #1

    More opengl and a sample :)

    I've made even more progress on my OpenGL learnings and now have something (well sort of) to show for it. I have random height mapping in place, texturing, and other fun things and started on lighting (headache of headaches). I'm hoping that someone can take a run through and look at what I've done and help point out my mistakes (I know there are several) as I'm getting to the point of just beating my head against the wall.

    1st thing to notice when running is that only 1 side of the spinning star is lighted (I'm guessing normals here)
    2nd thing is that the ground doesn't look right. Even though it has height it looks smooth. If you scale the size down or move to the edges you can see the height changers.
    3rd thing is the speed... I'm using display lists and everything I thought was the right way of doing things, but still, at only 100x100 land size I only get ~150 fps on a system that should do much better.

    This all tells me, I'm doing it wrong, but hey, I'm having fun learning

    Code:
     ESC     - Exit 
     Left Arrow - Turn Left 
     Right Arrow - Turn Right 
     Up Arrow  - Move Forward 
     Down Arrow - Move Backward 
     A      - Strafe Left 
     D      - Strafe Right 
     Q      - Float Up 
     Z      - Sink Down 
     R      - Reset Camera Position 
     H      - Toggle HUD 
     F11     - Toggle Full Screen 
     ?      - Display Help to console window
    Download at: http://www.eonclash.com/PGD/RenderingEngine.zip

    Thanks,
    - Jeremy

  2. #2

    Re: More opengl and a sample :)

    Hi Jeremy,

    I've tried the demo but it didn't work for me. It shuts down right on startup. I assume there aren't any dll's involved since its opengl, but still is there something missing from the package?

  3. #3

    Re: More opengl and a sample :)

    Shouldn't be anything missing... The sources are all there to build the app from scratch if you have Lazarus installed. I'd be interested to know what your running so I know where to start looking

  4. #4

    Re: More opengl and a sample :)

    Ah, tbh it was already getting late so I only tried the executable and didn't look at the source. Plus, I'm not that familiar with opengl so I probably couldn't tell what to improve anyway. I only use Delphi btw, no lazarus.

  5. #5

    Re: More opengl and a sample :)

    The executable doesn't work for some reason. It normally flashes and closes, but running from console i captured the message:
    An unhandled exception occurred at $004028D4 :
    EAccessViolation : Access violation
    $004028D4 BUILDHUDBACKGROUND, line 255 of EngineTest.lpr
    $00417A31 TGLHUD__REINIT, line 165 of D:/netti/RenderingEngine/RenderingEngi
    ne/lib/uGLHUD.pas
    $00410DBB TGLENGINE__RUN, line 488 of D:/netti/RenderingEngine/RenderingEngi
    ne/lib/uGLEngine.pas
    $00402E10 main, line 343 of EngineTest.lpr
    Weirdly when i first run it from Lazarus it worked. Cubes rotating and in HUD aswell. But then i modified code to force recompile, debugger stopped with SIGSEGV at:
    procedure BuildHUDBackground(const sender : TGLHUD);
    begin
    GLHUD.DrawRect(...

  6. #6

    Re: More opengl and a sample :)

    Talk about a DUHH moment, I had one! Apparently while testing my ability to load images I took out the default value for the image wrapper used by the HUD. Quick fix, put it back in. Of course, no one saw this when running in the IDE as it was passing the image name (test2.png) as a parameter and loading it properly (oops).

    Fixed now, download location is the same. Should be able to extract and re-run with no problems. Really need to get that logging stuff put back into place

    - Jeremy

    PS: Does anyone know a way to make a class method that still has class visibility? IE:
    Code:
    type
     TMyClass=Class
      class function test : TObject;
     end;
    
    class function TMyClass.test : TObject;
    begin
     if(assigned(self))then
      result := self
     else
      result := TMyClass.Create;
    end;
    And no, that's not what I'm trying to do, but singleton's make for a good example

  7. #7

    Re: More opengl and a sample :)

    You need a static member field in your class. This works at least in Delphi 2010.
    Code:
     TTest = class
     private
      class var Instance : TTest;
     public
     end;
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  8. #8

    Re: More opengl and a sample :)

    Looks solid. The only thing I can complain about is that the terrain (I suppose it's a terrain) doesn't have either normals calculated or the texture is of a poor quality. Other than that, everything seems to be working fine. I didn't have a look at the code, tho', but looking at the framerate I can assume your code is optimal.

    Keep up the great work.

  9. #9

    Re: More opengl and a sample :)

    Quote Originally Posted by Brainer
    Looks solid. The only thing I can complain about is that the terrain (I suppose it's a terrain) doesn't have either normals calculated or the texture is of a poor quality. Other than that, everything seems to be working fine. I didn't have a look at the code, tho', but looking at the framerate I can assume your code is optimal.

    Keep up the great work.
    The "Terrain" is simply random numbers stuck together into an array of points. So, um... yeah, it doesn't look good. The texture isn't exactly high quality either, it was just the first thing I found

    My problem really lies in when I start taking the land mass up to large (say 1000x1000) quads, then the performance drops off like a rock. Since I'm using Display Lists I didn't think this would happen, but I'm obviously wrong. So, back to the drawing board as I guess I'm going to have to tell OpenGL here is a sub block of land, render it.

    Seen lots of posts about VBO's but have yet to find easy to understand code about how to set this up AND use it in the end.

    - Jeremy

  10. #10

    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.

Page 1 of 2 12 LastLast

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
  •