0
\$\begingroup\$

I want to send each face as VBO, and I structured the data as this

facevbo[0] =  x x x x x x   //x,y,z,r,g,b,s,t
facevbo[1] =  x x x x x
facevbo[2] =  x x x x x x x 
facevbo[3] =  x x x x
.
.
.
facevbo[numfaces] = x x x x 

Basicly I have dynamic 2d array with different column size:

GLfloat** faceVBO = new GLfloat*[m_numOfFaces];
faceVBO[dfaceIndex] = new GLfloat[pFace->numOfVerts*8];

When I print all the faces, everything is fine, but when im trying to put them to use, i have problem at this line: (ideally I would iterate trough all the faces to bind each face, but lets take the first column)

glBufferData(GL_ARRAY_BUFFER, 4*oindices, faceVBO[0], GL_STATIC_DRAW);

the third parameter (faceVBO[0]) "argument of type GLfloat is incompatible with param. of type const void*"

but if i tead from array, like

GLfloat facevbo[] = {x,x,x,x...}

and

 glBufferData(GL_ARRAY_BUFFER, 4*oindices, faceVBO, GL_STATIC_DRAW);

it works OK. How should i send the data in this case?

Thanks

\$\endgroup\$
2
  • \$\begingroup\$ Is there any reason you need an array of pointers? This seems unnecessary. \$\endgroup\$
    – tkausl
    Jul 28, 2015 at 15:22
  • \$\begingroup\$ Seemed like logical solution... \$\endgroup\$
    – r3aktormk
    Jul 28, 2015 at 15:46

1 Answer 1

1
\$\begingroup\$

The problem is you are passing an address value to data rather than the data itself. A naive solution is to change:

glBufferData(GL_ARRAY_BUFFER, 4*oindices, faceVBO[0], GL_STATIC_DRAW);

to:

glBufferData(GL_ARRAY_BUFFER, 4*oindices, *faceVBO[0], GL_STATIC_DRAW);

To clarify: in your implementation, 'faceVBO' is a pointer to a set of pointers, and glBufferData() requires a pointer to the data, so sending it 'faceVBO[0]' directly is an attempt to send the pointer to the data as the data itself, which is incorrect.

\$\endgroup\$
12
  • \$\begingroup\$ *faceVBO[0] is a GLfloat, not a ptr \$\endgroup\$
    – tkausl
    Jul 28, 2015 at 15:15
  • \$\begingroup\$ @tkausl Actually, it is the first of (pFace->numOfVerts*8) floats, according to the OP's code, but that's just nitpicking; the fact is that faceVBO[0] itself is a pointer (whether to one or more floats) and not the actual data required by the function. \$\endgroup\$ Jul 28, 2015 at 15:38
  • \$\begingroup\$ I just saw that in the header file I already mistakenly defined GLfloat *faceVBO;. So I removed it and now accepts faceVBO[0]... and &faceVBO[0] ,also??? \$\endgroup\$
    – r3aktormk
    Jul 28, 2015 at 15:43
  • \$\begingroup\$ That is because &faceVBO[0] is a reference to faceVBO[0], used often in C++11. See en.wikipedia.org/wiki/Reference_(C%2B%2B) for an explanation. \$\endgroup\$ Jul 28, 2015 at 15:50
  • 1
    \$\begingroup\$ &faceVBO[0] is definitely wrong. faceVBO[0] might be right but not sure since you only fill faceVBO[dfaceIndex] and i do not know what dfaceIndex is. But as i said in my other comment to your question, it shouldn't be necessary to use a array of ptr's \$\endgroup\$
    – tkausl
    Jul 28, 2015 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .