Page 1 of 5 123 ... LastLast
Results 1 to 10 of 42

Thread: pascal and learning 3d

  1. #1

    pascal and learning 3d

    Hi guys. I'd like to make a 3D game in Lazarus. I don't know opengl yet but that's one of reasons for making it 3d. It's a voxel based game so I recon I don't need sophisticated 3d engine, just some painless access to opengl surface and I'll figure out how to build and draw those meshes.
    Now, is lazarus any good for this? I'd really like to use pascal for this project but after some searching I've found that most resources are for old 2.1 opengl/ in russian/ won't compile
    Should forget my pascal sympathy and just get back to c++ or is there some working solution that I've missed?

  2. #2
    Hi Laggyluk,
    For learning opengl, I suggest you to take a look into excellent tutorials by NeHe http://nehe.gamedev.net (you can find source files there).
    For an updated opengl header file, go to http://wiki.delphigl.com/index.php/dglOpenGL.pas/en

    EDIT: NeHe has examples in many languajes, pascal is one of them, the dglOpenGL header is ready for delphi and freepascal.
    Last edited by pitfiend; 20-11-2012 at 01:34 AM.

  3. #3
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    here http://www.spacesimulator.net/index.php?p=home and here http://www.arcsynthesis.org/gltut/ you will find some more modern info. it is what I am using to figure things out.

  4. #4
    thanks I'll check it out

  5. #5
    OpenGL is in a strange situation now. You really should learn OpenGL 3.2+ today, not OpenGL 1/2. If you do use OpenGL 2, go for VAOs/VBOs and shaders instead of fixed pipeline.

  6. #6
    yeah, I'm after 3.2+ just had problem finding a basic example for pascal. And I didn't, even among those links but managed to craft it from old pascal opengl 2.1 and new 3.2 c++ tutorial.
    btw in c++ stack (or vector? the one with .push() and pop() is used for keeping and traversing matrices hierarchy in a convenient way. There's no vector class in delphi/pascal so what you guys are using instead?

  7. #7
    TList is comparative to C++ vector-class? I don't use it though. Dynamic arrays are very handy, and keep the data linearily in it.

  8. #8
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    I would avoid creating classes to handle lower level stuff like vectors and matrix's use array's of record's as they are opengl friendly and well managed by fpc. never use multi dimensional array's as they will not be a single chunck of memory. for lower level stuff stick to procedural comands that dont require you to create a class ever time you want to use a command.
    Code:
     TFlt4 = packed record
        case Integer of
          0:(X,Y,Z,W:Single);
          1:(S:Array [0..3] of Single);
          2:(R,G,B,A:Single);
          3:(X1,Y1,X2,Y2:Single);
        end;
    
    TArrFlt4 = array of TFlt4;
    
    TFlt3 = packed record
      case Integer of
        0:(X,Y,Z:Single);
        1:(S:Array[0..2] of Single);
        2:(R,G,B:Single); 
      end;
    TArrFlt3 = array of TFlt3;
    
    Points:TArrFlt3;
    SetLength(Points,10);
    Points[0]:=VecFlt3(1,1,1);
    Points[1]:=Points[0];
    Points[1].X+=0.5;
    Points[1].S[2]:=2;// same as Points[1].Y but is index able Points[1].S[i]:=10;
    
    Colors:TArrFlt3;
    SetLength(Colors,10);
    Colors[i].R:=0.25;
    Colors[i].B:=0.125;
    Colors[i].G:=0;
    Colors[2]:=VecFlt3(0.5,1.0,0);
    
    Color:TFlt4;
    Color.R:=0.75;
    Color.B:=0.25;
    Color.G:=0;
    Color.A:=1.0;
    Color:=VecFlt4(1,0.75,1,1);
    
    Colors[2]:=Color;
    as I have said these record type arrays are opengl friendy you can pass them like this @Points[0]

  9. #9
    Quote Originally Posted by laggyluk View Post
    yeah, I'm after 3.2+ just had problem finding a basic example for pascal. And I didn't, even among those links but managed to craft it from old pascal opengl 2.1 and new 3.2 c++ tutorial.
    btw in c++ stack (or vector? the one with .push() and pop() is used for keeping and traversing matrices hierarchy in a convenient way. There's no vector class in delphi/pascal so what you guys are using instead?
    In Pascal, you can use TList, TStack and TQueue. You can also use generics with these.

  10. #10
    Quote Originally Posted by Carver413 View Post
    Code:
     TFlt4 = packed record
        case Integer of
          0:(X,Y,Z,W:Single);
          1:(S:Array [0..3] of Single);
          2:(R,G,B,A:Single);
          3:(X1,Y1,X2,Y2:Single);
        end;
    as I have said these record type arrays are opengl friendy you can pass them like this @Points[0]
    Should I use packed records for this purpose? the interweb says it has slower access performance than 'unpacked'

Page 1 of 5 123 ... 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
  •