Beispiel #1
0
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);
}
Beispiel #2
0
/*******************************************************************************
 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();
}
Beispiel #3
0
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;
}
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);
}
Beispiel #5
0
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);
}
//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);
    }

}
// ----------------------------------------------- //
void init_model() {
    model = glmReadOBJ("../data/al.obj");
    if (!model) exit(0);
    glmUnitize(model);
    glmFacetNormals(model);
    glmVertexNormals(model, 90.0);
    glmDimensions(model, model_dimensions);
}
Beispiel #8
0
//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;
}
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;
}
Beispiel #10
0
void drawModel () {
 if (!testModel) {
   testModel = glmReadOBJ("weapon.obj");
   if (!testModel) exit(0);
   glmUnitize(testModel);
   glmFacetNormals(testModel);
   glmVertexNormals(testModel, 90.0);
 }
 glmDraw (testModel, GLM_SMOOTH);
}
void MyGLCloudViewer::loadARModel(char *fileName)
{

	ARModel = glmReadOBJ(fileName);
    if (!ARModel) exit(0);
    glmUnitize(ARModel);
    glmFacetNormals(ARModel);
    glmVertexNormals(ARModel, 90.0);
    
}
Beispiel #12
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);
    }
}
Beispiel #13
0
Wheel::Wheel(char *tyreFile) {
	rad = 7;
	//getTextures();
	wheel_model = glmReadOBJ(tyreFile);
	glmUnitize(wheel_model);
	glmVertexNormals(wheel_model, 90.0, GL_TRUE);
	angle = 0;
    
    
    
}
Beispiel #14
0
House::House(char *filename, float x, float z, float scal) {
    posX = x;
    posZ = z;
    
  	
		hmodel = glmReadOBJ(filename);
		glmUnitize(hmodel);
		glmVertexNormals(hmodel, 90.0, GL_TRUE);
		makeHouseDispList();
		scalef = scal;
}
Beispiel #15
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);
}
Beispiel #16
0
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);
}
Beispiel #17
0
//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();
}
Beispiel #18
0
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);
}
Beispiel #19
0
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);
}
Beispiel #20
0
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);
}
Beispiel #21
0
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;
}
Beispiel #22
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;
	}
Beispiel #23
0
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);
}
Beispiel #24
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);
}
Beispiel #25
0
CGlObjLoader::CGlObjLoader(char* fname)
{
//    _left = 0.0;		/* ortho view volume params */
//    _right = 0.0;
//    _bottom = 0.0;
//    _top = 0.0;
//    _zNear = 0.1;
//    _zFar = 10.0;
//    fovy = 45.0;
//    prev_z = 0;

    //mode = 0;		/* viewing mode */

//     light_ambient[4] = { 1.0, 1.0, 1.0, 1.0 };
//     light_diffuse[4] = { 1.0, 1.0, 1.0, 1.0 };
//     light_specular[4] = { 1.0, 1.0, 1.0, 1.0 };
//     light_position[4] = { 1.0, 1.0, 1.0, 0.0 };

