Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Jun 04, 2024 12:50

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 9 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Sa Jan 12, 2008 19:12 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
It is time to go on and use the 'new' ways for rendering namely vertex buffer objects.

So i thougt i start simple an try to render a triangle first, but i must be doing something wrong ...

First i declare 4 vars:
Code:
  1.  
  2. var
  3.     FVBO: TGluInt;
  4.     FVBOPointer: PGlVoid;  
  5.     i: integer;
  6.     VertexPointer: PVertex;
  7.  


Then i initialize the vertex buffer object and fill it with the vertexes making up the triangle.

Code:
  1.  
  2. glGenBuffersARB(1, @FVBO); //create a vertex buffer
  3. glBindBufferARB(GL_ARRAY_BUFFER_ARB, FVBO); //bind the buffer
  4. glEnableClientState(GL_VERTEX_ARRAY); //enable the buffer
  5.  
  6. glBufferDataARB(GL_ARRAY_BUFFER_ARB, 3*SizeOf(TVertex), nil, GL_STATIC_DRAW_ARB); //reserve memory
  7.  
  8. FVBOPointer := glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); //get a pointer to the vbo
  9.  
  10. VertexPointer    := FVBOPointer;
  11. VertexPointer^.X := 1.0;
  12. VertexPointer^.Y := -1.0;
  13. VertexPointer^.Z := 0.0;
  14. inc(Integer(FVBOPointer), SizeOf(TVertex));
  15.  
  16. VertexPointer    := FVBOPointer;
  17. VertexPointer^.X := -1.0;
  18. VertexPointer^.Y := -1.0;
  19. VertexPointer^.Z := 0.0;
  20. inc(Integer(FVBOPointer), SizeOf(TVertex));
  21.  
  22. VertexPointer    := FVBOPointer;
  23. VertexPointer^.X := 0.0;
  24. VertexPointer^.Y := 1.0;
  25. VertexPointer^.Z := 0.0;
  26. inc(Integer(FVBOPointer), SizeOf(TVertex));
  27.  


Now when i want to render it i do:
Code:
  1.  
  2. glInterleavedArrays(GL_V3F, SizeOf(TVertex), nil);
  3. glDrawArrays(GL_TRIANGLES, 0, 3 );
  4.  


Enlighten me and tell me what i do wrong.
Thanks in advance.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jan 12, 2008 19:52 
Offline
DGL Member
Benutzeravatar

Registriert: Do Sep 02, 2004 19:42
Beiträge: 4158
Programmiersprache: FreePascal, C++
You didn't unmap the buffer before rendering with:
Code:
  1.  
  2. // if not bound, bind it first
  3. glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
  4.  


And the second parameter of glInterleavedArrays definies the space between one element in the vbo and another. Since your records are lying directly behind each other in the memory as far as i can see, this should be zero.

Also make sure that the client state GL_VERTEX_ARRAY is still activated at the point of rendering.

Greetz Lord Horazont

_________________
If you find any deadlinks, please send me a notification – Wenn du tote Links findest, sende mir eine Benachrichtigung.
current projects: ManiacLab; aioxmpp
zombofant networkmy photostream
„Writing code is like writing poetry“ - source unknown


