我正在使用一个处理Wavefront OBJ 3D对象文件的解析器,但我不确定我是否正确地将其加载到OpenGL中。
基本上,我读取我的Wavefront OBJ文件并解析所有数据。
通常在加载数据时,我会按照以下步骤在OpenGL ES 1.1中进行:
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();
关于OpenGL ES 2.0,我尝试了以下内容来处理顶点,但没有成功:
glBufferData(GL_ARRAY_BUFFER, obj.vertices.size()*sizeof(float), &(obj.vertices[0].v), GL_STATIC_DRAW);
我的数据结构:
struct vertex {
std::vector<float> v;
}
每个顶点都会创建一个名为v
的向量,其包含{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;
};
我该如何像在OpenGL ES 1.1中那样加载我的数据到2.0中?
另外,是否可以加载矢量(v
),而不是分别加载位置(float x,y,z
)?