Ejemplo n.º 1
0
void SceneBase::Init(string vertexShader, string fragmentShader)
{
	// Debug
	m_bShowDebug = false;

	// Simulation Speed
	m_speed = 1.0f;

	// Dark Blue Background
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
	// Enable depth test
	glEnable(GL_DEPTH_TEST);
	// Accept fragment if it closer to the camera than the former one
	glDepthFunc(GL_LESS);

	// Face Culling
	glEnable(GL_CULL_FACE);
	m_bCull = true;

	// Filled/Wireframe Mode
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	m_bWireframe = false;

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glGenVertexArrays(1, &m_vertexArrayID);
	glBindVertexArray(m_vertexArrayID);

	Math::InitRNG();
	InitShadersAndLights(vertexShader, fragmentShader);
	InitFog();


	/*
	* Resource Initialization
	*/
	// Colors
	InitColors();
	// Materials
	InitMaterials();
	// Textures
	InitTextures();
	// Meshes
	InitMeshes();

	// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 1000 units
	Mtx44 perspective;
	perspective.SetToPerspective(45.0f, 4.0f / 3.0f, 0.1f, 12000.0f);
	//perspective.SetToOrtho(-80, 80, -60, 60, -1000, 1000);
	projectionStack.LoadMatrix(perspective);

	bLightEnabled = true;
}
Ejemplo n.º 2
0
int main()
{
	GLFWwindow* window = nullptr;

	glfwSetErrorCallback(error_callback);

	// Inititiating GLFW library
	if (!glfwInit()) 
		exit(EXIT_FAILURE);

	// Sets hints for the next call to glfwCreateWindow - Keep these for future debugging
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
	glfwWindowHint(GLFW_REFRESH_RATE, GLFW_DONT_CARE);// This hint is ignored for windowed mode windows.

	// Creating window
	window = glfwCreateWindow(640, 480, "Title", NULL, NULL);

	// Failure check - Creating window
	if (!window)
	{
		glfwTerminate();
		exit(EXIT_FAILURE);
	}
	else
	{
		fprintf(stderr, "GLFW Window initialized\n");
	}

	// Bind key-inputs
	glfwSetKeyCallback(window, key_callback);

	// Fetch OpenGL version - Makes sure correct version is loaded from GLEW
	glfwMakeContextCurrent(window);
	// Inititiating GLEW library
	glewExperimental = true;
	GLenum err = glewInit();

	// Failure check - Inititiating GLEW
	if (GLEW_OK != err)
	{
		fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
	}
	else
	{
		fprintf(stderr, "GLEW initialized\n");
	}

#ifdef _DEBUG
	if (glDebugMessageCallback){
		std::cout << "Register OpenGL debug callback " << std::endl;
		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
		glDebugMessageCallback((GLDEBUGPROC)openglCallbackFunction, nullptr);
		GLuint unusedIds = 0;
		glDebugMessageControl(GL_DONT_CARE,
			GL_DONT_CARE,
			GL_DONT_CARE,
			0,
			&unusedIds,
			true);
	}
	else
	{
		std::cout << "glDebugMessageCallback not available" << std::endl;
	}
#endif

	// VSync
	glfwSwapInterval(1);

	////////////////////////////////////////////////////////////

	// Engine classes
	Graphics ge = Graphics();
	Physics ph = Physics();

	InitMeshes(&ge);

	InitCameras();
	ge.SetCamera(&cameras[cameraIndex]);
	
	fpsCounter fpsC;
	int tickCounter = 400;
	////////////////////////////////////////////////////////////
	while (!glfwWindowShouldClose(window))
	{
		std::stringstream ss;
		ss << fpsC.get();

		glfwSetWindowTitle(window, ss.str().c_str());

		KeyEvents(window, &ge, &ph);

		UpdateProjections(window);
		RotateCamera(&cameras[cameraIndex], window);
		MoveCamera(&cameras[cameraIndex], window);

		if (fpsC.deltaTime() > 0 && tickCounter < 1)
		{
			//ph.move(&mustangHigh, &fpsC);
			ph.move(&EndOfLine, &fpsC);
		}
		else
		{
			tickCounter--;
		}

		Collision(&EndOfLine, &target);
		Collision(&EndOfLine, &target2);

		ge.PrepareRender();
		ge.Render(&mustang);
		ge.Render(&mustang2);
		ge.Render(&mustang3);
		ge.Render(&mustang4);
		ge.Render(&mustangHigh);

		ge.Render(&ground);
		ge.Render(&target);
		ge.Render(&target2);

		ge.Render(&EndOfLine);

		fpsC.tick();
		Sleep(1000 / 120);

		glfwSwapBuffers(window);
		glfwPollEvents();// Processes all pending events
	}
	////////////////////////////////////////////////////////////
	
	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}