## Vertex Buffer Objects Problem

graphics

### Next

• 1. Is This a Good Application of OpenGL
I am looking for a way to display some 3-D data and am wondering if OpenGL is capable of doing what I want. The data is a three dimensional array of scaler numerical values that represent the amount of light emitted by corresponding points in a physical volume. These points collectively represent bodies of various shape in this volume. These bodies are transparent and emit light in all directions. The light comes from the entire volume of these diffuse bodies like glowing gas. I want calculate the 2-D representation of this 3-D volume for a particular viewing location. After reading through 'The Red Book', it is still unclear to me if the OpenGL functions can perform the operations I need. Perhaps my question is answered by 'The Red Book', but my understanding is very limited at this time. Is OpenGL appropriate, or is there something that is better suited to this problem? -- Gavrik Peterson
• 2. determining texture memory size
Hi, Does anybody know if/how its possible to find out the total and/or available texture memory for GeForce cards (or all graphics cards) from within a c++ program? Thanks
• 3. random view of a rect...
hallo, following source void CGLObjCst::Draw() { GLfloat x=m_x, y=m_y, z=m_z; if( m_state == OBJ_STATE_NONE ) glColor3f(0.40f, 0.40f, 0.40f); else if( m_state == OBJ_STATE_SELECT ) glColor3f(0.40f, 0.99f, 0.40f); //----------------- METHOD 1 /*glBegin( GL_QUADS ); glVertex3i( x , y , 0.0f); glVertex3i( x+0.6f, y , 0.0f); glVertex3i( x+0.6f, y+0.6f, 0.0f); glVertex3i( x , y+0.6f, 0.0f); glEnd();*/ //----------------- METHOD 2 glRectf(x,y,x+0.6f, y+0.6f); } If I draw the rect with method 1, sometimes it is not displayed. Method 2 shows the rect always. why? mario
• 4. Ball's trail
Hi, I'm programming a game in which I would like the ball have a trail. Do anyone have an idea different than a vector which memorizes positions? (scuse for my poor language !!!) Thanks -- Fanny <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> Hi, <p>I'm programming a game in which I would like the ball have a trail. <br>Do anyone have an idea different than a vector which memorizes <br>positions? <p>(scuse for my poor language !!!) <p>Thanks <pre>--  Fanny  </pre>  </html>

### Vertex Buffer Objects Problem

am using the Tao OpenGL libraries for .net in c# and I'm having a
problem with vertex buffer objects. My code builds buffers for vertex,
tex coord, normal and colour information into arrays of floats. Then
if it detects that the vbo extension is supported it binds the data to
vbos. Then it renders the arrays each frame using drawarrays.

The problem is that if I turn of vbos the terrain renders properly but
if I enable vbos the terrain renders with the opposite polygon winding
and with the z and y coordinates swapped (also the z value seems to be
negated). I don't understand why this should happen since I'm feeding
exactly the same data in regardless of whether I'm using vbos or not.

I am running this under linux through mono with an nvidia card. Could
this be a bug with my ogl drivers/mono/tao?

Any suggestions?
G!

Here's some code:

private void _generateVBOs()
{
vboVertexBuffer =new int[_width];
vboTexCoordBuffer =new int[_width];
vboNormalBuffer =new int[_width];
vboColourBuffer =new int[_width][];

float f=0.0f;
for(int i=0;i<_width;i++)
{
vboColourBuffer[i] =new int[TERRAIN_TEXTURE_COUNT];

Gl.glGenBuffersARB(1, out vboVertexBuffer[i]);
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, vboVertexBuffer[i]);
Gl.glBufferDataARB(
Gl.GL_ARRAY_BUFFER_ARB,
vertexBuffer[i].Length*Marshal.SizeOf(f.GetType()),
vertexBuffer[i],
Gl.GL_STATIC_DRAW_ARB
);

Gl.glGenBuffersARB(1, out vboTexCoordBuffer[i]);
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, vboTexCoordBuffer[i]);
Gl.glBufferDataARB(
Gl.GL_ARRAY_BUFFER_ARB,
texCoordBuffer[i].Length*Marshal.SizeOf(f.GetType()),
texCoordBuffer[i],
Gl.GL_STATIC_DRAW_ARB
);

Gl.glGenBuffersARB(1, out vboNormalBuffer[i]);
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, vboNormalBuffer[i]);
Gl.glBufferDataARB(
Gl.GL_ARRAY_BUFFER_ARB,
normalBuffer[i].Length*Marshal.SizeOf(f.GetType()),
normalBuffer[i],
Gl.GL_STATIC_DRAW_ARB
);

