Exemplo n.º 1
0
GLuint ObjectManager::obtainVertexArray( const void* key )
{
    const GLuint id = getVertexArray( key );
    if( id != INVALID )
        return id;
    return newVertexArray( key );
}
Exemplo n.º 2
0
int main( void )
{
	initGLFW();
	initWindow();
	initGLEW();
	initKeyboard();
	
	// Dark blue background
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

	int size = 5;
	float* map = generateHeightMap(size);
	printf("generated map\n" );
	std::vector<glm::vec3> terrain;
	mapHeightsToPoints(terrain, map, size);
	printf("mapped to points\n");
	// GLuint* indices = generateIndices(terrain, size);

	uint terrainVertexAmount = size* size * 3;
	uint indiceAmount = 3 * (1 << size);

	for(int i = 0; i < terrain.size(); ++i){
		printf("[%f, %f, %f]\n", terrain[i].x, terrain[i].y, terrain[i].z);
	}

	printf("vertices %d\n", terrainVertexAmount);

	GLuint VertexArrayID = newVertexArray();

	// Create and compile our GLSL program from the shaders
	GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
	printf("loaded\n");
	initMatrices(programID);

	
	GLuint vertexbuffer = newVertexBuffer(terrainVertexAmount, &terrain);
	
	double lastTime = glfwGetTime();
 	int nbFrames = 0;
 	printf("loop\n");


 	initDepth();
	do{

		// Clear the screen
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// Use our shader
		glUseProgram(programID);
		
		// TODO
		// recalculateMatrices();

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

		// 1rst attribute buffer : vertices
		bindVertexBuffer(vertexbuffer);

		// Draw the triangle !
		glDrawArrays(GL_TRIANGLE_FAN, 0, terrainVertexAmount); // 3 indices starting at 0 -> 1 triangle

		glDisableVertexAttribArray(0);

		// Swap buffers
		glfwSwapBuffers(window);
		glfwPollEvents();


		// measureTime(lastTime, &nbFrames);

	} // Check if the ESC key was pressed or the window was closed
	while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
		   glfwWindowShouldClose(window) == 0 );

	// Cleanup VBO
	glDeleteBuffers(1, &vertexbuffer);
	glDeleteVertexArrays(1, &VertexArrayID);
	glDeleteProgram(programID);

	// Close OpenGL window and terminate GLFW
	glfwTerminate();
	// normal** ns = generateNormals(map, size);
	return 0;
}