//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
void init()
{
	InitializeProgram();

	try
	{
		g_pCylinderMesh = new Framework::Mesh("UnitCylinder.xml");
		g_pPlaneMesh = new Framework::Mesh("LargePlane.xml");
	}
	catch(std::exception &except)
	{
		printf("%s\n", except.what());
		throw;
	}

	glutMouseFunc(MouseButton);
	glutMotionFunc(MouseMotion);
	glutMouseWheelFunc(MouseWheel);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
	glEnable(GL_DEPTH_CLAMP);

	glGenBuffers(1, &g_projectionUniformBuffer);
	glBindBuffer(GL_UNIFORM_BUFFER, g_projectionUniformBuffer);
	glBufferData(GL_UNIFORM_BUFFER, sizeof(ProjectionBlock), NULL, GL_DYNAMIC_DRAW);

	//Bind the static buffers.
	glBindBufferRange(GL_UNIFORM_BUFFER, g_projectionBlockIndex, g_projectionUniformBuffer,
		0, sizeof(ProjectionBlock));

	glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
Ejemplo n.º 2
0
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
void init()
{
	InitializeProgram();

	try
	{
		g_pConeMesh = new Framework::Mesh("\\objects\\UnitConeTint.xml");
		g_pCylinderMesh = new Framework::Mesh("\\objects\\UnitCylinderTint.xml");
		g_pCubeTintMesh = new Framework::Mesh("\\objects\\UnitCubeTint.xml");
		g_pCubeColorMesh = new Framework::Mesh("\\objects\\UnitCubeColor.xml");
		g_pPlaneMesh = new Framework::Mesh("\\objects\\UnitPlane.xml");
	}
	catch(std::exception &except)
	{
		printf("%s\n", except.what());
		throw;
	}

	LoadCollisionVolumes();

	mainCharacter.AttachCamera(userCamera);
	mainCharacter.AttachCollisionVolume_Cylinder();
	
	LoadTreasureEntities();

 	glutPassiveMotionFunc(HandlePassiveMovement);
	glutMotionFunc(HandleActiveMovement);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
	glEnable(GL_DEPTH_CLAMP);
}
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
void init()
{
	InitializeProgram();

	try
	{
		g_pShip = new Framework::Mesh("Ship.xml");
	}
	catch(std::exception &except)
	{
		printf("%s\n", except.what());
		throw;
	}

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
}
Ejemplo n.º 4
0
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
void init()
{
	InitializeProgram();

	try
	{
		loadObjects();
	}
	catch(std::exception &except)
	{
		printf("%s\n", except.what());
		throw;
	}

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
	glEnable(GL_DEPTH_CLAMP);
}
Ejemplo n.º 5
0
GeneralInitialization::GeneralInitialization()
{
	InitializeProgram();
}
Ejemplo n.º 6
0
void init() {
  InitializeProgram();
  InitializeVertexBuffer();
  glGenVertexArrays( 1, &vao );
  glBindVertexArray( vao );
}
Ejemplo n.º 7
0
GlHelper::GlHelper() {


    float vertexPositions[] = {
        +0.05f, +0.05f, -1.95f, 1.0f,
        -0.05f, -0.05f, -1.95f, 1.0f,
        -0.05f, +0.05f, -2.15f, 1.0f,
        +0.05f, -0.05f, -2.15f, 1.0f,

        -0.05f, -0.05f, -2.15f, 1.0f,
        +0.05f, +0.05f, -2.15f, 1.0f,
        +0.05f, -0.05f, -1.95f, 1.0f,
        -0.05f, +0.05f, -1.95f, 1.0f,
    };
    float vertexColors[] = {
        0.0f, 1.0f, 0.0f, 1.0f,
        0.0f, 0.0f, 1.0f, 1.0f,
        1.0f, 0.0f, 0.0f, 1.0f,
        0.5f, 0.5f, 0.0f, 1.0f,

        0.0f, 1.0f, 0.0f, 1.0f,
        0.0f, 0.0f, 1.0f, 1.0f,
        1.0f, 0.0f, 0.0f, 1.0f,
        0.5f, 0.5f, 0.0f, 1.0f,
    };
    unsigned short vertexIndex[] = {
        0, 1, 2,
        1, 0, 3,
        2, 3, 0,
        3, 2, 1,

        5, 4, 6,
        4, 5, 7,
        7, 6, 4,
        6, 7, 5,
    };

    xOffset = 0.0f;
    yOffset = 0.0f;

    std::copy(vertexPositions,vertexPositions + 8*4, this->vertexPositions);
    std::copy(vertexColors,vertexColors + 8*4, this->vertexColors);
    std::copy(vertexIndex,vertexIndex + 8*3, this->vertexIndex);

    float fFrustumScale=2.4f, zFar=3.0f, zNear=1.0f;
    memset(perspectiveMatrix,0,16*sizeof(float));
    perspectiveMatrix[0]=fFrustumScale;
    perspectiveMatrix[5]=fFrustumScale;
    perspectiveMatrix[10]= (zFar + zNear) / (zNear - zFar);
    perspectiveMatrix[14]= (2*zFar * zNear) / (zNear - zFar);
    perspectiveMatrix[11]= -1.0f;

    memset(translateMatrix,0,16*sizeof(float));
    translateMatrix[0] = 1.0f;
    translateMatrix[5] = 1.0f;
    translateMatrix[10]= 1.0f;
    translateMatrix[12]= 0.0f;
    translateMatrix[13]= 0.0f;
    translateMatrix[14]= 0.0f;
    translateMatrix[15]= 1.0f;

    memset(translateMatrix2,0,16*sizeof(float));
    translateMatrix2[0] = 1.0f;
    translateMatrix2[5] = 1.0f;
    translateMatrix2[10]= 1.0f;
    translateMatrix2[12]= -0.30f;
    translateMatrix2[13]= 0.0f;
    translateMatrix2[14]= 0.0f;
    translateMatrix2[15]= 1.0f;
    
    memset(translateMatrix3,0,16*sizeof(float));
    translateMatrix3[0] = 1.0f;
    translateMatrix3[5] = 1.0f;
    translateMatrix3[10]= 1.0f;
    translateMatrix3[12]= +0.30f;
    translateMatrix3[13]= 0.0f;
    translateMatrix3[14]= 0.0f;
    translateMatrix3[15]= 1.0f;
    
    InitializeProgram();
    InitializeVertexBuffer();

    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
    glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject);

    glBindVertexArray(0);
    glDisable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);

}
Ejemplo n.º 8
0
int main(int narg, char** argc)
{
	const char *strVertexPath = "vertex.shader", *strFragmentPath = "fragment.shader";

	/* read program parameters from command line */
	char *program = argc[0];

	while ((narg>1) && (argc[1][0]=='-')) {
		switch(argc[1][1]) {
			case 'f': strFragmentPath=&argc[1][3]; break;
			case 'v': strVertexPath=&argc[1][3]; break;
			default:
				std::cout << "Usage: " << program << " <options>" << std::endl
					<< "\t-v <file_name>\tVertex shader path" << std::endl
	                << "\t-f <file_name>\tFragment shader path" << std::endl;
				exit(EXIT_SUCCESS);
				break;
	        }

		narg--;
		argc++;
	}

	/* initialize GL context and window */
	window = GL_init();

	/* load shaders */
	dout << "Fragment shader: " << strFragmentPath << std::endl;
	dout << "Vertex shader: " << strVertexPath << std::endl;
	GLuint shaderProgram = InitializeProgram(strVertexPath, strFragmentPath);
	glUseProgram(shaderProgram);
	dout << "Loading shader program complete" << std::endl;

    // Get a handle for our "MVP" uniform
	GLuint MatrixID = glGetUniformLocation(shaderProgram, "MVP");

    // Get a handle for our buffers
	GLuint vertexPosition_modelspaceID = glGetAttribLocation(shaderProgram, "vertex");
    GLuint vertexNormalID = glGetAttribLocation(shaderProgram, "normal");

    // Read our .obj file
	std::vector<glm::vec3> vertices;
	std::vector<glm::vec3> normals;
	loadOBJ("monkey.obj", vertices, normals);

    // Load it into a VBO

	GLuint vertexbuffer;
	glGenBuffers(1, &vertexbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);

    GLuint normalbuffer;
	glGenBuffers(1, &normalbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
	glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), &normals[0], GL_STATIC_DRAW);

    // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
    glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 1.0f, 1000.0f);

    // Camera matrix
    glm::mat4 View = glm::lookAt(
        glm::vec3(0, 1, 3), // Camera is at (4,3,3), in World Space
        glm::vec3(0,0,0), // and looks at the origin
        glm::vec3(0,1,0)  // Head is up (set to 0,-1,0 to look upside-down)
    );

    // Model matrix : an identity matrix (model will be at the origin)
    glm::mat4 Model = glm::mat4(1.0f);
    // Our ModelViewProjection : multiplication of our 3 matrices
    glm::mat4 MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around

	/* loop until window closed */
	dout << "Entering main loop" << std::endl;
	while (!glfwWindowShouldClose(window)) {
        // Clear the screen
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Send our transformation to the currently bound shader,
		// in the "MVP" uniform
		glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

        // 1rst attribute buffer : vertices
		glEnableVertexAttribArray(vertexPosition_modelspaceID);
		glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
		glVertexAttribPointer(
			vertexPosition_modelspaceID,  // The attribute we want to configure
			3,                            // size
			GL_FLOAT,                     // type
			GL_FALSE,                     // normalized?
			0,                            // stride
			(void*)0                      // array buffer offset
		);

        glEnableVertexAttribArray(vertexNormalID);
		glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
		glVertexAttribPointer(
			vertexNormalID,               // The attribute we want to configure
			3,                            // size
			GL_FLOAT,                     // type
			GL_FALSE,                     // normalized?
			0,                            // stride
			(void*)0                      // array buffer offset
		);

        // Draw the triangles !
		glDrawArrays(GL_TRIANGLES, 0, vertices.size() );

		glDisableVertexAttribArray(vertexPosition_modelspaceID);
        glDisableVertexAttribArray(vertexNormalID);

		/* swap buffers */
		glfwSwapBuffers(window);

		/* poll events */
		glfwPollEvents();
	}

	/* terminate application */
	dout << "Loop ended, closing" << std::endl;
    // Cleanup VBO and shader
	glDeleteBuffers(1, &vertexbuffer);
    glDeleteBuffers(1, &normalbuffer);
	glDeleteProgram(shaderProgram);
	glfwDestroyWindow(window);
	glfwTerminate();

	exit(EXIT_SUCCESS);
}