for(int j=0;j<TERRAIN_TEXTURE_COUNT;j++)
{
Gl.glGenBuffersARB(1, out vboColourBuffer[i][j]);
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, vboColourBuffer[i][j]);
Gl.glBufferDataARB(
Gl.GL_ARRAY_BUFFER_ARB,
textureBlendingBuffer[i][j].Length*Marshal.SizeOf(f.GetType()),
textureBlendingBuffer[i][j],
Gl.GL_STATIC_DRAW_ARB
);
}
}
}

public void Render()
{
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
Gl.glEnableClientState(Gl.GL_NORMAL_ARRAY);
Gl.glEnableClientState(Gl.GL_COLOR_ARRAY);

Gl.glEnable(Gl.GL_COLOR_MATERIAL);

float[] matAmb=new float[4]{1.0f, 1.0f, 1.0f, 1.0f};
float[] matDif=new float[4]{1.0f, 1.0f, 1.0f, 1.0f};
float[] matSpe=new float[4]{1.0f, 1.0f, 1.0f, 1.0f};
float[] matEmi=new float[4]{0.0f, 0.0f, 0.0f, 1.0f};

Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT, matAmb);
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_DIFFUSE, matDif);
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, matSpe);
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_EMISSION, matEmi);
Gl.glMaterialf(Gl.GL_FRONT, Gl.GL_SHININESS, 50.0f);

Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);

Gl.glColorMaterial(Gl.GL_FRONT, Gl.GL_DIFFUSE);

