  Home Search Register Log in

 :: English Forum :: Questions (en) Share AuthorMessage
emtenteo

Messages : 2
Date d'inscription : 2012-03-03  Subject: Problem with GL_QUADS Sat Mar 03, 2012 1:19 am HiI'm iphone developer and i want to use this lib for my project, but i got some problem with GL_QUADS render because opengles don't have GL_QUADS, i try convert GL_QUADS to GL_TRIANGLES, all particle are render good after convert but the program got crash when the capacity of group is reach max. I use the demo writing for test it. Anyone can help me? Thanks you so much.Here is my codeSPK_GLQuadRenderer.hSplit SQUAD to two triangleCode:inline void GLQuadRenderer::GLCallColorAndVertex(const Particle& particle) const{   float x = particle.position().x;   float y = particle.position().y;   float z = particle.position().z;   // quads are drawn in a counter clockwise order :   // top right vertex   *(gpuIterator++) = x + quadSide().x + quadUp().x;   *(gpuIterator++) = y + quadSide().y + quadUp().y;   *(gpuIterator++) = z + quadSide().z + quadUp().z;   gpuIterator += 4;   // top left vertex   *(gpuIterator++) = x - quadSide().x + quadUp().x;   *(gpuIterator++) = y - quadSide().y + quadUp().y;   *(gpuIterator++) = z - quadSide().z + quadUp().z;   gpuIterator += 4;   // bottom left   *(gpuIterator++) = x - quadSide().x - quadUp().x;   *(gpuIterator++) = y - quadSide().y - quadUp().y;   *(gpuIterator++) = z - quadSide().z - quadUp().z;   *(gpuIterator++) = particle.getR();   *(gpuIterator++) = particle.getG();   *(gpuIterator++) = particle.getB();   *(gpuIterator++) = particle.getParamCurrentValue(PARAM_ALPHA);   // bottom left   *(gpuIterator++) = x - quadSide().x - quadUp().x;   *(gpuIterator++) = y - quadSide().y - quadUp().y;   *(gpuIterator++) = z - quadSide().z - quadUp().z;   gpuIterator += 4;   // bottom right   *(gpuIterator++) = x + quadSide().x - quadUp().x;   *(gpuIterator++) = y + quadSide().y - quadUp().y;   *(gpuIterator++) = z + quadSide().z - quadUp().z;   gpuIterator += 4;   // top right vertex   *(gpuIterator++) = x + quadSide().x + quadUp().x;   *(gpuIterator++) = y + quadSide().y + quadUp().y;   *(gpuIterator++) = z + quadSide().z + quadUp().z;         *(gpuIterator++) = particle.getR();   *(gpuIterator++) = particle.getG();   *(gpuIterator++) = particle.getB();   *(gpuIterator++) = particle.getParamCurrentValue(PARAM_ALPHA);}SPK_GLQuadRenderer.cppChange textcoordCode:float* GLQuadRenderer::createTextureBuffer(const Group& group) const{   FloatBuffer* fbuffer = NULL;   switch(texturingMode)   {   case TEXTURE_2D :      fbuffer = dynamic_cast(group.createBuffer(TEXTURE_BUFFER_NAME,FloatBufferCreator(12),TEXTURE_2D,false));      if (!group.getModel()->isEnabled(PARAM_TEXTURE_INDEX))      {         float t = {1.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f,1.0f,1.0f,1.0f,1.0f,0.0f};         for (size_t i = 0; i < group.getParticles().getNbReserved() * 12; ++i)            fbuffer->getData()[i] = t[i % 12];      }      break;            ......................Change glDrawArray with GL_QUADS to GL_TRIANGLESCode:void GLQuadRenderer::render(const Group& group){   ...........................   // interleaves vertex and color data   glVertexPointer(3,GL_FLOAT,7 * sizeof(float),gpuBuffer);   glColorPointer(4,GL_FLOAT,7 * sizeof(float),gpuBuffer + 3);   glDrawArrays(GL_TRIANGLES,0,group.getNbParticles() * 6);   glDisableClientState(GL_VERTEX_ARRAY);   glDisableClientState(GL_COLOR_ARRAY);   if (texturingMode != TEXTURE_NONE)      glDisableClientState(GL_TEXTURE_COORD_ARRAY);}  Juff
Developer

Messages : 539
Date d'inscription : 2009-07-14
Age : 37  Subject: Re: Problem with GL_QUADS Sat Mar 03, 2012 12:38 pm Hi, maybe the buffer used to sotre the positions/colors of particles is not big enough.Have you modified the capacity of this buffer accordingly ?The buffer is set to hold 28 floats per particles. As you need 6 vertices per particles, you need (3 float per positions + 4 floats per colors) * 6 = 42 floats per particles.So in SPK_GLQuadRenderer.cpp line 74, you must pass 42 :Code:FloatBuffer* fBuffer = dynamic_cast(group.createBuffer(GPU_BUFFER_NAME,FloatBufferCreator(42),0,false));But the best way to do to use triangles is to use index buffer and therefore still have only 4 vertices per particles but with 6 indices.The advantages will be the following :Less work to GPU due to vertex cachingLess data to transfer to GPU : 28 * 4 + 6 * 2 (by using short indices) = 124 bytes per particles instead of 42 * 4 = 168 bytesLess processing to fill the buffer (4 vertices instead of 6) as the index data can be preprocessed (it ll never change) a bit like the textureBuffer.If you want to use an index buffer, you ll have to create a new buffer of short and fill it once in the creates buffer.The optimal thing would also be to store the index buffer on the VRAM side and therefore upload it to the GPU only once but it would be more work as SPARK 1 does not support VBO only VA.Hope this helpsLast edited by Juff on Sat Mar 03, 2012 3:35 pm; edited 1 time in total   emtenteo

Messages : 2
Date d'inscription : 2012-03-03  Subject: Re: Problem with GL_QUADS Sat Mar 03, 2012 1:07 pm This problem is resolved when i change 28 to 42. Thanks you so much, you are so great ^^    Subject: Re: Problem with GL_QUADS   Problem with GL_QUADS  