Skip to content

Commit

Permalink
Added fps counter in title bar and tab unlocks the mouse.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdgiessen committed Jun 8, 2018
1 parent 7c73432 commit 183d251
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
15 changes: 14 additions & 1 deletion TerrainFPS/TerrainFPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ void do_movement(TerrainFPS terrain)
camera.UpdatePosition(terrain.TerrainHeight(camera.Position.x + terrain.nrows / 2, camera.Position.z + terrain.ncols / 2) * terrain.terrainHeightScale, deltaTime);
//std::cout << camera.Position.y << std::endl;

if (keys[GLFW_KEY_TAB]) {

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}

}

static void error_callback(int error, const char* description)
Expand Down Expand Up @@ -118,6 +123,9 @@ void OnMouseButton(GLFWwindow* window, int glfwButton, int glfwAction) {
else
bullet.Position.y += 0.0f;
bullets.push_back(bullet);

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

}
}

Expand Down Expand Up @@ -163,7 +171,6 @@ void setup_window() {

// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
glewExperimental = GL_TRUE;

glfwSwapInterval(1);

// Initialize GLEW to setup the OpenGL Function pointers
Expand Down Expand Up @@ -299,9 +306,11 @@ void TerrainFPS::GenSubDividedTerrainSurface() {
terVerts[curPlace++] = i - data->nrows / 2;
terVerts[curPlace++] = ((data->data[i][j]) - data->lowestValue) / data->range;
terVerts[curPlace++] = j - data->ncols / 2;

terVerts[curPlace++] = CalcColorAtElevation((data->data[i][j] - data->lowestValue) / data->range, 0);
terVerts[curPlace++] = CalcColorAtElevation((data->data[i][j] - data->lowestValue) / data->range, 1);
terVerts[curPlace++] = CalcColorAtElevation((data->data[i][j] - data->lowestValue) / data->range, 2);

float hL = Height(i + 1, j);
float hR = Height(i - 1, j);
float hD = Height(i, j + 1);
Expand Down Expand Up @@ -575,6 +584,10 @@ int main() {
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;

glfwSetWindowTitle(window,
std::string(std::string("Terrain FPS ") + std::to_string(1 / deltaTime).c_str()).c_str()
);

// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
glfwPollEvents();
do_movement(shooter);
Expand Down
1 change: 1 addition & 0 deletions TerrainFPS/TerrainFPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Camera camera(glm::vec3(0, 60, 0));
bool keys[1024];
GLfloat lastX = 400, lastY = 300;
bool firstMouse = true;
bool mouseControl = false;

// Deltatime
GLfloat deltaTime = 0.0f; // Time between current frame and last frame
Expand Down
16 changes: 14 additions & 2 deletions TerrainFPS/TerrainFPS.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,37 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>C:\openglstuff\include;$(IncludePath)</IncludePath>
<IncludePath>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glm\include;C:\openglstuff\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\openglstuff\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>C:\openglstuff\include;$(IncludePath)</IncludePath>
<IncludePath>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glm\include;C:\openglstuff\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\openglstuff\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glew\include;C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glm\include;C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glfw\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>SOIL.lib;opengl32.lib;glfw3.lib;glew32s.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\soil;C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glfw\lib;C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glew\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glm\include;C:\Users\Charles\Downloads\glew-2.0.0-win32\glew-2.0.0\include;C:\Users\Charles\Downloads\glfw-3.2.1\glfw-3.2.1\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>glfw3.lib;glew32s.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glew\lib;C:\Users\Charles\Downloads\glfw-3.2.1.bin.WIN32\glfw-3.2.1.bin.WIN32\lib-vc2015;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -101,11 +108,13 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glew\include;C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glm\include;C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glfw\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>SOIL.lib;opengl32.lib;glfw3.lib;glew32s.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\soil;C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glfw\lib;C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glew\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -115,10 +124,13 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glm\include;C:\Users\Charles\Downloads\glew-2.0.0-win32\glew-2.0.0\include;C:\Users\Charles\Downloads\glfw-3.2.1\glfw-3.2.1\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>glfw3.lib;glew32s.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\Charles\Documents\Visual Studio 2015\Libraries\glew\lib;C:\Users\Charles\Downloads\glfw-3.2.1.bin.WIN32\glfw-3.2.1.bin.WIN32\lib-vc2015;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down

0 comments on commit 183d251

Please sign in to comment.