for(int i=0;i<TERRAIN_TEXTURE_COUNT;i++)
{

### Re: Vertex Buffer Objects Problem

```Hello,

This isn't the way VBOs work. Only one buffer can be bound per buffer
target (and there's only GL_ARRAY_BUFFER_ARB for that kind of stuff) at
any time, so all vertex attributes must be stored in the same VBO. What
your code actually does is using the same data from your
vboColourBuffer-array as vertex coordinates, texcoords, normals and
colors.

Regards, Marcel
--
Marcel Heinz | < XXXX@XXXXX.COM > | PGP-KeyID: E78E9442

"Perfection is attained not when there is nothing more to add,
but when there is nothing more to remove."  -- Antoine de Saint-Exupy
```

### Re: Vertex Buffer Objects Problem

```

What makes you think that? The OpenGL spec disagrees.

```

### Re: Vertex Buffer Objects Problem

```Hello,

Oh, you are right. I forgot that there is a VBO binding point for every array
type.

--
Marcel Heinz | < XXXX@XXXXX.COM > | PGP-KeyID: E78E9442

"Perfection is attained not when there is nothing more to add,
but when there is nothing more to remove."  -- Antoine de Saint-Exupy
```

### Re: Vertex Buffer Objects Problem

```My app seems to work in windows xp pro under the .net framework 1.1
using vbos so I think it must be something wrong with my nvidia linux
there isn't a good way to know whether or not using vbos will work when
my application starts up...it doesn't even know if it's in windows or
linux...

:(

G!

```

### Re: Vertex Buffer Objects Problem

```

So your terrain shifts orientation? It sounds like there's a 90 degree
rotation on the whole thing?

---
Strange

```

### Re: Vertex Buffer Objects Problem

```

Yeah, only in linux, windows is fine.  The x and z axis are meant to
be longitude and latitude and y axis is height of the terrain.  When I
use vbos in linux the y axis is used for latitude and the z axis is
used for height, which is very odd.  It also looks like the winding of
the triangle strip is backwards so a mountain looks like a pit.

The only thing I can think to do is to try to render a square using
vbos at initialisation then read some pixel colours from the back
buffer and check if it's correct.  If not then assume this bug is in
effect and disable vbos... So say I draw a red square and the clear
colour is black, if the orientation is wrong I will be reading black
from the screen buffer instead of red.

G!

```

### Re: Vertex Buffer Objects Problem

```

I can't believe that VBO's are that broken on Linux. Indeed, I know that
they are not, in general.
Which leaves us with something in how you initialize Linux vs Windows which
is different.
A mixup in going from X11 coordinates to OpenGL maybe? (forgetting to flip
Y).
jbw

```

### Re: Vertex Buffer Objects Problem

```

The mono wrapper might still be broken.

```

```    Hello,

I've just implement the ARB_vertex_buffer_objet in one my my program,
all works perfectly, but ... All run Twice SLOWER than a normal loop.

I create all things like that :

GLuint vbo_v,vbo_nv...;

glGenBuffersARB(1,&vbo_v);
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_v);

glBufferDataARB(GL_ARRAY_BUFFER_ARB,3*nbrv*sizeof(float),v,GL_STATIC_DRAW_AR
B);

glGenBuffersARB(1,&vbo_nv);
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_nv);

glBufferDataARB(GL_ARRAY_BUFFER_ARB,3*nbrv*sizeof(float),nv,GL_STATIC_DRAW_A
RB);
...

Where v and nv and pointers on 2 arrays (vertices and vertices
normals) - i do the same with vertex color, tex coords ...

glGenBuffersARB(1,&vbo_f);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,vbo_f);

glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,3*nbrf*sizeof(int),f,GL_STATIC_D
RAW_ARB);

For indexs

When i bind all that

glEnableClientState(GL_COLOR_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_vc);
glColorPointer(4,GL_UNSIGNED_BYTE,0,NULL);

glEnableClientState(GL_NORMAL_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_nv);
glNormalPointer(GL_FLOAT,0,NULL);

glEnableClientState(GL_VERTEX_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB,vbo_v);
glVertexPointer(3,GL_FLOAT,0,NULL);

// DRAWING
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,vbo_f);
glDrawElements(GL_TRIANGLES,3*nbrf,GL_UNSIGNED_INT,NULL);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

I have with a normal loop about 60 fps and 30 fps when using VBO
I run on an AMD ATHLON 2Ghz 512Mo GeForce4MX

All Works perfectly but TWICE slower than normal loop with glNormals,
glVertex, glTexCoord ...
Why ? Did i do something wrong ? Isn't vertex buffer objects are
supposed to increase the number of fps and not make your programs run slower
? Help !

```

```Hi list.

I implemented rendering using display lists, vertex arrays, and vertex
buffer objects. And guess what was the faster ? ... display lists !

It should mean that I implemented badly those array stuff.
For the VBO part, I'm quite sure that today drivers are not correctly
implemented - systematically crash on some ATI hardware, even if
extention is detected, poor perfs on nVidia. After all, it runs as
fast as plain vertex arrays.
For the VA part ... I guess all static geometry could be rendered
using glLockArray() ... ? I think this is called compiled vertex array
? Is this an improvement compared to plain vertex arrays ?
Will I have to go to VAR to achieve correct perfs ?

Thx for enlightments

SeskaPeel.
```

```Hi,

Say you have this custom vertex structure:

struct CUSTOMVERTEX
{
float x, y, z;
DWORD color;
};

Is it possible once you've defined values for a vertex
buffer using that structure to subsequently change the
color for a vertex that you defined? If so, how?

Thanks :)
```

```The book I'm reading shows as illustration example, multiple objects
in a single v-buffer.  These more primitive though: sphere, box and a
cylinder.  Is it wise to have a v-buffer handle more than one object?

```

```I have a vertex buff obj, it's a meshed(tessulated) square in D3DX8,
Vertex *v;

g_pd3dDevice->CreateVertexBuffer( g_nTriCount*3*sizeof(Vertex),
D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, &g_pWallVB );

g_pWallVB->Lock( 0, 0, (BYTE**)&v, 0 );

float dX = 1.0f/(g_nNumVertsX-1);
float dZ = 2.0f/(g_nNumVertsZ-1);//dz=1.0f/
int i = 0;

for( int z = 0; z < (g_nNumVertsZ-1); ++z )
{
for( int x = 0; x < (g_nNumVertsX-1); ++x )
{
v[i].p = D3DXVECTOR3(10*x*dX, 0.0f, 10*z*dZ );
v[i].n = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
++i;
v[i].p = D3DXVECTOR3(10*x*dX, 0.0f, 10*(z+1)*dZ );
v[i].n = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
++i;
v[i].p = D3DXVECTOR3(10*(x+1)*dX, 0.0f, 10*(z+1)*dZ );
v[i].n = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
++i;
v[i].p = D3DXVECTOR3(10*x*dX, 0.0f, 10*z*dZ );
v[i].n = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
++i;
v[i].p = D3DXVECTOR3(10*(x+1)*dX, 0.0f, 10*(z+1)*dZ );
v[i].n = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
++i;
v[i].p = D3DXVECTOR3(10*(x+1)*dX, 0.0f, 10*z*dZ );
v[i].n = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
++i;
}
}

g_pWallVB->Unlock();

How can I rescale its size.

```