OpenGl does not display triangles using VBO - opengl

I am trying to display 2 simple triangles in OpenGL, but they don't appear, despite checking numerous sites. Did I forget anything in the code ?
#define BUFFER_OFFSET(bytes) ((GLubyte*) NULL + (bytes))
// Prepare:
GLfloat vertices[]={0,0,1,
0.5,0,-0.5,
0,0,0,
0,0,1,
0,0,0,
-0.5,0,-0.5};
GLushort indices[]={0,1,2,3,4,5};
GLfloat *generatedVertices=new GLfloat[18];
GLushort *generatedIndices=new GLushort[6];
GLfloat *colors=new GLfloat[18];
glGenBuffers( 3, triangleBuffers ); // triangleBuffers = Global GLuint
for (int p=0;p<6;p++)
{
MVector V(vertices[p*3],vertices[p*3+1],vertices[p*3+2]); // Maya type
generatedVertices[p*3]=V.x;
generatedVertices[p*3+1]=V.y;
generatedVertices[p*3+2]=V.z;
generatedIndices[p]=p;
colors[p*3]=0.8f;
colors[p*3+1]=0.6f;
colors[p*3+2]=0.0f;
}
// vertices
glBindBuffer(GL_ARRAY_BUFFER, data->triangleBuffers[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*18, generatedVertices, GL_STATIC_DRAW);
// indices
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data->triangleBuffers[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort)*6, generatedIndices, GL_STATIC_DRAW);
// couloirs
glBindBuffer(GL_ARRAY_BUFFER, data->triangleBuffers[2]);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*18*data->totalSize, colors, GL_STATIC_DRAW);
// Render:
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, data->triangleBuffers[0]);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data->triangleBuffers[1]);
glBindBuffer(GL_ARRAY_BUFFER, data->triangleBuffers[2]);
glColorPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glDrawElements(GL_TRIANGLES, totalSize*6, GL_UNSIGNED_INT, 0);
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );

Issue is coming from maya. In OpenGL-Legacy mode, the mesh is properly displayed, in OpenGL-Strict mode, it isn't. I will investigate in this direction.

Related

OpenGL catmull rom spline loop coloring

I have a catmull rom spline loop in c++. I able to make the spline and i have the curve points, but when I tried to fill the bordered area with GL_TRIANGLE_FAN I got too much straight line. And my question is, how can I fill the spline loop area with colour efficiently?
This is how I draw the spline:
glBindVertexArray(vao);
unsigned int vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(lines) * sizeof(float), lines, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_LINE_STRIP, 0, vecLinePoints.size());
EDIT:
This is how I tried to fill my concave polygone:
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_STENCIL_TEST);
glStencilMask(0xFF);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
glClear(GL_STENCIL_BUFFER_BIT);
glBindVertexArray(vao);
unsigned int vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(polyPoints) * sizeof(float), polyPoints, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLE_FAN, 0, vecPoints.size());
glStencilMask(0x00);
glStencilFunc(GL_NOTEQUAL, 0, 0xFF);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDisable(GL_STENCIL_TEST);

Can't make OpenGL Buffer Array work - glVertex works

