PDA

View Full Version : Drawing obj file



rooxue
10-30-2009, 06:44 PM
OBJ file: download the file (http://mail.qq.com/cgi-bin/ftnExs_download?k=7e386536a228c7ca437485221264041a 0d5903010454000015015d5306490201595a48540050011800 5d570e575107570008525034763652594a02594d08536a5b57 0959464a59575238&t=exs_ftn_download&code=88e64d65)
"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_UNSI GNED_SHORT,index);
in VC6,it collapsed,
how can I draw this obj file?Thanks

DarkShadow44
10-31-2009, 11:55 AM
how do you load the OBJ ?
Maybe you should use a Debugger or show more code :)

You also could search for an OBJ loader...

rooxue
11-01-2009, 06:18 AM
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_DIFF USE,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(&amp;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