//     mat_ambient[4] = { 0.7, 0.7, 0.7, 0.0 };
//     mat_diffuse[4] = { 0.8, 0.8, 0.8, 1.0 };
//     mat_specular[4] = { 1.0, 1.0, 1.0, 1.0 };
//     high_shininess[1] = { 100.0 };

    getMatrix();
    glClearColor(0.0, 0.0, 0.0, 0.0);   // glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
    //glutMainLoop();
    glClearAccum(0.0, 0.0, 0.0, 0.0);

    // if (lighting)
    glEnable(GL_LIGHTING);
    /// if (lighting)
    glEnable(GL_LIGHT0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_TEXTURE_2D);

    strncpy(filename, fname ,sizeof(filename));	/* get the last arg as the file always */

    if (!pmodel) {		/* load up the model */
        pmodel = glmReadOBJ(filename);
        if (!pmodel) {
            printf("\nUsage: objviewV2 <-s> <obj filename>\n");
            exit(0);
        }
        glmUnitize(pmodel);
        glmVertexNormals(pmodel, 90.0, GL_TRUE);
    }

}
Beispiel #26
0
void init(void) { 
	int i;
	for(i=0;i<numSpheres;i++){
		spheres[i][0] = (rand()%600)-300;//XPOS
		spheres[i][1] = (rand()%600)-300;//YPOS
		spheres[i][2] = rand()%400;//ZPOS
		spheres[i][3] = rand()%20;//SIZE
		spheres[i][4] = (rand()%20);//SPEED
	}
   
	MAXROT = 1.0/6.0*PI;
	glClearColor (0.0, 0.0, 0.0, 0.0);
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	pmodel = glmReadOBJ("city.obj");
	if (!pmodel) fprintf(stderr,"Cannot parse vase.obj");
	//glmUnitize(pmodel); // make model to fit in a unit cube
	glmFacetNormals(pmodel); // generate normals - is this needed?
	glmVertexNormals(pmodel, 90.0); // average joining normals - allow for hard edges.
	tmodel = glmReadOBJ("tower.obj");
	glmFacetNormals(tmodel); // generate normals - is this needed?
	glmVertexNormals(tmodel, 90.0); // average joining normals - allow for hard edges.
	readTop();
	readFront();
	readBack();
	readRight();
	readLeft();
	readFire();
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glGenTextures(1, &front);
	glGenTextures(1, &top);
	glGenTextures(1, &left);
	glGenTextures(1, &right);
	glGenTextures(1, &back);
	glGenTextures(1, &fire);
	qsphere = gluNewQuadric();
}
Beispiel #27
0
Canhao::Canhao(char *p_base, char *p_canhao){
    //std::cerr << "Inicio Canhao::Canhao(char *p_base, char *p_canhao)" << std::endl;
    _podeDisparar = true;

    _rotacaoBase = 0;
    _rotacaoCanhao = 0;

    _baseTanque = NULL;
    _canhaoTanque = NULL;

    _tiros.clear();

    if(!_baseTanque) {
        _baseTanque = glmReadOBJ(p_base);
        if(!_baseTanque) std::cerr << "Não foi possível carregar o arquivo .OBJ" << 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" << std::endl;
        glmUnitize(_canhaoTanque);
        glmFacetNormals(_canhaoTanque);
        glmVertexNormals(_canhaoTanque,180.0);
    }

    // definir posicao inicial do canhao deste jogador
    _posicaoBase[0] = 0.0;
    _posicaoBase[1] = 0.0;
    _posicaoBase[2] = 0.0;
    _posicaoCanhao[0] = 0.0;
    _posicaoCanhao[1] = 0.2;
    _posicaoCanhao[2] = 0.0;
    //std::cerr << "Fim Canhao::Canhao(char *p_base, char *p_canhao)" << std::endl;
}
Beispiel #28
0
void drawmodel_box(void)
{
    if (!pmodel1)
    {
        pmodel1 = glmReadOBJ("objects/monkey.obj");
        if (!pmodel1) {
            exit(0);
        }
        glmUnitize(pmodel1);
        glmFacetNormals(pmodel1);
        glmVertexNormals(pmodel1, 90.0);
    }
    /* glmDraw(pmodel1, GLM_SMOOTH | GLM_TEXTURE); */
    glmDraw(pmodel1, GLM_SMOOTH);
}
Beispiel #29
0
void init()
{
	glClearColor (.4,.4,.4,1);
	glEnable (GL_DEPTH_TEST);

	glEnable (GL_LIGHTING);
	glEnable (GL_LIGHT0);
	
	al = glmReadOBJ ("al.obj");
	glmUnitize (al);
	glmFacetNormals (al);
	glmVertexNormals (al, 90.0);
	
	floortex = pngBind("marble.png", PNG_NOMIPMAP, PNG_SOLID, NULL, GL_REPEAT, GL_NEAREST, GL_NEAREST);
}
Beispiel #30
0
void Player:: drawmodel_fish_mod()
{
	glTranslatef(x, y, -z);
	glRotatef(180-t,0,1,0);

	if (!pmodel2) 
	{
		pmodel2 = glmReadOBJ("fishLL.obj");	 //glm.cpp
        if (!pmodel2) exit(0);
	//	glmUnitize(pmodel1);				 //glm.cpp
		glmFacetNormals(pmodel2);			 //glm.cpp   
		glmVertexNormals(pmodel2, 90.0);     //glm.cpp
    }

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