示例#1
0
void Camera::SetViewportSize(float width, float height)
{
  camWidth = width;
  camHeight = height;
  camAspectRatio =  camWidth / camHeight;
  CalculatePerspectiveMatrix();
}
示例#2
0
void NativeApplication::OpenGLInit(HWND wnd, HDC deviceContext, HGLRC renderingContext)
{
	// GL thread class had loaded dummy context
	if (!gl.LoadOpenGLES2Functions())
		throw NativeException("OpenGLES2 function loading failed");

	hwnd = wnd;
	m_deviceContext = deviceContext;
	m_renderingContext = renderingContext;
	if (!ContextUtil::DestroyDummyAndCreateRealContext(gl, hwnd, &m_deviceContext, &m_renderingContext))
		return;

	std::vector<GLuint> shaderList;
	try
	{
		shaderList.push_back(ShaderUtil::LoadAndCompileShader(GL_VERTEX_SHADER, "..\\NativeApp\\shaders\\LocalTransform.vert"));
		shaderList.push_back(ShaderUtil::LoadAndCompileShader(GL_FRAGMENT_SHADER, "..\\NativeApp\\shaders\\StandardColors.frag"));
		theProgram = ShaderUtil::CreateProgram(shaderList);
	}
	catch(NativeException&) { throw; }

	offsetUniform = glGetUniformLocation(theProgram, "offset");
	modelMatrixUnif = glGetUniformLocation(theProgram, "modelMatrix");
	perspectiveMatrixUnif = glGetUniformLocation(theProgram, "perspectiveMatrix");

	CalculatePerspectiveMatrix();

	glUseProgram(theProgram);
	glUniformMatrix4fv(perspectiveMatrixUnif, 1, GL_FALSE, perspectiveMatrix);
	glUseProgram(0);

	InitializeVertexBuffer();

	// VAO is necessary when using core profile, unless code is run using NVidia card. At least, that's how I understood this obscure subject.
	// see https://www.opengl.org/discussion_boards/showthread.php/181092-Drawing-a-single-point-without-VAO-on-NVIDIA-and-AMD
	gl.glGenVertexArrays(1, &vao);
	gl.glBindVertexArray(vao);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);
}