コード例 #1
0
ファイル: viewer.c プロジェクト: andresrcc/opengl
void dibujar_objetos(){

  glEnable(GL_LIGHTING);
  //Dibujamos
  glPushMatrix();
  glTranslatef(objetos[1].x,objetos[1].y,objetos[1].z);
  glColor3f(2,8,3);

  //modelo = glmReadOBJ(path_archivo);
  //if (!modelo) exit (0); //si no existe, exit

  glmUnitize(modelo_CARRO);
  glmFacetNormals(modelo_CARRO);
  glmVertexNormals(modelo_CARRO, 90.0);
  glEnable(GL_COLOR_MATERIAL);
  glmDraw(modelo_CARRO, GLM_SMOOTH | GLM_MATERIAL);
  glDisable(GL_COLOR_MATERIAL);
  glPopMatrix();
  
  glPushMatrix();
  glTranslatef(objetos[2].x,objetos[2].y,objetos[2].z);
  glColor3f(2,8,3);
  
  glmUnitize(modelo_AVION);
  glmFacetNormals(modelo_AVION);
  glmVertexNormals(modelo_AVION, 90.0);
  glEnable(GL_COLOR_MATERIAL);
  glmDraw(modelo_AVION, GLM_SMOOTH | GLM_MATERIAL);
  glDisable(GL_COLOR_MATERIAL);
  glPopMatrix();
  glDisable(GL_LIGHTING);

}
コード例 #2
0
bool COBJNode::Load(char* filename) {

#if CAVEMOD
	/*init DLarr */
	for (int i=0; i<10; i++){
		DLarr[i]=-1;
	}
#endif

	if ( _model_p == NULL ) { // model still not loaded
		// read model from file
		_model_p = glmReadOBJ(filename);

		if(_model_p == NULL)
			return false;

		// translate model to the origin and scale it
		// to fit in a unit cube around the origin = "unitize"
		glmUnitize(_model_p);
		// precompute normal vectors
		glmFacetNormals(_model_p);
		glmVertexNormals(_model_p, 90.0);
#if CAVEMOD
		// do not create DL... create on first update instead
		//_modelDL = glmList(_model_p, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE);
#else
		// create display list
		_modelDL = glmList(_model_p, GLM_SMOOTH | GLM_MATERIAL | GLM_TEXTURE);
#endif
	}

	return true;
}
コード例 #3
0
ファイル: smooth.c プロジェクト: virtualboys/smoothVSM
void
init(void)
{
    
    renderShaderID = loadShaders("shaders/vShader.c", "shaders/fShader.c");
    shadowShaderID = loadShaders("shaders/shadowVShader.c", "shaders/shadowFShader.c");
    
    //initShadowMap();
    
    gltbInit(GLUT_LEFT_BUTTON);
    
    /* read in the model */
    model = glmReadOBJ(model_file);
    scale = glmUnitize(model);
    glmFacetNormals(model);
    glmVertexNormals(model, smoothing_angle);
    
    if (model->nummaterials > 0)
        material_mode = 2;
    
    /* create new display lists */
    lists();
    
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
    
    //glEnable(GL_DEPTH_TEST);
    
    //glEnable(GL_CULL_FACE);
}
コード例 #4
0
ファイル: IndoorModel.cpp プロジェクト: LucRyan/Final-Village
IndoorModel::IndoorModel(char* fileName, 
	stack<mat4> *mvStack, GLuint program,
	vec4 transVec, vec3 rotVec, vec3 scalVec,
	bool texFlag, char* fileTextrue, int txWidth, int txHeight )
{
	_model = glmReadOBJ(fileName); //Loading the model
	if (!_model) exit(0); // See if it success

	glmUnitize(_model);	// Normalize vertices
	glmFacetNormals(_model); // Compute facet normals
	glmVertexNormals(_model, 90.0); // Compute vertex normals
	glmLinearTexture(_model); //Map the texture to Model
	glmLoadGroupsInVBO(_model); // Load the model (vertices and normals) into a vertex buffer

	//World Coordinates Information
	_mvStack = mvStack;
	_program = program;
	_transVec = transVec;
	_rotVec = rotVec;
	_scalVec = scalVec;

	//Textures Information
	_texFlag = texFlag;
	_alphaFlag = false;
	if(texFlag){
		_textures = glmReadPPM(fileTextrue, txWidth, txHeight);
		_txWidth = txWidth;
		_txHeight = txHeight;
	}
}
コード例 #5
0
ファイル: Model.cpp プロジェクト: sidner/FF7-Chess
Model::Model (string mod, char prolog[2],float normal)
{
    //Model
    model = NULL;
    char* path = (char*)malloc(sizeof(char)*mod.length()*10);
    sprintf(path, "../obj/%s",mod.c_str ());

    if (!model)
    {
        // this is the call that actualy reads the OBJ and creates the model object
        model = glmReadOBJ (path);

        if (!model) exit (0);
        // This will rescale the object to fit into the unity matrix
        // Depending on your project you might want to keep the original size and positions you had in 3DS Max or GMAX so you may have to comment this.
        glmUnitize (model);
        // These 2 functions calculate triangle and vertex normals from the geometry data.
        // To be honest I had some problem with very complex models that didn't look to good because of how vertex normals were calculated
        // So if you can export these directly from you modeling tool do it and comment these line
        // 3DS Max can calculate these for you and GLM is perfectly capable of loading them
        glmFacetNormals (model);
        glmVertexNormals (model, normal);
    }

    pos[0] = 0.0;
    pos[1] = 0.0;
    pos[2] = 0.0;

    isPicked = false;
    
    name = 10;
    strcpy (prologRep,prolog);
    checked= false;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: Sylvanuszhy/IBL
void drawBunny(const char * objname)
{
	GLMmodel* pModel = NULL;
	// The obj file will be loaded
	char FileName[128];
	sprintf(FileName, "%smodels/%s.obj", root, objname);

	// Center of the model
	float modelCenter[] = { 0.0f, 0.0f, 0.0f };

	// Load the new obj model
	pModel = glmReadOBJ(FileName);

	// Scale the model to fit the screen
	glmUnitize(pModel, modelCenter);

	// Generate normal for the model
	glmFacetNormals(pModel);
	
	glmScale(pModel, 1.5);
	glmVertexNormals(pModel, 90.0f);

	if (pModel)
	{
		glmDraw(pModel, GLM_SMOOTH);
	}
}
コード例 #7
0
//GLuint resol = 50;
void init_object(void)
{
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat mat_shininess[] = { 50.0 };
    //GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_SMOOTH);

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    //glLightfv(GL_LIGHT, GL_POSITION, light_position);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT1);
    //glEnable(GL_DEPTH_TEST);

    {
        pmodel = glmReadOBJ("soccerball.obj");
        if (!pmodel) exit(0);
        glmUnitize(pmodel);
        glmFacetNormals(pmodel);
        glmVertexNormals(pmodel, 90.0);
    }

}
コード例 #8
0
ファイル: source.cpp プロジェクト: terryfeverpitch/GLSL
void init()
{
	glewInit();
	glEnable (GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	glClearColor(.4, .4, .4, 1);
	initFBO(fbo1, depthBuffer1, img1);
	initFBO(fbo2, depthBuffer2, img2);

	checkboard = pngBind("checkboard.png", PNG_NOMIPMAP, PNG_ALPHA, NULL, GL_REPEAT, GL_NEAREST, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, checkboard);
	glEnable(GL_TEXTURE_2D);

	extern GLuint setShaders(char* vert_file, char* frag_file);
	greyFilter = setShaders("greyFilter.vert", "greyFilter.frag");
	mosaicFilter = setShaders("mosaicFilter.vert", "mosaicFilter.frag");

	// load OBJ model
	m1 = glmReadOBJ ("al.obj");
	glmUnitize (m1);
	glmFacetNormals (m1);
	glmVertexNormals (m1, 90);
}
コード例 #9
0
ファイル: Model.cpp プロジェクト: FeiZhu/MeshColorRender
bool Model::LoadModel(char* obj_file, char* color_file)
{
	model = glmReadOBJ(obj_file);
	if(!model)
		return false;

	//normal
	if( ! model->normals )
	{
		glmFacetNormals(model);
		glmVertexNormals(model, 90.0);

		assert(model->numnormals == model->numvertices);
	}

	//bbox
	bbox = new BBox();
	float dim[3];
	float center[3];
	glmDimensions(model, dim);
	glmCenter(model, center);
	for(int i = 0; i < 3; i++)
	{
		bbox->min[i] = center[i] - dim[i] / 2.0;
		bbox->max[i] = center[i] + dim[i] / 2.0;
	}

	//color
	return readColor(color_file);
}
コード例 #10
0
ファイル: main - backup.cpp プロジェクト: istinj/MedRob_Rob2
/*******************************************************************************
 Initialize the OBJ Model and create display list.
*******************************************************************************/
void initOBJModel()
{
    if (!objmodel)
    {
        objmodel = glmReadOBJ(model1Path);

        if (!objmodel)
        {
            printf("OBJ file does not exist \n");
            exit(0);
        }

        glmUnitize(objmodel);
        glmFacetNormals(objmodel);
        glmVertexNormals(objmodel, 90.0);
    }

//Create display for the OBJ model
    objList = glGenLists(1);
    glNewList( objList, GL_COMPILE );
    glmDraw(objmodel, GLM_SMOOTH | GLM_TEXTURE );
    glEndList();

//Create the display list for the modified
// displacement mapped OBJ Model
    bumpList = glGenLists(1);
    glNewList( bumpList, GL_COMPILE );
    drawGLMbump();

    glEndList();
}
コード例 #11
0
ファイル: player.cpp プロジェクト: gverma14/Don-t-Be-Dinner
void Player::drawmodel_fish_AI()
{
	
	double x1 = x-2;
	double x2 = x+2;
	double y1 = y;
	double y2 = y+10;
	double z1 = -(z-2);
	double z2 = -(z+2);

	
	
	glTranslatef(x, y, -z);
	glRotatef(180-t,0,1,0);

	if (!pmodel4) 
	{
		//printf("Simple Loaded\n");
		pmodel4 = glmReadOBJ("test3.obj");	 //glm.cpp
        if (!pmodel4) exit(0);
	//	glmUnitize(pmodel1);				 //glm.cpp
		glmFacetNormals(pmodel4);			 //glm.cpp   
		glmVertexNormals(pmodel4, 90.0);     //glm.cpp
    }

    glmDraw(pmodel4, GLM_SMOOTH| GLM_TEXTURE);//glm.cpp
	


}
コード例 #12
0
void Object::loadOBJ(string filename) 
{

    if(filename.size() == 0)
    {
        cerr << "OBJ filename is empty.";
        exit(1);
    }

    char * OBJFilename = new char[filename.size() + 1];
    strcpy(OBJFilename, filename.c_str());

    model = glmReadOBJ(OBJFilename);
    if (!model) 
    {
        cerr << "Unable to load the model " << OBJFilename;
        exit(1);
    }

    glmUnitize(model);
    // These 2 functions calculate triangle and vertex normals from the geometry data.
    // To be honest I had some problem with very complex models that didn't look to good because of how vertex normals were calculated
    // So if you can export these directly from you modeling tool do it and comment these line
    // 3DS Max can calculate these for you and GLM is perfectly capable of loading them
    glmFacetNormals(model);
    glmVertexNormals(model, 90.0, GL_TRUE);
}
コード例 #13
0
ファイル: smooth.c プロジェクト: amlanpradhan/GLUT
void
init(void)
{
    gltbInit(GLUT_LEFT_BUTTON);
  
    /* read in the model */
    model = glmReadOBJ(model_file);
    scale = glmUnitize(model);
    glmFacetNormals(model);
    glmVertexNormals(model, smoothing_angle);

    if (model->nummaterials > 0)
	material_mode = 2;

    /* create new display lists */
    lists();

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

    glEnable(GL_DEPTH_TEST);

    glEnable(GL_CULL_FACE);
}
コード例 #14
0
ファイル: cModelLoader.cpp プロジェクト: euanmcmen/GPCWGame
//Loads the model with a given file name and no texture.
void cModelLoader::loadModel(const char* mdlFilename)
{
	m_model = glmReadOBJ(mdlFilename);
	glmUnitize(m_model);
	glmFacetNormals(m_model);
	glmVertexNormals(m_model, 180.0,false);
}
コード例 #15
0
// ----------------------------------------------- //
void init_model() {
    model = glmReadOBJ("../data/al.obj");
    if (!model) exit(0);
    glmUnitize(model);
    glmFacetNormals(model);
    glmVertexNormals(model, 90.0);
    glmDimensions(model, model_dimensions);
}
コード例 #16
0
ファイル: cModelLoader.cpp プロジェクト: euanmcmen/GPCWGame
//Loads a model with a given file name and texture ID.
void cModelLoader::loadModel(const char* mdlFilename, GLuint textureID)
{
	m_model = glmReadOBJ(mdlFilename);
	glmUnitize(m_model);
	glmFacetNormals(m_model);
	glmVertexNormals(m_model, 180.0,false);
	m_TextureID = textureID;
	m_model->textures[m_model->numtextures - 1].id = m_TextureID;
}
コード例 #17
0
void MyGLCloudViewer::loadARModel(char *fileName)
{

	ARModel = glmReadOBJ(fileName);
    if (!ARModel) exit(0);
    glmUnitize(ARModel);
    glmFacetNormals(ARModel);
    glmVertexNormals(ARModel, 90.0);
    
}
コード例 #18
0
ファイル: ex1.cpp プロジェクト: rd3k/WaterSprinkler
void drawModel () {
 if (!testModel) {
   testModel = glmReadOBJ("weapon.obj");
   if (!testModel) exit(0);
   glmUnitize(testModel);
   glmFacetNormals(testModel);
   glmVertexNormals(testModel, 90.0);
 }
 glmDraw (testModel, GLM_SMOOTH);
}
コード例 #19
0
GLMmodel* Model::get_obj_model(const char* filename)
{
    GLMmodel* m = glmReadOBJ((char*) filename);
    if (m->numnormals == 0) {
        VERBOSE("Auto generating normals...");
        glmFacetNormals(m);
        glmVertexNormals(m, 90.0);
    }
    return m;
}
コード例 #20
0
void Canhao::carregaOBJ(char* p_base, char* p_canhao){
    if(!_baseTanque) {
        _baseTanque = glmReadOBJ(p_base);
        if(!_baseTanque)
            std::cerr << "Não foi possível carregar o arquivo .OBJ da base do tanque" << std::endl;
        glmUnitize(_baseTanque);
        glmFacetNormals(_baseTanque);
        glmVertexNormals(_baseTanque,180.0);
    }

    if(!_canhaoTanque) {
        _canhaoTanque = glmReadOBJ(p_canhao);
        if(!_canhaoTanque)
            std::cerr << "Não foi possível carregar o arquivo .OBJ do canhao do tanque" << std::endl;
        glmUnitize(_canhaoTanque);
        glmFacetNormals(_canhaoTanque);
        glmVertexNormals(_canhaoTanque,180.0);
    }
}
コード例 #21
0
OFX_OBJLOADER_BEGIN_NAMESPACE

void load(string path, ofMesh& mesh, bool generateNormals, bool flipFace)
{
	path = ofToDataPath(path);

	mesh.clear();

	GLMmodel* m;

	m = glmReadOBJ((char*)path.c_str());

	if (generateNormals)
	{
		glmFacetNormals(m);
		glmVertexNormals(m, 90);
	}

	if (flipFace)
	{
		glmReverseWinding(m);
	}

	for (int j = 0; j < m->numtriangles; j++)
	{
		const GLMtriangle &tri = m->triangles[j];

		for (int k = 0; k < 3; k++)
		{
			GLfloat *v = m->vertices + (tri.vindices[k] * 3);
			mesh.addVertex(ofVec3f(v[0], v[1], v[2]));

			if (m->colors)
			{
				GLfloat *c = m->colors + (tri.vindices[k] * 3);
				mesh.addColor(ofFloatColor(c[0], c[1], c[2]));
			}

			if (m->normals && ofInRange(tri.nindices[k], 0, m->numnormals))
			{
				GLfloat *n = m->normals + (tri.nindices[k] * 3);
				mesh.addNormal(ofVec3f(n[0], n[1], n[2]));
			}

			if (m->texcoords && ofInRange(tri.tindices[k], 0, m->numtexcoords))
			{
				GLfloat *c = m->texcoords + (tri.tindices[k] * 2);
				mesh.addTexCoord(ofVec2f(c[0], c[1]));
			}
		}
	}

	glmDelete(m);
}
コード例 #22
0
ファイル: code(backup).cpp プロジェクト: felarof99/GhostRacer
void drawmodel_box4(void)
{
	if (!pmodel4)
	{
	    pmodel4 = glmReadOBJ("bike4.obj");
        if (!pmodel4) exit(0);
	    glmUnitize(pmodel4);
		glmFacetNormals(pmodel4);
		glmVertexNormals(pmodel4, 90.0);
    }
    glmDraw(pmodel4, GLM_SMOOTH| GLM_TEXTURE);
}
コード例 #23
0
ファイル: code(backup).cpp プロジェクト: felarof99/GhostRacer
void drawmodel_box3(void)
{
	if (!pmodel3)
	{
	    pmodel3 = glmReadOBJ("bike3.obj");
        if (!pmodel3) exit(0);
	    glmUnitize(pmodel3);
		glmFacetNormals(pmodel3);
		glmVertexNormals(pmodel3, 90.0);
    }
    glmDraw(pmodel3, GLM_SMOOTH| GLM_TEXTURE);
}
コード例 #24
0
ファイル: code(backup).cpp プロジェクト: felarof99/GhostRacer
void drawmodel_box(void)
{
	if (!pmodel1)
	{
	    pmodel1 = glmReadOBJ("bike1.obj");
        if (!pmodel1) exit(0);
	    glmUnitize(pmodel1);
		glmFacetNormals(pmodel1);
		glmVertexNormals(pmodel1, 90.0);
    }
    glmDraw(pmodel1, GLM_SMOOTH| GLM_TEXTURE);
}
コード例 #25
0
ファイル: code(backup).cpp プロジェクト: felarof99/GhostRacer
void drawmodel_box5(void)
{
	if (!pmodel5)
	{
	    pmodel5 = glmReadOBJ("bike5.obj");
        if (!pmodel5) exit(0);
	    glmUnitize(pmodel5);
		glmFacetNormals(pmodel5);
		glmVertexNormals(pmodel5, 90.0);
    }
    glmDraw(pmodel5, GLM_SMOOTH| GLM_TEXTURE);
}
コード例 #26
0
ファイル: cModelLoader.cpp プロジェクト: euanmcmen/GPCWGame
//Loads a model with a given file name and texture.
void cModelLoader::loadModel(const char* mdlFilename, cTexture mdlTexture)
{
	m_model = glmReadOBJ(mdlFilename);
	glmUnitize(m_model);
	glmFacetNormals(m_model);
	glmVertexNormals(m_model, 180.0f,false);
	m_TextureID = mdlTexture.getTexture();

	m_model->textures[m_model->numtextures - 1].id = m_TextureID;
	m_model->textures[m_model->numtextures - 1].width = mdlTexture.getTWidth();
	m_model->textures[m_model->numtextures - 1].height = mdlTexture.getTHeight();
}
コード例 #27
0
ファイル: projection.c プロジェクト: aquatix/amaze
void
drawmodel(void)
{
    if (!pmodel) {
        pmodel = glmReadOBJ("data/al.obj");
        if (!pmodel) exit(0);
        glmUnitize(pmodel);
        glmFacetNormals(pmodel);
        glmVertexNormals(pmodel, 90.0);
    }
    
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
}
コード例 #28
0
void
drawmodel(void)
{
    if (!pmodel) {
        pmodel = glmReadOBJ((char*)"../data/soccerball.obj");
        if (!pmodel) exit(0);
        glmUnitize(pmodel);
        glmFacetNormals(pmodel);
        glmVertexNormals(pmodel, 90.0);
    }

    glmDraw(pmodel, GLM_SMOOTH);
}
コード例 #29
0
	/**
	 * Loads a model from a .obj file and returns the model object.
	 * 
         * @param filename Filename of the model.
         * @return 
         */
	model* obj_loader::load_file(const char* filename) const
	{
		char* fptr = (char*)filename;
		GLMmodel* glm_model = glmReadOBJ(fptr);
	
		//glmUnitize(glm_model);
		glmFacetNormals(glm_model);
		glmVertexNormals(glm_model, 90.0);
		
		model* result = new model(glm_model);
		
		return result;
	}
コード例 #30
0
ファイル: ModelOBJ.cpp プロジェクト: DavidRVi/PhysicsPractice
bool ModelOBJ::Load(char *filename, bool addForCollision)
{
	model = glmReadOBJ(filename);
	if(!model) return false;
    glmUnitize(model);
    glmFacetNormals(model);
    glmVertexNormals(model, 90.0);
	
	if (addForCollision)
		AddToCollisionEngine();

	return true;
}