I have an Eigen::MatrixXf with vertices (N*3) and faces (N*3) as variables mvTemp2 and mF.
If I draw my vertices regularly, they give the correct output based on the code below:
while(1){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_LIGHTING);
glShadeModel( GL_SMOOTH );
glEnable( GL_TEXTURE_2D );
glViewport( 0, 0, (float)renderWidth/1, (float)renderHeight/1. );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60, (float)renderWidth/(float)renderHeight, 0.1, 10000. );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glPushMatrix();
glTranslatef(0,-0.5,-0.5);
// glBindVertexArray(vao);
// glDrawElements(GL_TRIANGLES, indexdata.size(), GL_UNSIGNED_BYTE, (void*)0);
for(int i=0; i<smpl.mF.rows(); i++){
glBegin(GL_POLYGON);
for(int j=0; j<smpl.mF.cols(); j++){
indexdata.push_back(smpl.mF(i,j)+1);
}
glVertex3fv((const GLfloat*)&vertexdata[smpl.mF(i,0)].position);
glVertex3fv((const GLfloat*)&vertexdata[smpl.mF(i,1)].position);
glVertex3fv((const GLfloat*)&vertexdata[smpl.mF(i,2)].position);
glEnd();
}
glPopMatrix();
glutSwapBuffers();
glutPostRedisplay();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
glutMainLoopEvent();
}
However, if I use vertex buffers, i get rubbish output:
// Iterate v
for(int i=0; i<smpl.mVTemp2.rows(); i++){
Vertex v;
for(int j=0; j<smpl.mVTemp2.cols(); j++){
v.position[j] = smpl.mVTemp2(i,j);
}
vertexdata.push_back(v);
}
std::vector<GLubyte> indexdata;
// Iterate f
for(int i=0; i<smpl.mF.rows(); i++){
for(int j=0; j<smpl.mF.cols(); j++){
indexdata.push_back(smpl.mF(i,j));
}
}
// Create and bind a VAO
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// Create and bind a BO for vertex data
GLuint vbuffer;
glGenBuffers(1, &vbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vbuffer);
// copy data into the buffer object
glBufferData(GL_ARRAY_BUFFER, vertexdata.size() * sizeof(Vertex), &vertexdata[0], GL_STATIC_DRAW);
// set up vertex attributes
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position)); // vertices
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex, normal)); // normals
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texcoord)); // normals
// Create and bind a BO for index data
GLuint ibuffer;
glGenBuffers(1, &ibuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer);
// copy data into the buffer object
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexdata.size() * sizeof(GLubyte), &indexdata[0], GL_STATIC_DRAW);
glBindVertexArray(0);
while(1){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable(GL_LIGHTING);
glShadeModel( GL_SMOOTH );
glEnable( GL_TEXTURE_2D );
glViewport( 0, 0, (float)renderWidth/1, (float)renderHeight/1. );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60, (float)renderWidth/(float)renderHeight, 0.1, 10000. );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glPushMatrix();
glTranslatef(0,-0.5,-0.5);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, indexdata.size(), GL_UNSIGNED_BYTE, (void*)0);
glPopMatrix();
glutSwapBuffers();
glutPostRedisplay();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
glutMainLoopEvent();
}
I can't understand what I am doing wrong. I am able to draw the faces normally with regular old glVertex and it works, but is too slow. So I want to use vertex buffers, but the code always gives junk output. Why is this the case?
EDIT:
I have solved the problem, however my normals are now wrong. If I draw it normally with Vertex and Normal calls, it works:
std::vector<Vertex> vertexdata;
for(int i=0; i<object.vertices.size(); i++){
Vertex v;
v.position[0] = object.vertices.at(i).coords[0];
v.position[1] = object.vertices.at(i).coords[1];
v.position[2] = object.vertices.at(i).coords[2];
v.normal[0] = object.computedNormals.at(i).coords[0];
v.normal[1] = object.computedNormals.at(i).coords[1];
v.normal[2] = object.computedNormals.at(i).coords[2];
vertexdata.push_back(v);
}
std::vector<GLushort> indexdata;
for(int i=0; i<object.faces.size(); i++){
OBJFace& face = object.faces.at(i);
indexdata.push_back(face.items[0].vertexIndex);
indexdata.push_back(face.items[1].vertexIndex);
indexdata.push_back(face.items[2].vertexIndex);
glBegin(GL_POLYGON);
glNormal3fv(vertexdata[face.items[0].vertexIndex].normal);
glVertex3fv(vertexdata[face.items[0].vertexIndex].position);
glNormal3fv(vertexdata[face.items[1].vertexIndex].normal);
glVertex3fv(vertexdata[face.items[1].vertexIndex].position);
glNormal3fv(vertexdata[face.items[2].vertexIndex].normal);
glVertex3fv(vertexdata[face.items[2].vertexIndex].position);
glEnd();
}
However, if I use it with Vertex Buffers, it does not:
std::vector<Vertex> vertexdata;
for(int i=0; i<object.vertices.size(); i++){
Vertex v;
v.position[0] = object.vertices.at(i).coords[0];
v.position[1] = object.vertices.at(i).coords[1];
v.position[2] = object.vertices.at(i).coords[2];
v.normal[0] = object.computedNormals.at(i).coords[0];
v.normal[1] = object.computedNormals.at(i).coords[1];
v.normal[2] = object.computedNormals.at(i).coords[2];
vertexdata.push_back(v);
}
std::vector<GLushort> indexdata;
for(int i=0; i<object.faces.size(); i++){
OBJFace& face = object.faces.at(i);
indexdata.push_back(face.items[0].vertexIndex);
indexdata.push_back(face.items[1].vertexIndex);
indexdata.push_back(face.items[2].vertexIndex);
}
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbuffer);
// copy data into the buffer object
glBufferData(GL_ARRAY_BUFFER, vertexdata.size() * sizeof(Vertex), &vertexdata[0], GL_STATIC_DRAW);
// set up vertex attributes
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position)); // vertices
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, normal)); // normals
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texcoord)); // normals
// Create and bind a BO for index data
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer);
// copy data into the buffer object
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexdata.size() * sizeof(GLushort), &indexdata[0], GL_STATIC_DRAW);
glBindVertexArray(0);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, indexdata.size(), GL_UNSIGNED_SHORT, (void*)0);
In addition to the answer of Nicol Bolas:
It looks like as the number of indices is too much to encode them in bytes (GLubyte). A byte can store data in the range [0, 255], so only 256 indices can be encoded in a byte. Use GLushort instead. The range of GLushort is [0, 65535]:
std::vector<GLushort> indexdata;
....
GLuint ibuffer;
glGenBuffers(1, &ibuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexdata.size()*sizeof(GLushort),
indexdata.data(), GL_STATIC_DRAW);
....
glDrawElements(GL_TRIANGLES, indexdata.size(), GL_UNSIGNED_SHORT, (void*)0);
You are not using shaders for vertex processing. As such, generic vertex attributes (as provided by VertexAttrib functions) cannot be used. So, you can either switch to using shaders, or use fixed-function attributes:
// set up vertex attributes
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, position)); // vertices
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, normal)); // normals
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, texcoord)); // normals

