Drawing obj file

OBJ file: download the file
“0.1 0.2 0.3” after the 1st “v” is the xyz position for the first vertex, and the numbers “0.8 0.8 0.8” after the 1st “vc” is its RGB color. Similarly, three integers after the 1st “f” are vertex indices for the first face.
when I use
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3,GL_FLOAT,0,vertex);
glColorPointer(3,GL_FLOAT,0,color);
glDrawElements(GL_TRIANGLES,3*NUMTRIANGLES,GL_UNSIGNED_SHORT,index);
in VC6,it collapsed,
how can I draw this obj file?Thanks

how do you load the OBJ ?
Maybe you should use a Debugger or show more code :slight_smile:

You also could search for an OBJ loader…

I draw it like this,but it do not work

#include <math.h>
#include <stdlib.h>
#ifdef APPLE
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <windows.h>
#include <stdio.h>
#include <data.h>
#define false 0
#define true 1
int i;
void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-0.5,0.5,-0.5,0.5,-0.5,0.5);
glMatrixMode(GL_MODELVIEW);
}

void colorcube(void)
{
static GLfloat position [] = {0.0,0.0,1.0,1.0};
static GLfloat color [] = {0.5,0.25,0.0,1.0};
glLightfv(GL_LIGHT0,GL_POSITION,position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,color);
glDrawElements(GL_TRIANGLES ,3*NUMTRIANGLES,GL_UNSIGNED_BYTE,index);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
colorcube();
glutSwapBuffers();
}

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow(“Mesh Grid”);
glutReshapeFunc(myReshape);
glutDisplayFunc(display);

glEnable(GL_DEPTH_TEST); 
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_INDEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3,GL_FLOAT,0,vertex);
glIndexPointer(GL_FLOAT,0,index);
glColorPointer(3,GL_FLOAT,0,color);
glutMainLoop();

}

data of (vertex color index ) in the objfile