예제 #1
0
void MaterialManager::Init(unsigned int reserveObjectsCount)
{
	LOG_INFO("Init material manager");
	mCurrentMaterial = nullptr;

	mMaterials.reserve(reserveObjectsCount);

	ShaderProgram * program = new ShaderProgram();
	Shader * vertexShader = new Shader(File::GetRelative("Shaders/default.vert"), ShaderType::VertexShader);
	Shader * fragmentShader = new Shader(File::GetRelative("Shaders/default.frag"), ShaderType::FragmentShader);
	program->AddShader(*vertexShader);
	program->AddShader(*fragmentShader);
	program->Compile();
	program->Bind(); // To make sure nothing goes wrong before the first update loop
	
	mDefaultMaterial = new Material(program);
	//mDefaultMaterial->SetShaderProgram(*program);
	//mDefaultMaterial->BindShadersAndTextures();
}
예제 #2
0
파일: main.cpp 프로젝트: AndersUa/NBody
	bool Init(int argc, char** argv)
	{
		GetCLDev();

		m_backend->Init(argc, argv);
		m_aspectRatio = m_win_h / (float)m_win_w;

		if (!m_backend->CreateWin(m_win_w, m_win_h, false, "OpenGL test app"))
		{
			fprintf(stderr, "Faild to create window");
			return false;
		}

		GLenum res = glewInit();
		if (res != GLEW_OK) {
			fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
			return false;
		}

		if (!InitCL())
		{
			return false;
		}

		wglSwapIntervalEXT(0);

		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		//glFrontFace(GL_CW);
		//glCullFace(GL_BACK);
		//glEnable(GL_CULL_FACE);

		//glEnable(GL_DEPTH_TEST);

		m_bodies.push_back(Body(Vector2f(-0.8f, -0.8f), Vector2f(0.021f, 0.0f), Vector2f(-0.05f, 0.11f), Vector2f(0.0f, 0.0f)));
		m_bodies.push_back(Body(Vector2f(0.8f, 0.8f), Vector2f(0.021f, 0.0f), Vector2f(0.05f, -0.11f), Vector2f(0.0f, 0.0f)));
		m_bodies.push_back(Body(Vector2f(-0.8f, 0.8f), Vector2f(0.014f, 0.0f), Vector2f(0.01f, 0.1f), Vector2f(0.0f, 0.0f)));
		m_bodies.push_back(Body(Vector2f(0.8f, -0.8f), Vector2f(0.016f, 0.0f), Vector2f(0.01f, 0.1f), Vector2f(0.0f, 0.0f)));
		m_bodies.push_back(Body(Vector2f(0.0f, 0.0f), Vector2f(0.3f, 0.0f), Vector2f(0.0f, 0.0f), Vector2f(0.0f, 0.0f)));

		for (int i = 0; i < 5000; ++i)
		{
			m_bodies.push_back(Body(Vector2f((rand() % 100000) / 1000.0f - 1.0f, (rand() % 100000) / 1000.0f - 1.0f), Vector2f(rand() % 300 / 1000.0f, 0.0f), Vector2f((rand() % 2000) / 1000.0f - 1.0f, (rand() % 2000) / 1000.0f - 1.0f), Vector2f(0.0f, 0.0f)));
		}

		glGenBuffers(1, &m_VB);
		glBindBuffer(GL_ARRAY_BUFFER, m_VB);
		glBufferData(GL_ARRAY_BUFFER, sizeof(Body) * m_bodies.size(), &m_bodies[0], GL_DYNAMIC_DRAW);

		cl_int ret = 0;
		m_clVB = clCreateFromGLBuffer(m_clContext, CL_MEM_READ_WRITE, m_VB, &ret);
		clErrNoAssert(ret);
		ret = clSetKernelArg(m_kernelCalcForces, 0, sizeof(cl_mem), (void *)&m_clVB);
		clErrNoAssert(ret);
		ret = clSetKernelArg(m_kernelMove, 0, sizeof(cl_mem), (void *)&m_clVB);
		clErrNoAssert(ret);

		m_last_time_dt = 0;
		m_time_shift = 1;
		m_dt = 0.00001f;

		m_shaderProgram = new CommonShaderProgram("vertexshader.txt", "pixelshader.txt", "geometryshader.txt");
		m_shaderProgram->Compile();
		m_shaderProgram->Apply();
		m_shaderProgram->SetScale(m_scale);
		m_shaderProgram->SetOffset(m_offset);
		m_shaderProgram->SetAspectRatio(m_aspectRatio);

		return true;
	}