Beispiel #1
0
Chair::Chair(Material m) {
    ObjReader reader;

    reader.read("/Users/Pedro/Desktop/CG/Obj/chair.obj", m);

    faces = reader.getFaces();
    bottomY = reader.getBottomY();
}
Beispiel #2
0
Chair::Chair() {
    ObjReader reader;
    // For any object
    material = Material();
    reader.read("/Users/Pedro/Desktop/CG/Obj/chair.obj", material);

    faces = reader.getFaces();
    bottomY = reader.getBottomY();
}
//--------------------------------------------------------------------------------
void GLWidget::loadScene(QString& fileName)
{
  // Remove possible old data
  scene.objects.clear();

  ObjReader reader;

  scene.objects = reader.parseFile(fileName.toUtf8().data());

  // Add lights
  //scene.lights.push_back(Light(Vector3F(-3.0, -5.0, -4.0), Color3F(15.0, 15.0, 15.0)));
  //scene.lights.push_back(Light(Vector3F(3.0, 5.0, 4.0), Color3F(15.0, 15.0, 15.0)));
}
int main(int argc, char** argv)
{
	if (argc <= 1)
	{
		printf("id_aviewer + file(obj/3ds) and if you want texture file\n");
		return (0);
	}
		
	int				ret;
	Display*			disp;
	unsigned short			chunkid;
	int 				fd;

	disp = Display::GetInstance();
	fd = open(argv[1], O_RDONLY);
	read(fd, &chunkid, 2);
	if (chunkid == 0x4d4d)
	{
		Loader3ds	L;
		init(argc, argv);
		close(fd);
		ret = L.Load3ds(argv[1]);
		if(ret)
		{
			exit();
			std::cout<<"error to load file"<<std::endl;
			return(42);
		}
	}
	else
	{
		ObjReader	R;
		init(argc, argv);
		close(fd);
		ret = R.read(argv[1]);
		if(ret)
		{
			std::cout<<"error to load file"<<std::endl;
			exit();
			return(42);
		}
	}
	glutMainLoop();
	return (0);
}
Beispiel #5
0
int main(int argc, char *argv[])
{
	GLfloat ambient[]         = {0.5,0.5,0.5,1.0};					// default ambient color for all light sources

	glutInit(&argc, argv);											// initialize GLUT
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);		// open an OpenGL context with double buffering, RGB colors, and depth buffering
	glutInitWindowSize(512, 512);									// set initial window size
	glutCreateWindow("Final Project");								// open window and set window title
	if (is_fullscreen)
		glutFullScreen();

	glEnable(GL_NORMALIZE);
	glEnable(GL_DEPTH_TEST);										// enable z-buffer
	glClearColor(0.0, 0.0, 0.0, 0.0);								// set clear color to black

	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);				// set the default ambient color
	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);		// allow glColor to set ambient and diffuse colors of geometry

	// Generate light source:
	glEnable(GL_LIGHTING);											// enables lighting; this changes the behavior of glColor
	glEnable(GL_LIGHT0);											// enable a light source; otherwise you will only see ambient light
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glDisable(GL_TEXTURE_2D);

	glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
	glLightfv(GL_LIGHT0, GL_SHININESS, light0_shininess);
	glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
	
	// Install callback functions:
	glutDisplayFunc(window::displayCallback);
	glutReshapeFunc(window::reshapeCallback);
	glutIdleFunc(window::idleCallback);

	glutMouseFunc(processMouse);
	glutMotionFunc(processMotion);
	glutKeyboardFunc(keyDown);
	glutKeyboardUpFunc(keyUp);

	// Initialize cube matrix:
	character.getMatrix().identity();
	all.getMatrix().identity();
	cube.getMatrix().identity();
	cube1.getMatrix().identity();
	cube2.getMatrix().identity();
	dragon.getMatrix().identity();
	base.getMatrix().identity();
	temp.getMatrix().identity();
	world.getMatrix().identity();
	terrain.getMatrix().identity();
	rotation.getMatrix().identity();

	// Shaders
	shader = new Shader(toon_vert,toon_frag,true);
	camera.lookAt(p,l,up);

	cout << "Loading .obj files" << endl;
	objReader.readObj("cow.obj", nVerts, &vertices, &normals, &texcoords, nIndices, &indices);

	cout << "Loading texture files" << endl;
	loadTexture(texture_array,"desert_front.ppm", SKYFRONT);
	loadTexture(texture_array,"desert_back.ppm", SKYBACK);
	loadTexture(texture_array,"desert_left.ppm", SKYLEFT);
	loadTexture(texture_array,"desert_right.ppm", SKYRIGHT);
	loadTexture(texture_array,"desert_top.ppm", SKYUP);

	cout << "Generating terrain1" << endl;
	TerrainHelper th1;
	th1.terrainLoad(800,800,1);
	th1.terrainScale(0,TERRAIN_ONE_HEIGHT);
	TERRAIN_ONE_ID = th1.terrainCreateDL(0,0,0);

	cout << "Generating terrain2" << endl;
	TerrainHelper th2;
	th2.terrainLoad(800,800,1);
	th2.terrainScale(0, TERRAIN_TWO_HEIGHT);
	TERRAIN_TWO_ID = th2.terrainCreateDL(0,0,0);

	cout << "Generating terrain3" << endl;
	TerrainHelper th3;
	th3.terrainLoad(800, 800,1);
	th3.terrainScale(0,TERRAIN_THREE_HEIGHT);
	TERRAIN_THREE_ID = th3.terrainCreateDL(0,0,0);

	CURRENT_TERRAIN_ID = TERRAIN_ONE_ID;

	cout << "Creating world" << endl;
	createWorld();

	//cout << "initializing particles" << endl;
	//initParticles(0.0,0.0,0.0);

	glutMainLoop();
	return 0;
}