How to load obj in opengl c++ without any jerks?

I loaded an obj file in opengl c++ by creating my own parser. I does work, but when i try rotating the obj,it rotates with a lot of jerks.
Is it possible to load the obj without affecting the program's speed?
Here is my code:

/*
*
* Demonstrates how to load and display an Wavefront OBJ file.
* Using triangles and normals as static object. No texture mapping.
*
* OBJ files must be triangulated!!!
* Non triangulated objects wont work!
* You can use Blender to triangulate
*
*/

#include <windows.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <SDL_opengl.h>
#include <glm.hpp>
#include <SOIL.h>
#include <glut.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
#include <postprocess.h>
#include <anim.h>
#include <mesh.h>
#include <scene.h>
#include <SOIL.h>

#define KEY_ESCAPE 27

using namespace std;

/************************************************************************
Window
************************************************************************/

typedef struct {
int width;
int height;
char* title;

float field_of_view_angle;
float z_near;
float z_far;
} glutWindow;



/***************************************************************************
OBJ Loading
***************************************************************************/


GLfloat scale = 0.5f;

#define POINTS_PER_VERTEX 3
#define TOTAL_FLOATS_IN_TRIANGLE 9
using namespace std;
int LoadObj(string name)
{
string line;
long double x[10000],y[10000],z[10000];
long double vt1[10000],vt2[10000];
long double vnx[10000],vny[10000],vnz[10000];
string material;
string texture;
int v[3], vt[3], vn[3];
string word;
int i = 0;
int l = 0;
int tt=0;
int k = 0;
ifstream myfile(name.c_str());
if(myfile.is_open())
{
while(!myfile.eof())
{
getline(myfile, line);
if(line.substr(0,7) == "usemtl ")
{
istringstream iss3(line.substr(6));
iss3 >> material;
if(material[material.length()-4]=='_')
{
material[material.length()-4]='.';
}
}
if(line.substr(0,2) == "v ")
{
i += 1;
istringstream iss(line.substr(2));
iss >> x[i]; iss >> y[i]; iss >> z[i];
}
if(line.substr(0,3) == "vt ")
{
l += 1;
istringstream iss(line.substr(3));
iss >> vt1[l]; iss >> vt2[l];
}
if(line.substr(0,3) == "vn ")
{
k += 1;
istringstream iss(line.substr(3));
iss >> vnx[k]; iss >> vny[k]; iss >> vnz[k];
}
if(line.substr(0,2) == "f ")
{
for(int j=0; j<line.length(); j++)
{
if(line[j] == '/')
{
line[j] = ' ';
}
}
istringstream iss(line.substr(2));
iss >> v[0]; iss >> vt[0]; iss >> vn[0]; iss >> v[1]; iss >> vt[1]; iss >> vn[1]; iss >> v[2]; iss >> vt[2]; iss >> vn[2];
static GLuint tex_2d1;
if(texture!= material)
{
tex_2d1 = SOIL_load_OGL_texture
(
material.c_str(),
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex_2d1);
glBegin(GL_TRIANGLES);
glTexCoord2d(vt1[vt[0]],vt2[vt[0]]);
glNormal3f(vnx[vn[0]], vny[vn[0]], vnz[vn[0]]);
glVertex3f(x[v[0]], y[v[0]], z[v[0]]);
glTexCoord2d(vt1[vt[1]],vt2[vt[1]]);
glNormal3f(vnx[vn[1]], vny[vn[1]], vnz[vn[1]]);
glVertex3f(x[v[1]], y[v[1]], z[v[1]]);
glTexCoord2d(vt1[vt[2]],vt2[vt[2]]);
glNormal3f(vnx[vn[2]], vny[vn[2]], vnz[vn[2]]);
glVertex3f(x[v[2]], y[v[2]], z[v[2]]);
glEnd();
glDisable(GL_TEXTURE_2D);
texture=material;
}
}
myfile.close();
}
else
{
cout << "Unable to open file";
}
return 1;
}



float g_rotation;
glutWindow win;

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt( 0,1,4, 0,0,0, 0,1,0);
glPushMatrix();
glRotatef(g_rotation,0,1,0);
glRotatef(-90,1,0,0);
glRotatef(0,1,0,0);
g_rotation+=1;
glScalef(0.2,0.2,0.2);
LoadObj("boy3.obj");
glEnable(GL_CULL_FACE);
glEnable(GL_SHADE_MODEL);
glPopMatrix();
glutSwapBuffers();
}


void initialize ()
{
glMatrixMode(GL_PROJECTION);
glViewport(0, 0, win.width, win.height);
GLfloat aspect = (GLfloat) win.width / win.height;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(win.field_of_view_angle, aspect, win.z_near, win.z_far);
glMatrixMode(GL_MODELVIEW);
glShadeModel( GL_SMOOTH );
glClearColor( 0.0f, 0.1f, 0.0f, 0.5f );
glClearDepth( 1.0f );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LEQUAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

GLfloat amb_light[] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat diffuse[] = { 0.6, 0.6, 0.6, 1 };
GLfloat specular[] = { 0.7, 0.7, 0.3, 1 };
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, amb_light );
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
glEnable( GL_LIGHT0 );
glEnable( GL_COLOR_MATERIAL );
glShadeModel( GL_SMOOTH );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
glDepthFunc( GL_LEQUAL );
glEnable( GL_DEPTH_TEST );
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}


void keyboard ( unsigned char key, int x, int y )
{
switch ( key ) {
case KEY_ESCAPE:
exit(0);
break;
default:
break;
}
}

int main(int argc, char **argv)
{
// set window values
win.width = 640;
win.height = 480;
win.title = "Blender";
win.field_of_view_angle = 45;
win.z_near = 1.0f;
win.z_far = 500.0f;

// initialize and run program
glutInit(&argc, argv); // GLUT initialization
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); // Display Mode
glutInitWindowSize(win.width,win.height); // set window size
glutCreateWindow(win.title); // create Window
glutDisplayFunc(display); // register Display Function
glutIdleFunc( display ); // register Idle Function
glutKeyboardFunc( keyboard ); // register Keyboard Handler
initialize();

glutMainLoop(); // run GLUT mainloop
return 0;
}

Please help me modify this code!
THANKS IN ADVANCE!!
Topic archived. No new replies allowed.