bool HeightMap::appMain() { if (!running) { return false; } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(program.programID()); running &= checkGLError("Error encountered enabling Shader Program\n", Logger::LOG_ERROR); _xform = Matrix4::translate(0.0f, -1.0f, _zPlane) * Matrix4::rotate(40.0f, 0.0f, 0.0f) * Matrix4::rotate(0.0f, _angle, 0.0f); glUniformMatrix4fv(_xformLoc, 1, false, _xform.buffer()); running &= checkGLError("Error encountered enabling loading Transform matrix: %s\n", Logger::LOG_ERROR); glDrawArrays(_drawMode, 0, _totalVerts); running &= checkGLError("Error encountered calling glDrawArrays: %s\n", Logger::LOG_ERROR); display->swapBuffers(); display->mainLoop(*this); _angle += 0.5f; if (_angle >= 360.0f) { _angle -= 360.0f; }; return true; }
void HeightMap::loadUniforms() { _xformLoc = program.uniformLocation("xform"); _projectionLoc = program.uniformLocation("projection"); glUniformMatrix4fv(_projectionLoc, 1, false, _projection.buffer()); _vpsLoc = program.uniformLocation("vertsPerSide"); glUniform1i(_vpsLoc, _vertsPerSide); _heightLoc = program.uniformLocation("heightMap"); glUniform1i(_heightLoc, 1); _lighting.setBinding(1); _lighting.setPosition(1, 0.0f, 0.0f, 1.0f); _lighting.setColor(1, 1.0f, 1.0f, 1.0f); _lighting.setAmbient(1, 0.2f, 0.2f, 0.2f); _lighting.loadRig(program); _flattenLoc = program.uniformLocation("flatten"); glUniform1i(_flattenLoc, _flatten); }
void HeightMap::resizeWindow(int newX, int newY) { _projection = Matrix4::fovHorizontal( 0.2f, 6.0f, 90.0f, display->aspectRatio()); glUniformMatrix4fv(_projectionLoc, 1, false, _projection.buffer()); running &= checkGLError("Error encountered updating Projection Matrix: %s\n", Logger::LOG_ERROR); }