Hey there, so for a while I've been trying to switch to glDrawArrays and I've been using glDrawElements. I tried to use the indices to create a new list with the new vertices in it so I don't need to use indices but it's not coming drawing properly :/
Any Ideas? Sorry for the messy code its my experiment project.
extern struct TEST
{
vector<GLfloat>vertices;
vector<GLfloat>texcoords;
vector<GLuint>indices;
};
extern vector<TEST> out_vertex;
int LOBJ_Loader::LoadTriOBJ(char *filename,int num)
{
ifstream fobj;
string line;
fobj.open(filename,ios::in);
while(!fobj.eof())
{
getline(fobj,line);
if(line[0] == 'v')
{
sscanf_s(line.c_str(),"v %f %f %f",&obj[num].x,&obj[num].y,&obj[num].z);
obj[num].vertices.push_back(obj[num].x);
obj[num].vertices.push_back(obj[num].y);
obj[num].vertices.push_back(obj[num].z);
}
if (line[0] == 'f ')
{
sscanf_s(line.c_str(), "f %d %d %d ", &obj[num].f1, &obj[num].f2, &obj[num].f3);
obj[num].f1 = obj[num].f1 - 1;
obj[num].f2 = obj[num].f2 - 1;
obj[num].f3 = obj[num].f3 - 1;
obj[num].faces.push_back(obj[num].f1);
obj[num].faces.push_back(obj[num].f2);
obj[num].faces.push_back(obj[num].f3);
}
}
fobj.close();
//convert old vertex to new vertex
for (int i = 0; i < obj[obj_num].faces.size(); i++)
{
out_vertex[0].vertices.push_back(obj[obj_num].vertices[obj[obj_num].faces[i]]);
//the line above runs through the indices using I and adds the vertex[indices] to the out_vertex vector
}
obj_num = obj_num+1;
return 0;
}
// rendering triangle
bool LRender::Render()
{
current = tim->GetTime();
if (GetKey[SPACEBAR])
{
tim->ResetTimer();
}
if(GetKey[LEFT_ARROW])
{
Camera.RAngleY(sensitivity);
//Display();
}
if(GetKey[VK_RIGHT])
{
Camera.RAngleY(-sensitivity);
//Display();
}
if(GetKey[W])
{
Camera.MoveForwards( -fSpeed ) ;
//Display();
}
if(GetKey[S])
{
Camera.MoveForwards( bSpeed) ;
//Display();
}
if(GetKey[UP_ARROW])
{
Camera.RAngleX(sensitivity);
//Display();
}
if(GetKey[DOWN_ARROW])
{
Camera.RAngleX(-sensitivity);
//Display();
}
if(GetKey[A])
{
Camera.StrafeRight(-StrafeSpeed);
//Display();
}
if(GetKey[D])
{
Camera.StrafeRight(StrafeSpeed);
//Display();
}
if(GetKey[E])
{
Camera.Move(F3dVector(0.0,-upSpeed,0.0));
//Display();
}
if(GetKey[Q])
{
Camera.Move(F3dVector(0.0,downSpeed,0.0));
//Display();
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glClearColor(0.1f, 0.4f, 0.7f, 0.3f);
Camera.Render();
for (int i = 0; i < 1; i++)
{
glPushMatrix();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &out_vertex[objt].vertices[0]);
glColor3d(1, 1, 1);
glTranslatef(com[i].Object.Triangle.translate[0], com[i].Object.Triangle.translate[1], com[i].Object.Triangle.translate[2]);
glScalef(com[i].Object.Triangle.scale[0] + 1, com[i].Object.Triangle.scale[1] + 1, com[i].Object.Triangle.scale[2] + 1);
glRotatef(com[i].Object.Triangle.rotation[0], com[i].Object.Triangle.rotation[1], com[i].Object.Triangle.rotation[2], com[i].Object.Triangle.rotation[3]);
glDrawArrays(GL_TRIANGLES, 0, out_vertex[objt].vertices.size());
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
return true;
};