Using Eigen::Vector3f with Opengl ES 2.0 VBO

I am having trouble getting Eigen::Vector3f and Opengl ES 2.0 VBO to work together.
My initial attempt was glVertexAttribPointer(VERTEX, 3, GL_FLOAT , sizeof(Vertex), 0 ).
While this draws nothing if I start to play with the stride values I can see a broken mesh.
This is my current code which leads to crash. In my old code I was using simple vector3 class made from 3 floats which was working fine.
struct Vertex {
Eigen::Vector3f pos ;
Eigen::Vector3f normal;
};
std::vector<Vertex> Vertices;
std::vector<ushort16> Indices;
...
GLuint vao;
uint32 vboID, vboID2;
glGenVertexArraysOES(1, &vao);
glBindVertexArrayOES(vao);
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, GL_STATIC_DRAW , sizeof(Vertex) * Vertices.size(), &Vertices[0]);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &vboID2);
glBindBuffer(GL_ARRAY_BUFFER, vboID2);
glBufferData(GL_ARRAY_BUFFER, GL_STATIC_DRAW , sizeof(ushort16) * m_vIndices.size(), &Indices[0]);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glEnableVertexAttribArray(VERTEX);
glVertexAttribPointer(VERTEX, 3, GL_FLOAT , sizeof(Vertex), &Vertices[0].pos );
glEnableVertexAttribArray(NORMAL);
glVertexAttribPointer(NORMAL, 3, GL_FLOAT , sizeof(Vertex), &Vertices[0].normal );
glBindBuffer(GL_ARRAY_BUFFER, vboID2);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArrayOES(0);
...
that solved my problem:
I removed the:
glBufferData(GL_ARRAY_BUFFER, GL_STATIC_DRAW , sizeof(Vertex) * Vertices.size(), &Vertices[0]);
And I changed these lines to
glVertexAttribPointer(VERTEX, 3, GL_FLOAT , sizeof(Vertex), Vertices[0].pos.data() );
....
glVertexAttribPointer(NORMAL, 3, GL_FLOAT , sizeof(Vertex), Vertices[0].normal.data() );

OpenGL VBO, VAO, Cubes, and Colors

I'm currently trying to get my head around VBOs and I'm running into some problems.
I'm using an interleaved array with position, colors, and normals. However, when I go to draw, the display is just white.
This is the structure of my array:
GLfloat position[3];
GLfloat normal[3];
GLfloat color[4];
Here's the code:
Initialization:
glGenBuffers(1, &arrays[0]);
glBindBuffer(GL_ARRAY_BUFFER, arrays[0]);
glBufferData(GL_ARRAY_BUFFER, 125*10*36*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenVertexArrays(1, &vaoID[1]);
glBindVertexArray(vaoID[1]);
glBindBuffer(GL_ARRAY_BUFFER, vaoID[1]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 40, ((void*)0));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 40, ((void*)12));
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, 40, ((void*)24));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBindVertexArray(0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Draw:
glPushMatrix();
glBindVertexArray(vaoID[1]);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 125*36);
glPopMatrix();
I'm making a 5x5 cube of cubes that spectrum in color from black to white. However, on draw, this is all I'm getting:
I see a problem with what you've posted above. You've defined your colors as being floats in the struct, but you're telling glVertexAttribPointer() that your colors are unsigned bytes. It should probably be something like this:
glVertexAttribPointer(2, 4, GL_FLOAT, GL_TRUE, 40, ((void*)24));
And that assumes that you're actually putting floats into those memory locations. How are you setting them?

VBO verses Vertex Array, vertex normals issue in VBO

