Halp plz [solved]

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Halp plz [solved]

Post 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
Last edited by GroundUpEngine on Wed May 19, 2010 12:19 pm, edited 1 time in total.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: Halp plz

Post 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 ) );
Genesis
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Mon May 17, 2010 9:01 am

Re: Halp plz

Post 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
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: Halp plz

Post 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:
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Halp plz [solved]

Post 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.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Post Reply