I am trying to get vbo vertex buffer objects working. But i cannot get it to work. Tutorials or simple bare bone examples would be nice.
I am trying to get vbo vertex buffer objects working. But i cannot get it to work. Tutorials or simple bare bone examples would be nice.
http://3das.noeska.com - create adventure games without programming
A NeHe tutorial: http://nehe.gamedev.net/data/lessons....asp?lesson=45
Some Extra links:
http://www.ozone3d.net/tutorials/opengl_vbo.php
http://www.devmaster.net/articles/oglVertexBuffer/
http://www.songho.ca/opengl/gl_vbo.html
Hope they are usefull
Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.
which method are trying to use? there are many ways to get VBOs work, some code would be nice to see what you are doing wrong.
This is my game project - Top Down City:
http://www.pascalgamedevelopment.com...y-Topic-Reboot
My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
http://www.pascalgamedevelopment.com...source+manager
This is the code i have now:
First i declare 4 vars:
Then i initialize the vertex buffer object and fill it with the vertexes making up the triangle.Code:var FVBO: TGluInt; FVBOPointer: PGlVoid; i: integer; VertexPointer: PVertex;
Now when i want to render it i do:Code:glGenBuffersARB(1, @FVBO); //create a vertex buffer glBindBufferARB(GL_ARRAY_BUFFER_ARB, FVBO); //bind the buffer glEnableClientState(GL_VERTEX_ARRAY); //enable the buffer glBufferDataARB(GL_ARRAY_BUFFER_ARB, 3*SizeOf(TVertex), nil, GL_STATIC_DRAW_ARB); //reserve memory FVBOPointer := glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); //get a pointer to the vbo VertexPointer := FVBOPointer; VertexPointer^.X := 1.0; VertexPointer^.Y := -1.0; VertexPointer^.Z := 0.0; inc(Integer(FVBOPointer), SizeOf(TVertex)); VertexPointer := FVBOPointer; VertexPointer^.X := -1.0; VertexPointer^.Y := -1.0; VertexPointer^.Z := 0.0; inc(Integer(FVBOPointer), SizeOf(TVertex)); VertexPointer := FVBOPointer; VertexPointer^.X := 0.0; VertexPointer^.Y := 1.0; VertexPointer^.Z := 0.0; inc(Integer(FVBOPointer), SizeOf(TVertex)); glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
Code:glInterleavedArrays(GL_V3F, SizeOf(TVertex), nil); glDrawArrays(GL_TRIANGLES, 0, 3 );
http://3das.noeska.com - create adventure games without programming
aren't you supposed to call glEnableClientState before binding or creating it? shouldn't it be th first thing you call?
This is my game project - Top Down City:
http://www.pascalgamedevelopment.com...y-Topic-Reboot
My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
http://www.pascalgamedevelopment.com...source+manager
I changed the possition of that line, but still nothing.
Also i forgot to post the typedef for PVertex:
Code:type PVertex = ^TVertex; TVertex = packed record X,Y,Z : TGLFloat; end;
http://3das.noeska.com - create adventure games without programming
And more importantly: You aren't incrementing your VertexPointer.
You are doing this:
Set to 0
write data
inc
Set to 0 again
write data
inc
Set to 0 again
write data
inc
So you are just overwriting one Vertex all the time.
changed that to
As it turned out the vertexes were all wrong also.Code:TVertex(FVBOPointer^).X := -1.0; TVertex(FVBOPointer^).Y := 1.0; TVertex(FVBOPointer^).Z := 0.0; inc(Integer(FVBOPointer), SizeOf(TVertex)); TVertex(FVBOPointer^).X := -1.0; TVertex(FVBOPointer^).Y := -1.0; TVertex(FVBOPointer^).Z := 0.0; inc(Integer(FVBOPointer), SizeOf(TVertex)); TVertex(FVBOPointer^).X := 1.0; TVertex(FVBOPointer^).Y := -1.0; TVertex(FVBOPointer^).Z := 0.0; inc(Integer(FVBOPointer), SizeOf(TVertex));
Now i see a nice white triangle.
Ok on to something more exiting...
http://3das.noeska.com - create adventure games without programming
The last incrementation is useless and so is the cast to "TVertex".
If you don't do this usually:
[pascal]
var
a: integer;
b: ^integer;
begin
b := @a;
integer(b^) := -123;
end.
[/pascal]
You might also have used GL_V2F instead of V3F since you aren't
using Z anyway.
Also you could cast the pointer to "cardinal" instead "integer" because
negative pointers don't make sense (to humans, the computer doesn't care).
It just sounds more logically.
Glad its working, now to make it more aesthetic; just giving tips here,
don't feel upset
So instead of making FVBOPointer: PGlVoid; i should make that a PVertex?
is not your example the same as what i do with TVertex?
You are right the last increment is useless as nothing new is added. So when used in a loop i should take care that the last time the increment is not done. Ok cardinals are the way to cast pointers to.
Z was not used for this specific triangle, but might be for another one. (e.g. i was not making a 2d example.) So i decided to use V3F.
http://3das.noeska.com - create adventure games without programming
Bookmarks