Esempio n. 1
0
void DrawScene(void)
{

	//Render Europe:
	glEnable(GL_LIGHTING);
	FlagTexture2.SetActive();
	Flag.Render();

	//Render Germany:
	glEnable(GL_LIGHTING);
	FlagTexture1.SetActive();
	glPushMatrix();
		glTranslatef(2.5,0.0,2.5);
		Flag.Render();
	glPopMatrix();

	//Render Portugal:
	glEnable(GL_LIGHTING);
	FlagTexture3.SetActive();
	glPushMatrix();
		glTranslatef(-2.5,0.0,2.5);
		Flag.Render();
	glPopMatrix();

	//Render ground:
	GroundTexture.SetActive();
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	float HalfGroundSize = 20.0f;

	glTranslatef(0.0,-4.0,0.0);
	glBegin(GL_POLYGON);
	  
	  glNormal3f(0.0,1.0,0.0);
	  
	  glTexCoord2f(0.0,0.0);
	  glVertex3f(-HalfGroundSize, 0.0, -HalfGroundSize);
	  glTexCoord2f(0.0,1.0);
	  glVertex3f(-HalfGroundSize, 0.0, +HalfGroundSize);
	  glTexCoord2f(1.0,1.0);
	  glVertex3f(+HalfGroundSize, 0.0, +HalfGroundSize);
	  glTexCoord2f(1.0,0.0);
	  glVertex3f(+HalfGroundSize, 0.0, -HalfGroundSize);
	  

	glEnd();


}
Esempio n. 2
0
int main (int argc, char **argv)
{
	//Initialize GLUT
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
	glutInitWindowSize(600,600);
	//Create a window with rendering context and everything else we need
	glutCreateWindow("Flag in the wind");


	//load the textures:
	FlagTexture1.LoadFromFile("germany.bmp");
	FlagTexture2.LoadFromFile("europe.bmp");
	FlagTexture3.LoadFromFile("portugal.bmp");
	GroundTexture.LoadFromFile("ground.bmp");

	//init texture stuff:
	GroundTexture.SetActive();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	FlagTexture1.SetActive();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	FlagTexture2.SetActive();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	FlagTexture3.SetActive();
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);


	//initialize the flag:
	Flag.Initialize(40,26,2.0f,50.0f,0.997f);
	//and the values affecting it:
	wind = F3dVector (0.2,0.04,0.00);
	gravity = F3dVector(0.0,-0.015,0.0005);

	//initialize camera: 
	Camera.Move(F3dVector(1.0f, 0.0f, 15.0f));


	//Enable the vertex array functionality:
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY );
	glClearColor(0.0,0.0,1.0,0.0);  //blue background = sky ;-)
	
	//Switch on solid rendering:
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE ,1);
	glEnable(GL_DEPTH_TEST);

	//Initialize lighting:
	glEnable(GL_LIGHT1);								
	glEnable(GL_LIGHT2);

	glEnable(GL_LIGHTING);

	glFrontFace(GL_CCW);   //Tell OGL which orientation shall be the front face
	glShadeModel(GL_SMOOTH);

	//initialize generation of random numbers:
	srand((unsigned)time(NULL));

	
	//Assign the two used Msg-routines
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutKeyboardFunc(KeyDown);
	glutIdleFunc(Idle);
	//Let GLUT get the msgs
	glutMainLoop();
	return 0;
}
Esempio n. 3
0
void glutDrawMesh(mesh2df &mesh, COGLTexture &texture)
{


    unsigned int num_tris = mesh.triangles.size();
    unsigned int vertex;
    unsigned int num_edges = mesh.edges.size();

    unsigned int i;

    // FIXME: correct for aspect ratio..

    glEnable(GL_TEXTURE_2D);

    texture.SetActive();


    glBegin(GL_TRIANGLES);

    for(i=0; i<num_tris; i++)
    {
        vector2df uv = mesh.uv[mesh.uv_triangles[i]];
        glTexCoord2f(uv.X, uv.Y);

        vertex = mesh.triangles[i];
        //glColor3f(mesh.colors[vertex].r, mesh.colors[vertex].g, mesh.colors[vertex].b);

        // transform.
        vector2df p = mesh.points[vertex];
        p += mesh.offset;
        p.rotateBy(mesh.rotation, vector2df(0.0, 0.0));
        p.X *= mesh.scale.X;
        p.Y *= mesh.scale.Y;

        p += mesh.position;
        p -= mesh.offset;

        glVertex2f(p.X, p.Y);

    }
    glEnd();
    glDisable(GL_TEXTURE_2D);
    /*
    	// draw all the edges (wireframe mode)
    	glBegin(GL_LINES);
    	glLineWidth(2.0);

    	// FIXME: this should only be for debugging? pass a bool.
    	for(i=0; i<num_edges; i++)
    	{
    		vertex = mesh.edges[i];
    		glColor3f(1.0, 1.0, 1.0);

    		// transform.
    		vector2df p = mesh.points[vertex];
    		p.rotateBy(mesh.rotation, vector2df(0.0, 0.0));
    		p.X *= mesh.scale.X;
    		p.Y *= mesh.scale.Y;
    		p += mesh.position;

    		glVertex2f(p.X, p.Y);
    	}

    	glEnd();
    	*/

}