I don't know what's wrong here, everything is working fine except normals.
When I use vertex array, model looks perfect but when I switch to VBO, model looks worse because of vertex normals. I spent a lot of time to fix it but do not know what's wrong. VBO generation seems perfect. but still do not know.
any idea?
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
void InitVBO(){
glGenBuffers(1, &vboNormID);
glBindBuffer(GL_ARRAY_BUFFER, vboNormID);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, NULL, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLpoint)*nb_Vertices, VertNormals);
glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12));
glGenBuffers(1, &vboVertID);
glBindBuffer(GL_ARRAY_BUFFER, vboVertID);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, NULL, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLpoint)*nb_Vertices, p_VERTICES);
glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0));
glGenBuffers(1, &indexVBOID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLFace)*nb_Faces, NULL, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(GLFace)*nb_Faces, p_indices);
//glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLFace)*nb_Faces, p_indices, GL_DYNAMIC_DRAW);}
Rendering code is followed. VBO + Vertex Array
Vertex array is working perfect. I can see the perfect shape of model with vertex normals, but with VBO there is some issue with vertex normals. I think I am doing something wrong with BUFFER_OFFSET(12).
void RenderTringularModel(GLvoid){
if(VertNormals && !MESH_SMOOTH)
{
glBindBuffer(GL_ARRAY_BUFFER, vboNormID);
glBindBuffer(GL_ARRAY_BUFFER, vboVertID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID);
glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12));
glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0));
glDrawElements(GL_TRIANGLES, nb_Faces*3, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glPopClientAttrib();
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
else
{
//glShadeModel (GL_FLAT);
glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), p_VERTICES);
glNormalPointer(GL_FLOAT, sizeof(GLpoint), VertNormals);
glDrawElements(GL_TRIANGLES, 3*nb_Faces, GL_UNSIGNED_INT, p_indices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glPopClientAttrib();
}
}
UPDATE 1:
I think you are talking about InitVBO.. I was wrong at that point. How about this...But it is also not working.. actually the issue it.. in many ways i tried to bind the vertex normals in InitVBO().. but result comes the same every time.
glGenBuffers(1, &vboVertID);
glBindBuffer(GL_ARRAY_BUFFER, vboVertID);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, NULL, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLpoint)*nb_Vertices, p_VERTICES);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, sizeof(GLpoint)*nb_Vertices, VertNormals);
glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0));
glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12));
Update 2:
Ok ... i don't bind the vertex normals (vboNormID). I am discarding it. is it ok now ? Now it should work.. Actually i have done everything in that way.. to bind the vertex normals with vboVertID and with vboNormID etc etc.. but not every single mathod is working.. give me any suggestion by analyzing this code.
void RenderTringularModel(GLvoid){
if(VertNormals && !MESH_SMOOTH)
{
glBindBuffer(GL_ARRAY_BUFFER, vboVertID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID);
glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(12));
glVertexPointer(3, GL_FLOAT, sizeof(GLpoint), BUFFER_OFFSET(0));
glDrawElements(GL_TRIANGLES, nb_Faces*3, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
Update 3:
I don't know who told me to use BUFFER_OFFSET()... just crap.. I have fixed it now, now working fine without this stupid BUFFER_OFFSET()..
Now the fixed code it really simple as follows:
void InitVBO(){
glGenBuffers(1, &vboVertID);
glBindBuffer(GL_ARRAY_BUFFER, vboVertID);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, p_VERTICES, GL_DYNAMIC_DRAW);
glGenBuffers(1, &vboNormID);
glBindBuffer(GL_ARRAY_BUFFER, vboNormID);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLpoint)*nb_Vertices, VertNormals, GL_DYNAMIC_DRAW);
glGenBuffers(1, &indexVBOID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLFace)*nb_Faces, p_indices, GL_DYNAMIC_DRAW);}
void RenderTringularModel(GLpoint *P, GLpoint *Vn, GLFace *T, int nbF){
glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vboVertID);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, vboNormID);
glNormalPointer(GL_FLOAT, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID);
glDrawElements(GL_TRIANGLES, nb_Faces*3, GL_UNSIGNED_INT, 0);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glPopClientAttrib();}
Now guys kindly guide me how can I update these buffers in real-time. I mean to say I need to update the whole data in real-time, normals, vertices, triangles.
for example: after subdivision of triangles, i would need to update the triangles buffer with vertices and normals too.. and another thing is, during cutting simulation of model, i need to update the vertices position and normals, so i would need to update the buffer at that point too.. so tell what do i do for this kind of issue ? how can i make it up ? do i need to delete the buffers and regenerate again ? if yes then how ?