„Give a man a fish, and you feed him for a day. Teach a man to fish and you feed him for a lifetime. “ ~ A Chinese Proverb


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jan 12, 2008 20:13 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Ok with glUnmapBufferARB subsequent renders work again by the vbo itself is still not drawn. :(

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jan 12, 2008 20:18 
Offline
DGL Member
Benutzeravatar

Registriert: Do Sep 02, 2004 19:42
Beiträge: 4158
Programmiersprache: FreePascal, C++
Did you changed the parameter of glInterleavedArrays also?

Does OpenGL returns any error with glGetError?

Greetz Lord Horazont

_________________
If you find any deadlinks, please send me a notification – Wenn du tote Links findest, sende mir eine Benachrichtigung.
current projects: ManiacLab; aioxmpp
zombofant networkmy photostream
„Writing code is like writing poetry“ - source unknown


„Give a man a fish, and you feed him for a day. Teach a man to fish and you feed him for a lifetime. “ ~ A Chinese Proverb


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jan 12, 2008 20:26 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Yes i changed the second parameter for glInterleavedArrays also. Same result nothing...
Now let's see what glGetError can tell me...

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jan 12, 2008 21:45 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
To start with: my vertexes were wrong to begin with. It would not even render properly the old way. :oops:

Also the filling part needed to be changed to:
Code:
  1.  
  2.     TVertex(FVBOPointer^).X := -1.0;
  3.     TVertex(FVBOPointer^).Y := 1.0;
  4.     TVertex(FVBOPointer^).Z := 0.0;
  5.     inc(Integer(FVBOPointer), SizeOf(TVertex));
  6.  
  7.  
  8.     TVertex(FVBOPointer^).X := -1.0;
  9.     TVertex(FVBOPointer^).Y := -1.0;
  10.     TVertex(FVBOPointer^).Z := 0.0;
  11.     inc(Integer(FVBOPointer), SizeOf(TVertex));
  12.  
  13.  
  14.     TVertex(FVBOPointer^).X := 1.0;
  15.     TVertex(FVBOPointer^).Y := -1.0;
  16.     TVertex(FVBOPointer^).Z := 0.0;
  17.     inc(Integer(FVBOPointer), SizeOf(TVertex));
  18.  


Now i see the triangle .

GlInterleafedArrays could stay like it originaly was.

To be compete here is the type for PVertex i forgot to post earlier:
Code:
  1. type
  2.   PVertex = ^TVertex;
  3.   TVertex = packed record
  4.     X,Y,Z : TGLFloat;
  5.   end;

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Jan 13, 2008 16:49 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Now larger meshes also work.
Now i read that there is also a thing called buffers with indexed arrays. If i understand it correctly i do not need to feed all the vertexes even double but only the unique ones and pass indices to them. So like i do in gld3ds where i have a list of vertexes and a list containing indices to them.

so i need two vbo's one for the vertexes and one for the indices.

but how are these combined? Simple example anyone?

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Jan 13, 2008 17:46 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Figured it out:

Code:
  1. procedure TRender.CreateIndexedVertexBufferObject;
  2. var
  3.   i: integer;
  4. begin
  5.   glEnableClientState(GL_VERTEX_ARRAY); //enable the buffer
  6.   glGenBuffersARB(1, @FVBO); //create a vertex buffer
  7.   glBindBufferARB(GL_ARRAY_BUFFER_ARB, FVBO); //bind the buffer
  8.   glBufferDataARB(GL_ARRAY_BUFFER_ARB, (FModels[0].Mesh[0].NumVertex)*SizeOf(TVertex), nil, GL_STATIC_DRAW_ARB); //reserve memory
  9.   FVBOPointer := glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); //get a pointer to the vbo
  10.  
  11.   //copy the vertex data into the vbo buffer
  12.   for i := 0 to (FModels[0].Mesh[0].NumVertex )-1 do
  13.   begin
  14.     FVBOPointer^.X := FModels[0].Mesh[0].Vertex[i].x;
  15.     FVBOPointer^.Y := FModels[0].Mesh[0].Vertex[i].y;
  16.     FVBOPointer^.Z := FModels[0].Mesh[0].Vertex[i].z;
  17.     if i < (FModels[0].Mesh[0].NumFaces)-1 then
  18.       inc(Cardinal(FVBOPointer), SizeOf(TVertex));
  19.   end;
  20.  
  21.   glUnMapBufferARB(GL_ARRAY_BUFFER_ARB); //after filling unmap the filled buffer
  22.  
  23.   //now create indices buffer
  24.   glGenBuffersARB(1, @FIVBO);
  25.     glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, FIVBO);
  26.     glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, (FModels[0].Mesh[0].NumFaces)*sizeof(GLushort), nil, GL_STREAM_DRAW_ARB); //allocate memory on board
  27.  
  28.     FIVBOPointer := glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); //get pointer to memory on board
  29.     for i:= 0 to (FModels[0].Mesh[0].NumFaces)-1 do
  30.   begin
  31.     FIVBOPointer^ := FModels[0].Mesh[0].Face[i]; //upload indices
  32.     inc(Cardinal(FIVBOPointer), SizeOf(TGluShort));
  33.   end;
  34.  
  35.     glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
  36. end;


and i render this with:
Code:
  1. glVertexPointer(3, GL_FLOAT, 0, nil);
  2.   glDrawElements(GL_TRIANGLES, FModels[0].Mesh[0].NumFaces, GL_UNSIGNED_SHORT, 0);


Now is there a best way?
Should i go for indexed or non-indexed?
Does that matter for vertex and or fragment programs?
Should i have used the second render method even for my first example?

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Jan 14, 2008 09:55 
Offline
DGL Member
Benutzeravatar

Registriert: Di Mai 18, 2004 16:45
Beiträge: 2622
Wohnort: Berlin
Programmiersprache: Go, C/C++
The best way is the second one with index array because smaller memory use and you can sort the tris very easy for vertex cache.
You can use Batches this mean you set a maximum cap for the vertex count.
Good values are 200-20k(r9800-x1950) with newer cards the top cap go up.
The most power come from vertex cache, high usage of cache mean higher FPS.
Test for the optimal balance between batchsize and number of batches.

_________________
"Wer die Freiheit aufgibt um Sicherheit zu gewinnen, der wird am Ende beides verlieren"
Benjamin Franklin

Projekte: https://github.com/tak2004


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 9 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 5 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.036s | 17 Queries | GZIP : On ]