Buffer Question

Once I send a Buffer to a gl call (e.g. Gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, colorBuf);

is it safe to reuse colorBuf? That is, once the call is made is the reference kept or can I change color buf without affecting the gl call?

Basically I’m doing this:

//set color buf to ambient
//call ambient light param
//set color buf to diffuse
//call diffuse light param
//set color buf to specular
//call specular light param.

Is that safe?

Most of the time it is - light properties and such are copied into the internal GL state if i remember correctly. Its just things like glVertexPointer that you can’t do that with.

Hi,

for me the reuse of Color Buffers are ok.
If you use some new Buffers in short intervals
you produce to much garbage. This can slow down performance .

  • jens

Hi,

Did someone made something with VertexPointer or NormalPointer ?
Seems to be trivial, simply some FloatBuffer that get filled
by some loop like:



      GL.glEnableClientState(GL.GL_NORMAL_ARRAY);
      GL.glEnableClientState(GL.GL_VERTEX_ARRAY);

      for(int i=0;i<hrm_v3Vertexes.length;i++)
      {
        v3Vertexes[i].store(vertexBuffer);
        v3Normals[i].store(normalBuffer);
      }

      GL.glVertexPointer(3,GL.GL_FLOAT,vertexBuffer);
      GL.glNormalPointer(GL.GL_FLOAT,vertexBuffer);

  • Jens

You forgot the flip()'s after filling the buffers with vertices!

Cas :slight_smile:

Thx,

i ran in some Exepetions without doing it ::slight_smile:

Seems to be a good Way to “serialize” Vertex or Normal
Data.

  • Jens

Hi again ;D

Did some see something why i get only crap on my Screen ?

The Vertex Buffer is the Vertex Buffer#
and the Normal Buffer holds the Normals
also the index Buffer seems to be correct!

Is there something i forgot ?


      GL.glEnableClientState(GL.GL_NORMAL_ARRAY);
      GL.glEnableClientState(GL.GL_VERTEX_ARRAY);

      for(int i=0;i<hrm_v3Vertexes.length-1;i++)
      {
        hrm_v3Vertexes[i].store(vertexBuffer);
        hrm_v3Normals[i].store(normalBuffer);
      }
      indexesBuffer.put(hrm_iIndexes);


      GL.glVertexPointer(4,GL.GL_FLOAT,vertexBuffer);// umwandeln der Vertex Pointer in floafBuffer !

      GL.glNormalPointer(GL.GL_FLOAT,normalBuffer);

      GL.glPushMatrix();

      //draw here
      GL.glDrawElements(GL.GL_QUADS,indexesBuffer);

      GL.glPopMatrix();

      vertexBuffer.flip();
      normalBuffer.flip();
      indexesBuffer.flip();

      GL.glDisableClientState(GL.GL_NORMAL_ARRAY);
      GL.glDisableClientState(GL.GL_VERTEX_ARRAY);

      GL.glDisable(GL.GL_TEXTURE_GEN_S);
      GL.glDisable(GL.GL_TEXTURE_GEN_T);


thx 4 helping :=)

  • jens

call flip() before calling glVertexPointer, etc.

Hi, ;D

im a bit frustated >:( about the fact that i cant get
any Quad / Triangle working with VertexBuffers
and NormalBuffers, and all other buffers like ColorBuffers.

Is it common that the following Code produce a VM crash ?


      GL.glColor3f(1.0f,1.0f,1.0f);
      GL.glLoadIdentity();
      GL.glTranslatef(0f,0.0f,-10.0f);
//      GL.glEnable(GL.GL_TEXTURE_2D);
      GL.glDisable(GL.GL_LIGHTING);

      GL.glEnableClientState(GL.GL_VERTEX_ARRAY);
//      GL.glEnableClientState(GL.GL_NORMAL_ARRAY);

      GL.glVertexPointer(4,GL.GL_FLOAT,vertexBuffer);// umwandeln der Vertex Pointer in floafBuffer !
      GL.glDrawElements(GL.GL_QUADS,indexesBuffer); //<- makes my VM crash

      GL.glDisableClientState(GL.GL_VERTEX_ARRAY);



I have disabled ligthing and set the Lighting Color to white. Now i moved the GL.glDrawElement( method behind GL.glDisableClientState(GL.GL_VERTEX_ARRAY);
and the Code work, but i see nowthing at all.

Now my Question : Must the glDrawElements called between the enabled Client States ? Or can it be done after the Vertex Pointer was comited to the Gfx Card,and the client state is disabled ?

Sorry for such stupid question again. but i see nothing or my VM crashes.

Thx 4 helping again.

  • jens

How do you set up your indexesBuffer?

Hi,

The Indexnuffer holds indicies for Quads.
all i do is to increment a variable when the
Vertex Data is Calulcated this way :



 loop:

           doCalcQuad(); //  

           hrm_iIndexes[ni] = ni;
           hrm_v3Normals[ntri] = n[0];
           hrm_v3Vertexes[ntri] = q[0];
           ntri++;
           ni++;

           hrm_iIndexes[ni] = ni;
           hrm_v3Normals[ntri] = n[1];
           hrm_v3Vertexes[ntri] = q[1];
           ntri++;
           ni++;

           hrm_iIndexes[ni] = ni;
           hrm_v3Normals[ntri] = n[2];
           hrm_v3Vertexes[ntri] = q[2];
           ntri++;
           ni++;

           hrm_iIndexes[ni] = ni;
           hrm_v3Normals[ntri] = n[3];
           hrm_v3Vertexes[ntri] = q[3];
           ntri++;
           ni++;

 loop:end


Well i haven’t post all code, coz it is lot more, but the indexing are done there.

thx,

  • jens

Well, if I were you, I’d confirm that your arrays are being set how you think they are. The actual rendering part looks fine to me, but if you are setting the data incorrectly, it won’t matter. Confirm your arrays and indices are correct first.

Well, i done this, the index goes up
from 0 to end nothing more.

Ok, i have a look again, it’s a very small bug to be find .
As some others also know: Working with new API’s
allways produce failures like this, it thing >:(

Thx mojo so far ;D

Did someone know some small Code that use the VertexBuffers ? So i be able test it …

  • jens