Im working with a parser that handles Wavefront OBJ 3D object files and im not quite sure if im doing the loading correctly into OpenGL.
So basically what i do is that i read my Wavefront OBJ files and parse all data.
Normally in OpenGL ES 1.1 i do following when loading data:
glBegin(GL_TRIANGLES);
glNormal3f(normals[faces[i].normal[0]].v[0], normals[faces[i].normal[0]].v[1], normals[faces[i].normal[0]].v[2]);
glVertex3f(vertices[faces[i].vertex[0]].v[0], vertices[faces[i].vertex[0]].v[1], vertices[faces[i].vertex[0]].v[2]);
glNormal3f(normals[faces[i].normal[1]].v[0], normals[faces[i].normal[1]].v[1], normals[faces[i].normal[1]].v[2]);
glVertex3f(vertices[faces[i].vertex[1]].v[0], vertices[faces[i].vertex[1]].v[1], vertices[faces[i].vertex[1]].v[2]);
glNormal3f(normals[faces[i].normal[2]].v[0], normals[faces[i].normal[2]].v[1], normals[faces[i].normal[2]].v[2]);
glVertex3f(vertices[faces[i].vertex[2]].v[0], vertices[faces[i].vertex[2]].v[1], vertices[faces[i].vertex[2]].v[2]);
glEnd();
As for OpenGL ES 2.0 i have tried following for the vertices without any luck:
glBufferData(GL_ARRAY_BUFFER, obj.vertices.size()*sizeof(float), &(obj.vertices[0].v), GL_STATIC_DRAW);
My datastructure:
struct vertex {
std::vector<float> v;
}
The v
vector is created for each vertex offcourse, with {x,y,z}
.
class waveObj {
public:
std::vector<vertex> vertices;
std::vector<vertex> texcoords;
std::vector<vertex> normals;
std::vector<vertex> parameters;
std::vector<face> faces;
}
struct face {
std::vector<int> vertex;
std::vector<int> texture;
std::vector<int> normal;
};
How can i load my data as i done with OpenGL ES 1.1 in 2.0?
Also is it even possible to load a vector (v
), rather than the positions seperate (float x,y,z
)?