Page 1 of 1

Halp plz [solved]

Posted: Wed May 19, 2010 11:02 am
by GroundUpEngine
I try not to seek help unless I really need it, but I'm really failing with VBO's. After fail #2 things were better but its still not right, can anyone help??
Here's what going on..

Anvil.obj ->

Code: Select all

1 Texture
50 Faces
150 Verts (vec3)
150 Normals (vec3)
150 TexCoords (vec2)
Code for data offset in buffer ->

Code: Select all

#define BUFFER_OFFSET(i) ((char*)NULL + (i))
Code snippet for this fail->
The data is used sizeof(float)*3 by default I think.

Code: Select all

glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(OffsetPosition));
glNormalPointer(GL_FLOAT, 0, BUFFER_OFFSET(OffsetNormal));
glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(OffsetTexcoord));
Image

Code snippet for this fail->
Here I added data padding sizeof(float)*4 which, seemed to fix things a little?! But it's still messed up.

Code: Select all

glVertexPointer(3, GL_FLOAT, 16, BUFFER_OFFSET(OffsetPosition));
glNormalPointer(GL_FLOAT, 16, BUFFER_OFFSET(OffsetNormal));
glTexCoordPointer(2, GL_FLOAT, 16, BUFFER_OFFSET(OffsetTexcoord));
Image

Re: Halp plz

Posted: Wed May 19, 2010 11:20 am
by qpHalcy0n
The third parameter to those mapping functions is the stride. This is the distance between consecutive "colors", or "positions", or what have you.

Remove the padding and go with: glVertexPointer( 3, GL_FLOAT, sizeof( vertex_format ), BUFFER_OFFSET( OffsetPosition ) );

Re: Halp plz

Posted: Wed May 19, 2010 11:23 am
by Genesis
Is your position, normal and texture coordinate data stored in the same vertex buffer? If so, the stride you set in each gl*Pointer function will be equal to the size of the vertex data combined (i.e sizeof(position) + sizeof(normal) + sizeof(texcoord)).

*beaten to it by qpHalcy0n* :p

Re: Halp plz

Posted: Wed May 19, 2010 12:17 pm
by GroundUpEngine
Thanks so much guys! Works like a freakin' charm :)

<problem here> mess up verts

Code: Select all

glVertexPointer(3, GL_FLOAT, 16, BUFFER_OFFSET(OffsetPosition));
to
glVertexPointer(3, GL_FLOAT, sizeof(vec3), BUFFER_OFFSET(OffsetPosition));
<main problem> pointing to wrong data

Code: Select all

glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, OffsetPosition, SizePosition, (const GLvoid*)(&Position[0]));
to
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, OffsetPosition, SizePosition, (const GLvoid*)(&Position[0].x));
I got some maps and terrains I wanna benchmark :mrgreen:

Re: Halp plz [solved]

Posted: Wed May 19, 2010 12:40 pm
by avansc
yeahm never just pass a constant to a size_t param, makes code non portable even if you happen to pass the right size.
but yeah, would love to see what kinda boost you get from going from intermediate to pipe, keep up updated.