当前位置: 首页>>代码示例>>C++>>正文


C++ ShaderProgram::SetScale方法代码示例

本文整理汇总了C++中ShaderProgram::SetScale方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::SetScale方法的具体用法?C++ ShaderProgram::SetScale怎么用?C++ ShaderProgram::SetScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShaderProgram的用法示例。


在下文中一共展示了ShaderProgram::SetScale方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnKeyPressed

	virtual void OnKeyPressed(KEY key)
	{
		float offsetStep = 0.1f * m_scale;
		const float scaleStep = 0.4f;

		switch (key)
		{
		case KEY::KEY_ESCAPE:
			m_backend->Terminate();
			break;

		case KEY::KEY_UP:
			m_offset.y -= offsetStep;
			m_shaderProgram->SetOffset(m_offset);
			break;
		case KEY::KEY_DOWN:
			m_offset.y += offsetStep;
			m_shaderProgram->SetOffset(m_offset);
			break;
		case KEY::KEY_LEFT:
			m_offset.x += offsetStep;
			m_shaderProgram->SetOffset(m_offset);
			break;
		case KEY::KEY_RIGHT:
			m_offset.x -= offsetStep;
			m_shaderProgram->SetOffset(m_offset);
			break;

		case KEY::KEY_q:
			m_scale += scaleStep;
			m_shaderProgram->SetScale(m_scale);
			break;
		case KEY::KEY_w:
			m_scale -= scaleStep;
			m_shaderProgram->SetScale(m_scale);
			break;
		case KEY::KEY_s:
			m_pause = !m_pause;
			break;
		}
	}
开发者ID:AndersUa,项目名称:NBody,代码行数:41,代码来源:main.cpp

示例2: OnMouseKey

	virtual void OnMouseKey(MOUSE_KEY key, MOUSE_STATE state, int x, int y)
	{
		float scaleStep = 2.0;
		switch (key)
		{
		case MOUSE_KEY::WHEEL_DOWN:
			m_scale += scaleStep;
			m_shaderProgram->SetScale(m_scale);
			break;
		case MOUSE_KEY::WHEEL_UP:
			m_scale -= scaleStep;
			m_shaderProgram->SetScale(m_scale);
			break;
		case MOUSE_KEY::LEFT:
			m_keyLeftPressed = !state;
			m_mouse_x = x;
			m_mouse_y = y;
			break;
		}


	}
开发者ID:AndersUa,项目名称:NBody,代码行数:22,代码来源:main.cpp

示例3: Init

	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;
	}
开发者ID:AndersUa,项目名称:NBody,代码行数:71,代码来源:main.cpp


注:本文中的ShaderProgram::SetScale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。