示例#1
0
Window::Window(Shader *aShader, int argc, char* argv[] ) :
	shader(aShader)  {

	eyeoffset[0] = 0; eyeoffset[1] = 0;
    window_size[0] = INITIAL_WIDTH;
    window_size[1] = INITIAL_HEIGHT;
	
	for(int i = 0; i < 4; i++) 
		ambientcolor[i] = 0.2f; 

	//camera setup
	up[0] = 0.0f; up[1] = 1.0f; up[2] = 0.0f;
	eye[0] = 0.0f; eye[1] = 1.0f; eye[2] = 3.0f;
	look[0] = eye[0]; look[1] = eye[1]-.5f; look[2] = eye[2];  //start looking at origin but slightly up
	setUpFrustrum();

	setupCallback();
}
// Very complex stuff, impossible to explain.
int main(int argc, char *argv [])
{
	//Set the error callback
	glfwSetErrorCallback(onError);

	//Initialize GLFW
	if (!glfwInit()){
		exit(EXIT_FAILURE);
	}

	//Set the GLFW window creation hints - these are optional
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //Request a specific OpenGL version
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); //Request a specific OpenGL version
	//glfwWindowHint(GLFW_SAMPLES, 4); //Request 4x antialiasing
	//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	//Declare a window object
	GLFWwindow* window;

	window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT,
		"Screen Space Fluid Rendering",
		NULL /* glfwGetPrimaryMonitor() */,
		NULL);

	if (!window){
		fprintf(stderr, "Failed to open GLFW window.\n");
		glfwTerminate();
		exit(EXIT_FAILURE);
	}
	glfwMakeContextCurrent(window);

	// Output some information
	puts(glfwGetVersionString());
	printf("OpenGL version supported %s\n", glGetString(GL_VERSION));

	
	setupCallback(window);
	
	// AssImp init
	// get a handle to the predefined STDOUT log stream and attach
	// it to the logging system. It remains active for all further
	// calls to aiImportFile(Ex) and aiApplyPostProcessing.
	aiLogStream aiStream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT, NULL);
	aiAttachLogStream(&aiStream);

	// --------------------------------------------
	//			Initialize GLEW
	// --------------------------------------------

	glewExperimental = GL_TRUE;
	GLenum err = glewInit();

	//If GLEW hasn't initialized
	if (err != GLEW_OK){
		fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
		return 1;
	}

	// --------------------------------------------
	//			DevIL init
	// --------------------------------------------

	ilInit();

	/* 
	* Now that we should have a valid GL context, perform our OpenGL
	* initialization, before we enter our main loop.
	*/
	initialize(window);

	mainLoop(window);

	unload(window);

	// We added a log stream to the library, it's our job to disable it
	// again. This will definitely release the last resources allocated
	// by Assimp.
	aiDetachAllLogStreams();

	//Close OpenGL window and terminate GLFW
	glfwDestroyWindow(window);
	//Finalize and clean up GLFW
	glfwTerminate();

	exit(EXIT_SUCCESS);
}