Add task 3
BIN
exercise3/Aufgabenstellung.pdf
Normal file
BIN
exercise3/Programmaufbau.pdf
Normal file
58
exercise3/build/cmake/CMakeLists.txt
Normal file
|
@ -0,0 +1,58 @@
|
|||
cmake_minimum_required( VERSION 2.6 )
|
||||
|
||||
project(exercise3)
|
||||
|
||||
# Gebraucht werden OpenGL und GLUT
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLUT REQUIRED)
|
||||
|
||||
# Definition der Headerdateien
|
||||
set(HEADERS
|
||||
../../include/abstract_scene.h
|
||||
../../include/cube_system_split.h
|
||||
../../include/example_primitives.h
|
||||
../../include/terrain.h
|
||||
../../include/application.h
|
||||
../../include/example_3d_primitives.h
|
||||
../../include/example_trans_order.h
|
||||
../../include/tiny_vec.h
|
||||
../../include/cube_system.h
|
||||
../../include/example_cons_primitives.h
|
||||
../../include/recursive_cubes.h
|
||||
../../dependencies/qdbmp/include/qdbmp.h
|
||||
)
|
||||
|
||||
# Definition der Sourcedateien
|
||||
set(SOURCES
|
||||
../../src/abstract_scene.cpp
|
||||
../../src/example_3d_primitives.cpp
|
||||
../../src/main.cpp
|
||||
../../src/application.cpp
|
||||
../../src/example_cons_primitives.cpp
|
||||
../../src/recursive_cubes.cpp
|
||||
../../src/cube_system.cpp
|
||||
../../src/example_primitives.cpp
|
||||
../../src/terrain.cpp
|
||||
../../src/cube_system_split.cpp
|
||||
../../src/example_trans_order.cpp
|
||||
../../dependencies/qdbmp/src/qdbmp.cpp
|
||||
)
|
||||
|
||||
# Includeverzeichnisse setzen
|
||||
include_directories(
|
||||
../../include
|
||||
../../dependencies/qdbmp/include
|
||||
)
|
||||
|
||||
|
||||
# Support fuer C++-11 aktivieren
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11")
|
||||
|
||||
# Ziel hinzufuegen
|
||||
add_executable(exercise3
|
||||
${SOURCES}
|
||||
${HEADERS}
|
||||
)
|
||||
|
||||
# Bibliotheken linken
|
||||
target_link_libraries(exercise3 ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
|
20
exercise3/build/vs2012/graph_prog.sln
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graph_prog", "graph_prog.vcxproj", "{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
117
exercise3/build/vs2012/graph_prog.vcxproj
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}</ProjectGuid>
|
||||
<RootNamespace>graph_prog</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>../../include;../../dependencies/freeglut/include;../../dependencies/qdbmp/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;FREEGLUT_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<ProjectReference>
|
||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
||||
</ProjectReference>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>../../dependencies/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>../../include;../../dependencies/freeglut/include;../../dependencies/qdbmp/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;FREEGLUT_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>../../dependencies/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\application.cpp" />
|
||||
<ClCompile Include="..\..\src\main.cpp" />
|
||||
<ClCompile Include="..\..\src\abstract_scene.cpp" />
|
||||
<ClCompile Include="..\..\src\cube_system.cpp" />
|
||||
<ClCompile Include="..\..\src\cube_system_split.cpp" />
|
||||
<ClCompile Include="..\..\src\recursive_cubes.cpp" />
|
||||
<ClCompile Include="..\..\src\terrain.cpp" />
|
||||
<ClCompile Include="..\..\src\example_3d_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_cons_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_trans_order.cpp" />
|
||||
<ClCompile Include="..\..\dependencies\qdbmp\src\qdbmp.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\application.h" />
|
||||
<ClInclude Include="..\..\include\tiny_vec.h" />
|
||||
<ClInclude Include="..\..\include\abstract_scene.h" />
|
||||
<ClInclude Include="..\..\include\cube_system.h" />
|
||||
<ClInclude Include="..\..\include\cube_system_split.h" />
|
||||
<ClInclude Include="..\..\include\recursive_cubes.h" />
|
||||
<ClInclude Include="..\..\include\terrain.h" />
|
||||
<ClInclude Include="..\..\include\example_3d_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_cons_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_trans_order.h" />
|
||||
<ClInclude Include="..\..\dependencies\qdbmp\include\qdbmp.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
20
exercise3/build/vs2015/graph_prog.sln
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2015
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graph_prog", "graph_prog.vcxproj", "{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
127
exercise3/build/vs2015/graph_prog.vcxproj
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}</ProjectGuid>
|
||||
<RootNamespace>graph_prog</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>15.0</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>../../include;../../dependencies/freeglut/include;../../dependencies/qdbmp/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<ProjectReference>
|
||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
||||
</ProjectReference>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>../../dependencies/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy /Y "..\..\dependencies\freeglut\lib\freeglut.dll" "$(SolutionDir)$(Configuration)"</Command>
|
||||
<Message>Copy freeglut .dll to executable location</Message>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>../../include;../../dependencies/freeglut/include;../../dependencies/qdbmp/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>../../dependencies/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy /Y "..\..\dependencies\freeglut\lib\freeglut.dll" "$(SolutionDir)$(Configuration)"</Command>
|
||||
<Message>Copy freeglut .dll to executable location</Message>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\application.cpp" />
|
||||
<ClCompile Include="..\..\src\main.cpp" />
|
||||
<ClCompile Include="..\..\src\abstract_scene.cpp" />
|
||||
<ClCompile Include="..\..\src\cube_system.cpp" />
|
||||
<ClCompile Include="..\..\src\cube_system_split.cpp" />
|
||||
<ClCompile Include="..\..\src\recursive_cubes.cpp" />
|
||||
<ClCompile Include="..\..\src\terrain.cpp" />
|
||||
<ClCompile Include="..\..\src\example_3d_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_cons_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_trans_order.cpp" />
|
||||
<ClCompile Include="..\..\dependencies\qdbmp\src\qdbmp.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\application.h" />
|
||||
<ClInclude Include="..\..\include\tiny_vec.h" />
|
||||
<ClInclude Include="..\..\include\abstract_scene.h" />
|
||||
<ClInclude Include="..\..\include\cube_system.h" />
|
||||
<ClInclude Include="..\..\include\cube_system_split.h" />
|
||||
<ClInclude Include="..\..\include\recursive_cubes.h" />
|
||||
<ClInclude Include="..\..\include\terrain.h" />
|
||||
<ClInclude Include="..\..\include\example_3d_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_cons_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_trans_order.h" />
|
||||
<ClInclude Include="..\..\dependencies\qdbmp\include\qdbmp.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
20
exercise3/build/vs2017/graph_prog.sln
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2017
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graph_prog", "graph_prog.vcxproj", "{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
127
exercise3/build/vs2017/graph_prog.vcxproj
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{ED74E400-FCC9-4F7A-AFD7-90A2C5300D90}</ProjectGuid>
|
||||
<RootNamespace>graph_prog</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>15.0</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>../../include;../../dependencies/freeglut/include;../../dependencies/qdbmp/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<ProjectReference>
|
||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
||||
</ProjectReference>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>../../dependencies/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy /Y "..\..\dependencies\freeglut\lib\freeglut.dll" "$(SolutionDir)$(Configuration)"</Command>
|
||||
<Message>Copy freeglut .dll to executable location</Message>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>../../include;../../dependencies/freeglut/include;../../dependencies/qdbmp/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>../../dependencies/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy /Y "..\..\dependencies\freeglut\lib\freeglut.dll" "$(SolutionDir)$(Configuration)"</Command>
|
||||
<Message>Copy freeglut .dll to executable location</Message>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\application.cpp" />
|
||||
<ClCompile Include="..\..\src\main.cpp" />
|
||||
<ClCompile Include="..\..\src\abstract_scene.cpp" />
|
||||
<ClCompile Include="..\..\src\cube_system.cpp" />
|
||||
<ClCompile Include="..\..\src\cube_system_split.cpp" />
|
||||
<ClCompile Include="..\..\src\recursive_cubes.cpp" />
|
||||
<ClCompile Include="..\..\src\terrain.cpp" />
|
||||
<ClCompile Include="..\..\src\example_3d_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_cons_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_primitives.cpp" />
|
||||
<ClCompile Include="..\..\src\example_trans_order.cpp" />
|
||||
<ClCompile Include="..\..\dependencies\qdbmp\src\qdbmp.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\application.h" />
|
||||
<ClInclude Include="..\..\include\tiny_vec.h" />
|
||||
<ClInclude Include="..\..\include\abstract_scene.h" />
|
||||
<ClInclude Include="..\..\include\cube_system.h" />
|
||||
<ClInclude Include="..\..\include\cube_system_split.h" />
|
||||
<ClInclude Include="..\..\include\recursive_cubes.h" />
|
||||
<ClInclude Include="..\..\include\terrain.h" />
|
||||
<ClInclude Include="..\..\include\example_3d_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_cons_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_primitives.h" />
|
||||
<ClInclude Include="..\..\include\example_trans_order.h" />
|
||||
<ClInclude Include="..\..\dependencies\qdbmp\include\qdbmp.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
BIN
exercise3/data/tex_height.bmp
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
exercise3/data/tex_height.png
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
exercise3/data/tex_height_small.bmp
Normal file
After Width: | Height: | Size: 454 B |
BIN
exercise3/data/tex_satellit.bmp
Normal file
After Width: | Height: | Size: 1 MiB |
BIN
exercise3/data/tex_satellit.png
Normal file
After Width: | Height: | Size: 451 KiB |
BIN
exercise3/data/tex_topo.bmp
Normal file
After Width: | Height: | Size: 1 MiB |
BIN
exercise3/data/tex_topo.png
Normal file
After Width: | Height: | Size: 226 KiB |
22
exercise3/dependencies/freeglut/include/GL/freeglut.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef __FREEGLUT_H__
|
||||
#define __FREEGLUT_H__
|
||||
|
||||
/*
|
||||
* freeglut.h
|
||||
*
|
||||
* The freeglut library include file
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "freeglut_std.h"
|
||||
#include "freeglut_ext.h"
|
||||
|
||||
/*** END OF FILE ***/
|
||||
|
||||
#endif /* __FREEGLUT_H__ */
|
271
exercise3/dependencies/freeglut/include/GL/freeglut_ext.h
Normal file
|
@ -0,0 +1,271 @@
|
|||
#ifndef __FREEGLUT_EXT_H__
|
||||
#define __FREEGLUT_EXT_H__
|
||||
|
||||
/*
|
||||
* freeglut_ext.h
|
||||
*
|
||||
* The non-GLUT-compatible extensions to the freeglut library include file
|
||||
*
|
||||
* Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
|
||||
* Written by Pawel W. Olszta, <olszta@sourceforge.net>
|
||||
* Creation date: Thu Dec 2 1999
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Additional GLUT Key definitions for the Special key function
|
||||
*/
|
||||
#define GLUT_KEY_NUM_LOCK 0x006D
|
||||
#define GLUT_KEY_BEGIN 0x006E
|
||||
#define GLUT_KEY_DELETE 0x006F
|
||||
#define GLUT_KEY_SHIFT_L 0x0070
|
||||
#define GLUT_KEY_SHIFT_R 0x0071
|
||||
#define GLUT_KEY_CTRL_L 0x0072
|
||||
#define GLUT_KEY_CTRL_R 0x0073
|
||||
#define GLUT_KEY_ALT_L 0x0074
|
||||
#define GLUT_KEY_ALT_R 0x0075
|
||||
|
||||
/*
|
||||
* GLUT API Extension macro definitions -- behaviour when the user clicks on an "x" to close a window
|
||||
*/
|
||||
#define GLUT_ACTION_EXIT 0
|
||||
#define GLUT_ACTION_GLUTMAINLOOP_RETURNS 1
|
||||
#define GLUT_ACTION_CONTINUE_EXECUTION 2
|
||||
|
||||
/*
|
||||
* Create a new rendering context when the user opens a new window?
|
||||
*/
|
||||
#define GLUT_CREATE_NEW_CONTEXT 0
|
||||
#define GLUT_USE_CURRENT_CONTEXT 1
|
||||
|
||||
/*
|
||||
* Direct/Indirect rendering context options (has meaning only in Unix/X11)
|
||||
*/
|
||||
#define GLUT_FORCE_INDIRECT_CONTEXT 0
|
||||
#define GLUT_ALLOW_DIRECT_CONTEXT 1
|
||||
#define GLUT_TRY_DIRECT_CONTEXT 2
|
||||
#define GLUT_FORCE_DIRECT_CONTEXT 3
|
||||
|
||||
/*
|
||||
* GLUT API Extension macro definitions -- the glutGet parameters
|
||||
*/
|
||||
#define GLUT_INIT_STATE 0x007C
|
||||
|
||||
#define GLUT_ACTION_ON_WINDOW_CLOSE 0x01F9
|
||||
|
||||
#define GLUT_WINDOW_BORDER_WIDTH 0x01FA
|
||||
#define GLUT_WINDOW_BORDER_HEIGHT 0x01FB
|
||||
#define GLUT_WINDOW_HEADER_HEIGHT 0x01FB /* Docs say it should always have been GLUT_WINDOW_BORDER_HEIGHT, keep this for backward compatibility */
|
||||
|
||||
#define GLUT_VERSION 0x01FC
|
||||
|
||||
#define GLUT_RENDERING_CONTEXT 0x01FD
|
||||
#define GLUT_DIRECT_RENDERING 0x01FE
|
||||
|
||||
#define GLUT_FULL_SCREEN 0x01FF
|
||||
|
||||
#define GLUT_SKIP_STALE_MOTION_EVENTS 0x0204
|
||||
|
||||
#define GLUT_GEOMETRY_VISUALIZE_NORMALS 0x0205
|
||||
|
||||
#define GLUT_STROKE_FONT_DRAW_JOIN_DOTS 0x0206 /* Draw dots between line segments of stroke fonts? */
|
||||
|
||||
/*
|
||||
* New tokens for glutInitDisplayMode.
|
||||
* Only one GLUT_AUXn bit may be used at a time.
|
||||
* Value 0x0400 is defined in OpenGLUT.
|
||||
*/
|
||||
#define GLUT_AUX 0x1000
|
||||
|
||||
#define GLUT_AUX1 0x1000
|
||||
#define GLUT_AUX2 0x2000
|
||||
#define GLUT_AUX3 0x4000
|
||||
#define GLUT_AUX4 0x8000
|
||||
|
||||
/*
|
||||
* Context-related flags, see fg_state.c
|
||||
* Set the requested OpenGL version
|
||||
*/
|
||||
#define GLUT_INIT_MAJOR_VERSION 0x0200
|
||||
#define GLUT_INIT_MINOR_VERSION 0x0201
|
||||
#define GLUT_INIT_FLAGS 0x0202
|
||||
#define GLUT_INIT_PROFILE 0x0203
|
||||
|
||||
/*
|
||||
* Flags for glutInitContextFlags, see fg_init.c
|
||||
*/
|
||||
#define GLUT_DEBUG 0x0001
|
||||
#define GLUT_FORWARD_COMPATIBLE 0x0002
|
||||
|
||||
|
||||
/*
|
||||
* Flags for glutInitContextProfile, see fg_init.c
|
||||
*/
|
||||
#define GLUT_CORE_PROFILE 0x0001
|
||||
#define GLUT_COMPATIBILITY_PROFILE 0x0002
|
||||
|
||||
/*
|
||||
* Process loop function, see fg_main.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutMainLoopEvent( void );
|
||||
FGAPI void FGAPIENTRY glutLeaveMainLoop( void );
|
||||
FGAPI void FGAPIENTRY glutExit ( void );
|
||||
|
||||
/*
|
||||
* Window management functions, see fg_window.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutFullScreenToggle( void );
|
||||
FGAPI void FGAPIENTRY glutLeaveFullScreen( void );
|
||||
|
||||
/*
|
||||
* Menu functions
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutSetMenuFont( int menuID, void* font );
|
||||
|
||||
/*
|
||||
* Window-specific callback functions, see fg_callbacks.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutPositionFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutCloseFunc( void (* callback)( void ) );
|
||||
FGAPI void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) );
|
||||
/* And also a destruction callback for menus */
|
||||
FGAPI void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) );
|
||||
|
||||
/*
|
||||
* State setting and retrieval functions, see fg_state.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutSetOption ( GLenum option_flag, int value );
|
||||
FGAPI int * FGAPIENTRY glutGetModeValues(GLenum mode, int * size);
|
||||
/* A.Donev: User-data manipulation */
|
||||
FGAPI void* FGAPIENTRY glutGetWindowData( void );
|
||||
FGAPI void FGAPIENTRY glutSetWindowData(void* data);
|
||||
FGAPI void* FGAPIENTRY glutGetMenuData( void );
|
||||
FGAPI void FGAPIENTRY glutSetMenuData(void* data);
|
||||
|
||||
/*
|
||||
* Font stuff, see fg_font.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutBitmapHeight( void* font );
|
||||
FGAPI GLfloat FGAPIENTRY glutStrokeHeight( void* font );
|
||||
FGAPI void FGAPIENTRY glutBitmapString( void* font, const unsigned char *string );
|
||||
FGAPI void FGAPIENTRY glutStrokeString( void* font, const unsigned char *string );
|
||||
|
||||
/*
|
||||
* Geometry functions, see fg_geometry.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutWireRhombicDodecahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidRhombicDodecahedron( void );
|
||||
FGAPI void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, double offset[3], double scale );
|
||||
FGAPI void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, double offset[3], double scale );
|
||||
FGAPI void FGAPIENTRY glutWireCylinder( double radius, double height, GLint slices, GLint stacks);
|
||||
FGAPI void FGAPIENTRY glutSolidCylinder( double radius, double height, GLint slices, GLint stacks);
|
||||
|
||||
/*
|
||||
* Rest of functions for rendering Newell's teaset, found in fg_teapot.c
|
||||
* NB: front facing polygons have clockwise winding, not counter clockwise
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutWireTeacup( double size );
|
||||
FGAPI void FGAPIENTRY glutSolidTeacup( double size );
|
||||
FGAPI void FGAPIENTRY glutWireTeaspoon( double size );
|
||||
FGAPI void FGAPIENTRY glutSolidTeaspoon( double size );
|
||||
|
||||
/*
|
||||
* Extension functions, see fg_ext.c
|
||||
*/
|
||||
typedef void (*GLUTproc)();
|
||||
FGAPI GLUTproc FGAPIENTRY glutGetProcAddress( const char *procName );
|
||||
|
||||
/*
|
||||
* Multi-touch/multi-pointer extensions
|
||||
*/
|
||||
|
||||
#define GLUT_HAS_MULTI 1
|
||||
|
||||
/* TODO: add device_id parameter,
|
||||
cf. http://sourceforge.net/mailarchive/forum.php?thread_name=20120518071314.GA28061%40perso.beuc.net&forum_name=freeglut-developer */
|
||||
FGAPI void FGAPIENTRY glutMultiEntryFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutMultiButtonFunc( void (* callback)( int, int, int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutMultiMotionFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutMultiPassiveFunc( void (* callback)( int, int, int ) );
|
||||
|
||||
/*
|
||||
* Joystick functions, see fg_joystick.c
|
||||
*/
|
||||
/* USE OF THESE FUNCTIONS IS DEPRECATED !!!!! */
|
||||
/* If you have a serious need for these functions in your application, please either
|
||||
* contact the "freeglut" developer community at freeglut-developer@lists.sourceforge.net,
|
||||
* switch to the OpenGLUT library, or else port your joystick functionality over to PLIB's
|
||||
* "js" library.
|
||||
*/
|
||||
int glutJoystickGetNumAxes( int ident );
|
||||
int glutJoystickGetNumButtons( int ident );
|
||||
int glutJoystickNotWorking( int ident );
|
||||
float glutJoystickGetDeadBand( int ident, int axis );
|
||||
void glutJoystickSetDeadBand( int ident, int axis, float db );
|
||||
float glutJoystickGetSaturation( int ident, int axis );
|
||||
void glutJoystickSetSaturation( int ident, int axis, float st );
|
||||
void glutJoystickSetMinRange( int ident, float *axes );
|
||||
void glutJoystickSetMaxRange( int ident, float *axes );
|
||||
void glutJoystickSetCenter( int ident, float *axes );
|
||||
void glutJoystickGetMinRange( int ident, float *axes );
|
||||
void glutJoystickGetMaxRange( int ident, float *axes );
|
||||
void glutJoystickGetCenter( int ident, float *axes );
|
||||
|
||||
/*
|
||||
* Initialization functions, see fg_init.c
|
||||
*/
|
||||
/* to get the typedef for va_list */
|
||||
#include <stdarg.h>
|
||||
FGAPI void FGAPIENTRY glutInitContextVersion( int majorVersion, int minorVersion );
|
||||
FGAPI void FGAPIENTRY glutInitContextFlags( int flags );
|
||||
FGAPI void FGAPIENTRY glutInitContextProfile( int profile );
|
||||
FGAPI void FGAPIENTRY glutInitErrorFunc( void (* callback)( const char *fmt, va_list ap ) );
|
||||
FGAPI void FGAPIENTRY glutInitWarningFunc( void (* callback)( const char *fmt, va_list ap ) );
|
||||
|
||||
/* OpenGL >= 2.0 support */
|
||||
FGAPI void FGAPIENTRY glutSetVertexAttribCoord3(GLint attrib);
|
||||
FGAPI void FGAPIENTRY glutSetVertexAttribNormal(GLint attrib);
|
||||
FGAPI void FGAPIENTRY glutSetVertexAttribTexCoord2(GLint attrib);
|
||||
|
||||
/* Mobile platforms lifecycle */
|
||||
FGAPI void FGAPIENTRY glutInitContextFunc(void (* callback)());
|
||||
FGAPI void FGAPIENTRY glutAppStatusFunc(void (* callback)(int));
|
||||
/* state flags that can be passed to callback set by glutAppStatusFunc */
|
||||
#define GLUT_APPSTATUS_PAUSE 0x0001
|
||||
#define GLUT_APPSTATUS_RESUME 0x0002
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the display mode definitions
|
||||
*/
|
||||
#define GLUT_CAPTIONLESS 0x0400
|
||||
#define GLUT_BORDERLESS 0x0800
|
||||
#define GLUT_SRGB 0x1000
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*** END OF FILE ***/
|
||||
|
||||
#endif /* __FREEGLUT_EXT_H__ */
|
653
exercise3/dependencies/freeglut/include/GL/freeglut_std.h
Normal file
|
@ -0,0 +1,653 @@
|
|||
#ifndef __FREEGLUT_STD_H__
|
||||
#define __FREEGLUT_STD_H__
|
||||
|
||||
/*
|
||||
* freeglut_std.h
|
||||
*
|
||||
* The GLUT-compatible part of the freeglut library include file
|
||||
*
|
||||
* Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
|
||||
* Written by Pawel W. Olszta, <olszta@sourceforge.net>
|
||||
* Creation date: Thu Dec 2 1999
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Under windows, we have to differentiate between static and dynamic libraries
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
/* #pragma may not be supported by some compilers.
|
||||
* Discussion by FreeGLUT developers suggests that
|
||||
* Visual C++ specific code involving pragmas may
|
||||
* need to move to a separate header. 24th Dec 2003
|
||||
*/
|
||||
|
||||
/* Define FREEGLUT_LIB_PRAGMAS to 1 to include library
|
||||
* pragmas or to 0 to exclude library pragmas.
|
||||
* The default behavior depends on the compiler/platform.
|
||||
*/
|
||||
# ifndef FREEGLUT_LIB_PRAGMAS
|
||||
# if ( defined(_MSC_VER) || defined(__WATCOMC__) ) && !defined(_WIN32_WCE)
|
||||
# define FREEGLUT_LIB_PRAGMAS 1
|
||||
# else
|
||||
# define FREEGLUT_LIB_PRAGMAS 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN 1
|
||||
# endif
|
||||
# ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
# endif
|
||||
# include <windows.h>
|
||||
|
||||
/* Windows static library */
|
||||
# ifdef FREEGLUT_STATIC
|
||||
|
||||
# define FGAPI
|
||||
# define FGAPIENTRY
|
||||
|
||||
/* Link with Win32 static freeglut lib */
|
||||
# if FREEGLUT_LIB_PRAGMAS
|
||||
# ifdef NDEBUG
|
||||
# pragma comment (lib, "freeglut_static.lib")
|
||||
# else
|
||||
# pragma comment (lib, "freeglut_staticd.lib")
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Windows shared library (DLL) */
|
||||
# else
|
||||
|
||||
# define FGAPIENTRY __stdcall
|
||||
# if defined(FREEGLUT_EXPORTS)
|
||||
# define FGAPI __declspec(dllexport)
|
||||
# else
|
||||
# define FGAPI __declspec(dllimport)
|
||||
|
||||
/* Link with Win32 shared freeglut lib */
|
||||
# if FREEGLUT_LIB_PRAGMAS
|
||||
# ifdef NDEBUG
|
||||
# pragma comment (lib, "freeglut.lib")
|
||||
# else
|
||||
# pragma comment (lib, "freeglutd.lib")
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
/* Drag in other Windows libraries as required by FreeGLUT */
|
||||
# if FREEGLUT_LIB_PRAGMAS
|
||||
# pragma comment (lib, "glu32.lib") /* link OpenGL Utility lib */
|
||||
# pragma comment (lib, "opengl32.lib") /* link Microsoft OpenGL lib */
|
||||
# pragma comment (lib, "gdi32.lib") /* link Windows GDI lib */
|
||||
# pragma comment (lib, "winmm.lib") /* link Windows MultiMedia lib */
|
||||
# pragma comment (lib, "user32.lib") /* link Windows user lib */
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
/* Non-Windows definition of FGAPI and FGAPIENTRY */
|
||||
# define FGAPI
|
||||
# define FGAPIENTRY
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The freeglut and GLUT API versions
|
||||
*/
|
||||
#define FREEGLUT 1
|
||||
#define GLUT_API_VERSION 4
|
||||
#define GLUT_XLIB_IMPLEMENTATION 13
|
||||
/* Deprecated:
|
||||
cf. http://sourceforge.net/mailarchive/forum.php?thread_name=CABcAi1hw7cr4xtigckaGXB5X8wddLfMcbA_rZ3NAuwMrX_zmsw%40mail.gmail.com&forum_name=freeglut-developer */
|
||||
#define FREEGLUT_VERSION_2_0 1
|
||||
|
||||
/*
|
||||
* Always include OpenGL and GLU headers
|
||||
*/
|
||||
/* Note: FREEGLUT_GLES is only used to cleanly bootstrap headers
|
||||
inclusion here; use GLES constants directly
|
||||
(e.g. GL_ES_VERSION_2_0) for all other needs */
|
||||
#ifdef FREEGLUT_GLES
|
||||
# include <EGL/egl.h>
|
||||
# include <GLES/gl.h>
|
||||
# include <GLES2/gl2.h>
|
||||
#elif __APPLE__
|
||||
# include <OpenGL/gl.h>
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/gl.h>
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the special key codes:
|
||||
*/
|
||||
#define GLUT_KEY_F1 0x0001
|
||||
#define GLUT_KEY_F2 0x0002
|
||||
#define GLUT_KEY_F3 0x0003
|
||||
#define GLUT_KEY_F4 0x0004
|
||||
#define GLUT_KEY_F5 0x0005
|
||||
#define GLUT_KEY_F6 0x0006
|
||||
#define GLUT_KEY_F7 0x0007
|
||||
#define GLUT_KEY_F8 0x0008
|
||||
#define GLUT_KEY_F9 0x0009
|
||||
#define GLUT_KEY_F10 0x000A
|
||||
#define GLUT_KEY_F11 0x000B
|
||||
#define GLUT_KEY_F12 0x000C
|
||||
#define GLUT_KEY_LEFT 0x0064
|
||||
#define GLUT_KEY_UP 0x0065
|
||||
#define GLUT_KEY_RIGHT 0x0066
|
||||
#define GLUT_KEY_DOWN 0x0067
|
||||
#define GLUT_KEY_PAGE_UP 0x0068
|
||||
#define GLUT_KEY_PAGE_DOWN 0x0069
|
||||
#define GLUT_KEY_HOME 0x006A
|
||||
#define GLUT_KEY_END 0x006B
|
||||
#define GLUT_KEY_INSERT 0x006C
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- mouse state definitions
|
||||
*/
|
||||
#define GLUT_LEFT_BUTTON 0x0000
|
||||
#define GLUT_MIDDLE_BUTTON 0x0001
|
||||
#define GLUT_RIGHT_BUTTON 0x0002
|
||||
#define GLUT_DOWN 0x0000
|
||||
#define GLUT_UP 0x0001
|
||||
#define GLUT_LEFT 0x0000
|
||||
#define GLUT_ENTERED 0x0001
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the display mode definitions
|
||||
*/
|
||||
#define GLUT_RGB 0x0000
|
||||
#define GLUT_RGBA 0x0000
|
||||
#define GLUT_INDEX 0x0001
|
||||
#define GLUT_SINGLE 0x0000
|
||||
#define GLUT_DOUBLE 0x0002
|
||||
#define GLUT_ACCUM 0x0004
|
||||
#define GLUT_ALPHA 0x0008
|
||||
#define GLUT_DEPTH 0x0010
|
||||
#define GLUT_STENCIL 0x0020
|
||||
#define GLUT_MULTISAMPLE 0x0080
|
||||
#define GLUT_STEREO 0x0100
|
||||
#define GLUT_LUMINANCE 0x0200
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- windows and menu related definitions
|
||||
*/
|
||||
#define GLUT_MENU_NOT_IN_USE 0x0000
|
||||
#define GLUT_MENU_IN_USE 0x0001
|
||||
#define GLUT_NOT_VISIBLE 0x0000
|
||||
#define GLUT_VISIBLE 0x0001
|
||||
#define GLUT_HIDDEN 0x0000
|
||||
#define GLUT_FULLY_RETAINED 0x0001
|
||||
#define GLUT_PARTIALLY_RETAINED 0x0002
|
||||
#define GLUT_FULLY_COVERED 0x0003
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- fonts definitions
|
||||
*
|
||||
* Steve Baker suggested to make it binary compatible with GLUT:
|
||||
*/
|
||||
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__WATCOMC__)
|
||||
# define GLUT_STROKE_ROMAN ((void *)0x0000)
|
||||
# define GLUT_STROKE_MONO_ROMAN ((void *)0x0001)
|
||||
# define GLUT_BITMAP_9_BY_15 ((void *)0x0002)
|
||||
# define GLUT_BITMAP_8_BY_13 ((void *)0x0003)
|
||||
# define GLUT_BITMAP_TIMES_ROMAN_10 ((void *)0x0004)
|
||||
# define GLUT_BITMAP_TIMES_ROMAN_24 ((void *)0x0005)
|
||||
# define GLUT_BITMAP_HELVETICA_10 ((void *)0x0006)
|
||||
# define GLUT_BITMAP_HELVETICA_12 ((void *)0x0007)
|
||||
# define GLUT_BITMAP_HELVETICA_18 ((void *)0x0008)
|
||||
#else
|
||||
/*
|
||||
* I don't really know if it's a good idea... But here it goes:
|
||||
*/
|
||||
extern void* glutStrokeRoman;
|
||||
extern void* glutStrokeMonoRoman;
|
||||
extern void* glutBitmap9By15;
|
||||
extern void* glutBitmap8By13;
|
||||
extern void* glutBitmapTimesRoman10;
|
||||
extern void* glutBitmapTimesRoman24;
|
||||
extern void* glutBitmapHelvetica10;
|
||||
extern void* glutBitmapHelvetica12;
|
||||
extern void* glutBitmapHelvetica18;
|
||||
|
||||
/*
|
||||
* Those pointers will be used by following definitions:
|
||||
*/
|
||||
# define GLUT_STROKE_ROMAN ((void *) &glutStrokeRoman)
|
||||
# define GLUT_STROKE_MONO_ROMAN ((void *) &glutStrokeMonoRoman)
|
||||
# define GLUT_BITMAP_9_BY_15 ((void *) &glutBitmap9By15)
|
||||
# define GLUT_BITMAP_8_BY_13 ((void *) &glutBitmap8By13)
|
||||
# define GLUT_BITMAP_TIMES_ROMAN_10 ((void *) &glutBitmapTimesRoman10)
|
||||
# define GLUT_BITMAP_TIMES_ROMAN_24 ((void *) &glutBitmapTimesRoman24)
|
||||
# define GLUT_BITMAP_HELVETICA_10 ((void *) &glutBitmapHelvetica10)
|
||||
# define GLUT_BITMAP_HELVETICA_12 ((void *) &glutBitmapHelvetica12)
|
||||
# define GLUT_BITMAP_HELVETICA_18 ((void *) &glutBitmapHelvetica18)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutGet parameters
|
||||
*/
|
||||
#define GLUT_WINDOW_X 0x0064
|
||||
#define GLUT_WINDOW_Y 0x0065
|
||||
#define GLUT_WINDOW_WIDTH 0x0066
|
||||
#define GLUT_WINDOW_HEIGHT 0x0067
|
||||
#define GLUT_WINDOW_BUFFER_SIZE 0x0068
|
||||
#define GLUT_WINDOW_STENCIL_SIZE 0x0069
|
||||
#define GLUT_WINDOW_DEPTH_SIZE 0x006A
|
||||
#define GLUT_WINDOW_RED_SIZE 0x006B
|
||||
#define GLUT_WINDOW_GREEN_SIZE 0x006C
|
||||
#define GLUT_WINDOW_BLUE_SIZE 0x006D
|
||||
#define GLUT_WINDOW_ALPHA_SIZE 0x006E
|
||||
#define GLUT_WINDOW_ACCUM_RED_SIZE 0x006F
|
||||
#define GLUT_WINDOW_ACCUM_GREEN_SIZE 0x0070
|
||||
#define GLUT_WINDOW_ACCUM_BLUE_SIZE 0x0071
|
||||
#define GLUT_WINDOW_ACCUM_ALPHA_SIZE 0x0072
|
||||
#define GLUT_WINDOW_DOUBLEBUFFER 0x0073
|
||||
#define GLUT_WINDOW_RGBA 0x0074
|
||||
#define GLUT_WINDOW_PARENT 0x0075
|
||||
#define GLUT_WINDOW_NUM_CHILDREN 0x0076
|
||||
#define GLUT_WINDOW_COLORMAP_SIZE 0x0077
|
||||
#define GLUT_WINDOW_NUM_SAMPLES 0x0078
|
||||
#define GLUT_WINDOW_STEREO 0x0079
|
||||
#define GLUT_WINDOW_CURSOR 0x007A
|
||||
|
||||
#define GLUT_SCREEN_WIDTH 0x00C8
|
||||
#define GLUT_SCREEN_HEIGHT 0x00C9
|
||||
#define GLUT_SCREEN_WIDTH_MM 0x00CA
|
||||
#define GLUT_SCREEN_HEIGHT_MM 0x00CB
|
||||
#define GLUT_MENU_NUM_ITEMS 0x012C
|
||||
#define GLUT_DISPLAY_MODE_POSSIBLE 0x0190
|
||||
#define GLUT_INIT_WINDOW_X 0x01F4
|
||||
#define GLUT_INIT_WINDOW_Y 0x01F5
|
||||
#define GLUT_INIT_WINDOW_WIDTH 0x01F6
|
||||
#define GLUT_INIT_WINDOW_HEIGHT 0x01F7
|
||||
#define GLUT_INIT_DISPLAY_MODE 0x01F8
|
||||
#define GLUT_ELAPSED_TIME 0x02BC
|
||||
#define GLUT_WINDOW_FORMAT_ID 0x007B
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutDeviceGet parameters
|
||||
*/
|
||||
#define GLUT_HAS_KEYBOARD 0x0258
|
||||
#define GLUT_HAS_MOUSE 0x0259
|
||||
#define GLUT_HAS_SPACEBALL 0x025A
|
||||
#define GLUT_HAS_DIAL_AND_BUTTON_BOX 0x025B
|
||||
#define GLUT_HAS_TABLET 0x025C
|
||||
#define GLUT_NUM_MOUSE_BUTTONS 0x025D
|
||||
#define GLUT_NUM_SPACEBALL_BUTTONS 0x025E
|
||||
#define GLUT_NUM_BUTTON_BOX_BUTTONS 0x025F
|
||||
#define GLUT_NUM_DIALS 0x0260
|
||||
#define GLUT_NUM_TABLET_BUTTONS 0x0261
|
||||
#define GLUT_DEVICE_IGNORE_KEY_REPEAT 0x0262
|
||||
#define GLUT_DEVICE_KEY_REPEAT 0x0263
|
||||
#define GLUT_HAS_JOYSTICK 0x0264
|
||||
#define GLUT_OWNS_JOYSTICK 0x0265
|
||||
#define GLUT_JOYSTICK_BUTTONS 0x0266
|
||||
#define GLUT_JOYSTICK_AXES 0x0267
|
||||
#define GLUT_JOYSTICK_POLL_RATE 0x0268
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutLayerGet parameters
|
||||
*/
|
||||
#define GLUT_OVERLAY_POSSIBLE 0x0320
|
||||
#define GLUT_LAYER_IN_USE 0x0321
|
||||
#define GLUT_HAS_OVERLAY 0x0322
|
||||
#define GLUT_TRANSPARENT_INDEX 0x0323
|
||||
#define GLUT_NORMAL_DAMAGED 0x0324
|
||||
#define GLUT_OVERLAY_DAMAGED 0x0325
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutVideoResizeGet parameters
|
||||
*/
|
||||
#define GLUT_VIDEO_RESIZE_POSSIBLE 0x0384
|
||||
#define GLUT_VIDEO_RESIZE_IN_USE 0x0385
|
||||
#define GLUT_VIDEO_RESIZE_X_DELTA 0x0386
|
||||
#define GLUT_VIDEO_RESIZE_Y_DELTA 0x0387
|
||||
#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 0x0388
|
||||
#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 0x0389
|
||||
#define GLUT_VIDEO_RESIZE_X 0x038A
|
||||
#define GLUT_VIDEO_RESIZE_Y 0x038B
|
||||
#define GLUT_VIDEO_RESIZE_WIDTH 0x038C
|
||||
#define GLUT_VIDEO_RESIZE_HEIGHT 0x038D
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutUseLayer parameters
|
||||
*/
|
||||
#define GLUT_NORMAL 0x0000
|
||||
#define GLUT_OVERLAY 0x0001
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutGetModifiers parameters
|
||||
*/
|
||||
#define GLUT_ACTIVE_SHIFT 0x0001
|
||||
#define GLUT_ACTIVE_CTRL 0x0002
|
||||
#define GLUT_ACTIVE_ALT 0x0004
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutSetCursor parameters
|
||||
*/
|
||||
#define GLUT_CURSOR_RIGHT_ARROW 0x0000
|
||||
#define GLUT_CURSOR_LEFT_ARROW 0x0001
|
||||
#define GLUT_CURSOR_INFO 0x0002
|
||||
#define GLUT_CURSOR_DESTROY 0x0003
|
||||
#define GLUT_CURSOR_HELP 0x0004
|
||||
#define GLUT_CURSOR_CYCLE 0x0005
|
||||
#define GLUT_CURSOR_SPRAY 0x0006
|
||||
#define GLUT_CURSOR_WAIT 0x0007
|
||||
#define GLUT_CURSOR_TEXT 0x0008
|
||||
#define GLUT_CURSOR_CROSSHAIR 0x0009
|
||||
#define GLUT_CURSOR_UP_DOWN 0x000A
|
||||
#define GLUT_CURSOR_LEFT_RIGHT 0x000B
|
||||
#define GLUT_CURSOR_TOP_SIDE 0x000C
|
||||
#define GLUT_CURSOR_BOTTOM_SIDE 0x000D
|
||||
#define GLUT_CURSOR_LEFT_SIDE 0x000E
|
||||
#define GLUT_CURSOR_RIGHT_SIDE 0x000F
|
||||
#define GLUT_CURSOR_TOP_LEFT_CORNER 0x0010
|
||||
#define GLUT_CURSOR_TOP_RIGHT_CORNER 0x0011
|
||||
#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 0x0012
|
||||
#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 0x0013
|
||||
#define GLUT_CURSOR_INHERIT 0x0064
|
||||
#define GLUT_CURSOR_NONE 0x0065
|
||||
#define GLUT_CURSOR_FULL_CROSSHAIR 0x0066
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- RGB color component specification definitions
|
||||
*/
|
||||
#define GLUT_RED 0x0000
|
||||
#define GLUT_GREEN 0x0001
|
||||
#define GLUT_BLUE 0x0002
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- additional keyboard and joystick definitions
|
||||
*/
|
||||
#define GLUT_KEY_REPEAT_OFF 0x0000
|
||||
#define GLUT_KEY_REPEAT_ON 0x0001
|
||||
#define GLUT_KEY_REPEAT_DEFAULT 0x0002
|
||||
|
||||
#define GLUT_JOYSTICK_BUTTON_A 0x0001
|
||||
#define GLUT_JOYSTICK_BUTTON_B 0x0002
|
||||
#define GLUT_JOYSTICK_BUTTON_C 0x0004
|
||||
#define GLUT_JOYSTICK_BUTTON_D 0x0008
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- game mode definitions
|
||||
*/
|
||||
#define GLUT_GAME_MODE_ACTIVE 0x0000
|
||||
#define GLUT_GAME_MODE_POSSIBLE 0x0001
|
||||
#define GLUT_GAME_MODE_WIDTH 0x0002
|
||||
#define GLUT_GAME_MODE_HEIGHT 0x0003
|
||||
#define GLUT_GAME_MODE_PIXEL_DEPTH 0x0004
|
||||
#define GLUT_GAME_MODE_REFRESH_RATE 0x0005
|
||||
#define GLUT_GAME_MODE_DISPLAY_CHANGED 0x0006
|
||||
|
||||
/*
|
||||
* Initialization functions, see fglut_init.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutInit( int* pargc, char** argv );
|
||||
FGAPI void FGAPIENTRY glutInitWindowPosition( int x, int y );
|
||||
FGAPI void FGAPIENTRY glutInitWindowSize( int width, int height );
|
||||
FGAPI void FGAPIENTRY glutInitDisplayMode( unsigned int displayMode );
|
||||
FGAPI void FGAPIENTRY glutInitDisplayString( const char* displayMode );
|
||||
|
||||
/*
|
||||
* Process loop function, see fg_main.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutMainLoop( void );
|
||||
|
||||
/*
|
||||
* Window management functions, see fg_window.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutCreateWindow( const char* title );
|
||||
FGAPI int FGAPIENTRY glutCreateSubWindow( int window, int x, int y, int width, int height );
|
||||
FGAPI void FGAPIENTRY glutDestroyWindow( int window );
|
||||
FGAPI void FGAPIENTRY glutSetWindow( int window );
|
||||
FGAPI int FGAPIENTRY glutGetWindow( void );
|
||||
FGAPI void FGAPIENTRY glutSetWindowTitle( const char* title );
|
||||
FGAPI void FGAPIENTRY glutSetIconTitle( const char* title );
|
||||
FGAPI void FGAPIENTRY glutReshapeWindow( int width, int height );
|
||||
FGAPI void FGAPIENTRY glutPositionWindow( int x, int y );
|
||||
FGAPI void FGAPIENTRY glutShowWindow( void );
|
||||
FGAPI void FGAPIENTRY glutHideWindow( void );
|
||||
FGAPI void FGAPIENTRY glutIconifyWindow( void );
|
||||
FGAPI void FGAPIENTRY glutPushWindow( void );
|
||||
FGAPI void FGAPIENTRY glutPopWindow( void );
|
||||
FGAPI void FGAPIENTRY glutFullScreen( void );
|
||||
|
||||
/*
|
||||
* Display-related functions, see fg_display.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutPostWindowRedisplay( int window );
|
||||
FGAPI void FGAPIENTRY glutPostRedisplay( void );
|
||||
FGAPI void FGAPIENTRY glutSwapBuffers( void );
|
||||
|
||||
/*
|
||||
* Mouse cursor functions, see fg_cursor.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutWarpPointer( int x, int y );
|
||||
FGAPI void FGAPIENTRY glutSetCursor( int cursor );
|
||||
|
||||
/*
|
||||
* Overlay stuff, see fg_overlay.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutEstablishOverlay( void );
|
||||
FGAPI void FGAPIENTRY glutRemoveOverlay( void );
|
||||
FGAPI void FGAPIENTRY glutUseLayer( GLenum layer );
|
||||
FGAPI void FGAPIENTRY glutPostOverlayRedisplay( void );
|
||||
FGAPI void FGAPIENTRY glutPostWindowOverlayRedisplay( int window );
|
||||
FGAPI void FGAPIENTRY glutShowOverlay( void );
|
||||
FGAPI void FGAPIENTRY glutHideOverlay( void );
|
||||
|
||||
/*
|
||||
* Menu stuff, see fg_menu.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutCreateMenu( void (* callback)( int menu ) );
|
||||
FGAPI void FGAPIENTRY glutDestroyMenu( int menu );
|
||||
FGAPI int FGAPIENTRY glutGetMenu( void );
|
||||
FGAPI void FGAPIENTRY glutSetMenu( int menu );
|
||||
FGAPI void FGAPIENTRY glutAddMenuEntry( const char* label, int value );
|
||||
FGAPI void FGAPIENTRY glutAddSubMenu( const char* label, int subMenu );
|
||||
FGAPI void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value );
|
||||
FGAPI void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int value );
|
||||
FGAPI void FGAPIENTRY glutRemoveMenuItem( int item );
|
||||
FGAPI void FGAPIENTRY glutAttachMenu( int button );
|
||||
FGAPI void FGAPIENTRY glutDetachMenu( int button );
|
||||
|
||||
/*
|
||||
* Global callback functions, see fg_callbacks.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutTimerFunc( unsigned int time, void (* callback)( int ), int value );
|
||||
FGAPI void FGAPIENTRY glutIdleFunc( void (* callback)( void ) );
|
||||
|
||||
/*
|
||||
* Window-specific callback functions, see fg_callbacks.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutKeyboardFunc( void (* callback)( unsigned char, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) );
|
||||
FGAPI void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) );
|
||||
FGAPI void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutEntryFunc( void (* callback)( int ) );
|
||||
|
||||
FGAPI void FGAPIENTRY glutKeyboardUpFunc( void (* callback)( unsigned char, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutJoystickFunc( void (* callback)( unsigned int, int, int, int ), int pollInterval );
|
||||
FGAPI void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) );
|
||||
FGAPI void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) );
|
||||
FGAPI void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) );
|
||||
|
||||
FGAPI void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) );
|
||||
|
||||
/*
|
||||
* State setting and retrieval functions, see fg_state.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutGet( GLenum query );
|
||||
FGAPI int FGAPIENTRY glutDeviceGet( GLenum query );
|
||||
FGAPI int FGAPIENTRY glutGetModifiers( void );
|
||||
FGAPI int FGAPIENTRY glutLayerGet( GLenum query );
|
||||
|
||||
/*
|
||||
* Font stuff, see fg_font.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutBitmapCharacter( void* font, int character );
|
||||
FGAPI int FGAPIENTRY glutBitmapWidth( void* font, int character );
|
||||
FGAPI void FGAPIENTRY glutStrokeCharacter( void* font, int character );
|
||||
FGAPI int FGAPIENTRY glutStrokeWidth( void* font, int character );
|
||||
FGAPI GLfloat FGAPIENTRY glutStrokeWidthf( void* font, int character ); /* GLUT 3.8 */
|
||||
FGAPI int FGAPIENTRY glutBitmapLength( void* font, const unsigned char* string );
|
||||
FGAPI int FGAPIENTRY glutStrokeLength( void* font, const unsigned char* string );
|
||||
FGAPI GLfloat FGAPIENTRY glutStrokeLengthf( void* font, const unsigned char *string ); /* GLUT 3.8 */
|
||||
|
||||
/*
|
||||
* Geometry functions, see fg_geometry.c
|
||||
*/
|
||||
|
||||
FGAPI void FGAPIENTRY glutWireCube( double size );
|
||||
FGAPI void FGAPIENTRY glutSolidCube( double size );
|
||||
FGAPI void FGAPIENTRY glutWireSphere( double radius, GLint slices, GLint stacks );
|
||||
FGAPI void FGAPIENTRY glutSolidSphere( double radius, GLint slices, GLint stacks );
|
||||
FGAPI void FGAPIENTRY glutWireCone( double base, double height, GLint slices, GLint stacks );
|
||||
FGAPI void FGAPIENTRY glutSolidCone( double base, double height, GLint slices, GLint stacks );
|
||||
FGAPI void FGAPIENTRY glutWireTorus( double innerRadius, double outerRadius, GLint sides, GLint rings );
|
||||
FGAPI void FGAPIENTRY glutSolidTorus( double innerRadius, double outerRadius, GLint sides, GLint rings );
|
||||
FGAPI void FGAPIENTRY glutWireDodecahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidDodecahedron( void );
|
||||
FGAPI void FGAPIENTRY glutWireOctahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidOctahedron( void );
|
||||
FGAPI void FGAPIENTRY glutWireTetrahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidTetrahedron( void );
|
||||
FGAPI void FGAPIENTRY glutWireIcosahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidIcosahedron( void );
|
||||
|
||||
/*
|
||||
* Teapot rendering functions, found in fg_teapot.c
|
||||
* NB: front facing polygons have clockwise winding, not counter clockwise
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutWireTeapot( double size );
|
||||
FGAPI void FGAPIENTRY glutSolidTeapot( double size );
|
||||
|
||||
/*
|
||||
* Game mode functions, see fg_gamemode.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutGameModeString( const char* string );
|
||||
FGAPI int FGAPIENTRY glutEnterGameMode( void );
|
||||
FGAPI void FGAPIENTRY glutLeaveGameMode( void );
|
||||
FGAPI int FGAPIENTRY glutGameModeGet( GLenum query );
|
||||
|
||||
/*
|
||||
* Video resize functions, see fg_videoresize.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutVideoResizeGet( GLenum query );
|
||||
FGAPI void FGAPIENTRY glutSetupVideoResizing( void );
|
||||
FGAPI void FGAPIENTRY glutStopVideoResizing( void );
|
||||
FGAPI void FGAPIENTRY glutVideoResize( int x, int y, int width, int height );
|
||||
FGAPI void FGAPIENTRY glutVideoPan( int x, int y, int width, int height );
|
||||
|
||||
/*
|
||||
* Colormap functions, see fg_misc.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutSetColor( int color, GLfloat red, GLfloat green, GLfloat blue );
|
||||
FGAPI GLfloat FGAPIENTRY glutGetColor( int color, int component );
|
||||
FGAPI void FGAPIENTRY glutCopyColormap( int window );
|
||||
|
||||
/*
|
||||
* Misc keyboard and joystick functions, see fg_misc.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutIgnoreKeyRepeat( int ignore );
|
||||
FGAPI void FGAPIENTRY glutSetKeyRepeat( int repeatMode );
|
||||
FGAPI void FGAPIENTRY glutForceJoystickFunc( void );
|
||||
|
||||
/*
|
||||
* Misc functions, see fg_misc.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutExtensionSupported( const char* extension );
|
||||
FGAPI void FGAPIENTRY glutReportErrors( void );
|
||||
|
||||
/* Comment from glut.h of classic GLUT:
|
||||
|
||||
Win32 has an annoying issue where there are multiple C run-time
|
||||
libraries (CRTs). If the executable is linked with a different CRT
|
||||
from the GLUT DLL, the GLUT DLL will not share the same CRT static
|
||||
data seen by the executable. In particular, atexit callbacks registered
|
||||
in the executable will not be called if GLUT calls its (different)
|
||||
exit routine). GLUT is typically built with the
|
||||
"/MD" option (the CRT with multithreading DLL support), but the Visual
|
||||
C++ linker default is "/ML" (the single threaded CRT).
|
||||
|
||||
One workaround to this issue is requiring users to always link with
|
||||
the same CRT as GLUT is compiled with. That requires users supply a
|
||||
non-standard option. GLUT 3.7 has its own built-in workaround where
|
||||
the executable's "exit" function pointer is covertly passed to GLUT.
|
||||
GLUT then calls the executable's exit function pointer to ensure that
|
||||
any "atexit" calls registered by the application are called if GLUT
|
||||
needs to exit.
|
||||
|
||||
Note that the __glut*WithExit routines should NEVER be called directly.
|
||||
To avoid the atexit workaround, #define GLUT_DISABLE_ATEXIT_HACK. */
|
||||
|
||||
/* to get the prototype for exit() */
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK) && !defined(__WATCOMC__)
|
||||
FGAPI void FGAPIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int));
|
||||
FGAPI int FGAPIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int));
|
||||
FGAPI int FGAPIENTRY __glutCreateMenuWithExit(void (* func)(int), void (__cdecl *exitfunc)(int));
|
||||
#ifndef FREEGLUT_BUILDING_LIB
|
||||
#if defined(__GNUC__)
|
||||
#define FGUNUSED __attribute__((unused))
|
||||
#else
|
||||
#define FGUNUSED
|
||||
#endif
|
||||
static void FGAPIENTRY FGUNUSED glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }
|
||||
#define glutInit glutInit_ATEXIT_HACK
|
||||
static int FGAPIENTRY FGUNUSED glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); }
|
||||
#define glutCreateWindow glutCreateWindow_ATEXIT_HACK
|
||||
static int FGAPIENTRY FGUNUSED glutCreateMenu_ATEXIT_HACK(void (* func)(int)) { return __glutCreateMenuWithExit(func, exit); }
|
||||
#define glutCreateMenu glutCreateMenu_ATEXIT_HACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*** END OF FILE ***/
|
||||
|
||||
#endif /* __FREEGLUT_STD_H__ */
|
||||
|
21
exercise3/dependencies/freeglut/include/GL/glut.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef __GLUT_H__
|
||||
#define __GLUT_H__
|
||||
|
||||
/*
|
||||
* glut.h
|
||||
*
|
||||
* The freeglut library include file
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "freeglut_std.h"
|
||||
|
||||
/*** END OF FILE ***/
|
||||
|
||||
#endif /* __GLUT_H__ */
|
BIN
exercise3/dependencies/freeglut/lib/freeglut.dll
Normal file
BIN
exercise3/dependencies/freeglut/lib/freeglut.lib
Normal file
BIN
exercise3/dependencies/freeglut/lib/freeglut_static.lib
Normal file
1
exercise3/dependencies/freeglut/version.txt
Normal file
|
@ -0,0 +1 @@
|
|||
freeglut-3.0.0
|
136
exercise3/dependencies/qdbmp/include/qdbmp.h
Normal file
|
@ -0,0 +1,136 @@
|
|||
#ifndef _BMP_H_
|
||||
#define _BMP_H_
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
|
||||
|
||||
/**************************************************************
|
||||
|
||||
QDBMP - Quick n' Dirty BMP
|
||||
|
||||
v1.0.0 - 2007-04-07
|
||||
http://qdbmp.sourceforge.net
|
||||
|
||||
|
||||
The library supports the following BMP variants:
|
||||
1. Uncompressed 32 BPP (alpha values are ignored)
|
||||
2. Uncompressed 24 BPP
|
||||
3. Uncompressed 8 BPP (indexed color)
|
||||
|
||||
QDBMP is free and open source software, distributed
|
||||
under the MIT licence.
|
||||
|
||||
Copyright (c) 2007 Chai Braudo (braudo@users.sourceforge.net)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
**************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
/* Type definitions */
|
||||
#ifndef UINT
|
||||
#define UINT unsigned long int
|
||||
#endif
|
||||
|
||||
#ifndef USHORT
|
||||
#define USHORT unsigned short
|
||||
#endif
|
||||
|
||||
#ifndef UCHAR
|
||||
#define UCHAR unsigned char
|
||||
#endif
|
||||
|
||||
|
||||
/* Version */
|
||||
#define QDBMP_VERSION_MAJOR 1
|
||||
#define QDBMP_VERSION_MINOR 0
|
||||
#define QDBMP_VERSION_PATCH 1
|
||||
|
||||
|
||||
/* Error codes */
|
||||
typedef enum
|
||||
{
|
||||
BMP_OK = 0, /* No error */
|
||||
BMP_ERROR, /* General error */
|
||||
BMP_OUT_OF_MEMORY, /* Could not allocate enough memory to complete the operation */
|
||||
BMP_IO_ERROR, /* General input/output error */
|
||||
BMP_FILE_NOT_FOUND, /* File not found */
|
||||
BMP_FILE_NOT_SUPPORTED, /* File is not a supported BMP variant */
|
||||
BMP_FILE_INVALID, /* File is not a BMP image or is an invalid BMP */
|
||||
BMP_INVALID_ARGUMENT, /* An argument is invalid or out of range */
|
||||
BMP_TYPE_MISMATCH, /* The requested action is not compatible with the BMP's type */
|
||||
BMP_ERROR_NUM
|
||||
} BMP_STATUS;
|
||||
|
||||
|
||||
/* Bitmap image */
|
||||
typedef struct _BMP BMP;
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************** Public methods **********************************/
|
||||
|
||||
|
||||
/* Construction/destruction */
|
||||
BMP* BMP_Create ( UINT width, UINT height, USHORT depth );
|
||||
void BMP_Free ( BMP* bmp );
|
||||
|
||||
|
||||
/* I/O */
|
||||
BMP* BMP_ReadFile ( const char* filename );
|
||||
void BMP_WriteFile ( BMP* bmp, const char* filename );
|
||||
|
||||
|
||||
/* Meta info */
|
||||
UINT BMP_GetWidth ( BMP* bmp );
|
||||
UINT BMP_GetHeight ( BMP* bmp );
|
||||
USHORT BMP_GetDepth ( BMP* bmp );
|
||||
|
||||
|
||||
/* Pixel access */
|
||||
void BMP_GetPixelRGB ( BMP* bmp, UINT x, UINT y, UCHAR* r, UCHAR* g, UCHAR* b );
|
||||
void BMP_SetPixelRGB ( BMP* bmp, UINT x, UINT y, UCHAR r, UCHAR g, UCHAR b );
|
||||
void BMP_GetPixelIndex ( BMP* bmp, UINT x, UINT y, UCHAR* val );
|
||||
void BMP_SetPixelIndex ( BMP* bmp, UINT x, UINT y, UCHAR val );
|
||||
unsigned char* BMP_GetImageData ( BMP *bmp );
|
||||
|
||||
|
||||
/* Palette handling */
|
||||
void BMP_GetPaletteColor ( BMP* bmp, UCHAR index, UCHAR* r, UCHAR* g, UCHAR* b );
|
||||
void BMP_SetPaletteColor ( BMP* bmp, UCHAR index, UCHAR r, UCHAR g, UCHAR b );
|
||||
|
||||
|
||||
/* Error handling */
|
||||
BMP_STATUS BMP_GetError ();
|
||||
const char* BMP_GetErrorDescription ();
|
||||
|
||||
|
||||
/* Useful macro that may be used after each BMP operation to check for an error */
|
||||
#define BMP_CHECK_ERROR( output_file, return_value ) \
|
||||
if ( BMP_GetError() != BMP_OK ) \
|
||||
{ \
|
||||
fprintf( ( output_file ), "BMP error: %s\n", BMP_GetErrorDescription() ); \
|
||||
return( return_value ); \
|
||||
} \
|
||||
|
||||
#endif
|
824
exercise3/dependencies/qdbmp/src/qdbmp.cpp
Normal file
|
@ -0,0 +1,824 @@
|
|||
#include "qdbmp.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* Bitmap header */
|
||||
typedef struct _BMP_Header
|
||||
{
|
||||
USHORT Magic; /* Magic identifier: "BM" */
|
||||
UINT FileSize; /* Size of the BMP file in bytes */
|
||||
USHORT Reserved1; /* Reserved */
|
||||
USHORT Reserved2; /* Reserved */
|
||||
UINT DataOffset; /* Offset of image data relative to the file's start */
|
||||
UINT HeaderSize; /* Size of the header in bytes */
|
||||
UINT Width; /* Bitmap's width */
|
||||
UINT Height; /* Bitmap's height */
|
||||
USHORT Planes; /* Number of color planes in the bitmap */
|
||||
USHORT BitsPerPixel; /* Number of bits per pixel */
|
||||
UINT CompressionType; /* Compression type */
|
||||
UINT ImageDataSize; /* Size of uncompressed image's data */
|
||||
UINT HPixelsPerMeter; /* Horizontal resolution (pixels per meter) */
|
||||
UINT VPixelsPerMeter; /* Vertical resolution (pixels per meter) */
|
||||
UINT ColorsUsed; /* Number of color indexes in the color table that are actually used by the bitmap */
|
||||
UINT ColorsRequired; /* Number of color indexes that are required for displaying the bitmap */
|
||||
} BMP_Header;
|
||||
|
||||
|
||||
/* Private data structure */
|
||||
struct _BMP
|
||||
{
|
||||
BMP_Header Header;
|
||||
UCHAR* Palette;
|
||||
UCHAR* Data;
|
||||
};
|
||||
|
||||
|
||||
/* Holds the last error code */
|
||||
static BMP_STATUS BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
|
||||
/* Error description strings */
|
||||
static const char* BMP_ERROR_STRING[] =
|
||||
{
|
||||
"No error",
|
||||
"General error",
|
||||
"Could not allocate enough memory to complete the operation",
|
||||
"File input/output error",
|
||||
"File not found",
|
||||
"File is not a supported BMP variant (must be uncompressed 8, 24 or 32 BPP)",
|
||||
"File is not a valid BMP image",
|
||||
"An argument is invalid or out of range",
|
||||
"The requested action is not compatible with the BMP's type"
|
||||
};
|
||||
|
||||
|
||||
/* Size of the palette data for 8 BPP bitmaps */
|
||||
#define BMP_PALETTE_SIZE ( 256 * 4 )
|
||||
|
||||
|
||||
|
||||
/*********************************** Forward declarations **********************************/
|
||||
int ReadHeader ( BMP* bmp, FILE* f );
|
||||
int WriteHeader ( BMP* bmp, FILE* f );
|
||||
|
||||
int ReadUINT ( UINT* x, FILE* f );
|
||||
int ReadUSHORT ( USHORT *x, FILE* f );
|
||||
|
||||
int WriteUINT ( UINT x, FILE* f );
|
||||
int WriteUSHORT ( USHORT x, FILE* f );
|
||||
|
||||
|
||||
|
||||
/*********************************** Public methods **********************************/
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Creates a blank BMP image with the specified dimensions
|
||||
and bit depth.
|
||||
**************************************************************/
|
||||
BMP* BMP_Create( UINT width, UINT height, USHORT depth )
|
||||
{
|
||||
BMP* bmp;
|
||||
int bytes_per_pixel = depth >> 3;
|
||||
UINT bytes_per_row;
|
||||
|
||||
if ( height <= 0 || width <= 0 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( depth != 8 && depth != 24 && depth != 32 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_FILE_NOT_SUPPORTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate the bitmap data structure */
|
||||
bmp = (BMP*)calloc( 1, sizeof( BMP ) );
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Set header' default values */
|
||||
bmp->Header.Magic = 0x4D42;
|
||||
bmp->Header.Reserved1 = 0;
|
||||
bmp->Header.Reserved2 = 0;
|
||||
bmp->Header.HeaderSize = 40;
|
||||
bmp->Header.Planes = 1;
|
||||
bmp->Header.CompressionType = 0;
|
||||
bmp->Header.HPixelsPerMeter = 0;
|
||||
bmp->Header.VPixelsPerMeter = 0;
|
||||
bmp->Header.ColorsUsed = 0;
|
||||
bmp->Header.ColorsRequired = 0;
|
||||
|
||||
|
||||
/* Calculate the number of bytes used to store a single image row. This is always
|
||||
rounded up to the next multiple of 4. */
|
||||
bytes_per_row = width * bytes_per_pixel;
|
||||
bytes_per_row += ( bytes_per_row % 4 ? 4 - bytes_per_row % 4 : 0 );
|
||||
|
||||
|
||||
/* Set header's image specific values */
|
||||
bmp->Header.Width = width;
|
||||
bmp->Header.Height = height;
|
||||
bmp->Header.BitsPerPixel = depth;
|
||||
bmp->Header.ImageDataSize = bytes_per_row * height;
|
||||
bmp->Header.FileSize = bmp->Header.ImageDataSize + 54 + ( depth == 8 ? BMP_PALETTE_SIZE : 0 );
|
||||
bmp->Header.DataOffset = 54 + ( depth == 8 ? BMP_PALETTE_SIZE : 0 );
|
||||
|
||||
|
||||
/* Allocate palette */
|
||||
if ( bmp->Header.BitsPerPixel == 8 )
|
||||
{
|
||||
bmp->Palette = (UCHAR*) calloc( BMP_PALETTE_SIZE, sizeof( UCHAR ) );
|
||||
if ( bmp->Palette == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OUT_OF_MEMORY;
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bmp->Palette = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate pixels */
|
||||
bmp->Data = (UCHAR*) calloc( bmp->Header.ImageDataSize, sizeof( UCHAR ) );
|
||||
if ( bmp->Data == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OUT_OF_MEMORY;
|
||||
free( bmp->Palette );
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Frees all the memory used by the specified BMP image.
|
||||
**************************************************************/
|
||||
void BMP_Free( BMP* bmp )
|
||||
{
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( bmp->Palette != NULL )
|
||||
{
|
||||
free( bmp->Palette );
|
||||
}
|
||||
|
||||
if ( bmp->Data != NULL )
|
||||
{
|
||||
free( bmp->Data );
|
||||
}
|
||||
|
||||
free( bmp );
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Reads the specified BMP image file.
|
||||
**************************************************************/
|
||||
BMP* BMP_ReadFile( const char* filename )
|
||||
{
|
||||
BMP* bmp;
|
||||
FILE* f;
|
||||
|
||||
if ( filename == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate */
|
||||
bmp = (BMP*)calloc( 1, sizeof( BMP ) );
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Open file */
|
||||
f = fopen( filename, "rb" );
|
||||
if ( f == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_FILE_NOT_FOUND;
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Read header */
|
||||
if ( ReadHeader( bmp, f ) != BMP_OK || bmp->Header.Magic != 0x4D42 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_FILE_INVALID;
|
||||
fclose( f );
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Verify that the bitmap variant is supported */
|
||||
if ( ( bmp->Header.BitsPerPixel != 32 && bmp->Header.BitsPerPixel != 24 && bmp->Header.BitsPerPixel != 8 )
|
||||
|| bmp->Header.CompressionType != 0 || bmp->Header.HeaderSize != 40 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_FILE_NOT_SUPPORTED;
|
||||
fclose( f );
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate and read palette */
|
||||
if ( bmp->Header.BitsPerPixel == 8 )
|
||||
{
|
||||
bmp->Palette = (UCHAR*) malloc( BMP_PALETTE_SIZE * sizeof( UCHAR ) );
|
||||
if ( bmp->Palette == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OUT_OF_MEMORY;
|
||||
fclose( f );
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( fread( bmp->Palette, sizeof( UCHAR ), BMP_PALETTE_SIZE, f ) != BMP_PALETTE_SIZE )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_FILE_INVALID;
|
||||
fclose( f );
|
||||
free( bmp->Palette );
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else /* Not an indexed image */
|
||||
{
|
||||
bmp->Palette = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate memory for image data */
|
||||
bmp->Data = (UCHAR*) malloc( bmp->Header.ImageDataSize );
|
||||
if ( bmp->Data == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OUT_OF_MEMORY;
|
||||
fclose( f );
|
||||
free( bmp->Palette );
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Read image data */
|
||||
if ( fread( bmp->Data, sizeof( UCHAR ), bmp->Header.ImageDataSize, f ) != bmp->Header.ImageDataSize )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_FILE_INVALID;
|
||||
fclose( f );
|
||||
free( bmp->Data );
|
||||
free( bmp->Palette );
|
||||
free( bmp );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
fclose( f );
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Writes the BMP image to the specified file.
|
||||
**************************************************************/
|
||||
void BMP_WriteFile( BMP* bmp, const char* filename )
|
||||
{
|
||||
FILE* f;
|
||||
|
||||
if ( filename == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Open file */
|
||||
f = fopen( filename, "wb" );
|
||||
if ( f == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_FILE_NOT_FOUND;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Write header */
|
||||
if ( WriteHeader( bmp, f ) != BMP_OK )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_IO_ERROR;
|
||||
fclose( f );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Write palette */
|
||||
if ( bmp->Palette )
|
||||
{
|
||||
if ( fwrite( bmp->Palette, sizeof( UCHAR ), BMP_PALETTE_SIZE, f ) != BMP_PALETTE_SIZE )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_IO_ERROR;
|
||||
fclose( f );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Write data */
|
||||
if ( fwrite( bmp->Data, sizeof( UCHAR ), bmp->Header.ImageDataSize, f ) != bmp->Header.ImageDataSize )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_IO_ERROR;
|
||||
fclose( f );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
fclose( f );
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Returns the image's width.
|
||||
**************************************************************/
|
||||
UINT BMP_GetWidth( BMP* bmp )
|
||||
{
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
return ( bmp->Header.Width );
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Returns the image's height.
|
||||
**************************************************************/
|
||||
UINT BMP_GetHeight( BMP* bmp )
|
||||
{
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
return ( bmp->Header.Height );
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Returns the image's color depth (bits per pixel).
|
||||
**************************************************************/
|
||||
USHORT BMP_GetDepth( BMP* bmp )
|
||||
{
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
return ( bmp->Header.BitsPerPixel );
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Populates the arguments with the specified pixel's RGB
|
||||
values.
|
||||
**************************************************************/
|
||||
void BMP_GetPixelRGB( BMP* bmp, UINT x, UINT y, UCHAR* r, UCHAR* g, UCHAR* b )
|
||||
{
|
||||
UCHAR* pixel;
|
||||
UINT bytes_per_row;
|
||||
UCHAR bytes_per_pixel;
|
||||
|
||||
if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
bytes_per_pixel = bmp->Header.BitsPerPixel >> 3;
|
||||
|
||||
/* Row's size is rounded up to the next multiple of 4 bytes */
|
||||
bytes_per_row = bmp->Header.ImageDataSize / bmp->Header.Height;
|
||||
|
||||
/* Calculate the location of the relevant pixel (rows are flipped) */
|
||||
pixel = bmp->Data + ( ( bmp->Header.Height - y - 1 ) * bytes_per_row + x * bytes_per_pixel );
|
||||
|
||||
|
||||
/* In indexed color mode the pixel's value is an index within the palette */
|
||||
if ( bmp->Header.BitsPerPixel == 8 )
|
||||
{
|
||||
pixel = bmp->Palette + *pixel * 4;
|
||||
}
|
||||
|
||||
/* Note: colors are stored in BGR order */
|
||||
if ( r ) *r = *( pixel + 2 );
|
||||
if ( g ) *g = *( pixel + 1 );
|
||||
if ( b ) *b = *( pixel + 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Sets the specified pixel's RGB values.
|
||||
**************************************************************/
|
||||
void BMP_SetPixelRGB( BMP* bmp, UINT x, UINT y, UCHAR r, UCHAR g, UCHAR b )
|
||||
{
|
||||
UCHAR* pixel;
|
||||
UINT bytes_per_row;
|
||||
UCHAR bytes_per_pixel;
|
||||
|
||||
if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
else if ( bmp->Header.BitsPerPixel != 24 && bmp->Header.BitsPerPixel != 32 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
bytes_per_pixel = bmp->Header.BitsPerPixel >> 3;
|
||||
|
||||
/* Row's size is rounded up to the next multiple of 4 bytes */
|
||||
bytes_per_row = bmp->Header.ImageDataSize / bmp->Header.Height;
|
||||
|
||||
/* Calculate the location of the relevant pixel (rows are flipped) */
|
||||
pixel = bmp->Data + ( ( bmp->Header.Height - y - 1 ) * bytes_per_row + x * bytes_per_pixel );
|
||||
|
||||
/* Note: colors are stored in BGR order */
|
||||
*( pixel + 2 ) = r;
|
||||
*( pixel + 1 ) = g;
|
||||
*( pixel + 0 ) = b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Gets the specified pixel's color index.
|
||||
**************************************************************/
|
||||
void BMP_GetPixelIndex( BMP* bmp, UINT x, UINT y, UCHAR* val )
|
||||
{
|
||||
UCHAR* pixel;
|
||||
UINT bytes_per_row;
|
||||
|
||||
if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
else if ( bmp->Header.BitsPerPixel != 8 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
/* Row's size is rounded up to the next multiple of 4 bytes */
|
||||
bytes_per_row = bmp->Header.ImageDataSize / bmp->Header.Height;
|
||||
|
||||
/* Calculate the location of the relevant pixel */
|
||||
pixel = bmp->Data + ( ( bmp->Header.Height - y - 1 ) * bytes_per_row + x );
|
||||
|
||||
|
||||
if ( val ) *val = *pixel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Sets the specified pixel's color index.
|
||||
**************************************************************/
|
||||
void BMP_SetPixelIndex( BMP* bmp, UINT x, UINT y, UCHAR val )
|
||||
{
|
||||
UCHAR* pixel;
|
||||
UINT bytes_per_row;
|
||||
|
||||
if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
else if ( bmp->Header.BitsPerPixel != 8 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
|
||||
/* Row's size is rounded up to the next multiple of 4 bytes */
|
||||
bytes_per_row = bmp->Header.ImageDataSize / bmp->Header.Height;
|
||||
|
||||
/* Calculate the location of the relevant pixel */
|
||||
pixel = bmp->Data + ( ( bmp->Header.Height - y - 1 ) * bytes_per_row + x );
|
||||
|
||||
*pixel = val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Gets the color value for the specified palette index.
|
||||
**************************************************************/
|
||||
void BMP_GetPaletteColor( BMP* bmp, UCHAR index, UCHAR* r, UCHAR* g, UCHAR* b )
|
||||
{
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
else if ( bmp->Header.BitsPerPixel != 8 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ( r ) *r = *( bmp->Palette + index * 4 + 2 );
|
||||
if ( g ) *g = *( bmp->Palette + index * 4 + 1 );
|
||||
if ( b ) *b = *( bmp->Palette + index * 4 + 0 );
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Sets the color value for the specified palette index.
|
||||
**************************************************************/
|
||||
void BMP_SetPaletteColor( BMP* bmp, UCHAR index, UCHAR r, UCHAR g, UCHAR b )
|
||||
{
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
else if ( bmp->Header.BitsPerPixel != 8 )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
*( bmp->Palette + index * 4 + 2 ) = r;
|
||||
*( bmp->Palette + index * 4 + 1 ) = g;
|
||||
*( bmp->Palette + index * 4 + 0 ) = b;
|
||||
|
||||
BMP_LAST_ERROR_CODE = BMP_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Returns the last error code.
|
||||
**************************************************************/
|
||||
BMP_STATUS BMP_GetError()
|
||||
{
|
||||
return BMP_LAST_ERROR_CODE;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Returns a description of the last error code.
|
||||
**************************************************************/
|
||||
const char* BMP_GetErrorDescription()
|
||||
{
|
||||
if ( BMP_LAST_ERROR_CODE >= 0 && BMP_LAST_ERROR_CODE < BMP_ERROR_NUM )
|
||||
{
|
||||
return BMP_ERROR_STRING[ BMP_LAST_ERROR_CODE ];
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************** Private methods **********************************/
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Reads the BMP file's header into the data structure.
|
||||
Returns BMP_OK on success.
|
||||
**************************************************************/
|
||||
int ReadHeader( BMP* bmp, FILE* f )
|
||||
{
|
||||
if ( bmp == NULL || f == NULL )
|
||||
{
|
||||
return BMP_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
/* The header's fields are read one by one, and converted from the format's
|
||||
little endian to the system's native representation. */
|
||||
if ( !ReadUSHORT( &( bmp->Header.Magic ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.FileSize ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUSHORT( &( bmp->Header.Reserved1 ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUSHORT( &( bmp->Header.Reserved2 ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.DataOffset ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.HeaderSize ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.Width ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.Height ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUSHORT( &( bmp->Header.Planes ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUSHORT( &( bmp->Header.BitsPerPixel ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.CompressionType ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.ImageDataSize ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.HPixelsPerMeter ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.VPixelsPerMeter ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.ColorsUsed ), f ) ) return BMP_IO_ERROR;
|
||||
if ( !ReadUINT( &( bmp->Header.ColorsRequired ), f ) ) return BMP_IO_ERROR;
|
||||
|
||||
return BMP_OK;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Writes the BMP file's header into the data structure.
|
||||
Returns BMP_OK on success.
|
||||
**************************************************************/
|
||||
int WriteHeader( BMP* bmp, FILE* f )
|
||||
{
|
||||
if ( bmp == NULL || f == NULL )
|
||||
{
|
||||
return BMP_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
/* The header's fields are written one by one, and converted to the format's
|
||||
little endian representation. */
|
||||
if ( !WriteUSHORT( bmp->Header.Magic, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.FileSize, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUSHORT( bmp->Header.Reserved1, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUSHORT( bmp->Header.Reserved2, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.DataOffset, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.HeaderSize, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.Width, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.Height, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUSHORT( bmp->Header.Planes, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUSHORT( bmp->Header.BitsPerPixel, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.CompressionType, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.ImageDataSize, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.HPixelsPerMeter, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.VPixelsPerMeter, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.ColorsUsed, f ) ) return BMP_IO_ERROR;
|
||||
if ( !WriteUINT( bmp->Header.ColorsRequired, f ) ) return BMP_IO_ERROR;
|
||||
|
||||
return BMP_OK;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Reads a little-endian unsigned int from the file.
|
||||
Returns non-zero on success.
|
||||
**************************************************************/
|
||||
int ReadUINT( UINT* x, FILE* f )
|
||||
{
|
||||
UCHAR little[ 4 ]; /* BMPs use 32 bit ints */
|
||||
|
||||
if ( x == NULL || f == NULL )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( fread( little, 4, 1, f ) != 1 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
*x = ( little[ 3 ] << 24 | little[ 2 ] << 16 | little[ 1 ] << 8 | little[ 0 ] );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Reads a little-endian unsigned short int from the file.
|
||||
Returns non-zero on success.
|
||||
**************************************************************/
|
||||
int ReadUSHORT( USHORT *x, FILE* f )
|
||||
{
|
||||
UCHAR little[ 2 ]; /* BMPs use 16 bit shorts */
|
||||
|
||||
if ( x == NULL || f == NULL )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( fread( little, 2, 1, f ) != 1 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
*x = ( little[ 1 ] << 8 | little[ 0 ] );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Writes a little-endian unsigned int to the file.
|
||||
Returns non-zero on success.
|
||||
**************************************************************/
|
||||
int WriteUINT( UINT x, FILE* f )
|
||||
{
|
||||
UCHAR little[ 4 ]; /* BMPs use 32 bit ints */
|
||||
|
||||
little[ 3 ] = (UCHAR)( ( x & 0xff000000 ) >> 24 );
|
||||
little[ 2 ] = (UCHAR)( ( x & 0x00ff0000 ) >> 16 );
|
||||
little[ 1 ] = (UCHAR)( ( x & 0x0000ff00 ) >> 8 );
|
||||
little[ 0 ] = (UCHAR)( ( x & 0x000000ff ) >> 0 );
|
||||
|
||||
return ( f && fwrite( little, 4, 1, f ) == 1 );
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Writes a little-endian unsigned short int to the file.
|
||||
Returns non-zero on success.
|
||||
**************************************************************/
|
||||
int WriteUSHORT( USHORT x, FILE* f )
|
||||
{
|
||||
UCHAR little[ 2 ]; /* BMPs use 16 bit shorts */
|
||||
|
||||
little[ 1 ] = (UCHAR)( ( x & 0xff00 ) >> 8 );
|
||||
little[ 0 ] = (UCHAR)( ( x & 0x00ff ) >> 0 );
|
||||
|
||||
return ( f && fwrite( little, 2, 1, f ) == 1 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned char* BMP_GetImageData( BMP *bmp )
|
||||
{
|
||||
int x, y, width, height;
|
||||
unsigned char* data;
|
||||
unsigned char r, g, b;
|
||||
|
||||
if ( bmp == NULL )
|
||||
{
|
||||
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
width = BMP_GetWidth(bmp);
|
||||
height = BMP_GetHeight(bmp);
|
||||
|
||||
data = (unsigned char*)calloc(1, width*height*3);
|
||||
for (x=0; x<width; x++)
|
||||
for (y=0; y<height; y++) {
|
||||
BMP_GetPixelRGB(bmp, x, y, &r, &g, &b);
|
||||
data[(x+y*width)*3 + 0] = r;
|
||||
data[(x+y*width)*3 + 1] = g;
|
||||
data[(x+y*width)*3 + 2] = b;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
35
exercise3/include/abstract_scene.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
/*************************************************************************
|
||||
Abstract scene.
|
||||
This class provides the basic super class for all scenes. To render a
|
||||
frame of the implemented scene the method "render" must be called. If
|
||||
the scene is animated the method "advance_frame" can be overwritten. It
|
||||
is called every 1/30sec (from the application-class).
|
||||
For debugging purpose a method "set_text" is provided which modifies a
|
||||
text stream that will be displayed in the main window.
|
||||
*************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include "GL/glut.h"
|
||||
|
||||
class abstract_scene
|
||||
{
|
||||
public:
|
||||
// Virtual Destructor
|
||||
virtual ~abstract_scene() {};
|
||||
// Render the scene
|
||||
virtual void render() = 0;
|
||||
|
||||
// Advance one frame
|
||||
virtual void advance_frame();
|
||||
|
||||
// Put a text into the stream "stream" which will be displayed
|
||||
// in the main window
|
||||
virtual void set_text(std::stringstream &stream);
|
||||
};
|
107
exercise3/include/application.h
Normal file
|
@ -0,0 +1,107 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
/*************************************************************************
|
||||
The main program.
|
||||
This class provides the functionality of the main program. The program
|
||||
starts after calling the "run" method. This method initializes the GLUT
|
||||
system for rendering (using OpenGL) and user interaction. During the
|
||||
initialization process different methods are connected to certain events
|
||||
such as "display the window content" or "act on key events".
|
||||
Furthermore the main context menu is initialized by calling the method
|
||||
"setup_context_menu".
|
||||
Whenever one of the events described above occurs the appropriate functions
|
||||
are called (They are however not called directly but via static functions
|
||||
that forward the event. Read the included PDF if you are interested why
|
||||
this is done and how it works).
|
||||
The actual rendering happens in the "display" method that completely
|
||||
handles the rendering over to the "render" method of the "content"-variable
|
||||
which is an instance of a child class of abstract_scene.
|
||||
For animations a timer is set up to call the "timer" method every 1/30 sec
|
||||
which calls the "advance_frame" method of the current "content" and
|
||||
refreshes the display.
|
||||
**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
// Needed for openGL rendering and GLUT commands
|
||||
#include "GL/glut.h"
|
||||
// Needed for displaying text in the main window
|
||||
#include "GL/freeglut_ext.h"
|
||||
// Contains the interface for abstract_scene
|
||||
#include "abstract_scene.h"
|
||||
|
||||
|
||||
|
||||
// An enumeration of menu actions. Whenever something
|
||||
// from the context menu is selected the method "context_menu_select"
|
||||
// is invoked with an element of this enumeration as a parameter
|
||||
enum MenuActions
|
||||
{
|
||||
MA_CUBE_SYSTEM, // Render the cube system
|
||||
MA_CUBE_SYSTEM_SPLIT, // Render the cube system in split screen
|
||||
MA_CUBES_RECURSIVE, // Render the recursive cubes
|
||||
MA_TERRAIN, // Render the terrain
|
||||
MA_TERRAIN_SOLID, // Show the terrain as solid
|
||||
MA_TERRAIN_WIREFRAME, // Show the terrain as wireframe
|
||||
MA_TERRAIN_LEVELS, // Show height level lines
|
||||
MA_EXAMPLE_PRIMITIVES, // Render the primitives example
|
||||
MA_EXAMPLE_CPRIMITIVES, // Render the consecutive primitives example
|
||||
MA_EXAMPLE_3D_PRIMITIVES, // Render the 3D primitives example
|
||||
MA_EXAMPLE_TRANS_ORDER // Render the transformation order example
|
||||
};
|
||||
|
||||
|
||||
|
||||
class application
|
||||
{
|
||||
public:
|
||||
// Initialize all non-GLUT related variables
|
||||
application();
|
||||
|
||||
// Run the program using the command line arguments
|
||||
int run(int argc, char* argv[]);
|
||||
|
||||
private:
|
||||
// The current scene to display
|
||||
abstract_scene *content;
|
||||
// States for the terrain scene
|
||||
bool terrain_solid, terrain_wireframe, terrain_levels;
|
||||
// Dirty flag to check if the menu must be updated
|
||||
bool menu_dirty;
|
||||
|
||||
// The static instance of this program. Read the PDF for more details
|
||||
static application *instance;
|
||||
|
||||
// Set the current scene
|
||||
void set_content(abstract_scene *new_content);
|
||||
|
||||
// The event method on key presses
|
||||
void key_down(unsigned char key, int x, int y);
|
||||
|
||||
// The event method on context menu selections
|
||||
void context_menu_select(int item);
|
||||
|
||||
// The event method on timer callbacks
|
||||
void timer(int value);
|
||||
|
||||
// The event method on window content rendering
|
||||
void display();
|
||||
|
||||
// Initialize the context menu
|
||||
void setup_context_menu();
|
||||
|
||||
// Update the context menu according to the settings
|
||||
void update_context_menu();
|
||||
|
||||
// Static callbacks...
|
||||
static void key_down_callback(unsigned char key, int x, int y);
|
||||
static void context_menu_callback(int item);
|
||||
static void display_callback();
|
||||
static void timer_callback(int value);
|
||||
static void idle_callback();
|
||||
|
||||
};
|
49
exercise3/include/cube_system.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
/*************************************************************************
|
||||
Cube system.
|
||||
This class represent a simple system of cubes which rotate around each
|
||||
other. It demonstrates the use of glPushMatrix and glPopMatrix to
|
||||
describe transformation trees.
|
||||
The actual rendering happens in the "render" method first calls
|
||||
"setup_projection" to enable a perspective projection and suitable
|
||||
viewer position. It then clears the screen and renders the cube system
|
||||
by calling "render_system". For the rendering of one cube this method calls
|
||||
"render_cube".
|
||||
See "abstract_scene" for more information on scenes.
|
||||
*************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "abstract_scene.h"
|
||||
|
||||
class cube_system: public abstract_scene
|
||||
{
|
||||
public:
|
||||
// Initialize variables
|
||||
cube_system();
|
||||
|
||||
// Setup the scene and render cube system
|
||||
virtual void render();
|
||||
|
||||
// Advance one frame by increasing the rotation angle
|
||||
void advance_frame();
|
||||
|
||||
// Set debug text
|
||||
virtual void set_text(std::stringstream &stream);
|
||||
|
||||
protected:
|
||||
// The current rotation angle
|
||||
int angle;
|
||||
|
||||
// Set the projection and the view
|
||||
void setup_projection();
|
||||
|
||||
// Render the cube system
|
||||
void render_system();
|
||||
|
||||
// Render one single cube
|
||||
void render_cube();
|
||||
};
|
27
exercise3/include/cube_system_split.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
/*************************************************************************
|
||||
Cube system in split screen.
|
||||
This class is inherited from cube_system to render different views of
|
||||
the system. While the top left, top right and bottom left views are
|
||||
orthographic projections of one of the major directions the fourth panel
|
||||
in the lower right renders a perspective version of the scene.
|
||||
This class demonstrates how to implement orthographic views and split
|
||||
screens.
|
||||
*************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "cube_system.h"
|
||||
|
||||
class cube_system_split: public cube_system
|
||||
{
|
||||
public:
|
||||
// Render the scene
|
||||
void render();
|
||||
|
||||
// Set debug text
|
||||
void set_text(std::stringstream &stream);
|
||||
};
|
28
exercise3/include/example_3d_primitives.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "abstract_scene.h"
|
||||
|
||||
class example_3d_primitives: public abstract_scene
|
||||
{
|
||||
public:
|
||||
example_3d_primitives();
|
||||
void render();
|
||||
void set_text(std::stringstream &stream);
|
||||
void advance_frame();
|
||||
|
||||
private:
|
||||
int angle;
|
||||
|
||||
void render_tetrahedron();
|
||||
void render_cylinder();
|
||||
void render_cube();
|
||||
void render_sphere();
|
||||
|
||||
void setup_projection();
|
||||
void setup_light();
|
||||
};
|
15
exercise3/include/example_cons_primitives.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "abstract_scene.h"
|
||||
|
||||
class example_consecutive_primitives: public abstract_scene
|
||||
{
|
||||
public:
|
||||
void render();
|
||||
void set_text(std::stringstream &stream);
|
||||
};
|
15
exercise3/include/example_primitives.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "abstract_scene.h"
|
||||
|
||||
class example_primitives: public abstract_scene
|
||||
{
|
||||
public:
|
||||
void render();
|
||||
void set_text(std::stringstream &stream);
|
||||
};
|
21
exercise3/include/example_trans_order.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "abstract_scene.h"
|
||||
|
||||
class example_trans_order: public abstract_scene
|
||||
{
|
||||
public:
|
||||
example_trans_order();
|
||||
void render();
|
||||
void set_text(std::stringstream &stream);
|
||||
void advance_frame();
|
||||
|
||||
private:
|
||||
int angle;
|
||||
void render_quad();
|
||||
};
|
55
exercise3/include/recursive_cubes.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
/*************************************************************************
|
||||
Recursive cubes.
|
||||
This class represents a recursive cube tree where an element is recursively
|
||||
defined as a cube with the same element at each side (only smaller).
|
||||
It demonstrates the use of glPushMatrix and glPopMatrix in the
|
||||
construction of recursive transformation trees.
|
||||
The method "render" sets the projection and view via "setup_projection",
|
||||
the scene light via "setup_light" and starts the recursion by calling
|
||||
"render_recursive". This method calls itself to perform the actual
|
||||
recursion. To render a single cube it uses "render_cube".
|
||||
*************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "abstract_scene.h"
|
||||
|
||||
class recursive_cubes: public abstract_scene
|
||||
{
|
||||
public:
|
||||
// Initialize variables
|
||||
recursive_cubes();
|
||||
|
||||
// Render the scene
|
||||
void render();
|
||||
|
||||
// Advance one frame
|
||||
void advance_frame();
|
||||
|
||||
// Set debug text
|
||||
void set_text(std::stringstream &stream);
|
||||
|
||||
private:
|
||||
// Rotation angle
|
||||
int angle;
|
||||
// Maximum recursion depth
|
||||
int depth;
|
||||
|
||||
// The recursive render method. "r" contains the current
|
||||
// recursion depth and "render_first" is a flag to inicate
|
||||
// that all sides have neighbours.
|
||||
void render_recursive(int r, bool render_all);
|
||||
|
||||
// Render one single cube
|
||||
void render_cube();
|
||||
|
||||
// Set the light parameters
|
||||
void setup_light();
|
||||
|
||||
// Set the projection and the view
|
||||
void setup_projection();
|
||||
};
|
113
exercise3/include/terrain.h
Normal file
|
@ -0,0 +1,113 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
/*************************************************************************
|
||||
Terrain.
|
||||
This class represents a textured and shaded terrain. Both, the texture
|
||||
and the height map is read from a bmp file (in the constructor).
|
||||
The height map is mapped to a regular grid consisting of triangle strips.
|
||||
During rendering the normals needed for lighting are calculated.
|
||||
There are some additional rendering modes:
|
||||
- solid: The terrain with texture and lighting
|
||||
- wireframe: The wireframe of the elevated triangle mesh
|
||||
- levels: Some height levels that were evaluated using the marching
|
||||
squares algorithm.
|
||||
The rendering is done in the "render" method which sets the projection
|
||||
and view via "setup_projection" and the light via "setup_light".
|
||||
Depending on the settings (that can be changed using "set_show_solid",
|
||||
"set_show_wireframe" and "set_show_levels") different passes are rendered
|
||||
using the appropriate rendering method ("render_solid_terrain",
|
||||
"render_wireframe_terrain", "render_level_lines"). They call the
|
||||
"render_terrain" method.
|
||||
*************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "GL/glut.h"
|
||||
#include "abstract_scene.h"
|
||||
#include "qdbmp.h"
|
||||
#include "tiny_vec.h"
|
||||
#include <vector>
|
||||
|
||||
class terrain: public abstract_scene
|
||||
{
|
||||
public:
|
||||
// Load images and initialize variables
|
||||
terrain();
|
||||
|
||||
// Unload images and textures
|
||||
~terrain();
|
||||
|
||||
// Render the actual scene
|
||||
void render();
|
||||
|
||||
// Advance one frame
|
||||
void advance_frame();
|
||||
|
||||
// (De)activate solid rendering
|
||||
void set_show_solid(bool state);
|
||||
|
||||
// (De)activate wireframe rendering
|
||||
void set_show_wireframe(bool state);
|
||||
|
||||
// (De)activate height level line rendering
|
||||
void set_show_levels(bool state);
|
||||
|
||||
// Set debug text
|
||||
void set_text(std::stringstream &stream);
|
||||
|
||||
private:
|
||||
// The current rotation angle
|
||||
int angle;
|
||||
// The heightmap data
|
||||
BMP *heightmap;
|
||||
// Texture handle
|
||||
GLuint texture_handle;
|
||||
// Is everything loaded?
|
||||
bool initialized;
|
||||
// Setting states
|
||||
bool show_solid, show_wireframe, show_levels;
|
||||
|
||||
// Display list handle
|
||||
GLuint dl_handle;
|
||||
// True if the display list is valid
|
||||
bool dl_valid;
|
||||
|
||||
// List of line points
|
||||
std::vector<point3d> level_lines;
|
||||
|
||||
// Render the terrain
|
||||
void render_terrain();
|
||||
// Calculate and set the normal for height map entry (x,y)
|
||||
void set_normal(int x, int y);
|
||||
|
||||
|
||||
// Render the terrain as solid
|
||||
void render_solid_terrain();
|
||||
// Render the terrain as wireframe
|
||||
void render_wireframe_terrain();
|
||||
// Render height level lines
|
||||
void render_level_lines();
|
||||
// Create height lines for the level "level"
|
||||
void create_level_line(int level);
|
||||
|
||||
|
||||
// Load the height map from the file "filename"
|
||||
bool load_heightmap(const char *filename);
|
||||
// Return the width of the height map
|
||||
int get_heightmap_width() const;
|
||||
// Return the height of the height map
|
||||
int get_heightmap_height() const;
|
||||
// Return the height value at (x,y)
|
||||
int get_heightmap_value(int x, int y) const;
|
||||
|
||||
// Set the light parameters
|
||||
void setup_light();
|
||||
// Set the projection and the view
|
||||
void setup_projection();
|
||||
|
||||
// Load a texture and store its handle in "handle"
|
||||
bool load_texture(const char* filename, GLuint *handle);
|
||||
|
||||
};
|
970
exercise3/include/tiny_vec.h
Normal file
|
@ -0,0 +1,970 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
/*************************************************************************
|
||||
Template class for vectors.
|
||||
This template class defines small vectors of a defined dimension with
|
||||
an arbitrary data type. Basic operations such as addition of vectors and
|
||||
multiplication of a vector and a scalar are supported via operator
|
||||
overloading. Also more advanced functions such as normalization and
|
||||
iterating through the elements are implemented.
|
||||
At the end of this file the data types "point2d", "point3d" and
|
||||
"point4d" are specified as a tinyvec of doubles with the according dimension.
|
||||
*************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4996 )
|
||||
#endif
|
||||
template <typename T,int N>
|
||||
class tiny_vec
|
||||
{
|
||||
|
||||
T _data[N];
|
||||
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
tiny_vec();
|
||||
|
||||
template <typename InputIterator>
|
||||
tiny_vec(InputIterator first,InputIterator last)
|
||||
{
|
||||
std::copy(first,last,begin());
|
||||
}
|
||||
|
||||
|
||||
tiny_vec(size_t n, const T* marray);
|
||||
|
||||
~tiny_vec();
|
||||
|
||||
tiny_vec(const T&x,const T&y);
|
||||
|
||||
tiny_vec(const T&x,const T&y, const T&z);
|
||||
|
||||
tiny_vec(const T&x, const T&y, const T&z,const T& w);
|
||||
|
||||
int size() const;
|
||||
|
||||
operator T*();
|
||||
|
||||
operator const T*() const;
|
||||
|
||||
void set(const T& x);
|
||||
|
||||
void set(const T& x, const T& y);
|
||||
|
||||
void set(const T& x, const T& y,const T& z);
|
||||
|
||||
void set(const T& x, const T& y,const T& z, const T& w);
|
||||
|
||||
tiny_vec& operator=(const T &s);
|
||||
|
||||
tiny_vec& operator=(int s);
|
||||
|
||||
tiny_vec& operator=(const tiny_vec & v);
|
||||
|
||||
void fill(const T& s);
|
||||
|
||||
void zeros();
|
||||
|
||||
void ones();
|
||||
|
||||
iterator begin();
|
||||
|
||||
iterator end();
|
||||
|
||||
const_iterator begin() const;
|
||||
|
||||
const_iterator end() const;
|
||||
|
||||
reverse_iterator rbegin();
|
||||
|
||||
reverse_iterator rend();
|
||||
|
||||
const_reverse_iterator rbegin() const;
|
||||
|
||||
const_reverse_iterator rend() const;
|
||||
|
||||
bool operator==(const tiny_vec& v) const;
|
||||
|
||||
bool operator!=(const tiny_vec& v) const;
|
||||
|
||||
tiny_vec operator-() const;
|
||||
|
||||
|
||||
|
||||
tiny_vec& operator+=(int s);
|
||||
|
||||
tiny_vec& operator+=(float s);
|
||||
|
||||
tiny_vec& operator+=(double s);
|
||||
|
||||
|
||||
|
||||
tiny_vec operator+(int s) const;
|
||||
|
||||
tiny_vec operator+(float s) const;
|
||||
|
||||
tiny_vec operator+(double s) const;
|
||||
|
||||
|
||||
|
||||
tiny_vec& operator-=(int s);
|
||||
|
||||
tiny_vec& operator-=(float s);
|
||||
|
||||
tiny_vec& operator-=(double s);
|
||||
|
||||
|
||||
|
||||
tiny_vec operator-(int s) const;
|
||||
|
||||
tiny_vec operator-(float s) const;
|
||||
|
||||
tiny_vec operator-(double s) const;
|
||||
|
||||
|
||||
|
||||
tiny_vec& operator*=(int s);
|
||||
|
||||
tiny_vec& operator*=(float s);
|
||||
|
||||
tiny_vec& operator*=(double s);
|
||||
|
||||
|
||||
|
||||
tiny_vec operator*(int s) const;
|
||||
|
||||
tiny_vec operator*(float s) const;
|
||||
|
||||
tiny_vec operator*(double s) const;
|
||||
|
||||
|
||||
|
||||
tiny_vec& operator/=(int s);
|
||||
|
||||
tiny_vec& operator/=(float s);
|
||||
|
||||
tiny_vec& operator/=(double s);
|
||||
|
||||
|
||||
|
||||
tiny_vec operator/(int s) const;
|
||||
|
||||
tiny_vec operator/(float s) const;
|
||||
|
||||
tiny_vec operator/(double s) const;
|
||||
|
||||
tiny_vec& operator+=(const tiny_vec& v);
|
||||
|
||||
tiny_vec operator+(const tiny_vec& v) const;
|
||||
|
||||
tiny_vec& operator-=(const tiny_vec& v);
|
||||
|
||||
tiny_vec operator-(const tiny_vec& v) const;
|
||||
|
||||
tiny_vec& operator*=(const tiny_vec& v);
|
||||
|
||||
tiny_vec operator*(const tiny_vec& v) const;
|
||||
|
||||
tiny_vec& operator/=(const tiny_vec& v);
|
||||
|
||||
tiny_vec operator/(const tiny_vec& v) const;
|
||||
|
||||
T& operator()(size_t i);
|
||||
|
||||
T operator()(size_t i) const;
|
||||
|
||||
T& x() {return _data[0];};
|
||||
T& y() {return _data[1];};
|
||||
T& z() {return _data[2];};
|
||||
|
||||
T x() const {return _data[0];};
|
||||
T y() const {return _data[1];};
|
||||
T z() const {return _data[2];};
|
||||
|
||||
|
||||
void sort();
|
||||
|
||||
void random_shuffle();
|
||||
|
||||
T& min_elem();
|
||||
|
||||
T min_elem() const;
|
||||
|
||||
size_t min_index() const;
|
||||
|
||||
T& max_elem();
|
||||
|
||||
T max_elem() const;
|
||||
|
||||
size_t max_index() const;
|
||||
|
||||
T& median_elem();
|
||||
|
||||
size_t median_index() const;
|
||||
|
||||
T sqr_length() const;
|
||||
|
||||
T length() const;
|
||||
|
||||
void normalize();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>::tiny_vec(){}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>::tiny_vec(size_t n,const T* marray)
|
||||
{
|
||||
std::copy(marray,marray+N,begin());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>::~tiny_vec(){}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>::tiny_vec(const T&x,const T&y)
|
||||
{
|
||||
_data[0]=x;
|
||||
_data[1]=y;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>::tiny_vec(const T&x,const T&y, const T&z)
|
||||
{
|
||||
_data[0]=x;
|
||||
_data[1]=y;
|
||||
_data[2]=z;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>::tiny_vec(const T&x, const T&y, const T&z,const T& w)
|
||||
{
|
||||
_data[0]=x;
|
||||
_data[1]=y;
|
||||
_data[2]=z;
|
||||
_data[3]=w;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::set(const T& x)
|
||||
{
|
||||
_data[0]=x;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::set(const T& x, const T& y)
|
||||
{
|
||||
_data[0]=x;
|
||||
_data[1]=y;
|
||||
|
||||
}
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::set(const T& x, const T& y,const T& z)
|
||||
{
|
||||
_data[0]=x;
|
||||
_data[1]=y;
|
||||
_data[2]=z;
|
||||
|
||||
}
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::set(const T& x, const T& y,const T& z, const T& w)
|
||||
{
|
||||
_data[0]=x;
|
||||
_data[1]=y;
|
||||
_data[2]=z;
|
||||
_data[3]=w;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
int tiny_vec<T,N>::size() const
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>::operator T*()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>::operator const T*() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator=(const T &s)
|
||||
{
|
||||
for(int i=0;i < N;i++)
|
||||
_data[i]=s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator=(int s)
|
||||
{
|
||||
for(int i=0;i<N;i++)
|
||||
_data[i]=(T)s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator=(const tiny_vec & v)
|
||||
{
|
||||
if(&v== this) return *this;
|
||||
|
||||
std::copy(v.begin(),v.end(),begin());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::fill(const T& s)
|
||||
{
|
||||
std::fill(begin(),end(),s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::zeros()
|
||||
{
|
||||
T zero;
|
||||
zero=0;
|
||||
std::fill(begin(), end(), zero);
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::ones()
|
||||
{
|
||||
T one;
|
||||
one = 1;
|
||||
std::fill(begin(), end(), one);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
typename tiny_vec<T,N>::iterator tiny_vec<T,N>::begin()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
typename tiny_vec<T,N>::const_iterator tiny_vec<T,N>::begin() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
typename tiny_vec<T,N>::iterator tiny_vec<T,N>::end()
|
||||
{
|
||||
return _data + N;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
typename tiny_vec<T,N>::const_iterator tiny_vec<T,N>::end() const
|
||||
{
|
||||
return _data +N;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
typename tiny_vec<T,N>::reverse_iterator tiny_vec<T,N>::rbegin()
|
||||
{
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
typename tiny_vec<T,N>::reverse_iterator tiny_vec<T,N>::rend()
|
||||
{
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
typename tiny_vec<T,N>::const_reverse_iterator tiny_vec<T,N>::rbegin() const
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
typename tiny_vec<T,N>::const_reverse_iterator tiny_vec<T,N>:: rend() const
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
bool tiny_vec<T,N>::operator==(const tiny_vec<T,N>& v) const
|
||||
{
|
||||
return std::equal(begin(),end(),v.begin());
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
bool tiny_vec<T,N>::operator!=(const tiny_vec<T,N>& v) const
|
||||
{
|
||||
return !(*this == v);
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator-() const
|
||||
{
|
||||
return (T)-1* *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator+=(int s)
|
||||
{
|
||||
|
||||
for(int i=0;i<size();i++)
|
||||
_data[i]+=s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator+=(float s)
|
||||
{
|
||||
|
||||
for(int i=0;i<size();i++)
|
||||
_data[i]+=(T)s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator+=(double s)
|
||||
{
|
||||
|
||||
for(int i=0;i<size();i++)
|
||||
_data[i]+=(T)s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator+(int s) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r += s;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator+(float s) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r += (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator+(double s) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r += (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator-=(int s)
|
||||
{
|
||||
|
||||
for(int i=0;i<N;i++)
|
||||
_data[i]-=(T)s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator-=(float s)
|
||||
{
|
||||
|
||||
for(int i=0;i<N;i++)
|
||||
_data[i]-=(T)s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator-=(double s)
|
||||
{
|
||||
|
||||
for(int i=0;i<N;i++)
|
||||
_data[i]-=(T)s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator-(int s) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r -= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator-(float s) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r -= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator-(double s) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r -= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator*=(int s)
|
||||
{
|
||||
for(int i=0; i <N; i++)
|
||||
_data[i]*=(T)s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator*=(float s)
|
||||
{
|
||||
for(int i=0; i <N; i++)
|
||||
_data[i]*=(T)s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator*=(double s)
|
||||
{
|
||||
for(int i=0; i <N; i++)
|
||||
_data[i]*=(T)s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator*(int s) const
|
||||
{
|
||||
tiny_vec<T,N> r = *this;
|
||||
r *= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator*(float s) const
|
||||
{
|
||||
tiny_vec<T,N> r = *this;
|
||||
r *= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator*(double s) const
|
||||
{
|
||||
tiny_vec<T,N> r = *this;
|
||||
r *= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator/=(int s)
|
||||
{
|
||||
|
||||
for(int i=0;i <N; i++)
|
||||
_data[i]/=(T)s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator/=(float s)
|
||||
{
|
||||
|
||||
for(int i=0;i <N; i++)
|
||||
_data[i]/=(T)s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator/=(double s)
|
||||
{
|
||||
|
||||
for(int i=0;i <N; i++)
|
||||
_data[i]/=(T)s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator/(int s) const
|
||||
{
|
||||
tiny_vec<T,N> r = *this;
|
||||
r /= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator/(float s) const
|
||||
{
|
||||
tiny_vec<T,N> r = *this;
|
||||
r /= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator/(double s) const
|
||||
{
|
||||
tiny_vec<T,N> r = *this;
|
||||
r /= (T)s;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator+=(const tiny_vec& v)
|
||||
{
|
||||
|
||||
for(int i=0; i <N;i++)
|
||||
_data[i] += v[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator+(const tiny_vec& v) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r += v;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator-=(const tiny_vec& v)
|
||||
{
|
||||
for(int i =0; i < N; i++)
|
||||
_data[i]-= v[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator-(const tiny_vec& v) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r -= v;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator*=(const tiny_vec& v)
|
||||
{
|
||||
for(int i=0; i < N; i++)
|
||||
_data[i]*= v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator*(const tiny_vec& v) const
|
||||
{
|
||||
tiny_vec<T,N> r = *this;
|
||||
r *= v;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N>& tiny_vec<T,N>::operator/=(const tiny_vec& v)
|
||||
{
|
||||
for(int i = 0; i < N; i++)
|
||||
_data[i] /= v[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> tiny_vec<T,N>::operator/(const tiny_vec<T,N>& v) const
|
||||
{
|
||||
tiny_vec r = *this;
|
||||
r /= v;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
T& tiny_vec<T,N>::operator()(size_t i)
|
||||
{
|
||||
assert(i >= 0 && i < N);
|
||||
return _data[i];
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
T tiny_vec<T,N>::operator()(size_t i) const
|
||||
{
|
||||
assert(i >= 0 && i < N);
|
||||
return _data[i];
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::sort()
|
||||
{
|
||||
std::sort(begin(),end());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::random_shuffle()
|
||||
{
|
||||
std::random_shuffle(begin(),end());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
T& tiny_vec<T,N>::min_elem()
|
||||
{
|
||||
return *std::min_element(begin(),end());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
T tiny_vec<T,N>::min_elem() const
|
||||
{
|
||||
return *std::min_element(begin(),end());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
size_t tiny_vec<T,N>::min_index() const
|
||||
{
|
||||
return std::distance(begin(),std::min_element(begin(),end()));
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
T& tiny_vec<T,N>::max_elem()
|
||||
{
|
||||
return *std::max_element(begin(),end());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
T tiny_vec<T,N>::max_elem() const
|
||||
{
|
||||
return *std::max_element(begin(),end());
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
size_t tiny_vec<T,N>::max_index() const
|
||||
{
|
||||
return std::distance(begin(),std::max_element(begin(),end()));
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
T tiny_vec<T,N>::sqr_length() const
|
||||
{
|
||||
iterator it= (double*)begin();
|
||||
T l = 0;
|
||||
while(it != end())
|
||||
l += (*it)*(*it++);
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
T tiny_vec<T,N>::length() const
|
||||
{
|
||||
T l = sqr_length();
|
||||
return sqrt(l);
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> operator+(const T& s, const tiny_vec<T,N>& v)
|
||||
{
|
||||
return v+s;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> operator+(int s, const tiny_vec<T,N>& v)
|
||||
{
|
||||
return v+(T)s;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> operator-(const T& s, const tiny_vec<T,N>& v)
|
||||
{
|
||||
return -v+s;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> operator-(int s, const tiny_vec<T,N>& v)
|
||||
{
|
||||
return -v+(T)s;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> operator*(const T& s, const tiny_vec<T,N>& v)
|
||||
{
|
||||
return v*s;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> operator*(int s, const tiny_vec<T,N>& v)
|
||||
{
|
||||
return v*(T)s;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> operator/(const T& s, const tiny_vec<T,N>& v)
|
||||
{
|
||||
return v*(T)(1.0/s);
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N> operator/(int s, const tiny_vec<T,N>& v)
|
||||
{
|
||||
return v*(T)(1.0/s);
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
T dot(const tiny_vec<T,N>& v1, const tiny_vec<T,N>& v2)
|
||||
{
|
||||
return std::inner_product(v1.begin(),v1.end(),v2.begin(),(T)0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
tiny_vec<T,3> cross(const tiny_vec<T,3>& b, const tiny_vec<T,3>& c)
|
||||
{
|
||||
tiny_vec<T,3> a;
|
||||
a[0] = b(1)*c(2) - b(2)*c(1);
|
||||
a[1] = b(2)*c(0) - b(0)*c(2);
|
||||
a[2] = b(0)*c(1) - b(1)*c(0);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N+1> homog(const tiny_vec<T,N>& v)
|
||||
{
|
||||
tiny_vec<T,N+1> vh;
|
||||
std::copy(v.begin(),v.end(),vh.begin());
|
||||
vh(v.size()) = (T)1;
|
||||
return vh;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
tiny_vec<T,N-1> unhomog(const tiny_vec<T,N>& v)
|
||||
{
|
||||
tiny_vec<T,N-1> vh;
|
||||
T w = *(v.end()-1);
|
||||
|
||||
for(int i = 0; i < N-1; i++)
|
||||
vh[i] = v[i]/w;
|
||||
|
||||
return vh;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename T, int N>
|
||||
std::ostream& operator<<(std::ostream& out, const tiny_vec<T,N>& v)
|
||||
{
|
||||
if(v.size() > 0)
|
||||
out << v[0];
|
||||
for(int i = 1; i < v.size(); i++)
|
||||
out <<" " <<v[i];
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
template <typename T,int N>
|
||||
std::istream& operator>>(std::istream& in, tiny_vec<T,N>& v)
|
||||
{
|
||||
for(int i = 0; i < v.size(); i++)
|
||||
in >> v[i];
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
void tiny_vec<T,N>::normalize()
|
||||
{
|
||||
T l = length();
|
||||
if(l != 0)
|
||||
operator/=(l);
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef tiny_vec<double, 2> point2d;
|
||||
typedef tiny_vec<double, 3> point3d;
|
||||
typedef tiny_vec<double, 4> point4d;
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
typedef tiny_vec<double, 2> vec2d;
|
||||
typedef tiny_vec<double, 3> vec3d;
|
||||
typedef tiny_vec<double, 4> vec4d;
|
BIN
exercise3/solution.exe
Normal file
24
exercise3/src/abstract_scene.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "abstract_scene.h"
|
||||
|
||||
|
||||
// Put a text into the stream "stream" which will be displayed
|
||||
// in the main window
|
||||
void abstract_scene::set_text(std::stringstream &stream)
|
||||
{
|
||||
// Nothing implemented here. Children of this class can implement
|
||||
// this method if needed
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Advance one frame
|
||||
void abstract_scene::advance_frame()
|
||||
{
|
||||
// Nothing implemented here. Children of this class can implement
|
||||
// this method if needed
|
||||
}
|
374
exercise3/src/application.cpp
Normal file
|
@ -0,0 +1,374 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "application.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <math.h>
|
||||
|
||||
#include "terrain.h"
|
||||
#include "cube_system.h"
|
||||
#include "cube_system_split.h"
|
||||
#include "recursive_cubes.h"
|
||||
#include "example_primitives.h"
|
||||
#include "example_cons_primitives.h"
|
||||
#include "example_3d_primitives.h"
|
||||
#include "example_trans_order.h"
|
||||
|
||||
|
||||
// Initialize all non-GLUT related variables
|
||||
application::application()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
content = 0;
|
||||
terrain_solid = true;
|
||||
terrain_wireframe = false;
|
||||
terrain_levels = false;
|
||||
|
||||
menu_dirty = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Run the program using the command line arguments
|
||||
int application::run(int argc, char* argv[])
|
||||
{
|
||||
// Initialize the GLUT system and let it evaluate additional
|
||||
// command line arguments.
|
||||
glutInit(&argc, argv);
|
||||
|
||||
// Set the openGL display mode to double buffering and have
|
||||
// channels R,G,B active.
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
|
||||
|
||||
// Initialize main window size
|
||||
glutInitWindowSize(640, 480);
|
||||
// Set a title
|
||||
glutCreateWindow("ECG OpenGL");
|
||||
|
||||
// Set the context menu
|
||||
setup_context_menu();
|
||||
|
||||
// Initialize the starting scene
|
||||
context_menu_select(MA_CUBE_SYSTEM);
|
||||
|
||||
// The following section tells GLUT which methods to call
|
||||
// whenever certain events happen.
|
||||
// ... when the screen shall be displayed
|
||||
glutDisplayFunc(display_callback);
|
||||
// ... when a key was pressed
|
||||
glutKeyboardFunc(key_down_callback);
|
||||
// ... when GLUT is in idle state. Here we check if we must
|
||||
// update the context menu entries
|
||||
glutIdleFunc(idle_callback);
|
||||
|
||||
// Run the timer callback which will trigger itself in the future
|
||||
timer_callback(0);
|
||||
|
||||
// The main loop runs the program itself. It repeatedly asks
|
||||
// the operating system whether there are events to process
|
||||
// and, according to the type of the event, calls the right
|
||||
// method (that was defined above).
|
||||
glutMainLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// The event method on context menu selections
|
||||
void application::context_menu_select(int item)
|
||||
{
|
||||
terrain *ter;
|
||||
|
||||
switch(item)
|
||||
{
|
||||
// Show the cube system
|
||||
case MA_CUBE_SYSTEM:
|
||||
set_content(new cube_system());
|
||||
break;
|
||||
|
||||
// Show the cube system in split screen
|
||||
case MA_CUBE_SYSTEM_SPLIT:
|
||||
set_content(new cube_system_split());
|
||||
break;
|
||||
|
||||
// Show the recursive cubes
|
||||
case MA_CUBES_RECURSIVE:
|
||||
set_content(new recursive_cubes());
|
||||
break;
|
||||
|
||||
// Show the terrain
|
||||
case MA_TERRAIN:
|
||||
ter = new terrain();
|
||||
// Apply the locally stored settings
|
||||
ter->set_show_solid(terrain_solid);
|
||||
ter->set_show_wireframe(terrain_wireframe);
|
||||
ter->set_show_levels(terrain_levels);
|
||||
set_content(ter);
|
||||
break;
|
||||
|
||||
// Show the solid version of the terrain
|
||||
case MA_TERRAIN_SOLID:
|
||||
terrain_solid = !terrain_solid;
|
||||
// Test whether the actual scene is the terrain
|
||||
ter = dynamic_cast<terrain*>(content);
|
||||
// If so, then apply the setting
|
||||
if (ter)
|
||||
ter->set_show_solid(terrain_solid);
|
||||
break;
|
||||
|
||||
// Show the wireframe version of the terrain
|
||||
case MA_TERRAIN_WIREFRAME:
|
||||
terrain_wireframe = !terrain_wireframe;
|
||||
// Test whether the actual scene is the terrain
|
||||
ter = dynamic_cast<terrain*>(content);
|
||||
// If so, then apply the setting
|
||||
if (ter)
|
||||
ter->set_show_wireframe(terrain_wireframe);
|
||||
break;
|
||||
|
||||
// Show the height level lines of the terrain
|
||||
case MA_TERRAIN_LEVELS:
|
||||
terrain_levels = !terrain_levels;
|
||||
// Test whether the actual scene is the terrain
|
||||
ter = dynamic_cast<terrain*>(content);
|
||||
// If so, then apply the setting
|
||||
if (ter)
|
||||
ter->set_show_levels(terrain_levels);
|
||||
break;
|
||||
|
||||
// Show the primitives example
|
||||
case MA_EXAMPLE_PRIMITIVES:
|
||||
set_content(new example_primitives());
|
||||
break;
|
||||
|
||||
// Show the consecutive primitives example
|
||||
case MA_EXAMPLE_CPRIMITIVES:
|
||||
set_content(new example_consecutive_primitives());
|
||||
break;
|
||||
|
||||
// Show the 3D primitives example
|
||||
case MA_EXAMPLE_3D_PRIMITIVES:
|
||||
set_content(new example_3d_primitives());
|
||||
break;
|
||||
|
||||
// Show the transformation order example
|
||||
case MA_EXAMPLE_TRANS_ORDER:
|
||||
set_content(new example_trans_order());
|
||||
break;
|
||||
}
|
||||
|
||||
// Mark the context menu as dirty and let it update by the
|
||||
// idle function.
|
||||
menu_dirty = true;
|
||||
|
||||
// Update display
|
||||
display();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Initialize the context menu
|
||||
void application::setup_context_menu()
|
||||
{
|
||||
|
||||
glutCreateMenu(context_menu_callback);
|
||||
|
||||
// Set the menu entries and associate them with the
|
||||
// appropriate menu action ID
|
||||
glutAddMenuEntry(" Show cube system (c) ", MA_CUBE_SYSTEM);
|
||||
glutAddMenuEntry(" Show terrain (t) ", MA_TERRAIN);
|
||||
glutAddMenuEntry(" ---- Terrain Settings ---- ", -1);
|
||||
glutAddMenuEntry(" ", MA_TERRAIN_SOLID);
|
||||
glutAddMenuEntry(" ", MA_TERRAIN_WIREFRAME);
|
||||
glutAddMenuEntry(" ", MA_TERRAIN_LEVELS);
|
||||
glutAddMenuEntry(" ---- Additional Tasks ---- ", -1);
|
||||
glutAddMenuEntry(" Show cube split screen (x) ", MA_CUBE_SYSTEM_SPLIT);
|
||||
glutAddMenuEntry(" Recursive cubes (r) ", MA_CUBES_RECURSIVE);
|
||||
glutAddMenuEntry(" ----- Example Codes ------ ", -1);
|
||||
glutAddMenuEntry(" Basic primitives (1) ", MA_EXAMPLE_PRIMITIVES);
|
||||
glutAddMenuEntry(" Consecutive primitives (2) ", MA_EXAMPLE_CPRIMITIVES);
|
||||
glutAddMenuEntry(" Simple 3D solids (3) ", MA_EXAMPLE_3D_PRIMITIVES);
|
||||
glutAddMenuEntry(" Transformation orders (4) ", MA_EXAMPLE_TRANS_ORDER);
|
||||
|
||||
|
||||
// Attach the menu to the right mouse button
|
||||
glutAttachMenu(GLUT_RIGHT_BUTTON);
|
||||
|
||||
// Initially fill in the missing menu entry names
|
||||
update_context_menu();
|
||||
}
|
||||
|
||||
|
||||
// Update the context menu according to the settings
|
||||
void application::update_context_menu()
|
||||
{
|
||||
std::stringstream mname;
|
||||
|
||||
// Update the solid terrain menu point and display a
|
||||
// [X] or [ ] at the beginning according to the setting
|
||||
mname.str("");
|
||||
if (terrain_solid)
|
||||
mname<<"[X]";
|
||||
else
|
||||
mname<<"[ ]";
|
||||
mname<<" Show solid terrain (s) ";
|
||||
|
||||
glutChangeToMenuEntry(4, mname.str().c_str(), MA_TERRAIN_SOLID);
|
||||
|
||||
// Update the wireframe terrain menu point and display a
|
||||
// [X] or [ ] at the beginning according to the setting
|
||||
mname.str("");
|
||||
if (terrain_wireframe)
|
||||
mname<<"[X]";
|
||||
else
|
||||
mname<<"[ ]";
|
||||
mname<<" Show wireframe (w) ";
|
||||
glutChangeToMenuEntry(5, mname.str().c_str(), MA_TERRAIN_WIREFRAME);
|
||||
|
||||
// Update the level lines menu point and display a
|
||||
// [X] or [ ] at the beginning according to the setting
|
||||
mname.str("");
|
||||
if (terrain_levels)
|
||||
mname<<"[X]";
|
||||
else
|
||||
mname<<"[ ]";
|
||||
mname<<" Show level lines (l) ";
|
||||
glutChangeToMenuEntry(6, mname.str().c_str(), MA_TERRAIN_LEVELS);
|
||||
|
||||
// The menu is current now
|
||||
menu_dirty = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// The event method on window content rendering
|
||||
void application::display()
|
||||
{
|
||||
// Render the current scene
|
||||
content->render();
|
||||
|
||||
|
||||
// To render the debug text the modelview matrix is reset and the
|
||||
// projection is set to be an orthogonal projection where one unit
|
||||
// corresponds to one pixel of the window
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, 1.0, -1.0);
|
||||
|
||||
std::stringstream stream;
|
||||
content->set_text(stream);
|
||||
glColor3d(0.0, 0.0, 0.0);
|
||||
// Go to the bottom left of the window
|
||||
glRasterPos2i(10, glutGet(GLUT_WINDOW_HEIGHT)-10);
|
||||
// Render the string
|
||||
glutBitmapString(GLUT_BITMAP_HELVETICA_12, reinterpret_cast<const unsigned char*>(stream.str().c_str()));
|
||||
|
||||
// Restore old projection and modelview matrix
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
// Swap the just filled back buffer with the front buffer
|
||||
// to display the result
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set the current scene
|
||||
void application::set_content(abstract_scene *new_content)
|
||||
{
|
||||
if (content)
|
||||
delete content;
|
||||
content = new_content;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// The event method on key presses
|
||||
void application::key_down(unsigned char key, int x, int y)
|
||||
{
|
||||
// According to the key different actions are performed
|
||||
// by using the "context_menu_select" method.
|
||||
switch(key)
|
||||
{
|
||||
case 'c': context_menu_select(MA_CUBE_SYSTEM); break;
|
||||
case 't': context_menu_select(MA_TERRAIN); break;
|
||||
case 'x': context_menu_select(MA_CUBE_SYSTEM_SPLIT); break;
|
||||
case 'r': context_menu_select(MA_CUBES_RECURSIVE); break;
|
||||
case 's': context_menu_select(MA_TERRAIN_SOLID); break;
|
||||
case 'w': context_menu_select(MA_TERRAIN_WIREFRAME); break;
|
||||
case 'l': context_menu_select(MA_TERRAIN_LEVELS); break;
|
||||
case '1': context_menu_select(MA_EXAMPLE_PRIMITIVES); break;
|
||||
case '2': context_menu_select(MA_EXAMPLE_CPRIMITIVES); break;
|
||||
case '3': context_menu_select(MA_EXAMPLE_3D_PRIMITIVES); break;
|
||||
case '4': context_menu_select(MA_EXAMPLE_TRANS_ORDER); break;
|
||||
case 27: glutDestroyWindow(1); break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// The event method on timer callbacks
|
||||
void application::timer(int value)
|
||||
{
|
||||
if (content)
|
||||
content->advance_frame();
|
||||
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
application *application::instance = 0;
|
||||
|
||||
|
||||
void application::key_down_callback(unsigned char key, int x, int y)
|
||||
{
|
||||
instance->key_down(key, x, y);
|
||||
}
|
||||
|
||||
|
||||
void application::display_callback()
|
||||
{
|
||||
instance->display();
|
||||
}
|
||||
|
||||
void application::context_menu_callback(int item)
|
||||
{
|
||||
instance->context_menu_select(item);
|
||||
}
|
||||
|
||||
|
||||
void application::timer_callback(int value)
|
||||
{
|
||||
instance->timer(value);
|
||||
// Trigger the timer again in 1000/30 milliseconds
|
||||
glutTimerFunc(1000/30, timer_callback, value);
|
||||
}
|
||||
|
||||
|
||||
void application::idle_callback()
|
||||
{
|
||||
// Check if we need to update the context menu
|
||||
// and leave method if this is not the case.
|
||||
if (!instance->menu_dirty)
|
||||
return;
|
||||
|
||||
instance->update_context_menu();
|
||||
}
|
120
exercise3/src/cube_system.cpp
Normal file
|
@ -0,0 +1,120 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "cube_system.h"
|
||||
|
||||
// Initialize variables
|
||||
cube_system::cube_system()
|
||||
{
|
||||
angle = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Setup the scene and render cube system
|
||||
void cube_system::render()
|
||||
{
|
||||
// Enable depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
// Disable lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
// Clear the screen and depth buffer
|
||||
glClearColor(1,1,1,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Set the projection and view
|
||||
setup_projection();
|
||||
|
||||
// Render the system
|
||||
render_system();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Advance one frame by increasing the rotation angle
|
||||
void cube_system::advance_frame()
|
||||
{
|
||||
// Increase angle and perform a modulo 360
|
||||
angle = (angle+1)%360;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Render the cube system
|
||||
void cube_system::render_system()
|
||||
{
|
||||
/********
|
||||
Task 2.1.2. Program the transformation tree from the exercise sheet. To store the
|
||||
active aggregated transformation matrix on top of a stack use glPushMatrix
|
||||
and to reactivate and remove the top element of the transformation stack
|
||||
use glPopMatrix. For animation a variable "angle" (which has values
|
||||
between 0 and 359) is defined. Use it for rotations as defined in
|
||||
the transformation tree.
|
||||
Aufgabe 2.1.2. Programmieren Sie den Transformationsbaum aus dem Uebungsblatt.
|
||||
Nutzen Sie glPushMatrix um die aktuelle Gesamttransformations-Matrix an die
|
||||
Spitze eines Stacks zu speichern und glPopMatrix um die vorderste Matrix
|
||||
im Stack zu entfernen und zu reaktivieren. Fuer Animationen steht eine Variable
|
||||
"angle" zur Verfuegung (die Werte zwischen 0 und 359 enthält). Nutzen Sie diese
|
||||
Variable für Rotationen analog zu den Angaben im gegebenen Transformationsbaum.
|
||||
*********/
|
||||
|
||||
|
||||
// Remove the following statement (if wanted) as it just serves 2.1.1.
|
||||
// Entfernen Sie die folgende Anweisung gegebenenfalls, da sie lediglich dem Testen
|
||||
// von Aufgabe 2.1.1 dient.
|
||||
render_cube();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Render one single cube
|
||||
void cube_system::render_cube()
|
||||
{
|
||||
/********
|
||||
Task 2.1.1. Tesellate a cube by specifying vertices and colors via the commands
|
||||
glVertex3d and glColor3d. Choose appropriate primitives (parameter to
|
||||
glBegin) and provide vertices and colors for all 6 sides. The cube shall
|
||||
range from (-1, -1, -1) to (1, 1, 1).
|
||||
Aufgabe 2.1.1. Tesellieren Sie einen Wuerfel, indem Sie Vertices und Farben mittels
|
||||
der Kommandos glVertex3d und glColor3d spezifizieren. Waehlen Sie
|
||||
zunaechst das passende Zeichenprimitiv (Parameter von glBegin) und
|
||||
erstellen Sie Vertices und Farben für alle 6 Seiten. Der Wuerfel soll
|
||||
von (-1, -1, -1) bis (1, 1, 1) reichen.
|
||||
*********/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Set the projection and the view
|
||||
void cube_system::setup_projection()
|
||||
{
|
||||
// For projection choose a perspective matrix with an aperture angle of
|
||||
// 45deg, an aspect ratio that corresponds to the width and height of the
|
||||
// window, z_near at 0.01 and z_far at 100.0
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45, glutGet(GLUT_WINDOW_WIDTH) / static_cast<double>(glutGet(GLUT_WINDOW_HEIGHT)), 0.01, 100.0);
|
||||
|
||||
// For the modelview matrix choose a view from the position (10.0, 6.0, -10.0) to
|
||||
// the position (0, 0, 0) where the up-direction is (0, 1, 0).
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(10.0,6.0,-10.0, 0,0,0, 0,1,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set debug text
|
||||
void cube_system::set_text(std::stringstream &stream)
|
||||
{
|
||||
stream<<"Showing cube system (with rotation parameter at "<<angle<<"°)";
|
||||
}
|
84
exercise3/src/cube_system_split.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "cube_system_split.h"
|
||||
|
||||
|
||||
// Render the scene
|
||||
void cube_system_split::render()
|
||||
{
|
||||
int width = glutGet(GLUT_WINDOW_WIDTH);
|
||||
int height = glutGet(GLUT_WINDOW_HEIGHT);
|
||||
|
||||
// Calculate the aspect ratio for use in glOrtho
|
||||
double aspect = width/static_cast<double>(height);
|
||||
|
||||
// Enable depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Save the current view port
|
||||
glPushAttrib(GL_VIEWPORT_BIT);
|
||||
|
||||
// Clear the screen
|
||||
glClearColor(1,1,1,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
/********
|
||||
Additional Task: Render the cube system in 4 small screens. Three of them
|
||||
shall be orthographic projections of the main layers while
|
||||
the fourth is a perspective projection. Take care that
|
||||
no content from one window renders above its area. The
|
||||
width and height of the window is stored in the variables
|
||||
"width" and "height". Do not remove any code from this method.
|
||||
Zusatzaufgabe: Rendern Sie das Wuerfelsystem in 4 kleinen Bildschirmen.
|
||||
Drei von ihnen sollen orthographische Projektionen der Haupt-
|
||||
eben und eine soll eine perspektivische Projektion sein.
|
||||
Achten Sie darauf, dass der Inhalt der Fenster nicht ueber seinen
|
||||
Bereich hinausrendert. Die Hoehe und Breite des Gesamtfensters
|
||||
ist in den Variablen "width" und "height" gespeichert. Entfernen
|
||||
Sie keinen Code aus dieser Methode.
|
||||
***********/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Restore the old view port
|
||||
glPopAttrib();
|
||||
|
||||
// Render split screen lines to span the whole window.
|
||||
// For this the projection matrix and modelview matrix is
|
||||
// set to the identity matrix. This ensures that the window
|
||||
// area always ranges from -1 to 1 in X and Y. The Z-direction
|
||||
// is omitted.
|
||||
// After that a cross is rendered
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
// Do not perform depth testing
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
// Render a cross in gray
|
||||
glColor3d(0.5, 0.5, 0.5);
|
||||
glLineWidth(1.0);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2d(0, -1);
|
||||
glVertex2d(0, 1);
|
||||
glVertex2d(-1, 0);
|
||||
glVertex2d(1, 0);
|
||||
glEnd();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set debug text
|
||||
void cube_system_split::set_text(std::stringstream &stream)
|
||||
{
|
||||
stream<<"Cube system (top left: XY, top right: YZ, bottom left: XZ, bottom right: perspective)";
|
||||
}
|
230
exercise3/src/example_3d_primitives.cpp
Normal file
|
@ -0,0 +1,230 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "example_3d_primitives.h"
|
||||
|
||||
|
||||
// define math constants such as M_PI in math.h
|
||||
#define _USE_MATH_DEFINES
|
||||
// needed for mathematical operations
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
example_3d_primitives::example_3d_primitives()
|
||||
{
|
||||
angle = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::render()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Clear the screen
|
||||
glClearColor(1,1,1,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Setup a perspective projection and lighting
|
||||
setup_projection();
|
||||
setup_light();
|
||||
|
||||
glScaled(0.4, 0.4, 0.4);
|
||||
|
||||
// Move 5 units to the left, save the current transformation
|
||||
// and show a rotated tetrahedron
|
||||
glTranslated(-5, 0, 0);
|
||||
glPushMatrix();
|
||||
glRotated(angle, 0, 1, 0);
|
||||
glColor3d(1, 1, 0);
|
||||
render_tetrahedron();
|
||||
glPopMatrix();
|
||||
|
||||
// Move 3 units to the right, save the current transformation
|
||||
// and show a rotated cylinder
|
||||
glTranslated(3, 0, 0);
|
||||
glPushMatrix();
|
||||
glRotated(angle, 1, 0, 0);
|
||||
glColor3d(0, 1, 0);
|
||||
render_cylinder();
|
||||
glPopMatrix();
|
||||
|
||||
// Move 3 units to the right, save the current transformation
|
||||
// and show a rotated cube
|
||||
glTranslated(3, 0, 0);
|
||||
glPushMatrix();
|
||||
glRotated(angle, 0, 1, 1);
|
||||
glColor3d(1, 0, 0);
|
||||
render_cube();
|
||||
glPopMatrix();
|
||||
|
||||
// Move 3 units to the right, save the current transformation
|
||||
// and show a rotated sphere
|
||||
glTranslated(3, 0, 0);
|
||||
glPushMatrix();
|
||||
glRotated(angle, 0, 1, 0);
|
||||
glColor3d(0, 0, 1);
|
||||
render_sphere();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::render_tetrahedron()
|
||||
{
|
||||
// The tetrahedron is rendered by explicitly providing all 4 sides
|
||||
|
||||
// Activate rendering of triangles
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glNormal3d(-1, 2, 1);
|
||||
glVertex3d(0, 1, 1);
|
||||
glVertex3d(-1, 1, -1);
|
||||
glVertex3d(0, -1, 0);
|
||||
|
||||
glNormal3d(1, 2, 1);
|
||||
glVertex3d(1, 1, -1);
|
||||
glVertex3d(0, 1, 1);
|
||||
glVertex3d(0, -1, 0);
|
||||
|
||||
glNormal3d(0, 2, -1);
|
||||
glVertex3d(0, -1, 0);
|
||||
glVertex3d(-1, 1, -1);
|
||||
glVertex3d(1, 1, -1);
|
||||
|
||||
glNormal3d(0, 2, 0);
|
||||
glVertex3d(0, 1, 1);
|
||||
glVertex3d(1, 1, -1);
|
||||
glVertex3d(-1, 1, -1);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::render_cylinder()
|
||||
{
|
||||
// The cylinder is first rendered by connected quads and then
|
||||
// two polygons for the top and bottom
|
||||
|
||||
// Begin a strip of rectangles
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (int i=0; i<=360; i+=10) {
|
||||
// One quad is specified by 2 vertices that are connected
|
||||
// to the last 2 vertices. Basically they are an extruded
|
||||
// circle in the X-Z-Layer.
|
||||
glNormal3d(cos(i*M_PI/180.0), 0, sin(i*M_PI/180.0));
|
||||
glVertex3d(cos(i*M_PI/180.0), -1, sin(i*M_PI/180.0));
|
||||
glVertex3d(cos(i*M_PI/180.0), 1, sin(i*M_PI/180.0));
|
||||
}
|
||||
glEnd();
|
||||
|
||||
// The top is a filled circle that is drawn with a single polygon
|
||||
glBegin(GL_POLYGON);
|
||||
glNormal3d(0, -1, 0);
|
||||
for (int i=0; i<=360; i+=10) {
|
||||
glVertex3d(cos(i*M_PI/180.0), -1, sin(i*M_PI/180.0));
|
||||
}
|
||||
glEnd();
|
||||
|
||||
|
||||
// The bottom is a filled circle that is drawn with a single polygon
|
||||
glBegin(GL_POLYGON);
|
||||
glNormal3d(0, 1, 0);
|
||||
for (int i=360; i>=0; i-=10) {
|
||||
glVertex3d(cos(i*M_PI/180.0), 1, sin(i*M_PI/180.0));
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::render_cube()
|
||||
{
|
||||
// Use predefined methods here
|
||||
glutSolidCube(2.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::render_sphere()
|
||||
{
|
||||
// An example for quadrics in GLU (GL-Utilities. Not to be
|
||||
// confused with GL or GLUT :)
|
||||
GLUquadric *sphere = gluNewQuadric();
|
||||
gluSphere(sphere, 1.0, 25, 25);
|
||||
gluDeleteQuadric(sphere);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::setup_projection()
|
||||
{
|
||||
// For projection choose a perspective matrix with an aperture angle of
|
||||
// 45deg, an aspect ratio that corresponds to the width and height of the
|
||||
// window, z_near at 0.01 and z_far at 10.0
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45, glutGet(GLUT_WINDOW_WIDTH) / static_cast<double>(glutGet(GLUT_WINDOW_HEIGHT)), 0.01, 10.0);
|
||||
|
||||
// For the modelview matrix choose a view from the position (2.5, 2.5, 0) to
|
||||
// the position (0, 0, 0) where the up-direction is (0, 1, 0).
|
||||
// Also rotate with the specified angle around the Y-axis
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(0,1,5, 0,0,0, 0,1,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::setup_light()
|
||||
{
|
||||
// Enable lighting and colored materials
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
// Enable light source 0
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
// Set the modelview matrix to be the identity to avoid
|
||||
// having the light position moved with the terrain.
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
// Set light parameters
|
||||
float position[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
float ambient_color[4]={0.0f,0.0f,0.0f,1.0f};
|
||||
float diffuse_color[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
float specular_color[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, position);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
|
||||
|
||||
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT, 10.0f);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::advance_frame()
|
||||
{
|
||||
angle = (angle+1)%360;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_3d_primitives::set_text(std::stringstream &stream)
|
||||
{
|
||||
stream<<"Basic 3D primitives (from example_3d_primitives.cpp)";
|
||||
}
|
103
exercise3/src/example_cons_primitives.cpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "example_cons_primitives.h"
|
||||
|
||||
|
||||
|
||||
// define math constants such as M_PI in math.h
|
||||
#define _USE_MATH_DEFINES
|
||||
// needed for mathematical operations
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
|
||||
void example_consecutive_primitives::render()
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
// Make OpenGL render only the outline of polygons
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
// No lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
// No depth testing
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
// No face culling (also draw polygones that are turned away from the eye point)
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
// Clear the screen
|
||||
glClearColor(1, 1, 1, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Clear the projection matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
// Clear the modelview matrix and set a scale
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glScaled(0.5, 0.5, 0.5);
|
||||
|
||||
// Move to the lower left corner
|
||||
glTranslated(-1, -1, 0);
|
||||
// An example of quad strips...
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (int i=0; i<5; i++) {
|
||||
glVertex3d(i*0.3-0.8, -0.3, 0);
|
||||
glVertex3d(i*0.3-0.8, 0.3, 0);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
// Move to the lower right corner
|
||||
glTranslated(2, 0, 0);
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
// An example of triangle strips. Initially 2 vertices
|
||||
// must be defined. Then every further vertex creates a new
|
||||
// triangle which is connected to the last 2 vertices.
|
||||
glVertex3d(-0.5, -0.6, 0);
|
||||
glVertex3d(-0.9, 0.6, 0);
|
||||
for (int i=1; i<4; i++) {
|
||||
glVertex3d(-0.6+i*0.3, -0.6, 0);
|
||||
glVertex3d(-0.6+i*0.5, 0.6, 0);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
|
||||
// Move to the upper right corner
|
||||
glTranslated(0, 2, 0);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
// An example of a triangle strip. Initially 1 vertex
|
||||
// must be defined. If 3 vertices are provided the first
|
||||
// triangle is drawn and with every new vertex a new triangle
|
||||
// from the actual point, the last point and the first point
|
||||
// is rendered.
|
||||
glVertex3d(0, 0, 0);
|
||||
for (int i=0; i<=360; i+=45)
|
||||
glVertex3d(cos(i*M_PI/180.0), sin(i*M_PI/180), 0);
|
||||
glEnd();
|
||||
|
||||
// Move to the upper left corner
|
||||
glTranslated(-2, 0, 0);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
// An example of a line strip. A line is created between the
|
||||
// current vertex and the last.
|
||||
for (int i=0; i<4; i++) {
|
||||
glVertex3d(-0.6+i*0.3, -0.6, 0);
|
||||
glVertex3d(-0.6+i*0.5, 0.6, 0);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
void example_consecutive_primitives::set_text(std::stringstream &stream)
|
||||
{
|
||||
stream<<"Basic consecutive primitives as wireframe (from example_cons_primitives.cpp)";
|
||||
}
|
110
exercise3/src/example_primitives.cpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "example_primitives.h"
|
||||
|
||||
void example_primitives::render()
|
||||
{
|
||||
// Disable lighting and depth testing
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
// Clear the screen to white
|
||||
glClearColor(1, 1, 1, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Clear the projection matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
// Clear the modelview matrix and set a scale
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glScaled(0.5, 0.5, 0.5);
|
||||
|
||||
// Set the point size to 3 pixels
|
||||
glPointSize(3);
|
||||
|
||||
// Set the drawing color to red
|
||||
glColor3d(1, 0, 0);
|
||||
|
||||
// Move to the lower left corner
|
||||
glTranslated(-1, -1, 0);
|
||||
|
||||
|
||||
// An example for points. Every vertex is represented as a point
|
||||
glBegin(GL_POINTS);
|
||||
glColor3d(0, 0, 0);
|
||||
glVertex3d(0, 0, 0);
|
||||
glColor3d(1, 0, 0);
|
||||
glVertex3d(-0.5, 0, 0);
|
||||
glColor3d(0, 1, 0);
|
||||
glVertex3d(0.7, 0, 0);
|
||||
glColor3d(0, 0, 1);
|
||||
glVertex3d(0.5, 0.7, 0);
|
||||
glColor3d(0.3, 0.1, 0.7);
|
||||
glVertex3d(0.2, -0.3, 0);
|
||||
glEnd();
|
||||
|
||||
|
||||
// Move to the lower right corner
|
||||
glTranslated(2, 0, 0);
|
||||
// An example for triangles. Each 3 vertices are connected
|
||||
// to one triangle. For every vertex a color can be defined which
|
||||
// is then interpolated in between
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3d(1, 0, 0);
|
||||
glVertex3d(-0.5, 0, 0);
|
||||
glVertex3d(0.1, -0.2, 0);
|
||||
glVertex3d(0.3, 0.5, 0);
|
||||
|
||||
glColor3d(1, 0, 0);
|
||||
glVertex3d(0.4, 0.3, 0);
|
||||
glColor3d(0, 1, 0);
|
||||
glVertex3d(0.8, 0.9, 0);
|
||||
glColor3d(0, 0, 1);
|
||||
glVertex3d(0.9, -0.2, 0);
|
||||
glEnd();
|
||||
|
||||
|
||||
|
||||
// Move to the upper right
|
||||
glTranslated(0, 2, 0);
|
||||
// An example for rectangles. Each 4 vertices are connected
|
||||
// to one quad.
|
||||
glBegin(GL_QUADS);
|
||||
glColor3d(0, 1, 0);
|
||||
glVertex3d(-0.5, -0.6, 0);
|
||||
glVertex3d(0.2, -0.5, 0);
|
||||
glColor3d(1, 1, 0);
|
||||
glVertex3d(0.3, 0.5, 0);
|
||||
glVertex3d(-0.5, 0.6, 0);
|
||||
glEnd();
|
||||
|
||||
|
||||
// Move to the upper left
|
||||
glTranslated(-2, 0, 0);
|
||||
// And example for lines. Each 2 vertices are connected
|
||||
// to one line.
|
||||
glBegin(GL_LINES);
|
||||
glColor3d(0, 0, 0);
|
||||
glVertex3d(-0.5, 0.3, 0);
|
||||
glVertex3d(0.4, -0.7, 0);
|
||||
|
||||
glColor3d(1, 0, 1);
|
||||
glVertex3d(0.4, -0.4, 0);
|
||||
glColor3d(0, 1, 0);
|
||||
glVertex3d(1.0, -0.2, 0);
|
||||
glEnd();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_primitives::set_text(std::stringstream &stream)
|
||||
{
|
||||
stream<<"Basic colored primitives (from example_primitives.cpp)";
|
||||
}
|
122
exercise3/src/example_trans_order.cpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "example_trans_order.h"
|
||||
|
||||
|
||||
example_trans_order::example_trans_order()
|
||||
{
|
||||
angle = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_trans_order::render()
|
||||
{
|
||||
// Disable depth testing and lighting
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
// Clear the screen
|
||||
glClearColor(1,1,1,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Set a perspective projection
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45, glutGet(GLUT_WINDOW_WIDTH) / static_cast<double>(glutGet(GLUT_WINDOW_HEIGHT)), 0.01, 10.0);
|
||||
|
||||
// Clear the modelview matrix
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslated(0, 0, -7);
|
||||
|
||||
glTranslated(-2, 1, 0);
|
||||
|
||||
// The first example first translates and then rotates
|
||||
glPushMatrix();
|
||||
// Render the green quad
|
||||
glColor3d(0, 1, 0);
|
||||
render_quad();
|
||||
glTranslated(1, 0, 0.1);
|
||||
glRotated(angle, 0, 0, 1);
|
||||
// Render the transformed black quad
|
||||
glColor3d(0, 0, 0);
|
||||
render_quad();
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
glTranslated(4, 0, 0);
|
||||
|
||||
// The second example first rotates and then translates
|
||||
glPushMatrix();
|
||||
// Render the green quad
|
||||
glColor3d(0, 1, 0);
|
||||
render_quad();
|
||||
glRotated(angle, 0, 0, 1);
|
||||
glTranslated(1, 0, 0.1);
|
||||
// Render the transformed black quad
|
||||
glColor3d(0, 0, 0);
|
||||
render_quad();
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
glTranslated(0, -2.5, 0);
|
||||
|
||||
// The third example first rotates and then scales
|
||||
glPushMatrix();
|
||||
// Render the green quad
|
||||
glColor3d(0, 1, 0);
|
||||
render_quad();
|
||||
glRotated(angle, 0, 0, 1);
|
||||
glScaled(0.8, 0.3, 1.0);
|
||||
// Render the transformed black quad
|
||||
glColor3d(0, 0, 0);
|
||||
render_quad();
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
glTranslated(-4, 0, 0);
|
||||
|
||||
// The fourth example first scales and then rotates
|
||||
glPushMatrix();
|
||||
// Render the green quad
|
||||
glColor3d(0, 1, 0);
|
||||
render_quad();
|
||||
glScaled(0.8, 0.3, 1.0);
|
||||
glRotated(angle, 0, 0, 1);
|
||||
// Render the transformed black quad
|
||||
glColor3d(0, 0, 0);
|
||||
render_quad();
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_trans_order::render_quad()
|
||||
{
|
||||
// Render a quad by using a line loop.
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex3d(-0.5, -0.5, 0);
|
||||
glVertex3d(0.5, -0.5, 0);
|
||||
glVertex3d(0.5, 0.5, 0);
|
||||
glVertex3d(-0.5, 0.5, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void example_trans_order::advance_frame()
|
||||
{
|
||||
angle = (angle+1)%360;
|
||||
}
|
||||
|
||||
|
||||
void example_trans_order::set_text(std::stringstream &stream)
|
||||
{
|
||||
stream<<"Transformation order matters (top left: trans, rot; top right: rot, trans; bottom left: scale, rot; bottom right: rot, scale)";
|
||||
}
|
34
exercise3/src/main.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include "application.h"
|
||||
|
||||
|
||||
#ifndef WIN32
|
||||
// These lines are needed if OpenGL is used under linux using nvidia drivers. The following error appears otherwise:
|
||||
// Inconsistency detected by ld.so: dl-version.c: 224: _dl_check_map_versions: Assertion `needed != ((void *)0)' failed!
|
||||
///http://stackoverflow.com/questions/20007961/error-running-a-compiled-c-file-uses-opengl-error-inconsistency-detected
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
void junk() {
|
||||
int i;
|
||||
i=pthread_getconcurrency();
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Instanciate the application...
|
||||
application app;
|
||||
|
||||
// ... and let it run!
|
||||
return app.run(argc, argv);
|
||||
}
|
157
exercise3/src/recursive_cubes.cpp
Normal file
|
@ -0,0 +1,157 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "recursive_cubes.h"
|
||||
|
||||
|
||||
// Initialize variables
|
||||
recursive_cubes::recursive_cubes()
|
||||
{
|
||||
angle = 0;
|
||||
// Set maximum recursion depth
|
||||
depth = 4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render the scene
|
||||
void recursive_cubes::render()
|
||||
{
|
||||
// Enable depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Set the light parameters, projection and view
|
||||
setup_light();
|
||||
setup_projection();
|
||||
|
||||
// Clear the screen
|
||||
glClearColor(1,1,1,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Start the recursive rendering
|
||||
render_recursive(depth, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void recursive_cubes::render_recursive(int r, bool render_all)
|
||||
{
|
||||
// Recursion end condition
|
||||
if (r<=0)
|
||||
return;
|
||||
|
||||
// Render the actual cube
|
||||
render_cube();
|
||||
|
||||
|
||||
/********
|
||||
Additional Task: Recursively render the cube tree. One cube in the
|
||||
tree contains another tree on every side which is
|
||||
scaled by the factor 0.5 and translated to 4 units
|
||||
away from the side. Use this method for the recursion.
|
||||
The parameter "r" specifies the current recursion steps
|
||||
that can still be made (must be decremented for every step)
|
||||
while the parameter "render_all" is true if all sides shall
|
||||
be rendered and false if the side facing a bigger side of
|
||||
the last recursion step shall be omitted.
|
||||
Zusatzaufgabe: Rendern Sie rekursiv den Wuerfelbaum. Ein Wuefel des Baums
|
||||
enthält einen weiteren Wuerfelbaum auf jeder Seite, der um
|
||||
den Faktor 0,5 skaliert und um 4 Einheiten von der Seite
|
||||
weg verschoben wurde. Nutzen Sie diese Methode für die Rekursion.
|
||||
Der Parameter "r" gibt die aktuell noch moeglichen Rekursions-
|
||||
schritte ein (und muss also bei jedem Schritt verringert werden).
|
||||
Der Paremter "render_all" soll auf true gesetzt werden, wenn
|
||||
alle Seiten gerendert werden sollen und auf false, wenn die Seite,
|
||||
die in Richtung einer größeren Seite eines Wuerfels aus dem vorherigen
|
||||
Schritt zeigt, ausgelassen werden soll.
|
||||
************/
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render one single cube
|
||||
void recursive_cubes::render_cube()
|
||||
{
|
||||
// Set color to yellow
|
||||
glColor3d(1, 1, 0);
|
||||
// Render a cube with side length 2
|
||||
glutSolidCube(2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set the projection and the view
|
||||
void recursive_cubes::setup_projection()
|
||||
{
|
||||
// For projection choose a perspective matrix with an aperture angle of
|
||||
// 45deg, an aspect ratio that corresponds to the width and height of the
|
||||
// window, z_near at 0.01 and z_far at 100.0
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45, glutGet(GLUT_WINDOW_WIDTH) / static_cast<double>(glutGet(GLUT_WINDOW_HEIGHT)), 0.01, 100.0);
|
||||
|
||||
// For the modelview matrix choose a view from the position (7.0, 3.0, 7.0) to
|
||||
// the position (0, 0, 0) where the up-direction is (0, 1, 0).
|
||||
// Also rotate with the specified angle around the Y-axis
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(7.0,3.0,7.0, 0,0,0, 0,1,0);
|
||||
glRotated(angle, 0, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set the light parameters
|
||||
void recursive_cubes::setup_light()
|
||||
{
|
||||
// Enable lighting
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
// Enable light source 0
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
// Set the modelview matrix to be the identity to avoid
|
||||
// having the light position moved with the terrain.
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
// Set light parameters
|
||||
float position[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
float ambient_color[4]={0.0f,0.0f,0.0f,1.0f};
|
||||
float diffuse_color[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
float specular_color[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, position);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_color);
|
||||
|
||||
|
||||
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT, 10.0f);
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Advance one frame
|
||||
void recursive_cubes::advance_frame()
|
||||
{
|
||||
// Increase angle and perform a modulo 360
|
||||
angle = (angle+1)%360;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set debug text
|
||||
void recursive_cubes::set_text(std::stringstream &stream)
|
||||
{
|
||||
stream<<"Recursive cubes with recursion depth "<<depth;
|
||||
}
|
562
exercise3/src/terrain.cpp
Normal file
|
@ -0,0 +1,562 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "terrain.h"
|
||||
|
||||
|
||||
// Load images and initialize variables
|
||||
terrain::terrain()
|
||||
{
|
||||
initialized = false;
|
||||
heightmap = 0;
|
||||
angle = 0;
|
||||
|
||||
// The display list is not valid
|
||||
dl_valid = false;
|
||||
dl_handle = 0;
|
||||
|
||||
// Try to load the heightmap
|
||||
if (!load_heightmap("../../data/tex_height.bmp"))
|
||||
return;
|
||||
|
||||
// Try to load the texture
|
||||
if (!load_texture("../../data/tex_topo.bmp", &texture_handle))
|
||||
return;
|
||||
|
||||
initialized = true;
|
||||
|
||||
// Basic initial settings
|
||||
set_show_solid(true);
|
||||
set_show_wireframe(false);
|
||||
set_show_levels(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Unload images and textures
|
||||
terrain::~terrain()
|
||||
{
|
||||
// Delete the texture
|
||||
glDeleteTextures(1, &texture_handle);
|
||||
// Free the memory for the height map
|
||||
BMP_Free(heightmap);
|
||||
// Delete the display list if neccessary
|
||||
if (glIsList(dl_handle))
|
||||
glDeleteLists(dl_handle, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render the actual scene
|
||||
void terrain::render()
|
||||
{
|
||||
// Enable depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Enable automatic normalization of normals
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
// Clear the screen
|
||||
glClearColor(1,1,1,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Nothing to do if we are not properly initialized
|
||||
if (!initialized)
|
||||
return;
|
||||
|
||||
// Setup perspective and modelview matrix
|
||||
setup_projection();
|
||||
// Setup light
|
||||
setup_light();
|
||||
|
||||
|
||||
// Render the solid terrain with lighting and texture mapping
|
||||
if (show_solid)
|
||||
render_solid_terrain();
|
||||
|
||||
// Render the outline of the terrain
|
||||
if (show_wireframe)
|
||||
render_wireframe_terrain();
|
||||
|
||||
// Eventually render level lines
|
||||
if (show_levels)
|
||||
render_level_lines();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Render the terrain as solid
|
||||
void terrain::render_solid_terrain()
|
||||
{
|
||||
// Enable lighting
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
// This is a trick which is neccessary in order to draw lines
|
||||
// later on. Otherwise there would be artifacts due to a z-fight.
|
||||
glPolygonOffset(1, 1);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
|
||||
/********
|
||||
Task 2.2.4. Activate 2D texture mapping and bind the texture that
|
||||
is identified by the handle "texture_handle". Do not remove
|
||||
any of the code in this method.
|
||||
Aufgabe 2.2.4. Aktivieren Sie 2D-Texturierung und binden Sie die
|
||||
Textur, die ueber das Handle "texture_handle" identifiziert
|
||||
ist. Entfernen Sie keinen Code in dieser Methode.
|
||||
************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Set the material color to white
|
||||
glColor3d(1, 1, 1);
|
||||
// Render the terrain
|
||||
render_terrain();
|
||||
|
||||
// Disable texture mapping
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
// Disable support for depth buffer offsets
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
// Disable lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Render the terrain as wireframe
|
||||
void terrain::render_wireframe_terrain()
|
||||
{
|
||||
// Set the line width to be 1 pixel
|
||||
glLineWidth(1.0);
|
||||
// Set the draw mode to draw outlines of polygons
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
// Set the color to black
|
||||
glColor3d(0, 0, 0);
|
||||
// Render the terrain
|
||||
render_terrain();
|
||||
|
||||
// Set the draw mode to fill polygons
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render the terrain
|
||||
void terrain::render_terrain()
|
||||
{
|
||||
// Store width and height for faster access
|
||||
int map_width = get_heightmap_width();
|
||||
int map_height = get_heightmap_height();
|
||||
|
||||
|
||||
// Move and scale the coordinate system so that we can work with
|
||||
// whole units. That means that a vertex at height map position (x, y)
|
||||
// with a height of h can be placed as glVertex3d(x, h, y). The
|
||||
// terrain extents in the XZ-layer while the height is on the Y-axis.
|
||||
glPushMatrix();
|
||||
glTranslated(-1, 0, -1);
|
||||
glScaled(2.0/static_cast<double>(map_width), 1.0/256.0, 2.0/static_cast<double>(map_height));
|
||||
|
||||
|
||||
|
||||
|
||||
/********
|
||||
Task 2.2.1. Complete the code below to create a regular grid which expands
|
||||
along the X-Z-layer. Create the grid by specifying triangle
|
||||
strips for each line. The coordinate system is already scaled
|
||||
and translated to use the values of the variables "x" and "y"
|
||||
defined below directly as coordinates. The initial height of
|
||||
the grid shall be 0.
|
||||
Aufgabe 2.2.1. Vervollstaendigen Sie den nachfolgenden Quelltext um die
|
||||
Erstellung eines regelmaessigen Gitters das sich ueber die
|
||||
X-Z-Ebene erstreckt. Erstellen Sie dieses Gitter, indem Sie
|
||||
zeilenweise Dreiecksstreifen definieren. Das Koordinatensystem
|
||||
ist bereits skaliert und verschoben, so dass Sie die Werte
|
||||
der Variablen "x" und "y", die unten definiert werden direkt
|
||||
als Koordinaten einsetzen koennen. Das Gitter soll zunaechst
|
||||
eine Hoehe von 0 besitzen.
|
||||
|
||||
|
||||
Task 2.2.2. Now elevate the height of the vertices to create the grid terrain
|
||||
that corresponds to the height map. Use "get_heightmap_value(x, y)".
|
||||
Aufgabe 2.2.2. Heben Sie jetzt die Vertices an um ein Drahtgitterterrain zu erstellen,
|
||||
das zur Hoehenkarte korrespondiert. Nutzen Sie die Methode
|
||||
"get_heightmap_value(x, y)".
|
||||
|
||||
|
||||
Task 2.2.3. Make sure to call "set_normal" for every vertex and continue this
|
||||
task in "set_normal".
|
||||
Aufgabe 2.2.3. Stellen Sie sicher, dass Sie "set_normal" für jeden Vertex aufrufen
|
||||
und fahren Sie in "set_normal" mit der Aufgabe fort.
|
||||
|
||||
|
||||
Task 2.2.4. Activate texture mapping and bind the texture in the method
|
||||
"render_solid_terrain". Provide 2D texture coordinates per vertex in
|
||||
this method using "glTexCoord2d".
|
||||
Aufgabe 2.2.4. Aktivieren Sie Texturmapping und binden Sie eine Textur in der
|
||||
Methode "render_solid_terrain". Spezifizieren Sie in dieser Methode pro
|
||||
Vertex eine Texturkoordinate mittels der Methode "glTexCoord2d".
|
||||
*********/
|
||||
|
||||
|
||||
// Go through all rows (-1)
|
||||
for (int y = 0; y<map_height-1; y++) {
|
||||
|
||||
// ... to be completed
|
||||
|
||||
// Draw one strip
|
||||
for (int x = 0; x<map_width; x++) {
|
||||
|
||||
// ... to be completed
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Calculate and set the normal for height map entry (x,y)
|
||||
void terrain::set_normal(int x, int y)
|
||||
{
|
||||
/********
|
||||
Task 2.2.3. Calculate the normal for the vertex that corresponds to
|
||||
the height map value (x, y). You can either use forward differences,
|
||||
backward differences or central differences. The latter will give
|
||||
the best results. The calculation is done by first determining direction
|
||||
vectors in X and Z and then using vector operations to get a vector that
|
||||
is perpendicular to both. You find some examples for vector operations in
|
||||
this project below. Do not forget to pass the normal to OpenGL using
|
||||
the command glNormal3d.
|
||||
|
||||
Aufgabe 2.2.3. Berechnen Sie die Normalen fuer den Vertex der zum Hoehenwert (x, y)
|
||||
gehoert. Sie koennen entweder Vorwaerts-, Rueckwaerts- oder Zentral-
|
||||
Differenzen verwenden. Die letzte Methode erzeugt die besten Resultate.
|
||||
Fuer die Berechnung werden zunaechst Richtungvektoren in X- und Z-Richtung
|
||||
gebildet und anschliessend mittels Vektoroperationen ein zu beiden Vektoren
|
||||
senkrechter Vektor berechnet. Nachfolgend ein paar Beispiele fuer Vektor-
|
||||
rechnungen in diesem Projekt. Vergessen Sie nicht die Normale nach der
|
||||
Berechnung mittels glNormal3d an OpenGL zu senden.
|
||||
|
||||
// Create a vector
|
||||
vec3d vec1(1.0, 1.0, 1.0);
|
||||
// Create another vector
|
||||
vec3d vec2(0.5, -1.0, 2.0);
|
||||
// Normalize the first vector
|
||||
vec1.normalize();
|
||||
// Add the first vector to the second
|
||||
vec2 = vec1 + vec2;
|
||||
// Increase the length of the first vector
|
||||
vec1 *= 10.0;
|
||||
// Calculate the dot product
|
||||
double x = dot(vec1, vec2);
|
||||
// Calculate the cross product
|
||||
vec3d vec3 = cross(vec1, vec2);
|
||||
// Get the length
|
||||
double l = vec3.length();
|
||||
// Get the components for a vector
|
||||
double x = vec3.x();
|
||||
double y = vec3.y();
|
||||
double z = vec3.z();
|
||||
*****************/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Render height level lines
|
||||
void terrain::render_level_lines()
|
||||
{
|
||||
// Set color to gray
|
||||
glColor3d(0.5, 0.5, 0.5);
|
||||
// Set the line width to 3 pixels
|
||||
glLineWidth(2.0);
|
||||
|
||||
// Change the coordinate system so that one can work with whole units
|
||||
glPushMatrix();
|
||||
glTranslated(-1, 0, -1);
|
||||
glScaled(2.0/static_cast<double>(get_heightmap_width()), 1.0/256.0, 2.0/static_cast<double>(get_heightmap_height()));
|
||||
|
||||
// Connect with lines
|
||||
glBegin(GL_LINES);
|
||||
|
||||
// Render lines which were created in "create_level_lines" and stored into
|
||||
// the list "level_lines"
|
||||
for (int i=0; i<(int)level_lines.size(); i+=2) {
|
||||
glVertex3d(level_lines[i ].x(), level_lines[i ].y(), level_lines[i ].z());
|
||||
glVertex3d(level_lines[i+1].x(), level_lines[i+1].y(), level_lines[i+1].z());
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
// Set the width back to 1.0
|
||||
glLineWidth(1.0);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create height lines for the level "level"
|
||||
void terrain::create_level_line(int level)
|
||||
{
|
||||
/********
|
||||
Additional Task: Find iso lines with the "Marching Squares" algorithm for the
|
||||
height value "level". Store the start and end points of the
|
||||
found lines in the list "level_lines".
|
||||
Zusatzaufgabe: Finden Sie Hoehenlinien mittels des "Marching Squares"-Algorithmus
|
||||
fuer den Hoehenwert "level". Legen Sie die Start- und Endpunkte
|
||||
der gefundenen Linien in der Liste "level_lines" ab.
|
||||
*************/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Set the light parameters
|
||||
void terrain::setup_light()
|
||||
{
|
||||
// Enable lighting and colored materials
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
// Enable light source 0
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
// Set the modelview matrix to be the identity to avoid
|
||||
// having the light position moved with the terrain.
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
// Set light parameters
|
||||
float position[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
float ambient_color[4]={0.0f,0.0f,0.0f,1.0f};
|
||||
float diffuse_color[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
float specular_color[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, position);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
|
||||
|
||||
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT, 10.0f);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set the projection and the view
|
||||
void terrain::setup_projection()
|
||||
{
|
||||
// For projection choose a perspective matrix with an aperture angle of
|
||||
// 45deg, an aspect ratio that corresponds to the width and height of the
|
||||
// window, z_near at 0.01 and z_far at 10.0
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45, glutGet(GLUT_WINDOW_WIDTH) / static_cast<double>(glutGet(GLUT_WINDOW_HEIGHT)), 0.01, 10.0);
|
||||
|
||||
// For the modelview matrix choose a view from the position (2.5, 2.5, 0) to
|
||||
// the position (0, 0, 0) where the up-direction is (0, 1, 0).
|
||||
// Also rotate with the specified angle around the Y-axis
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(2.5,2.5,0, 0,0,0, 0,1,0);
|
||||
glRotated(angle, 0,1,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Advance one frame
|
||||
void terrain::advance_frame()
|
||||
{
|
||||
// Increase angle and perform a modulo 360
|
||||
angle = (angle+1)%360;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// (De)activate solid rendering
|
||||
void terrain::set_show_solid(bool state)
|
||||
{
|
||||
show_solid = state;
|
||||
// The current display list is outdated now
|
||||
dl_valid = false;
|
||||
}
|
||||
|
||||
|
||||
// (De)activate wireframe rendering
|
||||
void terrain::set_show_wireframe(bool state)
|
||||
{
|
||||
show_wireframe = state;
|
||||
// The current display list is outdated now
|
||||
dl_valid = false;
|
||||
}
|
||||
|
||||
|
||||
// (De)activate height level line rendering
|
||||
void terrain::set_show_levels(bool state)
|
||||
{
|
||||
show_levels = state;
|
||||
|
||||
// If level lines shall be displayed then
|
||||
// recreate them in equidistant ranges
|
||||
if (show_levels) {
|
||||
level_lines.clear();
|
||||
for (int i=20; i<=255; i+=20)
|
||||
create_level_line(i);
|
||||
}
|
||||
|
||||
// The current display list is outdated now
|
||||
dl_valid = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Load the height map from the file "filename"
|
||||
bool terrain::load_heightmap(const char *filename)
|
||||
{
|
||||
// Load the heightmap by reading a bmp file
|
||||
heightmap = BMP_ReadFile(filename);
|
||||
|
||||
// Return false and show an error message if the file
|
||||
// could not be loaded
|
||||
if (BMP_GetError() != BMP_OK) {
|
||||
std::cout<<BMP_GetErrorDescription()<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// All went well...
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Load a texture and store its handle in "handle"
|
||||
bool terrain::load_texture(const char *filename, GLuint *handle)
|
||||
{
|
||||
BMP *bitmap;
|
||||
|
||||
// Load the texture by reading a bmp file
|
||||
bitmap = BMP_ReadFile(filename);
|
||||
|
||||
// Return false and show an error message if the file
|
||||
// could not be loaded
|
||||
if (BMP_GetError() != BMP_OK) {
|
||||
std::cout<<BMP_GetErrorDescription()<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get a pointer to the bitmap data
|
||||
unsigned char* data = BMP_GetImageData(bitmap);
|
||||
|
||||
// Generate one texture and store its ID in "handle"
|
||||
glGenTextures(1, handle);
|
||||
// Bind the texture
|
||||
glBindTexture(GL_TEXTURE_2D, *handle);
|
||||
// Enable linear blending between different mipmapping levels
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
// Clamp the texture at the borders
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
// Transfer the image data to the graphics card.
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP_GetWidth(bitmap), BMP_GetHeight(bitmap), 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
|
||||
// Not needed anymore
|
||||
free(data);
|
||||
BMP_Free(bitmap);
|
||||
|
||||
// Unbind texture
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Return the width of the height map
|
||||
int terrain::get_heightmap_width() const
|
||||
{
|
||||
return BMP_GetWidth(heightmap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Return the height of the height map
|
||||
int terrain::get_heightmap_height() const
|
||||
{
|
||||
return BMP_GetHeight(heightmap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Return the height value at (x,y)
|
||||
int terrain::get_heightmap_value(int x, int y) const
|
||||
{
|
||||
// Returns one value from the heightmap. The image should
|
||||
// be in grayscale so just the red channel is returned.
|
||||
// The image is mirrored at the edges (by adjusting the
|
||||
// coordinates) to assure correct normal estimation.
|
||||
unsigned char r, g, b;
|
||||
|
||||
// Mirror at the left and upper edge if neccessary
|
||||
x = abs(x);
|
||||
y = abs(y);
|
||||
|
||||
// Mirror at the right and bottom edge if neccessary
|
||||
if (x>=get_heightmap_width())
|
||||
x = 2*get_heightmap_width()-x-1;
|
||||
if (y>=get_heightmap_height())
|
||||
y = 2*get_heightmap_height()-y-1;
|
||||
|
||||
// Read the pixel and return the red component
|
||||
BMP_GetPixelRGB(heightmap, x, y, &r, &g, &b);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set debug text
|
||||
void terrain::set_text(std::stringstream &stream)
|
||||
{
|
||||
if (!initialized) {
|
||||
stream<<"Cannot show terrain - not all files were loaded!";
|
||||
return;
|
||||
}
|
||||
stream<<"Showing terrain";
|
||||
|
||||
if (!show_solid && !show_wireframe && !show_levels) {
|
||||
stream<<" (all features disabled)";
|
||||
return;
|
||||
}
|
||||
|
||||
stream<<" (";
|
||||
if (show_solid)
|
||||
stream<<"as solid geometry";
|
||||
if (show_solid && show_wireframe)
|
||||
stream<<", ";
|
||||
if (show_wireframe)
|
||||
stream<<"as wireframe";
|
||||
if (show_wireframe && show_levels)
|
||||
stream<<", ";
|
||||
if (show_levels)
|
||||
stream<<"with level lines";
|
||||
stream<<")";
|
||||
}
|
148
exercise3/src_solution/src/cube_system.cpp
Normal file
|
@ -0,0 +1,148 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "cube_system.h"
|
||||
|
||||
// Initialize variables
|
||||
cube_system::cube_system()
|
||||
{
|
||||
angle = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Setup the scene and render cube system
|
||||
void cube_system::render()
|
||||
{
|
||||
// Enable depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
// Disable lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
// Clear the screen and depth buffer
|
||||
glClearColor(1,1,1,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Set the projection and view
|
||||
setup_projection();
|
||||
|
||||
// Render the system
|
||||
render_system();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render the cube system
|
||||
void cube_system::render_system()
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glRotated(angle, 0, 1, 0);
|
||||
render_cube();
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glRotated(-angle, 0, 1, 0);
|
||||
glTranslated(5, 0, 0);
|
||||
glScaled(0.6, 0.6, 0.6);
|
||||
render_cube();
|
||||
|
||||
glPushMatrix();
|
||||
glRotated(angle*2, 0, 0, 1);
|
||||
glTranslated(3, 0, 0);
|
||||
glScaled(0.5, 0.5, 0.5);
|
||||
render_cube();
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glRotated(angle*2+180, 0, 0, 1);
|
||||
glTranslated(3, 0, 0);
|
||||
glScaled(0.5, 0.5, 0.5);
|
||||
render_cube();
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Advance one frame by increasing the rotation angle
|
||||
void cube_system::advance_frame()
|
||||
{
|
||||
// Increase angle and perform a modulo 360
|
||||
angle = (angle+1)%360;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render one single cube
|
||||
void cube_system::render_cube()
|
||||
{
|
||||
glPushMatrix();
|
||||
for (int i=0; i<4; i++) {
|
||||
|
||||
switch(i) {
|
||||
case 0: glColor3d(165/255.0, 165/255.0, 165/255.0); break;
|
||||
case 1: glColor3d( 73/255.0, 68/255.0, 41/255.0); break;
|
||||
case 2: glColor3d( 23/255.0, 54/255.0, 93/255.0); break;
|
||||
case 3: glColor3d(149/255.0, 55/255.0, 52/255.0); break;
|
||||
}
|
||||
|
||||
glRotated(90, 0, 1, 0);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3d(-1, 1, -1);
|
||||
glVertex3d(1, 1, -1);
|
||||
glVertex3d(1, -1, -1);
|
||||
glVertex3d(-1, -1, -1);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor3d(118/255.0, 146/255.0, 60/255.0);
|
||||
glVertex3d(-1, 1, -1);
|
||||
glVertex3d(-1, 1, 1);
|
||||
glVertex3d( 1, 1, 1);
|
||||
glVertex3d(1, 1, -1);
|
||||
|
||||
glColor3d(95/255.0, 73/255.0, 122/255.0);
|
||||
glVertex3d(1, -1, -1);
|
||||
glVertex3d( 1, -1, 1);
|
||||
glVertex3d(-1, -1, 1);
|
||||
glVertex3d(-1, -1, -1);
|
||||
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set the projection and the view
|
||||
void cube_system::setup_projection()
|
||||
{
|
||||
// For projection choose a perspective matrix with an aperture angle of
|
||||
// 45deg, an aspect ratio that corresponds to the width and height of the
|
||||
// window, z_near at 0.01 and z_far at 100.0
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45, glutGet(GLUT_WINDOW_WIDTH) / static_cast<double>(glutGet(GLUT_WINDOW_HEIGHT)), 0.01, 100.0);
|
||||
|
||||
// For the modelview matrix choose a view from the position (10.0, 6.0, -10.0) to
|
||||
// the position (0, 0, 0) where the up-direction is (0, 1, 0).
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(10.0,6.0,-10.0, 0,0,0, 0,1,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set debug text
|
||||
void cube_system::set_text(std::stringstream &stream)
|
||||
{
|
||||
stream<<"Showing cube system (with rotation parameter at "<<angle<<"°)";
|
||||
}
|
502
exercise3/src_solution/src/terrain.cpp
Normal file
|
@ -0,0 +1,502 @@
|
|||
//
|
||||
// This source code is property of the Computer Graphics and Visualization
|
||||
// chair of the TU Dresden. Do not distribute in modified or unmodified form!
|
||||
// Copyright (C) 2016 CGV TU Dresden - All Rights Reserved
|
||||
//
|
||||
#include "terrain.h"
|
||||
|
||||
|
||||
// Load images and initialize variables
|
||||
terrain::terrain()
|
||||
{
|
||||
initialized = false;
|
||||
heightmap = 0;
|
||||
angle = 0;
|
||||
|
||||
// The display list is not valid
|
||||
dl_valid = false;
|
||||
dl_handle = 0;
|
||||
|
||||
// Try to load the heightmap. First try it from
|
||||
// "../../data" and then from "data/"
|
||||
if (!load_heightmap("../../data/tex_height.bmp") &&
|
||||
!load_heightmap("data/tex_height.bmp")) {
|
||||
std::cout<<"Could not load the heightmap!"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to load the texture. First try it from
|
||||
// "../../data" and then from "data/"
|
||||
if (!load_texture("../../data/tex_topo.bmp", &texture_handle) &&
|
||||
!load_texture("data/tex_topo.bmp", &texture_handle)) {
|
||||
std::cout<<"Could not load the texture!"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
|
||||
// Basic initial settings
|
||||
set_show_solid(true);
|
||||
set_show_wireframe(false);
|
||||
set_show_levels(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Unload images and textures
|
||||
terrain::~terrain()
|
||||
{
|
||||
// Delete the texture
|
||||
glDeleteTextures(1, &texture_handle);
|
||||
// Free the memory for the height map
|
||||
BMP_Free(heightmap);
|
||||
// Delete the display list if neccessary
|
||||
if (glIsList(dl_handle))
|
||||
glDeleteLists(dl_handle, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render the actual scene
|
||||
void terrain::render()
|
||||
{
|
||||
// Enable depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Enable automatic normalization of normals
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
// Clear the screen
|
||||
glClearColor(1,1,1,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Nothing to do if we are not properly initialized
|
||||
if (!initialized)
|
||||
return;
|
||||
|
||||
// Setup perspective and modelview matrix
|
||||
setup_projection();
|
||||
// Setup light
|
||||
setup_light();
|
||||
|
||||
|
||||
// Render the solid terrain with lighting and texture mapping
|
||||
if (show_solid)
|
||||
render_solid_terrain();
|
||||
|
||||
// Render the outline of the terrain
|
||||
if (show_wireframe)
|
||||
render_wireframe_terrain();
|
||||
|
||||
// Eventually render level lines
|
||||
if (show_levels)
|
||||
render_level_lines();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Render the terrain as solid
|
||||
void terrain::render_solid_terrain()
|
||||
{
|
||||
// Enable lighting
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
// This is a trick which is neccessary in order to draw lines
|
||||
// later on. Otherwise there would be artifacts due to a z-fight.
|
||||
glPolygonOffset(1, 1);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
// Enable texture mapping and bind our texture
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_handle);
|
||||
|
||||
// Set the material color to white
|
||||
glColor3d(1, 1, 1);
|
||||
// Render the terrain
|
||||
render_terrain();
|
||||
|
||||
// Disable texture mapping
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
// Disable support for depth buffer offsets
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
// Disable lighting
|
||||
glDisable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Render the terrain as wireframe
|
||||
void terrain::render_wireframe_terrain()
|
||||
{
|
||||
// Set the line width to be 1 pixel
|
||||
glLineWidth(1.0);
|
||||
// Set the draw mode to draw outlines of polygons
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
// Set the color to black
|
||||
glColor3d(0, 0, 0);
|
||||
// Render the terrain
|
||||
render_terrain();
|
||||
|
||||
// Set the draw mode to fill polygons
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Render the terrain
|
||||
void terrain::render_terrain()
|
||||
{
|
||||
// Store width and height for faster access
|
||||
int map_width = get_heightmap_width();
|
||||
int map_height = get_heightmap_height();
|
||||
|
||||
// Factors needed for texture mapping
|
||||
double factor_x = 1.0/static_cast<double>(map_width);
|
||||
double factor_y = 1.0/static_cast<double>(map_height);
|
||||
|
||||
// Move and scale the coordinate system so that we can work with
|
||||
// whole units. That means that a vertex at height map position (x, y)
|
||||
// with a height of h can be placed as glVertex3d(x, h, y). The
|
||||
// terrain extents in the XZ-layer while the height is on the Y-axis.
|
||||
glPushMatrix();
|
||||
glTranslated(-1, 0, -1);
|
||||
glScaled(2.0/static_cast<double>(map_width), 1.0/256.0, 2.0/static_cast<double>(map_height));
|
||||
|
||||
|
||||
// Go through all rows (-1)
|
||||
for (int y = 0; y<map_height-1; y++) {
|
||||
|
||||
// Begin a new triangle strip
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
|
||||
// Draw the strip by consecutively passing two points
|
||||
for (int x = 0; x<map_width; x++) {
|
||||
|
||||
// Set texture coordinates, normal and vertex for the first point
|
||||
glTexCoord2d(x*factor_x, y*factor_y);
|
||||
set_normal(x, y);
|
||||
glVertex3d(x, get_heightmap_value(x, y), y);
|
||||
|
||||
// Set texture coordinates, normal and vertex for the second point
|
||||
glTexCoord2d(x*factor_x, (y+1)*factor_y);
|
||||
set_normal(x, y+1);
|
||||
glVertex3d(x, get_heightmap_value(x, y+1), y+1);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Calculate and set the normal for height map entry (x,y)
|
||||
void terrain::set_normal(int x, int y)
|
||||
{
|
||||
// The normal is estimated using central differences.
|
||||
// Also forward or backward differences could be used. Mind that no border
|
||||
// checks need to be done as this is handled in the get_heightmap_value method.
|
||||
|
||||
// Get the vector in x-direction
|
||||
vec3d dx(2.0, get_heightmap_value(x+1, y) - get_heightmap_value(x-1, y), 0.0);
|
||||
// Get the vector in y-direction
|
||||
vec3d dz(0.0, get_heightmap_value(x, y+1) - get_heightmap_value(x, y-1), 2.0);
|
||||
|
||||
// Normalize both vectors
|
||||
dx.normalize();
|
||||
dz.normalize();
|
||||
|
||||
// Get a vector which is perpendicular to dx and dy by using the cross product
|
||||
vec3d normal = cross(dz, dx);
|
||||
|
||||
// Pass the normal
|
||||
glNormal3d(normal.x(), normal.y(), normal.z());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Render height level lines
|
||||
void terrain::render_level_lines()
|
||||
{
|
||||
// Set color to gray
|
||||
glColor3d(0.5, 0.5, 0.5);
|
||||
// Set the line width to 3 pixels
|
||||
glLineWidth(2.0);
|
||||
|
||||
// Change the coordinate system so that one can work with whole units
|
||||
glPushMatrix();
|
||||
glTranslated(-1, 0, -1);
|
||||
glScaled(2.0/static_cast<double>(get_heightmap_width()), 1.0/256.0, 2.0/static_cast<double>(get_heightmap_height()));
|
||||
|
||||
// Connect with lines
|
||||
glBegin(GL_LINES);
|
||||
|
||||
// Render lines which were created in "create_level_lines" and stored into
|
||||
// the list "level_lines"
|
||||
for (int i=0; i<(int)level_lines.size(); i+=2) {
|
||||
glVertex3d(level_lines[i ].x(), level_lines[i ].y(), level_lines[i ].z());
|
||||
glVertex3d(level_lines[i+1].x(), level_lines[i+1].y(), level_lines[i+1].z());
|
||||
}
|
||||
|
||||
glEnd();
|
||||
|
||||
// Set the width back to 1.0
|
||||
glLineWidth(1.0);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create height lines for the level "level"
|
||||
void terrain::create_level_line(int level)
|
||||
{
|
||||
/********
|
||||
Additional Task: Find iso lines with the "Marching Squares" algorithm for the
|
||||
height value "level". Store the start and end points of the
|
||||
found lines in the list "level_lines".
|
||||
Zusatzaufgabe: Finden Sie Hoehenlinien mittels des "Marching Squares"-Algorithmus
|
||||
fuer den Hoehenwert "level". Legen Sie die Start- und Endpunkte
|
||||
der gefundenen Linien in der Liste "level_lines" ab.
|
||||
*************/
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set the light parameters
|
||||
void terrain::setup_light()
|
||||
{
|
||||
// Enable lighting and colored materials
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
// Enable light source 0
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
// Set the modelview matrix to be the identity to avoid
|
||||
// having the light position moved with the terrain.
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
// Set light parameters
|
||||
float position[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
float ambient_color[4]={0.0f,0.0f,0.0f,1.0f};
|
||||
float diffuse_color[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
float specular_color[4]={1.0f,1.0f,1.0f,1.0f};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, position);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color);
|
||||
|
||||
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT, 10.0f);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set the projection and the view
|
||||
void terrain::setup_projection()
|
||||
{
|
||||
// For projection choose a perspective matrix with an aperture angle of
|
||||
// 45deg, an aspect ratio that corresponds to the width and height of the
|
||||
// window, z_near at 0.01 and z_far at 10.0
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45, glutGet(GLUT_WINDOW_WIDTH) / static_cast<double>(glutGet(GLUT_WINDOW_HEIGHT)), 0.01, 10.0);
|
||||
|
||||
// For the modelview matrix choose a view from the position (2.5, 2.5, 0) to
|
||||
// the position (0, 0, 0) where the up-direction is (0, 1, 0).
|
||||
// Also rotate with the specified angle around the Y-axis
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(2.5,2.5,0, 0,0,0, 0,1,0);
|
||||
glRotated(angle, 0,1,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Advance one frame
|
||||
void terrain::advance_frame()
|
||||
{
|
||||
// Increase angle and perform a modulo 360
|
||||
angle = (angle+1)%360;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// (De)activate solid rendering
|
||||
void terrain::set_show_solid(bool state)
|
||||
{
|
||||
show_solid = state;
|
||||
// The current display list is outdated now
|
||||
dl_valid = false;
|
||||
}
|
||||
|
||||
|
||||
// (De)activate wireframe rendering
|
||||
void terrain::set_show_wireframe(bool state)
|
||||
{
|
||||
show_wireframe = state;
|
||||
// The current display list is outdated now
|
||||
dl_valid = false;
|
||||
}
|
||||
|
||||
|
||||
// (De)activate height level line rendering
|
||||
void terrain::set_show_levels(bool state)
|
||||
{
|
||||
show_levels = state;
|
||||
|
||||
// If level lines shall be displayed then
|
||||
// recreate them in equidistant ranges
|
||||
if (show_levels) {
|
||||
level_lines.clear();
|
||||
for (int i=20; i<=255; i+=20)
|
||||
create_level_line(i);
|
||||
}
|
||||
|
||||
// The current display list is outdated now
|
||||
dl_valid = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Load the height map from the file "filename"
|
||||
bool terrain::load_heightmap(const char *filename)
|
||||
{
|
||||
// Load the heightmap by reading a bmp file
|
||||
heightmap = BMP_ReadFile(filename);
|
||||
|
||||
// Return false and show an error message if the file
|
||||
// could not be loaded
|
||||
if (BMP_GetError() != BMP_OK)
|
||||
return false;
|
||||
|
||||
// All went well...
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Load a texture and store its handle in "handle"
|
||||
bool terrain::load_texture(const char *filename, GLuint *handle)
|
||||
{
|
||||
BMP *bitmap;
|
||||
|
||||
// Load the texture by reading a bmp file
|
||||
bitmap = BMP_ReadFile(filename);
|
||||
|
||||
// Return false and show an error message if the file
|
||||
// could not be loaded
|
||||
if (BMP_GetError() != BMP_OK)
|
||||
return false;
|
||||
|
||||
// Get a pointer to the bitmap data
|
||||
unsigned char* data = BMP_GetImageData(bitmap);
|
||||
|
||||
// Generate one texture and store its ID in "handle"
|
||||
glGenTextures(1, handle);
|
||||
// Bind the texture
|
||||
glBindTexture(GL_TEXTURE_2D, *handle);
|
||||
// Enable linear blending between different mipmapping levels
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
// Clamp the texture at the borders
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
// Transfer the image data to the graphics card.
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP_GetWidth(bitmap), BMP_GetHeight(bitmap), 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
|
||||
// Not needed anymore
|
||||
free(data);
|
||||
BMP_Free(bitmap);
|
||||
|
||||
// Unbind texture
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Return the width of the height map
|
||||
int terrain::get_heightmap_width() const
|
||||
{
|
||||
return BMP_GetWidth(heightmap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Return the height of the height map
|
||||
int terrain::get_heightmap_height() const
|
||||
{
|
||||
return BMP_GetHeight(heightmap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Return the height value at (x,y)
|
||||
int terrain::get_heightmap_value(int x, int y) const
|
||||
{
|
||||
// Returns one value from the heightmap. The image should
|
||||
// be in grayscale so just the red channel is returned.
|
||||
// The image is mirrored at the edges (by adjusting the
|
||||
// coordinates) to assure correct normal estimation.
|
||||
unsigned char r, g, b;
|
||||
|
||||
// Mirror at the left and upper edge if neccessary
|
||||
x = abs(x);
|
||||
y = abs(y);
|
||||
|
||||
// Mirror at the right and bottom edge if neccessary
|
||||
if (x>=get_heightmap_width())
|
||||
x = 2*get_heightmap_width()-x-1;
|
||||
if (y>=get_heightmap_height())
|
||||
y = 2*get_heightmap_height()-y-1;
|
||||
|
||||
// Read the pixel and return the red component
|
||||
BMP_GetPixelRGB(heightmap, x, y, &r, &g, &b);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set debug text
|
||||
void terrain::set_text(std::stringstream &stream)
|
||||
{
|
||||
if (!initialized) {
|
||||
stream<<"Cannot show terrain - not all files were loaded!";
|
||||
return;
|
||||
}
|
||||
stream<<"Showing terrain";
|
||||
|
||||
if (!show_solid && !show_wireframe && !show_levels) {
|
||||
stream<<" (all features disabled)";
|
||||
return;
|
||||
}
|
||||
|
||||
stream<<" (";
|
||||
if (show_solid)
|
||||
stream<<"as solid geometry";
|
||||
if (show_solid && show_wireframe)
|
||||
stream<<", ";
|
||||
if (show_wireframe)
|
||||
stream<<"as wireframe";
|
||||
if (show_wireframe && show_levels)
|
||||
stream<<", ";
|
||||
if (show_levels)
|
||||
stream<<"with level lines";
|
||||
stream<<")";
|
||||
}
|