first
BIN
Debug/Projekt_test.exe
Normal file
BIN
Debug/Projekt_test.pdb
Normal file
31
Projekt_test.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34221.43
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Projekt_test", "Projekt_test\Projekt_test.vcxproj", "{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}.Debug|x64.Build.0 = Debug|x64
|
||||
{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}.Debug|x86.Build.0 = Debug|Win32
|
||||
{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}.Release|x64.ActiveCfg = Release|x64
|
||||
{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}.Release|x64.Build.0 = Release|x64
|
||||
{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}.Release|x86.ActiveCfg = Release|Win32
|
||||
{B4B7C6CC-9633-4DD5-A5C8-D95142C286FB}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D3B83365-2974-4E32-A5BF-C17CC7B0DF5E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
BIN
Projekt_test/Debug/Box.obj
Normal file
BIN
Projekt_test/Debug/Camera.obj
Normal file
4
Projekt_test/Debug/GrafikaProjekt.Build.CppClean.log
Normal file
@ -0,0 +1,4 @@
|
||||
d:\projekt z grafiki\grafikaprojekt\grafikaprojekt\debug\box.obj
|
||||
d:\projekt z grafiki\grafikaprojekt\grafikaprojekt\debug\vc143.idb
|
||||
d:\projekt z grafiki\grafikaprojekt\grafikaprojekt\debug\vc143.pdb
|
||||
d:\projekt z grafiki\grafikaprojekt\grafikaprojekt\debug\grafikaprojekt.tlog\cl.command.1.tlog
|
60
Projekt_test/Debug/GrafikaProjekt.log
Normal file
@ -0,0 +1,60 @@
|
||||
main.cpp
|
||||
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\minwindef.h(130,1): warning C4005: "APIENTRY": ponowna definicja makra
|
||||
D:\Projekt z grafiki\GrafikaProjekt\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123,1): message : zobacz poprzednią definicję „APIENTRY”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\objload.h(156,50): warning C4267: "argument": konwersja z "size_t" do "_Ty", możliwa utrata danych
|
||||
with
|
||||
[
|
||||
_Ty=unsigned int
|
||||
]
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\objload.h(163,42): warning C4267: "argument": konwersja z "size_t" do "_Ty", możliwa utrata danych
|
||||
with
|
||||
[
|
||||
_Ty=unsigned int
|
||||
]
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\objload.h(179,51): warning C4267: "argument": konwersja z "size_t" do "_Ty", możliwa utrata danych
|
||||
with
|
||||
[
|
||||
_Ty=unsigned int
|
||||
]
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\objload.h(185,47): warning C4267: "argument": konwersja z "size_t" do "_Ty", możliwa utrata danych
|
||||
with
|
||||
[
|
||||
_Ty=unsigned int
|
||||
]
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\objload.h(189,39): warning C4267: "argument": konwersja z "size_t" do "_Ty", możliwa utrata danych
|
||||
with
|
||||
[
|
||||
_Ty=unsigned int
|
||||
]
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\objload.h(227,55): warning C4244: "inicjowanie": konwersja z "__int64" do "unsigned short", możliwa utrata danych
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\objload.h(227,40): warning C4244: "inicjowanie": konwersja z "__int64" do "const unsigned short", możliwa utrata danych
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(92,10): warning C4305: "inicjowanie": obcięcie z "double" do "float"
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(143,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(269,24): error C2664: „GLuint Core::Shader_Loader::CreateProgram(char *,char *)”: nie można dokonać konwersji argumentu 1 z „const char [20]” do „char *”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(269,39): message : Konwersja z literału ciągu znaków powoduje utratę kwalifikatora const (patrz: /Zc:strictStrings)
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.h(23,10): message : zobacz deklarację „Core::Shader_Loader::CreateProgram”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(269,24): message : podczas próby dopasowania listy argumentów "(const char [20], const char [20])"
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(270,27): error C2664: „GLuint Core::Shader_Loader::CreateProgram(char *,char *)”: nie można dokonać konwersji argumentu 1 z „const char [24]” do „char *”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(270,42): message : Konwersja z literału ciągu znaków powoduje utratę kwalifikatora const (patrz: /Zc:strictStrings)
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.h(23,10): message : zobacz deklarację „Core::Shader_Loader::CreateProgram”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(270,27): message : podczas próby dopasowania listy argumentów "(const char [24], const char [24])"
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(271,29): error C2664: „GLuint Core::Shader_Loader::CreateProgram(char *,char *)”: nie można dokonać konwersji argumentu 1 z „const char [24]” do „char *”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(271,44): message : Konwersja z literału ciągu znaków powoduje utratę kwalifikatora const (patrz: /Zc:strictStrings)
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.h(23,10): message : zobacz deklarację „Core::Shader_Loader::CreateProgram”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(271,29): message : podczas próby dopasowania listy argumentów "(const char [24], const char [24])"
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(272,31): error C2664: „GLuint Core::Shader_Loader::CreateProgram(char *,char *)”: nie można dokonać konwersji argumentu 1 z „const char [24]” do „char *”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(272,46): message : Konwersja z literału ciągu znaków powoduje utratę kwalifikatora const (patrz: /Zc:strictStrings)
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.h(23,10): message : zobacz deklarację „Core::Shader_Loader::CreateProgram”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\project.hpp(272,31): message : podczas próby dopasowania listy argumentów "(const char [24], const char [24])"
|
||||
Shader_Loader.cpp
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(39,42): warning C4267: "inicjowanie": konwersja z "size_t" do "int", możliwa utrata danych
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(39,29): warning C4267: "inicjowanie": konwersja z "size_t" do "const int", możliwa utrata danych
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(68,25): error C2664: „GLuint Core::Shader_Loader::CreateShader(GLenum,std::string,char *)”: nie można dokonać konwersji argumentu 3 z „const char [14]” do „char *”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(68,76): message : Konwersja z literału ciągu znaków powoduje utratę kwalifikatora const (patrz: /Zc:strictStrings)
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(31,23): message : zobacz deklarację „Core::Shader_Loader::CreateShader”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(68,25): message : podczas próby dopasowania listy argumentów "(int, std::string, const char [14])"
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(69,27): error C2664: „GLuint Core::Shader_Loader::CreateShader(GLenum,std::string,char *)”: nie można dokonać konwersji argumentu 3 z „const char [16]” do „char *”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(69,82): message : Konwersja z literału ciągu znaków powoduje utratę kwalifikatora const (patrz: /Zc:strictStrings)
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(31,23): message : zobacz deklarację „Core::Shader_Loader::CreateShader”
|
||||
D:\Projekt z grafiki\GrafikaProjekt\GrafikaProjekt\src\Shader_Loader.cpp(69,27): message : podczas próby dopasowania listy argumentów "(int, std::string, const char [16])"
|
||||
Generowanie kodu...
|
BIN
Projekt_test/Debug/GrafikaProjekt.tlog/CL.command.1.tlog
Normal file
BIN
Projekt_test/Debug/GrafikaProjekt.tlog/CL.read.1.tlog
Normal file
BIN
Projekt_test/Debug/GrafikaProjekt.tlog/CL.write.1.tlog
Normal file
@ -0,0 +1,2 @@
|
||||
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.37.32822:TargetPlatformVersion=10.0.22000.0:VcpkgTriplet=x64-windows:
|
||||
Debug|x64|D:\Projekt z grafiki\GrafikaProjekt\|
|
11
Projekt_test/Debug/Projekt_test.exe.recipe
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<ProjectOutputs>
|
||||
<ProjectOutput>
|
||||
<FullPath>V:\Projekt_test\Debug\Projekt_test.exe</FullPath>
|
||||
</ProjectOutput>
|
||||
</ProjectOutputs>
|
||||
<ContentFiles />
|
||||
<SatelliteDlls />
|
||||
<NonRecipeFileRefs />
|
||||
</Project>
|
54
Projekt_test/Debug/Projekt_test.log
Normal file
@ -0,0 +1,54 @@
|
||||
E:\visual_studio\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(531,5): warning MSB8028: промежуточный каталог (Debug\) содержит файлы, которые используются совместно с другим проектом (GrafikaProjekt.vcxproj). Это может привести к ошибкам очистки и перестроения.
|
||||
Box.cpp
|
||||
Camera.cpp
|
||||
main.cpp
|
||||
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared\minwindef.h(130,1): warning C4005: APIENTRY: изменение макроопределения
|
||||
(компиляция исходного файла "src/main.cpp")
|
||||
V:\Projekt_test\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123,1):
|
||||
см. предыдущее определение "APIENTRY"
|
||||
|
||||
V:\Projekt_test\Projekt_test\src\project.hpp(129,10): warning C4305: инициализация: усечение из "double" в "float"
|
||||
(компиляция исходного файла "src/main.cpp")
|
||||
|
||||
V:\Projekt_test\Projekt_test\src\project.hpp(182,62): warning C4305: аргумент: усечение из "double" в "GLfloat"
|
||||
(компиляция исходного файла "src/main.cpp")
|
||||
|
||||
V:\Projekt_test\Projekt_test\src\project.hpp(229,13): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
|
||||
(компиляция исходного файла "src/main.cpp")
|
||||
|
||||
V:\Projekt_test\Projekt_test\src\project.hpp(346,23): warning C4018: <: несоответствие типов со знаком и без знака
|
||||
(компиляция исходного файла "src/main.cpp")
|
||||
|
||||
Render_Utils.cpp
|
||||
Shader_Loader.cpp
|
||||
Texture.cpp
|
||||
Создание кода...
|
||||
image_DXT.c
|
||||
image_helper.c
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\image_DXT.c(92,9): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\image_helper.c(325,17): warning C4244: инициализация: преобразование "double" в "float", возможна потеря данных
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\image_helper.c(366,13): warning C4244: =: преобразование "double" в "float", возможна потеря данных
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\image_helper.c(373,20): warning C4244: =: преобразование "float" в "int", возможна потеря данных
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\image_helper.c(415,13): warning C4244: =: преобразование "double" в "float", возможна потеря данных
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\image_helper.c(422,20): warning C4244: =: преобразование "float" в "int", возможна потеря данных
|
||||
SOIL.c
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\SOIL.c(1719,36): warning C4018: <=: несоответствие типов со знаком и без знака
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\SOIL.c(1729,19): warning C4018: <: несоответствие типов со знаком и без знака
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\SOIL.c(1841,6): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
|
||||
stb_image_aug.c
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\stbi_DDS_aug_c.h(362,19): warning C4018: >: несоответствие типов со знаком и без знака
|
||||
(компиляция исходного файла "src/SOIL/stb_image_aug.c")
|
||||
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\stbi_DDS_aug_c.h(366,19): warning C4018: >: несоответствие типов со знаком и без знака
|
||||
(компиляция исходного файла "src/SOIL/stb_image_aug.c")
|
||||
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\stbi_DDS_aug_c.h(390,19): warning C4018: <: несоответствие типов со знаком и без знака
|
||||
(компиляция исходного файла "src/SOIL/stb_image_aug.c")
|
||||
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\stbi_DDS_aug_c.h(427,19): warning C4018: <: несоответствие типов со знаком и без знака
|
||||
(компиляция исходного файла "src/SOIL/stb_image_aug.c")
|
||||
|
||||
Создание кода...
|
||||
Box.obj : warning LNK4075: не учитывается "/EDITANDCONTINUE" из-за спецификации "/INCREMENTAL:NO"
|
||||
LINK : warning LNK4098: библиотека по умолчанию "MSVCRT" конфликтует с использованием других библиотек; используйте /NODEFAULTLIB:library
|
||||
Projekt_test.vcxproj -> V:\Projekt_test\Debug\Projekt_test.exe
|
BIN
Projekt_test/Debug/Projekt_test.tlog/CL.command.1.tlog
Normal file
BIN
Projekt_test/Debug/Projekt_test.tlog/CL.read.1.tlog
Normal file
BIN
Projekt_test/Debug/Projekt_test.tlog/CL.write.1.tlog
Normal file
10
Projekt_test/Debug/Projekt_test.tlog/Cl.items.tlog
Normal file
@ -0,0 +1,10 @@
|
||||
V:\Projekt_test\Projekt_test\src\Box.cpp;V:\Projekt_test\Projekt_test\Debug\Box.obj
|
||||
V:\Projekt_test\Projekt_test\src\Camera.cpp;V:\Projekt_test\Projekt_test\Debug\Camera.obj
|
||||
V:\Projekt_test\Projekt_test\src\main.cpp;V:\Projekt_test\Projekt_test\Debug\main.obj
|
||||
V:\Projekt_test\Projekt_test\src\Render_Utils.cpp;V:\Projekt_test\Projekt_test\Debug\Render_Utils.obj
|
||||
V:\Projekt_test\Projekt_test\src\Shader_Loader.cpp;V:\Projekt_test\Projekt_test\Debug\Shader_Loader.obj
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\image_DXT.c;V:\Projekt_test\Projekt_test\Debug\image_DXT.obj
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\image_helper.c;V:\Projekt_test\Projekt_test\Debug\image_helper.obj
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\SOIL.c;V:\Projekt_test\Projekt_test\Debug\SOIL.obj
|
||||
V:\Projekt_test\Projekt_test\src\SOIL\stb_image_aug.c;V:\Projekt_test\Projekt_test\Debug\stb_image_aug.obj
|
||||
V:\Projekt_test\Projekt_test\src\Texture.cpp;V:\Projekt_test\Projekt_test\Debug\Texture.obj
|
@ -0,0 +1,2 @@
|
||||
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.38.33130:TargetPlatformVersion=10.0.22621.0:
|
||||
Debug|Win32|V:\Projekt_test\|
|
BIN
Projekt_test/Debug/Projekt_test.tlog/link.command.1.tlog
Normal file
BIN
Projekt_test/Debug/Projekt_test.tlog/link.read.1.tlog
Normal file
BIN
Projekt_test/Debug/Projekt_test.tlog/link.write.1.tlog
Normal file
BIN
Projekt_test/Debug/Render_Utils.obj
Normal file
BIN
Projekt_test/Debug/SOIL.obj
Normal file
BIN
Projekt_test/Debug/Shader_Loader.obj
Normal file
BIN
Projekt_test/Debug/Texture.obj
Normal file
BIN
Projekt_test/Debug/image_DXT.obj
Normal file
BIN
Projekt_test/Debug/image_helper.obj
Normal file
BIN
Projekt_test/Debug/main.obj
Normal file
BIN
Projekt_test/Debug/stb_image_aug.obj
Normal file
BIN
Projekt_test/Debug/vc143.idb
Normal file
BIN
Projekt_test/Debug/vc143.pdb
Normal file
1
Projekt_test/Debug/vcpkg.applocal.log
Normal file
@ -0,0 +1 @@
|
||||
|
179
Projekt_test/Projekt_test.vcxproj
Normal file
@ -0,0 +1,179 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" 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>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{b4b7c6cc-9633-4dd5-a5c8-d95142c286fb}</ProjectGuid>
|
||||
<RootNamespace>Projekttest</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
|
||||
<IncludePath>$(SolutionDir)dependencies\freeglut\include\GL;$(SolutionDir)dependencies\glew-2.0.0\include\GL;$(SolutionDir)dependencies\glm;$(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\include;$(SolutionDir)dependencies\assimp\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)dependencies\freeglut\lib;$(SolutionDir)dependencies\glew-2.0.0\lib\Release\Win32;$(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019;$(SolutionDir)dependencies\assimp;$(LibraryPath)</LibraryPath>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>
|
||||
</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>opengl32.lib;freeglut.lib;glew32.lib;$(SolutionDir)\dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019\glfw3.lib;$(SolutionDir)\dependencies\glfw-3.3.8.bin.WIN32\lib-vc2019\glfw3dll.lib;zlibd.lib;assimp-vc141-mtd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\shader.frag" />
|
||||
<None Include="shaders\shader.vert" />
|
||||
<None Include="shaders\shader_skybox.frag" />
|
||||
<None Include="shaders\shader_skybox.vert" />
|
||||
<None Include="shaders\shader_sun.frag" />
|
||||
<None Include="shaders\shader_sun.vert" />
|
||||
<None Include="shaders\shader_tex.frag" />
|
||||
<None Include="shaders\shader_tex.vert" />
|
||||
<None Include="shaders\shader_unmap.frag" />
|
||||
<None Include="shaders\shader_unmap.vert" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Box.cpp" />
|
||||
<ClCompile Include="src\Camera.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
<ClCompile Include="src\Render_Utils.cpp" />
|
||||
<ClCompile Include="src\Shader_Loader.cpp" />
|
||||
<ClCompile Include="src\SOIL\image_DXT.c" />
|
||||
<ClCompile Include="src\SOIL\image_helper.c" />
|
||||
<ClCompile Include="src\SOIL\SOIL.c" />
|
||||
<ClCompile Include="src\SOIL\stb_image_aug.c" />
|
||||
<ClCompile Include="src\Texture.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\Camera.h" />
|
||||
<ClInclude Include="src\objload.h" />
|
||||
<ClInclude Include="src\project.hpp" />
|
||||
<ClInclude Include="src\Render_Utils.h" />
|
||||
<ClInclude Include="src\Shader_Loader.h" />
|
||||
<ClInclude Include="src\SOIL\image_DXT.h" />
|
||||
<ClInclude Include="src\SOIL\image_helper.h" />
|
||||
<ClInclude Include="src\SOIL\SOIL.h" />
|
||||
<ClInclude Include="src\SOIL\stbi_DDS_aug.h" />
|
||||
<ClInclude Include="src\SOIL\stbi_DDS_aug_c.h" />
|
||||
<ClInclude Include="src\SOIL\stb_image_aug.h" />
|
||||
<ClInclude Include="src\Texture.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
122
Projekt_test/Projekt_test.vcxproj.filters
Normal file
@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{3ff1db85-c852-4d60-9e12-61507559b7de}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{f17dda14-7571-4260-839d-443d459f2de5}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Shader Files">
|
||||
<UniqueIdentifier>{127e9308-6a53-4a76-aa14-5f7800185d46}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{87a5fffb-2384-4dce-b4bf-a92018094b43}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\SOIL">
|
||||
<UniqueIdentifier>{9362f89a-edd6-494a-b3f3-545998ae4af8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\shader_tex.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_tex.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_sun.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_sun.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_skybox.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_skybox.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_unmap.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_unmap.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\SOIL\image_DXT.c">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\SOIL\image_helper.c">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\SOIL\SOIL.c">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\SOIL\stb_image_aug.c">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Box.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Camera.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Render_Utils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Shader_Loader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Texture.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\SOIL\image_DXT.h">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SOIL\image_helper.h">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SOIL\SOIL.h">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SOIL\stb_image_aug.h">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SOIL\stbi_DDS_aug.h">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\SOIL\stbi_DDS_aug_c.h">
|
||||
<Filter>Source Files\SOIL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Camera.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\objload.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\project.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Render_Utils.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Shader_Loader.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Texture.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
6
Projekt_test/Projekt_test.vcxproj.user
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
BIN
Projekt_test/assimp-vc141-mt.dll
Normal file
BIN
Projekt_test/assimp-vc141-mtd.dll
Normal file
BIN
Projekt_test/freeglut.dll
Normal file
BIN
Projekt_test/glew32.dll
Normal file
12
Projekt_test/models/cube.mtl
Normal file
@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl _PBR
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.053704 0.053704 0.053704
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 3
|
40
Projekt_test/models/cube.obj
Normal file
@ -0,0 +1,40 @@
|
||||
# Blender v2.90.0 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib cube.mtl
|
||||
o Cube
|
||||
v -10.000000 -10.000000 10.000000
|
||||
v -10.000000 10.000000 10.000000
|
||||
v -10.000000 -10.000000 -10.000000
|
||||
v -10.000000 10.000000 -10.000000
|
||||
v 10.000000 -10.000000 10.000000
|
||||
v 10.000000 10.000000 10.000000
|
||||
v 10.000000 -10.000000 -10.000000
|
||||
v 10.000000 10.000000 -10.000000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.625000 1.000000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.125000 0.750000
|
||||
vt 0.875000 0.500000
|
||||
vt 0.875000 0.750000
|
||||
vn -1.0000 0.0000 0.0000
|
||||
vn 0.0000 0.0000 -1.0000
|
||||
vn 1.0000 0.0000 0.0000
|
||||
vn 0.0000 0.0000 1.0000
|
||||
vn 0.0000 -1.0000 0.0000
|
||||
vn 0.0000 1.0000 0.0000
|
||||
usemtl _PBR
|
||||
s 1
|
||||
f 1/1/1 2/2/1 4/3/1 3/4/1
|
||||
f 3/4/2 4/3/2 8/5/2 7/6/2
|
||||
f 7/6/3 8/5/3 6/7/3 5/8/3
|
||||
f 5/8/4 6/7/4 2/9/4 1/10/4
|
||||
f 3/11/5 7/6/5 5/8/5 1/12/5
|
||||
f 8/5/6 4/13/6 2/14/6 6/7/6
|
2482
Projekt_test/models/spaceship.obj
Normal file
315
Projekt_test/models/spaceship0.obj
Normal file
@ -0,0 +1,315 @@
|
||||
# Blender v2.90.0 OBJ File: 'spaceship.blend'
|
||||
# www.blender.org
|
||||
mtllib spaceship.mtl
|
||||
o spaceship
|
||||
v -0.466043 -0.046099 0.061004
|
||||
v -0.496632 -0.038727 -0.744142
|
||||
v -0.284772 -0.093266 -0.411636
|
||||
v -0.169612 -0.147446 -0.381196
|
||||
v -0.169612 -0.147446 0.061004
|
||||
v -0.091309 -0.100093 0.472421
|
||||
v -0.182617 -0.069341 0.472421
|
||||
v -0.182617 -0.001722 0.472421
|
||||
v -0.466043 0.045632 0.061004
|
||||
v -0.647568 0.071442 -0.238048
|
||||
v -0.169612 0.164038 0.061004
|
||||
v -0.284772 0.045632 -0.411636
|
||||
v -0.169612 0.116537 -0.381196
|
||||
v -0.053437 -0.049075 0.720448
|
||||
v -0.053437 -0.102143 0.720448
|
||||
v -0.040834 -0.049075 0.734564
|
||||
v -0.040834 -0.102143 0.734564
|
||||
v 0.000000 -0.049075 0.744142
|
||||
v 0.000000 -0.118734 0.744142
|
||||
v 0.040834 -0.049075 0.734564
|
||||
v 0.000000 0.045779 0.472421
|
||||
v 0.000000 -0.116684 0.472421
|
||||
v 0.091309 -0.100093 0.472421
|
||||
v 0.040834 -0.102143 0.734564
|
||||
v 0.000000 0.116537 -0.350755
|
||||
v 0.000000 0.164038 0.061004
|
||||
v 0.169612 -0.147446 -0.381196
|
||||
v 0.000000 -0.164038 -0.350755
|
||||
v 0.169612 0.164038 0.061004
|
||||
v 0.169612 0.116537 -0.381196
|
||||
v 0.000000 -0.164038 0.061004
|
||||
v 0.169612 -0.147446 0.061004
|
||||
v -0.647568 -0.038727 -0.238048
|
||||
v -0.496632 0.071442 -0.744142
|
||||
v -0.091309 0.045779 0.472421
|
||||
v 0.466043 -0.046099 0.061004
|
||||
v 0.647568 0.071442 -0.238048
|
||||
v 0.466043 0.045632 0.061004
|
||||
v 0.496632 -0.038727 -0.744142
|
||||
v 0.647568 -0.038727 -0.238048
|
||||
v 0.284772 -0.093266 -0.411636
|
||||
v 0.182617 -0.001722 0.472421
|
||||
v 0.182617 -0.069341 0.472421
|
||||
v 0.284772 0.045632 -0.411636
|
||||
v 0.053437 -0.049075 0.720448
|
||||
v 0.053437 -0.102143 0.720448
|
||||
v 0.496632 0.071442 -0.744142
|
||||
v 0.091309 0.045779 0.472421
|
||||
vt 0.542758 0.543965
|
||||
vt 0.356004 0.244407
|
||||
vt 0.504680 0.319696
|
||||
vt 0.553316 0.302407
|
||||
vt 0.649859 0.471001
|
||||
vt 0.766053 0.611338
|
||||
vt 0.733075 0.633795
|
||||
vt 0.942531 0.273938
|
||||
vt 0.916601 0.470616
|
||||
vt 0.908930 0.272020
|
||||
vt 0.906245 0.133229
|
||||
vt 0.060793 0.659810
|
||||
vt 0.095301 0.442790
|
||||
vt 0.182444 0.620892
|
||||
vt 0.912119 0.905444
|
||||
vt 0.989612 0.943366
|
||||
vt 0.900946 0.955153
|
||||
vt 0.229586 0.822972
|
||||
vt 0.045790 0.812939
|
||||
vt 0.871970 0.876051
|
||||
vt 0.270733 0.797357
|
||||
vt 0.928563 0.581569
|
||||
vt 0.948002 0.582679
|
||||
vt 0.928200 0.588981
|
||||
vt 0.833604 0.696984
|
||||
vt 0.841128 0.699424
|
||||
vt 0.941370 0.472030
|
||||
vt 0.927606 0.601110
|
||||
vt 0.953122 0.602566
|
||||
vt 0.116239 0.298971
|
||||
vt 0.134935 0.296266
|
||||
vt 0.170287 0.416872
|
||||
vt 0.947639 0.590091
|
||||
vt 0.858040 0.692927
|
||||
vt 0.798664 0.589407
|
||||
vt 1.000000 0.000000
|
||||
vt 0.975078 0.013585
|
||||
vt 0.974484 0.001457
|
||||
vt 0.830416 0.568707
|
||||
vt 0.869911 0.680359
|
||||
vt 0.785184 0.955792
|
||||
vt 0.850736 0.970525
|
||||
vt 0.334379 0.757520
|
||||
vt 0.252163 0.593452
|
||||
vt 0.740866 0.846584
|
||||
vt 0.807753 0.855379
|
||||
vt 0.321881 0.566013
|
||||
vt 0.410170 0.742478
|
||||
vt 0.620171 0.273802
|
||||
vt 0.672876 0.223217
|
||||
vt 0.710068 0.430790
|
||||
vt 0.769418 0.391811
|
||||
vt 0.946599 0.135534
|
||||
vt 0.413299 0.472597
|
||||
vt 0.208789 0.994633
|
||||
vt 0.953122 0.002304
|
||||
vt 0.980750 0.982793
|
||||
vt 0.912767 0.000000
|
||||
vt 0.101366 0.309478
|
||||
vt 0.132755 0.431644
|
||||
vt 0.099001 0.317265
|
||||
vt 0.989409 0.328628
|
||||
vt 0.953122 0.469337
|
||||
vt 0.955808 0.330547
|
||||
vt 0.871271 0.326374
|
||||
vt 0.706080 0.012535
|
||||
vt 0.869769 0.170254
|
||||
vt 0.705415 0.186739
|
||||
vt 0.963479 0.131951
|
||||
vt 0.988248 0.130536
|
||||
vt 0.443922 0.509019
|
||||
vt 0.463695 0.730833
|
||||
vt 0.578150 0.603414
|
||||
vt 0.692001 0.855970
|
||||
vt 0.680828 0.905679
|
||||
vt 0.605734 0.857085
|
||||
vt 0.719632 0.941058
|
||||
vt 0.975441 0.020998
|
||||
vt 0.994879 0.019888
|
||||
vt 0.142931 0.299975
|
||||
vt 0.245429 0.383703
|
||||
vt 0.994516 0.012475
|
||||
vt 0.871271 0.672035
|
||||
vt 0.861802 0.548533
|
||||
vt 0.993477 0.467033
|
||||
vt 1.000000 0.600262
|
||||
vt 0.959645 0.602566
|
||||
vt 0.617066 0.833945
|
||||
vt 0.596872 0.896513
|
||||
vt 0.207819 0.402100
|
||||
vn -0.2502 -0.9682 0.0006
|
||||
vn -0.3235 -0.9462 -0.0000
|
||||
vn -0.3158 -0.9343 0.1651
|
||||
vn -0.3186 -0.9329 0.1677
|
||||
vn -0.3148 -0.9349 0.1641
|
||||
vn -0.8235 0.0000 0.5673
|
||||
vn -0.8548 0.0000 0.5189
|
||||
vn -0.3487 0.8731 0.3407
|
||||
vn 0.8434 0.0000 -0.5374
|
||||
vn -0.4103 -0.9095 -0.0666
|
||||
vn 0.0862 0.9958 0.0321
|
||||
vn 0.0832 0.9962 0.0257
|
||||
vn 0.0868 0.9957 0.0333
|
||||
vn 0.2556 0.0000 -0.9668
|
||||
vn -0.5043 0.8586 -0.0922
|
||||
vn -0.8869 0.0000 0.4619
|
||||
vn -0.7459 0.0000 0.6660
|
||||
vn 0.0112 -0.9999 -0.0100
|
||||
vn -0.2284 0.0000 0.9736
|
||||
vn 0.0771 0.9413 0.3286
|
||||
vn -0.1788 -0.9839 -0.0074
|
||||
vn 0.2284 0.0000 0.9736
|
||||
vn 0.3892 -0.9187 0.0677
|
||||
vn 0.1766 0.0000 -0.9843
|
||||
vn 0.0000 0.9934 -0.1146
|
||||
vn -0.1766 0.0000 -0.9843
|
||||
vn -0.0192 0.9941 -0.1068
|
||||
vn 0.0974 -0.9952 -0.0000
|
||||
vn -0.0974 -0.9952 -0.0000
|
||||
vn -0.0965 -0.9866 0.1319
|
||||
vn 0.1776 -0.9776 0.1125
|
||||
vn -0.0272 -0.9996 -0.0081
|
||||
vn 0.0827 0.9963 0.0247
|
||||
vn -0.9583 -0.0000 -0.2858
|
||||
vn -0.3892 -0.9187 0.0677
|
||||
vn 0.0000 0.9403 0.3403
|
||||
vn -0.4230 0.8237 0.3776
|
||||
vn -0.4240 0.8230 0.3780
|
||||
vn -0.4228 0.8239 0.3775
|
||||
vn 0.0192 0.9941 -0.1068
|
||||
vn -0.3672 0.9194 -0.1408
|
||||
vn 0.0000 0.9611 0.2763
|
||||
vn -0.4366 0.8392 0.3243
|
||||
vn -0.3189 -0.9328 0.1681
|
||||
vn -0.4270 0.8209 0.3792
|
||||
vn -0.0771 0.9413 0.3286
|
||||
vn -0.1776 -0.9776 0.1125
|
||||
vn 0.1788 -0.9839 -0.0074
|
||||
vn -0.3189 -0.9469 0.0409
|
||||
vn 0.8548 -0.0000 0.5189
|
||||
vn 0.0272 -0.9996 -0.0081
|
||||
vn 0.4103 -0.9095 -0.0666
|
||||
vn 0.3158 -0.9343 0.1651
|
||||
vn 0.3186 -0.9329 0.1677
|
||||
vn 0.3189 -0.9328 0.1681
|
||||
vn 0.8235 0.0000 0.5673
|
||||
vn 0.3672 0.9194 -0.1408
|
||||
vn -0.0868 0.9957 0.0333
|
||||
vn -0.0832 0.9962 0.0257
|
||||
vn -0.0862 0.9958 0.0321
|
||||
vn 0.2502 -0.9682 0.0006
|
||||
vn -0.2556 0.0000 -0.9668
|
||||
vn -0.8434 0.0000 -0.5374
|
||||
vn 0.7459 0.0000 0.6660
|
||||
vn 0.4228 0.8239 0.3775
|
||||
vn 0.4240 0.8230 0.3780
|
||||
vn 0.4230 0.8237 0.3776
|
||||
vn 0.3189 -0.9469 0.0409
|
||||
vn 0.8869 0.0000 0.4619
|
||||
vn 0.9583 -0.0000 -0.2858
|
||||
vn -0.0827 0.9963 0.0247
|
||||
vn -0.0112 -0.9999 -0.0100
|
||||
vn 0.4270 0.8209 0.3792
|
||||
vn 0.5043 0.8586 -0.0922
|
||||
vn 0.3487 0.8731 0.3407
|
||||
vn 0.3235 -0.9462 -0.0000
|
||||
vn 0.0965 -0.9866 0.1319
|
||||
vn 0.4366 0.8392 0.3243
|
||||
vn 0.3148 -0.9349 0.1641
|
||||
usemtl cube1_auv
|
||||
s 1
|
||||
f 1/1/1 2/2/1 3/3/1
|
||||
f 1/1/2 4/4/2 5/5/2
|
||||
f 1/1/3 6/6/4 7/7/5
|
||||
f 1/8/6 8/9/6 9/10/6
|
||||
f 9/10/7 10/11/7 1/8/7
|
||||
f 9/12/8 8/13/8 11/14/8
|
||||
f 3/15/9 2/16/9 12/17/9
|
||||
f 3/3/10 4/4/10 1/1/10
|
||||
f 12/18/11 10/19/12 9/12/13
|
||||
f 12/17/14 4/20/14 3/15/14
|
||||
f 12/18/15 11/14/15 13/21/15
|
||||
f 14/22/16 8/9/16 15/23/16
|
||||
f 15/23/17 16/24/17 14/22/17
|
||||
f 15/25/18 6/6/18 17/26/18
|
||||
f 15/23/16 8/9/16 7/27/16
|
||||
f 18/28/19 16/24/19 19/29/19
|
||||
f 18/30/20 20/31/20 21/32/20
|
||||
f 19/29/19 16/24/19 17/33/19
|
||||
f 19/34/21 6/6/21 22/35/21
|
||||
f 19/36/22 20/37/22 18/38/22
|
||||
f 19/34/23 23/39/23 24/40/23
|
||||
f 25/41/24 4/20/24 13/42/24
|
||||
f 25/43/25 11/14/25 26/44/25
|
||||
f 25/41/26 27/45/26 28/46/26
|
||||
f 25/43/27 29/47/27 30/48/27
|
||||
f 28/46/24 4/20/24 25/41/24
|
||||
f 28/49/28 27/50/28 31/51/28
|
||||
f 26/44/25 29/47/25 25/43/25
|
||||
f 31/51/29 4/4/29 28/49/29
|
||||
f 31/51/30 6/6/30 5/5/30
|
||||
f 31/51/28 27/50/28 32/52/28
|
||||
f 31/51/31 23/39/31 22/35/31
|
||||
f 33/53/7 1/8/7 10/11/7
|
||||
f 33/54/32 2/2/32 1/1/32
|
||||
f 10/19/12 12/18/11 34/55/33
|
||||
f 10/11/34 2/56/34 33/53/34
|
||||
f 34/57/9 12/17/9 2/16/9
|
||||
f 34/58/34 2/56/34 10/11/34
|
||||
f 17/33/17 16/24/17 15/23/17
|
||||
f 17/26/35 6/6/35 19/34/35
|
||||
f 16/59/36 21/32/36 35/60/36
|
||||
f 16/59/37 8/13/38 14/61/39
|
||||
f 13/42/14 4/20/14 12/17/14
|
||||
f 13/21/40 11/14/40 25/43/40
|
||||
f 11/14/41 12/18/41 9/12/41
|
||||
f 11/14/42 21/32/42 26/44/42
|
||||
f 11/14/43 8/13/43 35/60/43
|
||||
f 5/5/29 4/4/29 31/51/29
|
||||
f 5/5/44 6/6/4 1/1/3
|
||||
f 35/60/42 21/32/42 11/14/42
|
||||
f 35/60/45 8/13/38 16/59/37
|
||||
f 21/32/46 16/59/46 18/30/46
|
||||
f 21/32/42 29/47/42 26/44/42
|
||||
f 22/35/47 6/6/47 31/51/47
|
||||
f 22/35/48 23/39/48 19/34/48
|
||||
f 7/7/49 6/6/49 15/25/49
|
||||
f 7/27/6 8/9/6 1/8/6
|
||||
f 36/62/50 37/63/50 38/64/50
|
||||
f 36/65/51 39/66/51 40/67/51
|
||||
f 36/65/52 27/50/52 41/68/52
|
||||
f 36/65/53 23/39/54 32/52/55
|
||||
f 36/62/56 42/69/56 43/70/56
|
||||
f 38/71/57 44/72/57 29/47/57
|
||||
f 38/71/58 37/73/59 44/72/60
|
||||
f 38/64/56 42/69/56 36/62/56
|
||||
f 41/68/61 39/66/61 36/65/61
|
||||
f 41/74/62 27/45/62 44/75/62
|
||||
f 44/75/63 39/76/63 41/74/63
|
||||
f 44/75/62 27/45/62 30/77/62
|
||||
f 45/78/64 20/37/64 46/79/64
|
||||
f 45/80/65 42/81/66 20/31/67
|
||||
f 46/79/64 20/37/64 24/82/64
|
||||
f 46/83/68 23/39/68 43/84/68
|
||||
f 46/79/69 42/69/69 45/78/69
|
||||
f 40/85/70 39/86/70 37/63/70
|
||||
f 37/63/50 36/62/50 40/85/50
|
||||
f 37/63/70 39/86/70 47/87/70
|
||||
f 47/88/71 44/72/60 37/73/59
|
||||
f 39/76/63 44/75/63 47/89/63
|
||||
f 24/82/22 20/37/22 19/36/22
|
||||
f 24/40/72 23/39/72 46/83/72
|
||||
f 20/31/67 42/81/66 48/90/73
|
||||
f 30/77/26 27/45/26 25/41/26
|
||||
f 30/48/74 29/47/74 44/72/74
|
||||
f 29/47/42 21/32/42 48/90/42
|
||||
f 29/47/75 42/81/75 38/71/75
|
||||
f 32/52/76 27/50/76 36/65/76
|
||||
f 32/52/77 23/39/77 31/51/77
|
||||
f 48/90/36 21/32/36 20/31/36
|
||||
f 48/90/78 42/81/78 29/47/78
|
||||
f 43/84/79 23/39/54 36/65/53
|
||||
f 43/70/69 42/69/69 46/79/69
|
6674
Projekt_test/models/spaceship1.obj
Normal file
2431332
Projekt_test/models/spaceship_2.obj
Normal file
29
Projekt_test/models/spaceship_station.mtl
Normal file
@ -0,0 +1,29 @@
|
||||
# WaveFront *.mtl file (generated by CINEMA 4D)
|
||||
|
||||
newmtl BigPlatform
|
||||
Ka 1 1 1
|
||||
Kd 0.80000001192093 0.80000001192093 0.80000001192093
|
||||
map_Kd BigPlatform.jpg
|
||||
Ks 1 1 1
|
||||
map_Ks BigPlatform_Metallic.jpg
|
||||
Ns 100
|
||||
illum 7
|
||||
|
||||
newmtl Platform2
|
||||
Ka 1 1 1
|
||||
Kd 0.80000001192093 0.80000001192093 0.80000001192093
|
||||
map_Kd Platform2.jpg
|
||||
Ks 1 1 1
|
||||
map_Ks PLatform2_Metallic.jpg
|
||||
Ns 100
|
||||
illum 7
|
||||
|
||||
newmtl SmalPlatform
|
||||
Ka 1 1 1
|
||||
Kd 0.80000001192093 0.80000001192093 0.80000001192093
|
||||
map_Kd SmalStationPlatform.jpg
|
||||
Ks 1 1 1
|
||||
map_Ks SmalStationPlatform_Metallic.jpg
|
||||
Ns 100
|
||||
illum 7
|
||||
|
223500
Projekt_test/models/spaceship_station.obj
Normal file
2500
Projekt_test/models/sphere.obj
Normal file
7
Projekt_test/render.py
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
import os
|
||||
rootdir = './'
|
||||
for filename in os.listdir(rootdir):
|
||||
if filename.endswith(".md"):
|
||||
name = filename[:-3]
|
||||
os.system(f'pandoc -s -o "{name}.html" "{name}.md" --mathjax --css style.css')
|
18
Projekt_test/shaders/shader.frag
Normal file
@ -0,0 +1,18 @@
|
||||
#version 430 core
|
||||
|
||||
float AMBIENT = 0.1;
|
||||
|
||||
uniform vec3 color;
|
||||
uniform vec3 lightPos;
|
||||
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
|
||||
out vec4 outColor;
|
||||
void main()
|
||||
{
|
||||
vec3 lightDir = normalize(lightPos-worldPos);
|
||||
vec3 normal = normalize(vecNormal);
|
||||
float diffuse=max(0,dot(normal,lightDir));
|
||||
outColor = vec4(color*min(1,AMBIENT+diffuse), 1.0);
|
||||
}
|
18
Projekt_test/shaders/shader.vert
Normal file
@ -0,0 +1,18 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec3 vertexNormal;
|
||||
layout(location = 2) in vec2 vertexTexCoord;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
out vec3 vecNormal;
|
||||
out vec3 worldPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
|
||||
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
}
|
12
Projekt_test/shaders/shader_skybox.frag
Normal file
@ -0,0 +1,12 @@
|
||||
#version 430 core
|
||||
|
||||
uniform samplerCube skybox;
|
||||
|
||||
in vec3 texCoord;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
out_color = texture(skybox,texCoord);
|
||||
}
|
13
Projekt_test/shaders/shader_skybox.vert
Normal file
@ -0,0 +1,13 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
|
||||
uniform mat4 transformation;
|
||||
|
||||
out vec3 texCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
texCoord = vertexPosition;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
}
|
21
Projekt_test/shaders/shader_sun.frag
Normal file
@ -0,0 +1,21 @@
|
||||
#version 430 core
|
||||
|
||||
uniform sampler2D colorTexture; // Texture of the sun
|
||||
uniform bool isHighlighted; // Check if the object is highlighted
|
||||
uniform vec3 highlightColor; // Color for highlighting
|
||||
|
||||
in vec2 vecTex; // Texture coordinates
|
||||
|
||||
out vec4 outColor; // Output color of the fragment
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 textureColor = texture(colorTexture, vecTex).xyz; // Get the texture color
|
||||
|
||||
// Check if the object is highlighted and mix the colors accordingly
|
||||
if(isHighlighted) {
|
||||
textureColor = mix(textureColor, highlightColor, 0.5);
|
||||
}
|
||||
|
||||
outColor = vec4(textureColor, 1.0); // Set the output color
|
||||
}
|
23
Projekt_test/shaders/shader_sun.vert
Normal file
@ -0,0 +1,23 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec3 vertexNormal;
|
||||
layout(location = 2) in vec2 vertexTexCoord;
|
||||
layout(location = 3) in vec3 vertexTangent;
|
||||
layout(location = 4) in vec3 vertexBitangent;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
out vec3 vecNormal;
|
||||
out vec3 worldPos;
|
||||
out vec2 vecTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
|
||||
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
|
||||
vecTex = vertexTexCoord;
|
||||
vecTex.y = 1.0 - vecTex.y;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
}
|
89
Projekt_test/shaders/shader_tex.frag
Normal file
@ -0,0 +1,89 @@
|
||||
#version 430 core
|
||||
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
in vec2 vecTex;
|
||||
|
||||
uniform vec3 albedo;
|
||||
uniform float metallic;
|
||||
uniform float roughness;
|
||||
uniform float ao;
|
||||
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 cameraPos;
|
||||
uniform sampler2D colorTexture;
|
||||
uniform float brightnessFactor = 10; // Faktor jasności
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
// Funkcje pomocnicze dla PBR
|
||||
vec3 getNormal() {
|
||||
return normalize(vecNormal);
|
||||
}
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness) {
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float num = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = 3.14159265359 * denom * denom;
|
||||
|
||||
return num / denom;
|
||||
}
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float roughness) {
|
||||
float r = (roughness + 1.0);
|
||||
float k = (r*r) / 8.0;
|
||||
|
||||
float num = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return num / denom;
|
||||
}
|
||||
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) {
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0) {
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 N = getNormal();
|
||||
vec3 V = normalize(cameraPos - worldPos);
|
||||
vec3 L = normalize(lightPos - worldPos);
|
||||
vec3 H = normalize(V + L);
|
||||
|
||||
vec3 albedo = texture(colorTexture, vecTex).rgb;
|
||||
albedo *= brightnessFactor; // Zwiększ jasność albedo
|
||||
|
||||
float NDF = DistributionGGX(N, H, roughness);
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), vec3(0.04) * (1.0 - metallic) + albedo * metallic);
|
||||
|
||||
vec3 nominator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001; // Avoid division by zero
|
||||
vec3 specular = nominator / denominator;
|
||||
|
||||
// Contribution from light
|
||||
vec3 kS = F;
|
||||
vec3 kD = vec3(1.0) - kS;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
vec3 ambient = (vec3(0.03) * albedo); // Minimalne światło otoczenia
|
||||
vec3 lighting = (kD * albedo / 3.14159265359 + specular) * NdotL;
|
||||
vec3 color = ambient + lighting;
|
||||
color = color / (color + vec3(1.0));
|
||||
|
||||
outColor = vec4(color, 1.0);
|
||||
}
|
23
Projekt_test/shaders/shader_tex.vert
Normal file
@ -0,0 +1,23 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec3 vertexNormal;
|
||||
layout(location = 2) in vec2 vertexTexCoord;
|
||||
layout(location = 3) in vec3 vertexTangent;
|
||||
layout(location = 4) in vec3 vertexBitangent;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
out vec3 vecNormal;
|
||||
out vec3 worldPos;
|
||||
out vec2 vecTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
|
||||
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
|
||||
vecTex = vertexTexCoord;
|
||||
vecTex.y = 1.0 - vecTex.y;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
}
|
82
Projekt_test/shaders/shader_unmap.frag
Normal file
@ -0,0 +1,82 @@
|
||||
#version 430 core
|
||||
|
||||
uniform sampler2D colorTexture;
|
||||
uniform sampler2D normalMap; // Normal map
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 cameraPos; // Pozycja kamery dla PBR
|
||||
uniform bool isHighlighted;
|
||||
uniform vec3 highlightColor;
|
||||
uniform float brightnessFactor = 2; // Faktor jasności dla PBR
|
||||
|
||||
uniform float metallic;
|
||||
uniform float roughness;
|
||||
uniform float ao; // Ambient occlusion factor, not used directly in this example
|
||||
|
||||
in vec3 FragPos;
|
||||
in vec2 TexCoords;
|
||||
in mat3 TBN; // TBN matrix for normal mapping
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
// Funkcje pomocnicze dla PBR, jak wcześniej
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness) {
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
float num = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = 3.14159265359 * denom * denom;
|
||||
return num / denom;
|
||||
}
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float roughness) {
|
||||
float r = (roughness + 1.0);
|
||||
float k = (r*r) / 8.0;
|
||||
float num = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
return num / denom;
|
||||
}
|
||||
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) {
|
||||
float ggx2 = GeometrySchlickGGX(max(dot(N, V), 0.0), roughness);
|
||||
float ggx1 = GeometrySchlickGGX(max(dot(N, L), 0.0), roughness);
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0) {
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Teksturowanie z uwzględnieniem mapy normalnych
|
||||
vec3 albedo = texture(colorTexture, TexCoords).rgb * brightnessFactor;
|
||||
vec3 normal = texture(normalMap, TexCoords).rgb;
|
||||
normal = normalize(normal * 2.0 - 1.0); // Do przestrzeni [-1, 1]
|
||||
vec3 N = normalize(TBN * normal); // Do przestrzeni świata
|
||||
|
||||
vec3 V = normalize(cameraPos - FragPos);
|
||||
vec3 L = normalize(lightPos - FragPos);
|
||||
vec3 H = normalize(V + L);
|
||||
|
||||
// Obliczenia PBR
|
||||
float NDF = DistributionGGX(N, H, roughness);
|
||||
float G = GeometrySmith(N, V, L, roughness);
|
||||
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), vec3(0.04) * (1.0 - metallic) + albedo * metallic);
|
||||
vec3 nominator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001;
|
||||
vec3 specular = nominator / denominator;
|
||||
|
||||
// Światło otoczenia i dyfuzyjne
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
vec3 ambient = vec3(0.03) * albedo;
|
||||
vec3 lighting = (vec3(1.0) - F) * albedo / 3.14159265359 + specular;
|
||||
lighting *= NdotL;
|
||||
|
||||
vec3 result = ambient + lighting;
|
||||
if(isHighlighted) {
|
||||
result = mix(result, highlightColor, 0.5);
|
||||
}
|
||||
|
||||
outColor = vec4(result, 1.0);
|
||||
}
|
30
Projekt_test/shaders/shader_unmap.vert
Normal file
@ -0,0 +1,30 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec3 vertexNormal;
|
||||
layout(location = 2) in vec2 vertexTexCoord;
|
||||
layout(location = 3) in vec3 vertexTangent;
|
||||
layout(location = 4) in vec3 vertexBitangent;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec2 TexCoords;
|
||||
out mat3 TBN;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragPos = vec3(modelMatrix * vec4(vertexPosition, 1.0));
|
||||
TexCoords = vertexTexCoord;
|
||||
|
||||
vec3 T = normalize(mat3(modelMatrix) * vertexTangent);
|
||||
vec3 N = normalize(mat3(modelMatrix) * vertexNormal);
|
||||
// Gram-Schmidt orthogonalize
|
||||
T = normalize(T - dot(T, N) * N);
|
||||
vec3 B = cross(N, T);
|
||||
|
||||
TBN = mat3(T, B, N);
|
||||
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
}
|
55
Projekt_test/src/Box.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
|
||||
// dane 36 wierzcholkow i kolorow opisujace model pudelka
|
||||
const float box[] = {
|
||||
|
||||
// points colors
|
||||
0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
||||
0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
||||
-0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
||||
|
||||
0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
||||
-0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
||||
-0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
||||
|
||||
0.25f, 0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
|
||||
-0.25f, 0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
|
||||
0.25f, -0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
|
||||
|
||||
0.25f, -0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
|
||||
-0.25f, 0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
|
||||
-0.25f, -0.25f, -0.75f, 1.0f, 0.8f, 0.8f, 0.8f, 1.0f,
|
||||
|
||||
-0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||
-0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||
-0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||
|
||||
-0.25f, 0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||
-0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||
-0.25f, 0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||
|
||||
0.25f, 0.25f, 0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
|
||||
0.25f, -0.25f, -0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
|
||||
0.25f, -0.25f, 0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
|
||||
|
||||
0.25f, 0.25f, 0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
|
||||
0.25f, 0.25f, -0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
|
||||
0.25f, -0.25f, -0.75f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f,
|
||||
|
||||
0.25f, 0.25f, -0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.25f, 0.25f, 0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
-0.25f, 0.25f, 0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
|
||||
0.25f, 0.25f, -0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
-0.25f, 0.25f, 0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
-0.25f, 0.25f, -0.75f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
|
||||
0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
-0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
|
||||
0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
-0.25f, -0.25f, -0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
-0.25f, -0.25f, 0.75f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
};
|
||||
|
31
Projekt_test/src/Camera.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "Camera.h"
|
||||
|
||||
glm::mat4 Core::createPerspectiveMatrix(float zNear, float zFar, float frustumScale)
|
||||
{
|
||||
glm::mat4 perspective;
|
||||
perspective[0][0] = 1.f;
|
||||
perspective[1][1] = frustumScale;
|
||||
perspective[2][2] = (zFar + zNear) / (zNear - zFar);
|
||||
perspective[3][2] = (2 * zFar * zNear) / (zNear - zFar);
|
||||
perspective[2][3] = -1;
|
||||
perspective[3][3] = 0;
|
||||
|
||||
return perspective;
|
||||
}
|
||||
|
||||
glm::mat4 Core::createViewMatrix( glm::vec3 position, glm::vec3 forward, glm::vec3 up )
|
||||
{
|
||||
glm::vec3 side = glm::cross(forward, up);
|
||||
|
||||
// Trzeba pamietac o minusie przy ustawianiu osi Z kamery.
|
||||
// Wynika to z tego, ze standardowa macierz perspektywiczna zaklada, ze "z przodu" jest ujemna (a nie dodatnia) czesc osi Z.
|
||||
glm::mat4 cameraRotation;
|
||||
cameraRotation[0][0] = side.x; cameraRotation[1][0] = side.y; cameraRotation[2][0] = side.z;
|
||||
cameraRotation[0][1] = up.x; cameraRotation[1][1] = up.y; cameraRotation[2][1] = up.z;
|
||||
cameraRotation[0][2] = -forward.x; cameraRotation[1][2] = -forward.y; cameraRotation[2][2] = -forward.z;
|
||||
|
||||
glm::mat4 cameraTranslation;
|
||||
cameraTranslation[3] = glm::vec4(-position, 1.0f);
|
||||
|
||||
return cameraRotation * cameraTranslation;
|
||||
}
|
14
Projekt_test/src/Camera.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "glm.hpp"
|
||||
|
||||
namespace Core
|
||||
{
|
||||
glm::mat4 createPerspectiveMatrix(float zNear = 0.1f, float zFar = 100.0f, float frustumScale = 1.f);
|
||||
|
||||
// position - pozycja kamery
|
||||
// forward - wektor "do przodu" kamery (jednostkowy)
|
||||
// up - wektor "w gore" kamery (jednostkowy)
|
||||
// up i forward musza byc ortogonalne!
|
||||
glm::mat4 createViewMatrix(glm::vec3 position, glm::vec3 forward, glm::vec3 up);
|
||||
}
|
128
Projekt_test/src/Render_Utils.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
#include "Render_Utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "glew.h"
|
||||
#include "freeglut.h"
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
|
||||
|
||||
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
|
||||
vertexArray = 0;
|
||||
vertexBuffer = 0;
|
||||
vertexIndexBuffer = 0;
|
||||
|
||||
std::vector<float> textureCoord;
|
||||
std::vector<unsigned int> indices;
|
||||
//tex coord must be converted to 2d vecs
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
||||
{
|
||||
if (mesh->mTextureCoords[0] != nullptr) {
|
||||
textureCoord.push_back(mesh->mTextureCoords[0][i].x);
|
||||
textureCoord.push_back(mesh->mTextureCoords[0][i].y);
|
||||
}
|
||||
else {
|
||||
textureCoord.push_back(0.0f);
|
||||
textureCoord.push_back(0.0f);
|
||||
}
|
||||
}
|
||||
if (mesh->mTextureCoords[0] == nullptr) {
|
||||
std::cout << "no uv coords\n";
|
||||
}
|
||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
|
||||
{
|
||||
aiFace face = mesh->mFaces[i];
|
||||
// retrieve all indices of the face and store them in the indices vector
|
||||
for (unsigned int j = 0; j < face.mNumIndices; j++)
|
||||
indices.push_back(face.mIndices[j]);
|
||||
}
|
||||
|
||||
unsigned int vertexDataBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
||||
unsigned int vertexNormalBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
||||
unsigned int vertexTexBufferSize = sizeof(float) * mesh->mNumVertices * 2;
|
||||
unsigned int vertexTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
||||
unsigned int vertexBiTangentBufferSize = sizeof(float) * mesh->mNumVertices * 3;
|
||||
|
||||
unsigned int vertexElementBufferSize = sizeof(unsigned int) * indices.size();
|
||||
size = indices.size();
|
||||
|
||||
glGenVertexArrays(1, &vertexArray);
|
||||
glBindVertexArray(vertexArray);
|
||||
|
||||
|
||||
glGenBuffers(1, &vertexIndexBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexIndexBuffer);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexElementBufferSize, &indices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &vertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||
//std::cout << vertexBuffer;
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize + vertexBiTangentBufferSize, NULL, GL_STATIC_DRAW);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, vertexDataBufferSize, mesh->mVertices);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize, vertexNormalBufferSize, mesh->mNormals);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize, vertexTexBufferSize, &textureCoord[0]);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize, vertexTangentBufferSize, mesh->mTangents);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize, vertexBiTangentBufferSize, mesh->mBitangents);
|
||||
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0));
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize));
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertexNormalBufferSize + vertexDataBufferSize));
|
||||
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize));
|
||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertexDataBufferSize + vertexNormalBufferSize + vertexTexBufferSize + vertexTangentBufferSize));
|
||||
|
||||
}
|
||||
|
||||
void Core::DrawVertexArray(const float * vertexArray, int numVertices, int elementSize )
|
||||
{
|
||||
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, numVertices);
|
||||
}
|
||||
|
||||
void Core::DrawVertexArrayIndexed( const float * vertexArray, const int * indexArray, int numIndexes, int elementSize )
|
||||
{
|
||||
glVertexAttribPointer(0, elementSize, GL_FLOAT, false, 0, vertexArray);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, numIndexes, GL_UNSIGNED_INT, indexArray);
|
||||
}
|
||||
|
||||
|
||||
void Core::DrawVertexArray( const VertexData & data )
|
||||
{
|
||||
int numAttribs = std::min(VertexData::MAX_ATTRIBS, data.NumActiveAttribs);
|
||||
for(int i = 0; i < numAttribs; i++)
|
||||
{
|
||||
glVertexAttribPointer(i, data.Attribs[i].Size, GL_FLOAT, false, 0, data.Attribs[i].Pointer);
|
||||
glEnableVertexAttribArray(i);
|
||||
}
|
||||
glDrawArrays(GL_TRIANGLES, 0, data.NumVertices);
|
||||
}
|
||||
|
||||
void Core::DrawContext(Core::RenderContext& context)
|
||||
{
|
||||
|
||||
glBindVertexArray(context.vertexArray);
|
||||
glDrawElements(
|
||||
GL_TRIANGLES, // mode
|
||||
context.size, // count
|
||||
GL_UNSIGNED_INT, // type
|
||||
(void*)0 // element array buffer offset
|
||||
);
|
||||
glBindVertexArray(0);
|
||||
}
|
72
Projekt_test/src/Render_Utils.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
#include "glm.hpp"
|
||||
#include "glew.h"
|
||||
#include "objload.h"
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
namespace Core
|
||||
{
|
||||
struct RenderContext
|
||||
{
|
||||
GLuint vertexArray;
|
||||
GLuint vertexBuffer;
|
||||
GLuint vertexIndexBuffer;
|
||||
int size = 0;
|
||||
|
||||
void initFromOBJ(obj::Model& model);
|
||||
|
||||
void initFromAssimpMesh(aiMesh* mesh);
|
||||
};
|
||||
|
||||
// vertexArray - jednowymiarowa tablica zawierajaca wartosci opisujace pozycje kolejnych wierzcholkow w jednym ciagu (x1, y1, z1, w1, x2, y2, z2, w2, ...)
|
||||
// numVertices - liczba wierzcholkow do narysowania
|
||||
// elementSize - liczba wartosci opisujacych pojedynczy wierzcholek (np. 3 gdy wierzcholek opisany jest trojka (x, y, z))
|
||||
void DrawVertexArray(const float * vertexArray, int numVertices, int elementSize);
|
||||
|
||||
// indexArray - jednowymiarowa tablica zawierajaca indeksy wierzcholkow kolejnych trojkatow w jednym ciagu (t1_i1, t1_i2, t1_i3, t2_i1, t2_i2, t2_i3, ...)
|
||||
// numIndexes - liczba indeksow w tablicy indexArray
|
||||
void DrawVertexArrayIndexed(const float * vertexArray, const int * indexArray, int numIndexes, int elementSize);
|
||||
|
||||
|
||||
struct VertexAttribute
|
||||
{
|
||||
const void * Pointer;
|
||||
int Size;
|
||||
};
|
||||
|
||||
struct VertexData
|
||||
{
|
||||
static const int MAX_ATTRIBS = 8;
|
||||
VertexAttribute Attribs[MAX_ATTRIBS];
|
||||
int NumActiveAttribs;
|
||||
int NumVertices;
|
||||
};
|
||||
|
||||
// Ta funkcja sluzy do rysowania trojkatow, ktorych wierzcholki moga byc opisane wiecej niz jednym atrybutem.
|
||||
// Funkcja przyjmuje jako parametr strukture, w ktorej nalezy zawrzec wszystkie potrzebne dane.
|
||||
//
|
||||
// Przykladowe wywolanie funkcji - narysowanie trojkata jak na pierwszych zajeciach:
|
||||
/*
|
||||
|
||||
const float vertices[] = {
|
||||
0.25f, 0.25f, 0.0f, 1.0f,
|
||||
0.25f, -0.25f, 0.0f, 1.0f,
|
||||
-0.25f, -0.25f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
Core::VertexData vertexData;
|
||||
vertexData.NumActiveAttribs = 1; // Liczba uzywanych atrybutow wierzcholka
|
||||
vertexData.Attribs[0].Pointer = vertices; // Wskaznik na dane zerowego atrybutu
|
||||
vertexData.Attribs[0].Size = 4; // Wielkosc zerowego atrybutu (ilosc liczb opisujacych ten atrybut w pojedynczym wierzcholku)
|
||||
vertexData.NumVertices = 3; // Liczba wierzcholkow do narysowania
|
||||
Core::DrawVertexArray(vertexData);
|
||||
|
||||
*/
|
||||
void DrawVertexArray(const VertexData & data);
|
||||
|
||||
void DrawContext(RenderContext& context);
|
||||
}
|
2024
Projekt_test/src/SOIL/SOIL.c
Normal file
433
Projekt_test/src/SOIL/SOIL.h
Normal file
@ -0,0 +1,433 @@
|
||||
/**
|
||||
@mainpage SOIL
|
||||
|
||||
Jonathan Dummer
|
||||
2007-07-26-10.36
|
||||
|
||||
Simple OpenGL Image Library
|
||||
|
||||
A tiny c library for uploading images as
|
||||
textures into OpenGL. Also saving and
|
||||
loading of images is supported.
|
||||
|
||||
I'm using Sean's Tool Box image loader as a base:
|
||||
http://www.nothings.org/
|
||||
|
||||
I'm upgrading it to load TGA and DDS files, and a direct
|
||||
path for loading DDS files straight into OpenGL textures,
|
||||
when applicable.
|
||||
|
||||
Image Formats:
|
||||
- BMP load & save
|
||||
- TGA load & save
|
||||
- DDS load & save
|
||||
- PNG load
|
||||
- JPG load
|
||||
|
||||
OpenGL Texture Features:
|
||||
- resample to power-of-two sizes
|
||||
- MIPmap generation
|
||||
- compressed texture S3TC formats (if supported)
|
||||
- can pre-multiply alpha for you, for better compositing
|
||||
- can flip image about the y-axis (except pre-compressed DDS files)
|
||||
|
||||
Thanks to:
|
||||
* Sean Barret - for the awesome stb_image
|
||||
* Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts
|
||||
* everybody at gamedev.net
|
||||
**/
|
||||
|
||||
#ifndef HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY
|
||||
#define HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
The format of images that may be loaded (force_channels).
|
||||
SOIL_LOAD_AUTO leaves the image in whatever format it was found.
|
||||
SOIL_LOAD_L forces the image to load as Luminous (greyscale)
|
||||
SOIL_LOAD_LA forces the image to load as Luminous with Alpha
|
||||
SOIL_LOAD_RGB forces the image to load as Red Green Blue
|
||||
SOIL_LOAD_RGBA forces the image to load as Red Green Blue Alpha
|
||||
**/
|
||||
enum
|
||||
{
|
||||
SOIL_LOAD_AUTO = 0,
|
||||
SOIL_LOAD_L = 1,
|
||||
SOIL_LOAD_LA = 2,
|
||||
SOIL_LOAD_RGB = 3,
|
||||
SOIL_LOAD_RGBA = 4
|
||||
};
|
||||
|
||||
/**
|
||||
Passed in as reuse_texture_ID, will cause SOIL to
|
||||
register a new texture ID using glGenTextures().
|
||||
If the value passed into reuse_texture_ID > 0 then
|
||||
SOIL will just re-use that texture ID (great for
|
||||
reloading image assets in-game!)
|
||||
**/
|
||||
enum
|
||||
{
|
||||
SOIL_CREATE_NEW_ID = 0
|
||||
};
|
||||
|
||||
/**
|
||||
flags you can pass into SOIL_load_OGL_texture()
|
||||
and SOIL_create_OGL_texture().
|
||||
(note that if SOIL_FLAG_DDS_LOAD_DIRECT is used
|
||||
the rest of the flags with the exception of
|
||||
SOIL_FLAG_TEXTURE_REPEATS will be ignored while
|
||||
loading already-compressed DDS files.)
|
||||
|
||||
SOIL_FLAG_POWER_OF_TWO: force the image to be POT
|
||||
SOIL_FLAG_MIPMAPS: generate mipmaps for the texture
|
||||
SOIL_FLAG_TEXTURE_REPEATS: otherwise will clamp
|
||||
SOIL_FLAG_MULTIPLY_ALPHA: for using (GL_ONE,GL_ONE_MINUS_SRC_ALPHA) blending
|
||||
SOIL_FLAG_INVERT_Y: flip the image vertically
|
||||
SOIL_FLAG_COMPRESS_TO_DXT: if the card can display them, will convert RGB to DXT1, RGBA to DXT5
|
||||
SOIL_FLAG_DDS_LOAD_DIRECT: will load DDS files directly without _ANY_ additional processing
|
||||
SOIL_FLAG_NTSC_SAFE_RGB: clamps RGB components to the range [16,235]
|
||||
SOIL_FLAG_CoCg_Y: Google YCoCg; RGB=>CoYCg, RGBA=>CoCgAY
|
||||
SOIL_FLAG_TEXTURE_RECTANGE: uses ARB_texture_rectangle ; pixel indexed & no repeat or MIPmaps or cubemaps
|
||||
**/
|
||||
enum
|
||||
{
|
||||
SOIL_FLAG_POWER_OF_TWO = 1,
|
||||
SOIL_FLAG_MIPMAPS = 2,
|
||||
SOIL_FLAG_TEXTURE_REPEATS = 4,
|
||||
SOIL_FLAG_MULTIPLY_ALPHA = 8,
|
||||
SOIL_FLAG_INVERT_Y = 16,
|
||||
SOIL_FLAG_COMPRESS_TO_DXT = 32,
|
||||
SOIL_FLAG_DDS_LOAD_DIRECT = 64,
|
||||
SOIL_FLAG_NTSC_SAFE_RGB = 128,
|
||||
SOIL_FLAG_CoCg_Y = 256,
|
||||
SOIL_FLAG_TEXTURE_RECTANGLE = 512
|
||||
};
|
||||
|
||||
/**
|
||||
The types of images that may be saved.
|
||||
(TGA supports uncompressed RGB / RGBA)
|
||||
(BMP supports uncompressed RGB)
|
||||
(DDS supports DXT1 and DXT5)
|
||||
**/
|
||||
enum
|
||||
{
|
||||
SOIL_SAVE_TYPE_TGA = 0,
|
||||
SOIL_SAVE_TYPE_BMP = 1,
|
||||
SOIL_SAVE_TYPE_DDS = 2
|
||||
};
|
||||
|
||||
/**
|
||||
Defines the order of faces in a DDS cubemap.
|
||||
I recommend that you use the same order in single
|
||||
image cubemap files, so they will be interchangeable
|
||||
with DDS cubemaps when using SOIL.
|
||||
**/
|
||||
#define SOIL_DDS_CUBEMAP_FACE_ORDER "EWUDNS"
|
||||
|
||||
/**
|
||||
The types of internal fake HDR representations
|
||||
|
||||
SOIL_HDR_RGBE: RGB * pow( 2.0, A - 128.0 )
|
||||
SOIL_HDR_RGBdivA: RGB / A
|
||||
SOIL_HDR_RGBdivA2: RGB / (A*A)
|
||||
**/
|
||||
enum
|
||||
{
|
||||
SOIL_HDR_RGBE = 0,
|
||||
SOIL_HDR_RGBdivA = 1,
|
||||
SOIL_HDR_RGBdivA2 = 2
|
||||
};
|
||||
|
||||
/**
|
||||
Loads an image from disk into an OpenGL texture.
|
||||
\param filename the name of the file to upload as a texture
|
||||
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_load_OGL_texture
|
||||
(
|
||||
const char *filename,
|
||||
int force_channels,
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Loads 6 images from disk into an OpenGL cubemap texture.
|
||||
\param x_pos_file the name of the file to upload as the +x cube face
|
||||
\param x_neg_file the name of the file to upload as the -x cube face
|
||||
\param y_pos_file the name of the file to upload as the +y cube face
|
||||
\param y_neg_file the name of the file to upload as the -y cube face
|
||||
\param z_pos_file the name of the file to upload as the +z cube face
|
||||
\param z_neg_file the name of the file to upload as the -z cube face
|
||||
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_load_OGL_cubemap
|
||||
(
|
||||
const char *x_pos_file,
|
||||
const char *x_neg_file,
|
||||
const char *y_pos_file,
|
||||
const char *y_neg_file,
|
||||
const char *z_pos_file,
|
||||
const char *z_neg_file,
|
||||
int force_channels,
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Loads 1 image from disk and splits it into an OpenGL cubemap texture.
|
||||
\param filename the name of the file to upload as a texture
|
||||
\param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc.
|
||||
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_load_OGL_single_cubemap
|
||||
(
|
||||
const char *filename,
|
||||
const char face_order[6],
|
||||
int force_channels,
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Loads an HDR image from disk into an OpenGL texture.
|
||||
\param filename the name of the file to upload as a texture
|
||||
\param fake_HDR_format SOIL_HDR_RGBE, SOIL_HDR_RGBdivA, SOIL_HDR_RGBdivA2
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_load_OGL_HDR_texture
|
||||
(
|
||||
const char *filename,
|
||||
int fake_HDR_format,
|
||||
int rescale_to_max,
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Loads an image from RAM into an OpenGL texture.
|
||||
\param buffer the image data in RAM just as if it were still in a file
|
||||
\param buffer_length the size of the buffer in bytes
|
||||
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_load_OGL_texture_from_memory
|
||||
(
|
||||
const unsigned char *const buffer,
|
||||
int buffer_length,
|
||||
int force_channels,
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Loads 6 images from memory into an OpenGL cubemap texture.
|
||||
\param x_pos_buffer the image data in RAM to upload as the +x cube face
|
||||
\param x_pos_buffer_length the size of the above buffer
|
||||
\param x_neg_buffer the image data in RAM to upload as the +x cube face
|
||||
\param x_neg_buffer_length the size of the above buffer
|
||||
\param y_pos_buffer the image data in RAM to upload as the +x cube face
|
||||
\param y_pos_buffer_length the size of the above buffer
|
||||
\param y_neg_buffer the image data in RAM to upload as the +x cube face
|
||||
\param y_neg_buffer_length the size of the above buffer
|
||||
\param z_pos_buffer the image data in RAM to upload as the +x cube face
|
||||
\param z_pos_buffer_length the size of the above buffer
|
||||
\param z_neg_buffer the image data in RAM to upload as the +x cube face
|
||||
\param z_neg_buffer_length the size of the above buffer
|
||||
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_load_OGL_cubemap_from_memory
|
||||
(
|
||||
const unsigned char *const x_pos_buffer,
|
||||
int x_pos_buffer_length,
|
||||
const unsigned char *const x_neg_buffer,
|
||||
int x_neg_buffer_length,
|
||||
const unsigned char *const y_pos_buffer,
|
||||
int y_pos_buffer_length,
|
||||
const unsigned char *const y_neg_buffer,
|
||||
int y_neg_buffer_length,
|
||||
const unsigned char *const z_pos_buffer,
|
||||
int z_pos_buffer_length,
|
||||
const unsigned char *const z_neg_buffer,
|
||||
int z_neg_buffer_length,
|
||||
int force_channels,
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Loads 1 image from RAM and splits it into an OpenGL cubemap texture.
|
||||
\param buffer the image data in RAM just as if it were still in a file
|
||||
\param buffer_length the size of the buffer in bytes
|
||||
\param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc.
|
||||
\param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_load_OGL_single_cubemap_from_memory
|
||||
(
|
||||
const unsigned char *const buffer,
|
||||
int buffer_length,
|
||||
const char face_order[6],
|
||||
int force_channels,
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a 2D OpenGL texture from raw image data. Note that the raw data is
|
||||
_NOT_ freed after the upload (so the user can load various versions).
|
||||
\param data the raw data to be uploaded as an OpenGL texture
|
||||
\param width the width of the image in pixels
|
||||
\param height the height of the image in pixels
|
||||
\param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_create_OGL_texture
|
||||
(
|
||||
const unsigned char *const data,
|
||||
int width, int height, int channels,
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Creates an OpenGL cubemap texture by splitting up 1 image into 6 parts.
|
||||
\param data the raw data to be uploaded as an OpenGL texture
|
||||
\param width the width of the image in pixels
|
||||
\param height the height of the image in pixels
|
||||
\param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
|
||||
\param face_order the order of the faces in the file, and combination of NSWEUD, for North, South, Up, etc.
|
||||
\param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
|
||||
\param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT
|
||||
\return 0-failed, otherwise returns the OpenGL texture handle
|
||||
**/
|
||||
unsigned int
|
||||
SOIL_create_OGL_single_cubemap
|
||||
(
|
||||
const unsigned char *const data,
|
||||
int width, int height, int channels,
|
||||
const char face_order[6],
|
||||
unsigned int reuse_texture_ID,
|
||||
unsigned int flags
|
||||
);
|
||||
|
||||
/**
|
||||
Captures the OpenGL window (RGB) and saves it to disk
|
||||
\return 0 if it failed, otherwise returns 1
|
||||
**/
|
||||
int
|
||||
SOIL_save_screenshot
|
||||
(
|
||||
const char *filename,
|
||||
int image_type,
|
||||
int x, int y,
|
||||
int width, int height
|
||||
);
|
||||
|
||||
/**
|
||||
Loads an image from disk into an array of unsigned chars.
|
||||
Note that *channels return the original channel count of the
|
||||
image. If force_channels was other than SOIL_LOAD_AUTO,
|
||||
the resulting image has force_channels, but *channels may be
|
||||
different (if the original image had a different channel
|
||||
count).
|
||||
\return 0 if failed, otherwise returns 1
|
||||
**/
|
||||
unsigned char*
|
||||
SOIL_load_image
|
||||
(
|
||||
const char *filename,
|
||||
int *width, int *height, int *channels,
|
||||
int force_channels
|
||||
);
|
||||
|
||||
/**
|
||||
Loads an image from memory into an array of unsigned chars.
|
||||
Note that *channels return the original channel count of the
|
||||
image. If force_channels was other than SOIL_LOAD_AUTO,
|
||||
the resulting image has force_channels, but *channels may be
|
||||
different (if the original image had a different channel
|
||||
count).
|
||||
\return 0 if failed, otherwise returns 1
|
||||
**/
|
||||
unsigned char*
|
||||
SOIL_load_image_from_memory
|
||||
(
|
||||
const unsigned char *const buffer,
|
||||
int buffer_length,
|
||||
int *width, int *height, int *channels,
|
||||
int force_channels
|
||||
);
|
||||
|
||||
/**
|
||||
Saves an image from an array of unsigned chars (RGBA) to disk
|
||||
\return 0 if failed, otherwise returns 1
|
||||
**/
|
||||
int
|
||||
SOIL_save_image
|
||||
(
|
||||
const char *filename,
|
||||
int image_type,
|
||||
int width, int height, int channels,
|
||||
const unsigned char *const data
|
||||
);
|
||||
|
||||
/**
|
||||
Frees the image data (note, this is just C's "free()"...this function is
|
||||
present mostly so C++ programmers don't forget to use "free()" and call
|
||||
"delete []" instead [8^)
|
||||
**/
|
||||
void
|
||||
SOIL_free_image_data
|
||||
(
|
||||
unsigned char *img_data
|
||||
);
|
||||
|
||||
/**
|
||||
This function resturn a pointer to a string describing the last thing
|
||||
that happened inside SOIL. It can be used to determine why an image
|
||||
failed to load.
|
||||
**/
|
||||
const char*
|
||||
SOIL_last_result
|
||||
(
|
||||
void
|
||||
);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY */
|
632
Projekt_test/src/SOIL/image_DXT.c
Normal file
@ -0,0 +1,632 @@
|
||||
/*
|
||||
Jonathan Dummer
|
||||
2007-07-31-10.32
|
||||
|
||||
simple DXT compression / decompression code
|
||||
|
||||
public domain
|
||||
*/
|
||||
|
||||
#include "image_DXT.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* set this =1 if you want to use the covarince matrix method...
|
||||
which is better than my method of using standard deviations
|
||||
overall, except on the infintesimal chance that the power
|
||||
method fails for finding the largest eigenvector */
|
||||
#define USE_COV_MAT 1
|
||||
|
||||
/********* Function Prototypes *********/
|
||||
/*
|
||||
Takes a 4x4 block of pixels and compresses it into 8 bytes
|
||||
in DXT1 format (color only, no alpha). Speed is valued
|
||||
over prettyness, at least for now.
|
||||
*/
|
||||
void compress_DDS_color_block(
|
||||
int channels,
|
||||
const unsigned char *const uncompressed,
|
||||
unsigned char compressed[8] );
|
||||
/*
|
||||
Takes a 4x4 block of pixels and compresses the alpha
|
||||
component it into 8 bytes for use in DXT5 DDS files.
|
||||
Speed is valued over prettyness, at least for now.
|
||||
*/
|
||||
void compress_DDS_alpha_block(
|
||||
const unsigned char *const uncompressed,
|
||||
unsigned char compressed[8] );
|
||||
|
||||
/********* Actual Exposed Functions *********/
|
||||
int
|
||||
save_image_as_DDS
|
||||
(
|
||||
const char *filename,
|
||||
int width, int height, int channels,
|
||||
const unsigned char *const data
|
||||
)
|
||||
{
|
||||
/* variables */
|
||||
FILE *fout;
|
||||
unsigned char *DDS_data;
|
||||
DDS_header header;
|
||||
int DDS_size;
|
||||
/* error check */
|
||||
if( (NULL == filename) ||
|
||||
(width < 1) || (height < 1) ||
|
||||
(channels < 1) || (channels > 4) ||
|
||||
(data == NULL ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* Convert the image */
|
||||
if( (channels & 1) == 1 )
|
||||
{
|
||||
/* no alpha, just use DXT1 */
|
||||
DDS_data = convert_image_to_DXT1( data, width, height, channels, &DDS_size );
|
||||
} else
|
||||
{
|
||||
/* has alpha, so use DXT5 */
|
||||
DDS_data = convert_image_to_DXT5( data, width, height, channels, &DDS_size );
|
||||
}
|
||||
/* save it */
|
||||
memset( &header, 0, sizeof( DDS_header ) );
|
||||
header.dwMagic = ('D' << 0) | ('D' << 8) | ('S' << 16) | (' ' << 24);
|
||||
header.dwSize = 124;
|
||||
header.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_LINEARSIZE;
|
||||
header.dwWidth = width;
|
||||
header.dwHeight = height;
|
||||
header.dwPitchOrLinearSize = DDS_size;
|
||||
header.sPixelFormat.dwSize = 32;
|
||||
header.sPixelFormat.dwFlags = DDPF_FOURCC;
|
||||
if( (channels & 1) == 1 )
|
||||
{
|
||||
header.sPixelFormat.dwFourCC = ('D' << 0) | ('X' << 8) | ('T' << 16) | ('1' << 24);
|
||||
} else
|
||||
{
|
||||
header.sPixelFormat.dwFourCC = ('D' << 0) | ('X' << 8) | ('T' << 16) | ('5' << 24);
|
||||
}
|
||||
header.sCaps.dwCaps1 = DDSCAPS_TEXTURE;
|
||||
/* write it out */
|
||||
fout = fopen( filename, "wb");
|
||||
fwrite( &header, sizeof( DDS_header ), 1, fout );
|
||||
fwrite( DDS_data, 1, DDS_size, fout );
|
||||
fclose( fout );
|
||||
/* done */
|
||||
free( DDS_data );
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned char* convert_image_to_DXT1(
|
||||
const unsigned char *const uncompressed,
|
||||
int width, int height, int channels,
|
||||
int *out_size )
|
||||
{
|
||||
unsigned char *compressed;
|
||||
int i, j, x, y;
|
||||
unsigned char ublock[16*3];
|
||||
unsigned char cblock[8];
|
||||
int index = 0, chan_step = 1;
|
||||
int block_count = 0;
|
||||
/* error check */
|
||||
*out_size = 0;
|
||||
if( (width < 1) || (height < 1) ||
|
||||
(NULL == uncompressed) ||
|
||||
(channels < 1) || (channels > 4) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/* for channels == 1 or 2, I do not step forward for R,G,B values */
|
||||
if( channels < 3 )
|
||||
{
|
||||
chan_step = 0;
|
||||
}
|
||||
/* get the RAM for the compressed image
|
||||
(8 bytes per 4x4 pixel block) */
|
||||
*out_size = ((width+3) >> 2) * ((height+3) >> 2) * 8;
|
||||
compressed = (unsigned char*)malloc( *out_size );
|
||||
/* go through each block */
|
||||
for( j = 0; j < height; j += 4 )
|
||||
{
|
||||
for( i = 0; i < width; i += 4 )
|
||||
{
|
||||
/* copy this block into a new one */
|
||||
int idx = 0;
|
||||
int mx = 4, my = 4;
|
||||
if( j+4 >= height )
|
||||
{
|
||||
my = height - j;
|
||||
}
|
||||
if( i+4 >= width )
|
||||
{
|
||||
mx = width - i;
|
||||
}
|
||||
for( y = 0; y < my; ++y )
|
||||
{
|
||||
for( x = 0; x < mx; ++x )
|
||||
{
|
||||
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels];
|
||||
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels+chan_step];
|
||||
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels+chan_step+chan_step];
|
||||
}
|
||||
for( x = mx; x < 4; ++x )
|
||||
{
|
||||
ublock[idx++] = ublock[0];
|
||||
ublock[idx++] = ublock[1];
|
||||
ublock[idx++] = ublock[2];
|
||||
}
|
||||
}
|
||||
for( y = my; y < 4; ++y )
|
||||
{
|
||||
for( x = 0; x < 4; ++x )
|
||||
{
|
||||
ublock[idx++] = ublock[0];
|
||||
ublock[idx++] = ublock[1];
|
||||
ublock[idx++] = ublock[2];
|
||||
}
|
||||
}
|
||||
/* compress the block */
|
||||
++block_count;
|
||||
compress_DDS_color_block( 3, ublock, cblock );
|
||||
/* copy the data from the block into the main block */
|
||||
for( x = 0; x < 8; ++x )
|
||||
{
|
||||
compressed[index++] = cblock[x];
|
||||
}
|
||||
}
|
||||
}
|
||||
return compressed;
|
||||
}
|
||||
|
||||
unsigned char* convert_image_to_DXT5(
|
||||
const unsigned char *const uncompressed,
|
||||
int width, int height, int channels,
|
||||
int *out_size )
|
||||
{
|
||||
unsigned char *compressed;
|
||||
int i, j, x, y;
|
||||
unsigned char ublock[16*4];
|
||||
unsigned char cblock[8];
|
||||
int index = 0, chan_step = 1;
|
||||
int block_count = 0, has_alpha;
|
||||
/* error check */
|
||||
*out_size = 0;
|
||||
if( (width < 1) || (height < 1) ||
|
||||
(NULL == uncompressed) ||
|
||||
(channels < 1) || ( channels > 4) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/* for channels == 1 or 2, I do not step forward for R,G,B vales */
|
||||
if( channels < 3 )
|
||||
{
|
||||
chan_step = 0;
|
||||
}
|
||||
/* # channels = 1 or 3 have no alpha, 2 & 4 do have alpha */
|
||||
has_alpha = 1 - (channels & 1);
|
||||
/* get the RAM for the compressed image
|
||||
(16 bytes per 4x4 pixel block) */
|
||||
*out_size = ((width+3) >> 2) * ((height+3) >> 2) * 16;
|
||||
compressed = (unsigned char*)malloc( *out_size );
|
||||
/* go through each block */
|
||||
for( j = 0; j < height; j += 4 )
|
||||
{
|
||||
for( i = 0; i < width; i += 4 )
|
||||
{
|
||||
/* local variables, and my block counter */
|
||||
int idx = 0;
|
||||
int mx = 4, my = 4;
|
||||
if( j+4 >= height )
|
||||
{
|
||||
my = height - j;
|
||||
}
|
||||
if( i+4 >= width )
|
||||
{
|
||||
mx = width - i;
|
||||
}
|
||||
for( y = 0; y < my; ++y )
|
||||
{
|
||||
for( x = 0; x < mx; ++x )
|
||||
{
|
||||
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels];
|
||||
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels+chan_step];
|
||||
ublock[idx++] = uncompressed[(j+y)*width*channels+(i+x)*channels+chan_step+chan_step];
|
||||
ublock[idx++] =
|
||||
has_alpha * uncompressed[(j+y)*width*channels+(i+x)*channels+channels-1]
|
||||
+ (1-has_alpha)*255;
|
||||
}
|
||||
for( x = mx; x < 4; ++x )
|
||||
{
|
||||
ublock[idx++] = ublock[0];
|
||||
ublock[idx++] = ublock[1];
|
||||
ublock[idx++] = ublock[2];
|
||||
ublock[idx++] = ublock[3];
|
||||
}
|
||||
}
|
||||
for( y = my; y < 4; ++y )
|
||||
{
|
||||
for( x = 0; x < 4; ++x )
|
||||
{
|
||||
ublock[idx++] = ublock[0];
|
||||
ublock[idx++] = ublock[1];
|
||||
ublock[idx++] = ublock[2];
|
||||
ublock[idx++] = ublock[3];
|
||||
}
|
||||
}
|
||||
/* now compress the alpha block */
|
||||
compress_DDS_alpha_block( ublock, cblock );
|
||||
/* copy the data from the compressed alpha block into the main buffer */
|
||||
for( x = 0; x < 8; ++x )
|
||||
{
|
||||
compressed[index++] = cblock[x];
|
||||
}
|
||||
/* then compress the color block */
|
||||
++block_count;
|
||||
compress_DDS_color_block( 4, ublock, cblock );
|
||||
/* copy the data from the compressed color block into the main buffer */
|
||||
for( x = 0; x < 8; ++x )
|
||||
{
|
||||
compressed[index++] = cblock[x];
|
||||
}
|
||||
}
|
||||
}
|
||||
return compressed;
|
||||
}
|
||||
|
||||
/********* Helper Functions *********/
|
||||
int convert_bit_range( int c, int from_bits, int to_bits )
|
||||
{
|
||||
int b = (1 << (from_bits - 1)) + c * ((1 << to_bits) - 1);
|
||||
return (b + (b >> from_bits)) >> from_bits;
|
||||
}
|
||||
|
||||
int rgb_to_565( int r, int g, int b )
|
||||
{
|
||||
return
|
||||
(convert_bit_range( r, 8, 5 ) << 11) |
|
||||
(convert_bit_range( g, 8, 6 ) << 05) |
|
||||
(convert_bit_range( b, 8, 5 ) << 00);
|
||||
}
|
||||
|
||||
void rgb_888_from_565( unsigned int c, int *r, int *g, int *b )
|
||||
{
|
||||
*r = convert_bit_range( (c >> 11) & 31, 5, 8 );
|
||||
*g = convert_bit_range( (c >> 05) & 63, 6, 8 );
|
||||
*b = convert_bit_range( (c >> 00) & 31, 5, 8 );
|
||||
}
|
||||
|
||||
void compute_color_line_STDEV(
|
||||
const unsigned char *const uncompressed,
|
||||
int channels,
|
||||
float point[3], float direction[3] )
|
||||
{
|
||||
const float inv_16 = 1.0f / 16.0f;
|
||||
int i;
|
||||
float sum_r = 0.0f, sum_g = 0.0f, sum_b = 0.0f;
|
||||
float sum_rr = 0.0f, sum_gg = 0.0f, sum_bb = 0.0f;
|
||||
float sum_rg = 0.0f, sum_rb = 0.0f, sum_gb = 0.0f;
|
||||
/* calculate all data needed for the covariance matrix
|
||||
( to compare with _rygdxt code) */
|
||||
for( i = 0; i < 16*channels; i += channels )
|
||||
{
|
||||
sum_r += uncompressed[i+0];
|
||||
sum_rr += uncompressed[i+0] * uncompressed[i+0];
|
||||
sum_g += uncompressed[i+1];
|
||||
sum_gg += uncompressed[i+1] * uncompressed[i+1];
|
||||
sum_b += uncompressed[i+2];
|
||||
sum_bb += uncompressed[i+2] * uncompressed[i+2];
|
||||
sum_rg += uncompressed[i+0] * uncompressed[i+1];
|
||||
sum_rb += uncompressed[i+0] * uncompressed[i+2];
|
||||
sum_gb += uncompressed[i+1] * uncompressed[i+2];
|
||||
}
|
||||
/* convert the sums to averages */
|
||||
sum_r *= inv_16;
|
||||
sum_g *= inv_16;
|
||||
sum_b *= inv_16;
|
||||
/* and convert the squares to the squares of the value - avg_value */
|
||||
sum_rr -= 16.0f * sum_r * sum_r;
|
||||
sum_gg -= 16.0f * sum_g * sum_g;
|
||||
sum_bb -= 16.0f * sum_b * sum_b;
|
||||
sum_rg -= 16.0f * sum_r * sum_g;
|
||||
sum_rb -= 16.0f * sum_r * sum_b;
|
||||
sum_gb -= 16.0f * sum_g * sum_b;
|
||||
/* the point on the color line is the average */
|
||||
point[0] = sum_r;
|
||||
point[1] = sum_g;
|
||||
point[2] = sum_b;
|
||||
#if USE_COV_MAT
|
||||
/*
|
||||
The following idea was from ryg.
|
||||
(https://mollyrocket.com/forums/viewtopic.php?t=392)
|
||||
The method worked great (less RMSE than mine) most of
|
||||
the time, but had some issues handling some simple
|
||||
boundary cases, like full green next to full red,
|
||||
which would generate a covariance matrix like this:
|
||||
|
||||
| 1 -1 0 |
|
||||
| -1 1 0 |
|
||||
| 0 0 0 |
|
||||
|
||||
For a given starting vector, the power method can
|
||||
generate all zeros! So no starting with {1,1,1}
|
||||
as I was doing! This kind of error is still a
|
||||
slight posibillity, but will be very rare.
|
||||
*/
|
||||
/* use the covariance matrix directly
|
||||
(1st iteration, don't use all 1.0 values!) */
|
||||
sum_r = 1.0f;
|
||||
sum_g = 2.718281828f;
|
||||
sum_b = 3.141592654f;
|
||||
direction[0] = sum_r*sum_rr + sum_g*sum_rg + sum_b*sum_rb;
|
||||
direction[1] = sum_r*sum_rg + sum_g*sum_gg + sum_b*sum_gb;
|
||||
direction[2] = sum_r*sum_rb + sum_g*sum_gb + sum_b*sum_bb;
|
||||
/* 2nd iteration, use results from the 1st guy */
|
||||
sum_r = direction[0];
|
||||
sum_g = direction[1];
|
||||
sum_b = direction[2];
|
||||
direction[0] = sum_r*sum_rr + sum_g*sum_rg + sum_b*sum_rb;
|
||||
direction[1] = sum_r*sum_rg + sum_g*sum_gg + sum_b*sum_gb;
|
||||
direction[2] = sum_r*sum_rb + sum_g*sum_gb + sum_b*sum_bb;
|
||||
/* 3rd iteration, use results from the 2nd guy */
|
||||
sum_r = direction[0];
|
||||
sum_g = direction[1];
|
||||
sum_b = direction[2];
|
||||
direction[0] = sum_r*sum_rr + sum_g*sum_rg + sum_b*sum_rb;
|
||||
direction[1] = sum_r*sum_rg + sum_g*sum_gg + sum_b*sum_gb;
|
||||
direction[2] = sum_r*sum_rb + sum_g*sum_gb + sum_b*sum_bb;
|
||||
#else
|
||||
/* use my standard deviation method
|
||||
(very robust, a tiny bit slower and less accurate) */
|
||||
direction[0] = sqrt( sum_rr );
|
||||
direction[1] = sqrt( sum_gg );
|
||||
direction[2] = sqrt( sum_bb );
|
||||
/* which has a greater component */
|
||||
if( sum_gg > sum_rr )
|
||||
{
|
||||
/* green has greater component, so base the other signs off of green */
|
||||
if( sum_rg < 0.0f )
|
||||
{
|
||||
direction[0] = -direction[0];
|
||||
}
|
||||
if( sum_gb < 0.0f )
|
||||
{
|
||||
direction[2] = -direction[2];
|
||||
}
|
||||
} else
|
||||
{
|
||||
/* red has a greater component */
|
||||
if( sum_rg < 0.0f )
|
||||
{
|
||||
direction[1] = -direction[1];
|
||||
}
|
||||
if( sum_rb < 0.0f )
|
||||
{
|
||||
direction[2] = -direction[2];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void LSE_master_colors_max_min(
|
||||
int *cmax, int *cmin,
|
||||
int channels,
|
||||
const unsigned char *const uncompressed )
|
||||
{
|
||||
int i, j;
|
||||
/* the master colors */
|
||||
int c0[3], c1[3];
|
||||
/* used for fitting the line */
|
||||
float sum_x[] = { 0.0f, 0.0f, 0.0f };
|
||||
float sum_x2[] = { 0.0f, 0.0f, 0.0f };
|
||||
float dot_max = 1.0f, dot_min = -1.0f;
|
||||
float vec_len2 = 0.0f;
|
||||
float dot;
|
||||
/* error check */
|
||||
if( (channels < 3) || (channels > 4) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
compute_color_line_STDEV( uncompressed, channels, sum_x, sum_x2 );
|
||||
vec_len2 = 1.0f / ( 0.00001f +
|
||||
sum_x2[0]*sum_x2[0] + sum_x2[1]*sum_x2[1] + sum_x2[2]*sum_x2[2] );
|
||||
/* finding the max and min vector values */
|
||||
dot_max =
|
||||
(
|
||||
sum_x2[0] * uncompressed[0] +
|
||||
sum_x2[1] * uncompressed[1] +
|
||||
sum_x2[2] * uncompressed[2]
|
||||
);
|
||||
dot_min = dot_max;
|
||||
for( i = 1; i < 16; ++i )
|
||||
{
|
||||
dot =
|
||||
(
|
||||
sum_x2[0] * uncompressed[i*channels+0] +
|
||||
sum_x2[1] * uncompressed[i*channels+1] +
|
||||
sum_x2[2] * uncompressed[i*channels+2]
|
||||
);
|
||||
if( dot < dot_min )
|
||||
{
|
||||
dot_min = dot;
|
||||
} else if( dot > dot_max )
|
||||
{
|
||||
dot_max = dot;
|
||||
}
|
||||
}
|
||||
/* and the offset (from the average location) */
|
||||
dot = sum_x2[0]*sum_x[0] + sum_x2[1]*sum_x[1] + sum_x2[2]*sum_x[2];
|
||||
dot_min -= dot;
|
||||
dot_max -= dot;
|
||||
/* post multiply by the scaling factor */
|
||||
dot_min *= vec_len2;
|
||||
dot_max *= vec_len2;
|
||||
/* OK, build the master colors */
|
||||
for( i = 0; i < 3; ++i )
|
||||
{
|
||||
/* color 0 */
|
||||
c0[i] = (int)(0.5f + sum_x[i] + dot_max * sum_x2[i]);
|
||||
if( c0[i] < 0 )
|
||||
{
|
||||
c0[i] = 0;
|
||||
} else if( c0[i] > 255 )
|
||||
{
|
||||
c0[i] = 255;
|
||||
}
|
||||
/* color 1 */
|
||||
c1[i] = (int)(0.5f + sum_x[i] + dot_min * sum_x2[i]);
|
||||
if( c1[i] < 0 )
|
||||
{
|
||||
c1[i] = 0;
|
||||
} else if( c1[i] > 255 )
|
||||
{
|
||||
c1[i] = 255;
|
||||
}
|
||||
}
|
||||
/* down_sample (with rounding?) */
|
||||
i = rgb_to_565( c0[0], c0[1], c0[2] );
|
||||
j = rgb_to_565( c1[0], c1[1], c1[2] );
|
||||
if( i > j )
|
||||
{
|
||||
*cmax = i;
|
||||
*cmin = j;
|
||||
} else
|
||||
{
|
||||
*cmax = j;
|
||||
*cmin = i;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
compress_DDS_color_block
|
||||
(
|
||||
int channels,
|
||||
const unsigned char *const uncompressed,
|
||||
unsigned char compressed[8]
|
||||
)
|
||||
{
|
||||
/* variables */
|
||||
int i;
|
||||
int next_bit;
|
||||
int enc_c0, enc_c1;
|
||||
int c0[4], c1[4];
|
||||
float color_line[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
float vec_len2 = 0.0f, dot_offset = 0.0f;
|
||||
/* stupid order */
|
||||
int swizzle4[] = { 0, 2, 3, 1 };
|
||||
/* get the master colors */
|
||||
LSE_master_colors_max_min( &enc_c0, &enc_c1, channels, uncompressed );
|
||||
/* store the 565 color 0 and color 1 */
|
||||
compressed[0] = (enc_c0 >> 0) & 255;
|
||||
compressed[1] = (enc_c0 >> 8) & 255;
|
||||
compressed[2] = (enc_c1 >> 0) & 255;
|
||||
compressed[3] = (enc_c1 >> 8) & 255;
|
||||
/* zero out the compressed data */
|
||||
compressed[4] = 0;
|
||||
compressed[5] = 0;
|
||||
compressed[6] = 0;
|
||||
compressed[7] = 0;
|
||||
/* reconstitute the master color vectors */
|
||||
rgb_888_from_565( enc_c0, &c0[0], &c0[1], &c0[2] );
|
||||
rgb_888_from_565( enc_c1, &c1[0], &c1[1], &c1[2] );
|
||||
/* the new vector */
|
||||
vec_len2 = 0.0f;
|
||||
for( i = 0; i < 3; ++i )
|
||||
{
|
||||
color_line[i] = (float)(c1[i] - c0[i]);
|
||||
vec_len2 += color_line[i] * color_line[i];
|
||||
}
|
||||
if( vec_len2 > 0.0f )
|
||||
{
|
||||
vec_len2 = 1.0f / vec_len2;
|
||||
}
|
||||
/* pre-proform the scaling */
|
||||
color_line[0] *= vec_len2;
|
||||
color_line[1] *= vec_len2;
|
||||
color_line[2] *= vec_len2;
|
||||
/* compute the offset (constant) portion of the dot product */
|
||||
dot_offset = color_line[0]*c0[0] + color_line[1]*c0[1] + color_line[2]*c0[2];
|
||||
/* store the rest of the bits */
|
||||
next_bit = 8*4;
|
||||
for( i = 0; i < 16; ++i )
|
||||
{
|
||||
/* find the dot product of this color, to place it on the line
|
||||
(should be [-1,1]) */
|
||||
int next_value = 0;
|
||||
float dot_product =
|
||||
color_line[0] * uncompressed[i*channels+0] +
|
||||
color_line[1] * uncompressed[i*channels+1] +
|
||||
color_line[2] * uncompressed[i*channels+2] -
|
||||
dot_offset;
|
||||
/* map to [0,3] */
|
||||
next_value = (int)( dot_product * 3.0f + 0.5f );
|
||||
if( next_value > 3 )
|
||||
{
|
||||
next_value = 3;
|
||||
} else if( next_value < 0 )
|
||||
{
|
||||
next_value = 0;
|
||||
}
|
||||
/* OK, store this value */
|
||||
compressed[next_bit >> 3] |= swizzle4[ next_value ] << (next_bit & 7);
|
||||
next_bit += 2;
|
||||
}
|
||||
/* done compressing to DXT1 */
|
||||
}
|
||||
|
||||
void
|
||||
compress_DDS_alpha_block
|
||||
(
|
||||
const unsigned char *const uncompressed,
|
||||
unsigned char compressed[8]
|
||||
)
|
||||
{
|
||||
/* variables */
|
||||
int i;
|
||||
int next_bit;
|
||||
int a0, a1;
|
||||
float scale_me;
|
||||
/* stupid order */
|
||||
int swizzle8[] = { 1, 7, 6, 5, 4, 3, 2, 0 };
|
||||
/* get the alpha limits (a0 > a1) */
|
||||
a0 = a1 = uncompressed[3];
|
||||
for( i = 4+3; i < 16*4; i += 4 )
|
||||
{
|
||||
if( uncompressed[i] > a0 )
|
||||
{
|
||||
a0 = uncompressed[i];
|
||||
} else if( uncompressed[i] < a1 )
|
||||
{
|
||||
a1 = uncompressed[i];
|
||||
}
|
||||
}
|
||||
/* store those limits, and zero the rest of the compressed dataset */
|
||||
compressed[0] = a0;
|
||||
compressed[1] = a1;
|
||||
/* zero out the compressed data */
|
||||
compressed[2] = 0;
|
||||
compressed[3] = 0;
|
||||
compressed[4] = 0;
|
||||
compressed[5] = 0;
|
||||
compressed[6] = 0;
|
||||
compressed[7] = 0;
|
||||
/* store the all of the alpha values */
|
||||
next_bit = 8*2;
|
||||
scale_me = 7.9999f / (a0 - a1);
|
||||
for( i = 3; i < 16*4; i += 4 )
|
||||
{
|
||||
/* convert this alpha value to a 3 bit number */
|
||||
int svalue;
|
||||
int value = (int)((uncompressed[i] - a1) * scale_me);
|
||||
svalue = swizzle8[ value&7 ];
|
||||
/* OK, store this value, start with the 1st byte */
|
||||
compressed[next_bit >> 3] |= svalue << (next_bit & 7);
|
||||
if( (next_bit & 7) > 5 )
|
||||
{
|
||||
/* spans 2 bytes, fill in the start of the 2nd byte */
|
||||
compressed[1 + (next_bit >> 3)] |= svalue >> (8 - (next_bit & 7) );
|
||||
}
|
||||
next_bit += 3;
|
||||
}
|
||||
/* done compressing to DXT1 */
|
||||
}
|
123
Projekt_test/src/SOIL/image_DXT.h
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
Jonathan Dummer
|
||||
2007-07-31-10.32
|
||||
|
||||
simple DXT compression / decompression code
|
||||
|
||||
public domain
|
||||
*/
|
||||
|
||||
#ifndef HEADER_IMAGE_DXT
|
||||
#define HEADER_IMAGE_DXT
|
||||
|
||||
/**
|
||||
Converts an image from an array of unsigned chars (RGB or RGBA) to
|
||||
DXT1 or DXT5, then saves the converted image to disk.
|
||||
\return 0 if failed, otherwise returns 1
|
||||
**/
|
||||
int
|
||||
save_image_as_DDS
|
||||
(
|
||||
const char *filename,
|
||||
int width, int height, int channels,
|
||||
const unsigned char *const data
|
||||
);
|
||||
|
||||
/**
|
||||
take an image and convert it to DXT1 (no alpha)
|
||||
**/
|
||||
unsigned char*
|
||||
convert_image_to_DXT1
|
||||
(
|
||||
const unsigned char *const uncompressed,
|
||||
int width, int height, int channels,
|
||||
int *out_size
|
||||
);
|
||||
|
||||
/**
|
||||
take an image and convert it to DXT5 (with alpha)
|
||||
**/
|
||||
unsigned char*
|
||||
convert_image_to_DXT5
|
||||
(
|
||||
const unsigned char *const uncompressed,
|
||||
int width, int height, int channels,
|
||||
int *out_size
|
||||
);
|
||||
|
||||
/** A bunch of DirectDraw Surface structures and flags **/
|
||||
typedef struct
|
||||
{
|
||||
unsigned int dwMagic;
|
||||
unsigned int dwSize;
|
||||
unsigned int dwFlags;
|
||||
unsigned int dwHeight;
|
||||
unsigned int dwWidth;
|
||||
unsigned int dwPitchOrLinearSize;
|
||||
unsigned int dwDepth;
|
||||
unsigned int dwMipMapCount;
|
||||
unsigned int dwReserved1[ 11 ];
|
||||
|
||||
/* DDPIXELFORMAT */
|
||||
struct
|
||||
{
|
||||
unsigned int dwSize;
|
||||
unsigned int dwFlags;
|
||||
unsigned int dwFourCC;
|
||||
unsigned int dwRGBBitCount;
|
||||
unsigned int dwRBitMask;
|
||||
unsigned int dwGBitMask;
|
||||
unsigned int dwBBitMask;
|
||||
unsigned int dwAlphaBitMask;
|
||||
}
|
||||
sPixelFormat;
|
||||
|
||||
/* DDCAPS2 */
|
||||
struct
|
||||
{
|
||||
unsigned int dwCaps1;
|
||||
unsigned int dwCaps2;
|
||||
unsigned int dwDDSX;
|
||||
unsigned int dwReserved;
|
||||
}
|
||||
sCaps;
|
||||
unsigned int dwReserved2;
|
||||
}
|
||||
DDS_header ;
|
||||
|
||||
/* the following constants were copied directly off the MSDN website */
|
||||
|
||||
/* The dwFlags member of the original DDSURFACEDESC2 structure
|
||||
can be set to one or more of the following values. */
|
||||
#define DDSD_CAPS 0x00000001
|
||||
#define DDSD_HEIGHT 0x00000002
|
||||
#define DDSD_WIDTH 0x00000004
|
||||
#define DDSD_PITCH 0x00000008
|
||||
#define DDSD_PIXELFORMAT 0x00001000
|
||||
#define DDSD_MIPMAPCOUNT 0x00020000
|
||||
#define DDSD_LINEARSIZE 0x00080000
|
||||
#define DDSD_DEPTH 0x00800000
|
||||
|
||||
/* DirectDraw Pixel Format */
|
||||
#define DDPF_ALPHAPIXELS 0x00000001
|
||||
#define DDPF_FOURCC 0x00000004
|
||||
#define DDPF_RGB 0x00000040
|
||||
|
||||
/* The dwCaps1 member of the DDSCAPS2 structure can be
|
||||
set to one or more of the following values. */
|
||||
#define DDSCAPS_COMPLEX 0x00000008
|
||||
#define DDSCAPS_TEXTURE 0x00001000
|
||||
#define DDSCAPS_MIPMAP 0x00400000
|
||||
|
||||
/* The dwCaps2 member of the DDSCAPS2 structure can be
|
||||
set to one or more of the following values. */
|
||||
#define DDSCAPS2_CUBEMAP 0x00000200
|
||||
#define DDSCAPS2_CUBEMAP_POSITIVEX 0x00000400
|
||||
#define DDSCAPS2_CUBEMAP_NEGATIVEX 0x00000800
|
||||
#define DDSCAPS2_CUBEMAP_POSITIVEY 0x00001000
|
||||
#define DDSCAPS2_CUBEMAP_NEGATIVEY 0x00002000
|
||||
#define DDSCAPS2_CUBEMAP_POSITIVEZ 0x00004000
|
||||
#define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000
|
||||
#define DDSCAPS2_VOLUME 0x00200000
|
||||
|
||||
#endif /* HEADER_IMAGE_DXT */
|
435
Projekt_test/src/SOIL/image_helper.c
Normal file
@ -0,0 +1,435 @@
|
||||
/*
|
||||
Jonathan Dummer
|
||||
|
||||
image helper functions
|
||||
|
||||
MIT license
|
||||
*/
|
||||
|
||||
#include "image_helper.h"
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
/* Upscaling the image uses simple bilinear interpolation */
|
||||
int
|
||||
up_scale_image
|
||||
(
|
||||
const unsigned char* const orig,
|
||||
int width, int height, int channels,
|
||||
unsigned char* resampled,
|
||||
int resampled_width, int resampled_height
|
||||
)
|
||||
{
|
||||
float dx, dy;
|
||||
int x, y, c;
|
||||
|
||||
/* error(s) check */
|
||||
if ( (width < 1) || (height < 1) ||
|
||||
(resampled_width < 2) || (resampled_height < 2) ||
|
||||
(channels < 1) ||
|
||||
(NULL == orig) || (NULL == resampled) )
|
||||
{
|
||||
/* signify badness */
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
for each given pixel in the new map, find the exact location
|
||||
from the original map which would contribute to this guy
|
||||
*/
|
||||
dx = (width - 1.0f) / (resampled_width - 1.0f);
|
||||
dy = (height - 1.0f) / (resampled_height - 1.0f);
|
||||
for ( y = 0; y < resampled_height; ++y )
|
||||
{
|
||||
/* find the base y index and fractional offset from that */
|
||||
float sampley = y * dy;
|
||||
int inty = (int)sampley;
|
||||
/* if( inty < 0 ) { inty = 0; } else */
|
||||
if( inty > height - 2 ) { inty = height - 2; }
|
||||
sampley -= inty;
|
||||
for ( x = 0; x < resampled_width; ++x )
|
||||
{
|
||||
float samplex = x * dx;
|
||||
int intx = (int)samplex;
|
||||
int base_index;
|
||||
/* find the base x index and fractional offset from that */
|
||||
/* if( intx < 0 ) { intx = 0; } else */
|
||||
if( intx > width - 2 ) { intx = width - 2; }
|
||||
samplex -= intx;
|
||||
/* base index into the original image */
|
||||
base_index = (inty * width + intx) * channels;
|
||||
for ( c = 0; c < channels; ++c )
|
||||
{
|
||||
/* do the sampling */
|
||||
float value = 0.5f;
|
||||
value += orig[base_index]
|
||||
*(1.0f-samplex)*(1.0f-sampley);
|
||||
value += orig[base_index+channels]
|
||||
*(samplex)*(1.0f-sampley);
|
||||
value += orig[base_index+width*channels]
|
||||
*(1.0f-samplex)*(sampley);
|
||||
value += orig[base_index+width*channels+channels]
|
||||
*(samplex)*(sampley);
|
||||
/* move to the next channel */
|
||||
++base_index;
|
||||
/* save the new value */
|
||||
resampled[y*resampled_width*channels+x*channels+c] =
|
||||
(unsigned char)(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* done */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
mipmap_image
|
||||
(
|
||||
const unsigned char* const orig,
|
||||
int width, int height, int channels,
|
||||
unsigned char* resampled,
|
||||
int block_size_x, int block_size_y
|
||||
)
|
||||
{
|
||||
int mip_width, mip_height;
|
||||
int i, j, c;
|
||||
|
||||
/* error check */
|
||||
if( (width < 1) || (height < 1) ||
|
||||
(channels < 1) || (orig == NULL) ||
|
||||
(resampled == NULL) ||
|
||||
(block_size_x < 1) || (block_size_y < 1) )
|
||||
{
|
||||
/* nothing to do */
|
||||
return 0;
|
||||
}
|
||||
mip_width = width / block_size_x;
|
||||
mip_height = height / block_size_y;
|
||||
if( mip_width < 1 )
|
||||
{
|
||||
mip_width = 1;
|
||||
}
|
||||
if( mip_height < 1 )
|
||||
{
|
||||
mip_height = 1;
|
||||
}
|
||||
for( j = 0; j < mip_height; ++j )
|
||||
{
|
||||
for( i = 0; i < mip_width; ++i )
|
||||
{
|
||||
for( c = 0; c < channels; ++c )
|
||||
{
|
||||
const int index = (j*block_size_y)*width*channels + (i*block_size_x)*channels + c;
|
||||
int sum_value;
|
||||
int u,v;
|
||||
int u_block = block_size_x;
|
||||
int v_block = block_size_y;
|
||||
int block_area;
|
||||
/* do a bit of checking so we don't over-run the boundaries
|
||||
(necessary for non-square textures!) */
|
||||
if( block_size_x * (i+1) > width )
|
||||
{
|
||||
u_block = width - i*block_size_y;
|
||||
}
|
||||
if( block_size_y * (j+1) > height )
|
||||
{
|
||||
v_block = height - j*block_size_y;
|
||||
}
|
||||
block_area = u_block*v_block;
|
||||
/* for this pixel, see what the average
|
||||
of all the values in the block are.
|
||||
note: start the sum at the rounding value, not at 0 */
|
||||
sum_value = block_area >> 1;
|
||||
for( v = 0; v < v_block; ++v )
|
||||
for( u = 0; u < u_block; ++u )
|
||||
{
|
||||
sum_value += orig[index + v*width*channels + u*channels];
|
||||
}
|
||||
resampled[j*mip_width*channels + i*channels + c] = sum_value / block_area;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
scale_image_RGB_to_NTSC_safe
|
||||
(
|
||||
unsigned char* orig,
|
||||
int width, int height, int channels
|
||||
)
|
||||
{
|
||||
const float scale_lo = 16.0f - 0.499f;
|
||||
const float scale_hi = 235.0f + 0.499f;
|
||||
int i, j;
|
||||
int nc = channels;
|
||||
unsigned char scale_LUT[256];
|
||||
/* error check */
|
||||
if( (width < 1) || (height < 1) ||
|
||||
(channels < 1) || (orig == NULL) )
|
||||
{
|
||||
/* nothing to do */
|
||||
return 0;
|
||||
}
|
||||
/* set up the scaling Look Up Table */
|
||||
for( i = 0; i < 256; ++i )
|
||||
{
|
||||
scale_LUT[i] = (unsigned char)((scale_hi - scale_lo) * i / 255.0f + scale_lo);
|
||||
}
|
||||
/* for channels = 2 or 4, ignore the alpha component */
|
||||
nc -= 1 - (channels & 1);
|
||||
/* OK, go through the image and scale any non-alpha components */
|
||||
for( i = 0; i < width*height*channels; i += channels )
|
||||
{
|
||||
for( j = 0; j < nc; ++j )
|
||||
{
|
||||
orig[i+j] = scale_LUT[orig[i+j]];
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned char clamp_byte( int x ) { return ( (x) < 0 ? (0) : ( (x) > 255 ? 255 : (x) ) ); }
|
||||
|
||||
/*
|
||||
This function takes the RGB components of the image
|
||||
and converts them into YCoCg. 3 components will be
|
||||
re-ordered to CoYCg (for optimum DXT1 compression),
|
||||
while 4 components will be ordered CoCgAY (for DXT5
|
||||
compression).
|
||||
*/
|
||||
int
|
||||
convert_RGB_to_YCoCg
|
||||
(
|
||||
unsigned char* orig,
|
||||
int width, int height, int channels
|
||||
)
|
||||
{
|
||||
int i;
|
||||
/* error check */
|
||||
if( (width < 1) || (height < 1) ||
|
||||
(channels < 3) || (channels > 4) ||
|
||||
(orig == NULL) )
|
||||
{
|
||||
/* nothing to do */
|
||||
return -1;
|
||||
}
|
||||
/* do the conversion */
|
||||
if( channels == 3 )
|
||||
{
|
||||
for( i = 0; i < width*height*3; i += 3 )
|
||||
{
|
||||
int r = orig[i+0];
|
||||
int g = (orig[i+1] + 1) >> 1;
|
||||
int b = orig[i+2];
|
||||
int tmp = (2 + r + b) >> 2;
|
||||
/* Co */
|
||||
orig[i+0] = clamp_byte( 128 + ((r - b + 1) >> 1) );
|
||||
/* Y */
|
||||
orig[i+1] = clamp_byte( g + tmp );
|
||||
/* Cg */
|
||||
orig[i+2] = clamp_byte( 128 + g - tmp );
|
||||
}
|
||||
} else
|
||||
{
|
||||
for( i = 0; i < width*height*4; i += 4 )
|
||||
{
|
||||
int r = orig[i+0];
|
||||
int g = (orig[i+1] + 1) >> 1;
|
||||
int b = orig[i+2];
|
||||
unsigned char a = orig[i+3];
|
||||
int tmp = (2 + r + b) >> 2;
|
||||
/* Co */
|
||||
orig[i+0] = clamp_byte( 128 + ((r - b + 1) >> 1) );
|
||||
/* Cg */
|
||||
orig[i+1] = clamp_byte( 128 + g - tmp );
|
||||
/* Alpha */
|
||||
orig[i+2] = a;
|
||||
/* Y */
|
||||
orig[i+3] = clamp_byte( g + tmp );
|
||||
}
|
||||
}
|
||||
/* done */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
This function takes the YCoCg components of the image
|
||||
and converts them into RGB. See above.
|
||||
*/
|
||||
int
|
||||
convert_YCoCg_to_RGB
|
||||
(
|
||||
unsigned char* orig,
|
||||
int width, int height, int channels
|
||||
)
|
||||
{
|
||||
int i;
|
||||
/* error check */
|
||||
if( (width < 1) || (height < 1) ||
|
||||
(channels < 3) || (channels > 4) ||
|
||||
(orig == NULL) )
|
||||
{
|
||||
/* nothing to do */
|
||||
return -1;
|
||||
}
|
||||
/* do the conversion */
|
||||
if( channels == 3 )
|
||||
{
|
||||
for( i = 0; i < width*height*3; i += 3 )
|
||||
{
|
||||
int co = orig[i+0] - 128;
|
||||
int y = orig[i+1];
|
||||
int cg = orig[i+2] - 128;
|
||||
/* R */
|
||||
orig[i+0] = clamp_byte( y + co - cg );
|
||||
/* G */
|
||||
orig[i+1] = clamp_byte( y + cg );
|
||||
/* B */
|
||||
orig[i+2] = clamp_byte( y - co - cg );
|
||||
}
|
||||
} else
|
||||
{
|
||||
for( i = 0; i < width*height*4; i += 4 )
|
||||
{
|
||||
int co = orig[i+0] - 128;
|
||||
int cg = orig[i+1] - 128;
|
||||
unsigned char a = orig[i+2];
|
||||
int y = orig[i+3];
|
||||
/* R */
|
||||
orig[i+0] = clamp_byte( y + co - cg );
|
||||
/* G */
|
||||
orig[i+1] = clamp_byte( y + cg );
|
||||
/* B */
|
||||
orig[i+2] = clamp_byte( y - co - cg );
|
||||
/* A */
|
||||
orig[i+3] = a;
|
||||
}
|
||||
}
|
||||
/* done */
|
||||
return 0;
|
||||
}
|
||||
|
||||
float
|
||||
find_max_RGBE
|
||||
(
|
||||
unsigned char *image,
|
||||
int width, int height
|
||||
)
|
||||
{
|
||||
float max_val = 0.0f;
|
||||
unsigned char *img = image;
|
||||
int i, j;
|
||||
for( i = width * height; i > 0; --i )
|
||||
{
|
||||
/* float scale = powf( 2.0f, img[3] - 128.0f ) / 255.0f; */
|
||||
float scale = ldexp( 1.0f / 255.0f, (int)(img[3]) - 128 );
|
||||
for( j = 0; j < 3; ++j )
|
||||
{
|
||||
if( img[j] * scale > max_val )
|
||||
{
|
||||
max_val = img[j] * scale;
|
||||
}
|
||||
}
|
||||
/* next pixel */
|
||||
img += 4;
|
||||
}
|
||||
return max_val;
|
||||
}
|
||||
|
||||
int
|
||||
RGBE_to_RGBdivA
|
||||
(
|
||||
unsigned char *image,
|
||||
int width, int height,
|
||||
int rescale_to_max
|
||||
)
|
||||
{
|
||||
/* local variables */
|
||||
int i, iv;
|
||||
unsigned char *img = image;
|
||||
float scale = 1.0f;
|
||||
/* error check */
|
||||
if( (!image) || (width < 1) || (height < 1) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* convert (note: no negative numbers, but 0.0 is possible) */
|
||||
if( rescale_to_max )
|
||||
{
|
||||
scale = 255.0f / find_max_RGBE( image, width, height );
|
||||
}
|
||||
for( i = width * height; i > 0; --i )
|
||||
{
|
||||
/* decode this pixel, and find the max */
|
||||
float r,g,b,e, m;
|
||||
/* e = scale * powf( 2.0f, img[3] - 128.0f ) / 255.0f; */
|
||||
e = scale * ldexp( 1.0f / 255.0f, (int)(img[3]) - 128 );
|
||||
r = e * img[0];
|
||||
g = e * img[1];
|
||||
b = e * img[2];
|
||||
m = (r > g) ? r : g;
|
||||
m = (b > m) ? b : m;
|
||||
/* and encode it into RGBdivA */
|
||||
iv = (m != 0.0f) ? (int)(255.0f / m) : 1.0f;
|
||||
iv = (iv < 1) ? 1 : iv;
|
||||
img[3] = (iv > 255) ? 255 : iv;
|
||||
iv = (int)(img[3] * r + 0.5f);
|
||||
img[0] = (iv > 255) ? 255 : iv;
|
||||
iv = (int)(img[3] * g + 0.5f);
|
||||
img[1] = (iv > 255) ? 255 : iv;
|
||||
iv = (int)(img[3] * b + 0.5f);
|
||||
img[2] = (iv > 255) ? 255 : iv;
|
||||
/* and on to the next pixel */
|
||||
img += 4;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
RGBE_to_RGBdivA2
|
||||
(
|
||||
unsigned char *image,
|
||||
int width, int height,
|
||||
int rescale_to_max
|
||||
)
|
||||
{
|
||||
/* local variables */
|
||||
int i, iv;
|
||||
unsigned char *img = image;
|
||||
float scale = 1.0f;
|
||||
/* error check */
|
||||
if( (!image) || (width < 1) || (height < 1) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/* convert (note: no negative numbers, but 0.0 is possible) */
|
||||
if( rescale_to_max )
|
||||
{
|
||||
scale = 255.0f * 255.0f / find_max_RGBE( image, width, height );
|
||||
}
|
||||
for( i = width * height; i > 0; --i )
|
||||
{
|
||||
/* decode this pixel, and find the max */
|
||||
float r,g,b,e, m;
|
||||
/* e = scale * powf( 2.0f, img[3] - 128.0f ) / 255.0f; */
|
||||
e = scale * ldexp( 1.0f / 255.0f, (int)(img[3]) - 128 );
|
||||
r = e * img[0];
|
||||
g = e * img[1];
|
||||
b = e * img[2];
|
||||
m = (r > g) ? r : g;
|
||||
m = (b > m) ? b : m;
|
||||
/* and encode it into RGBdivA */
|
||||
iv = (m != 0.0f) ? (int)sqrtf( 255.0f * 255.0f / m ) : 1.0f;
|
||||
iv = (iv < 1) ? 1 : iv;
|
||||
img[3] = (iv > 255) ? 255 : iv;
|
||||
iv = (int)(img[3] * img[3] * r / 255.0f + 0.5f);
|
||||
img[0] = (iv > 255) ? 255 : iv;
|
||||
iv = (int)(img[3] * img[3] * g / 255.0f + 0.5f);
|
||||
img[1] = (iv > 255) ? 255 : iv;
|
||||
iv = (int)(img[3] * img[3] * b / 255.0f + 0.5f);
|
||||
img[2] = (iv > 255) ? 255 : iv;
|
||||
/* and on to the next pixel */
|
||||
img += 4;
|
||||
}
|
||||
return 1;
|
||||
}
|
115
Projekt_test/src/SOIL/image_helper.h
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
Jonathan Dummer
|
||||
|
||||
Image helper functions
|
||||
|
||||
MIT license
|
||||
*/
|
||||
|
||||
#ifndef HEADER_IMAGE_HELPER
|
||||
#define HEADER_IMAGE_HELPER
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
This function upscales an image.
|
||||
Not to be used to create MIPmaps,
|
||||
but to make it square,
|
||||
or to make it a power-of-two sized.
|
||||
**/
|
||||
int
|
||||
up_scale_image
|
||||
(
|
||||
const unsigned char* const orig,
|
||||
int width, int height, int channels,
|
||||
unsigned char* resampled,
|
||||
int resampled_width, int resampled_height
|
||||
);
|
||||
|
||||
/**
|
||||
This function downscales an image.
|
||||
Used for creating MIPmaps,
|
||||
the incoming image should be a
|
||||
power-of-two sized.
|
||||
**/
|
||||
int
|
||||
mipmap_image
|
||||
(
|
||||
const unsigned char* const orig,
|
||||
int width, int height, int channels,
|
||||
unsigned char* resampled,
|
||||
int block_size_x, int block_size_y
|
||||
);
|
||||
|
||||
/**
|
||||
This function takes the RGB components of the image
|
||||
and scales each channel from [0,255] to [16,235].
|
||||
This makes the colors "Safe" for display on NTSC
|
||||
displays. Note that this is _NOT_ a good idea for
|
||||
loading images like normal- or height-maps!
|
||||
**/
|
||||
int
|
||||
scale_image_RGB_to_NTSC_safe
|
||||
(
|
||||
unsigned char* orig,
|
||||
int width, int height, int channels
|
||||
);
|
||||
|
||||
/**
|
||||
This function takes the RGB components of the image
|
||||
and converts them into YCoCg. 3 components will be
|
||||
re-ordered to CoYCg (for optimum DXT1 compression),
|
||||
while 4 components will be ordered CoCgAY (for DXT5
|
||||
compression).
|
||||
**/
|
||||
int
|
||||
convert_RGB_to_YCoCg
|
||||
(
|
||||
unsigned char* orig,
|
||||
int width, int height, int channels
|
||||
);
|
||||
|
||||
/**
|
||||
This function takes the YCoCg components of the image
|
||||
and converts them into RGB. See above.
|
||||
**/
|
||||
int
|
||||
convert_YCoCg_to_RGB
|
||||
(
|
||||
unsigned char* orig,
|
||||
int width, int height, int channels
|
||||
);
|
||||
|
||||
/**
|
||||
Converts an HDR image from an array
|
||||
of unsigned chars (RGBE) to RGBdivA
|
||||
\return 0 if failed, otherwise returns 1
|
||||
**/
|
||||
int
|
||||
RGBE_to_RGBdivA
|
||||
(
|
||||
unsigned char *image,
|
||||
int width, int height,
|
||||
int rescale_to_max
|
||||
);
|
||||
|
||||
/**
|
||||
Converts an HDR image from an array
|
||||
of unsigned chars (RGBE) to RGBdivA2
|
||||
\return 0 if failed, otherwise returns 1
|
||||
**/
|
||||
int
|
||||
RGBE_to_RGBdivA2
|
||||
(
|
||||
unsigned char *image,
|
||||
int width, int height,
|
||||
int rescale_to_max
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_IMAGE_HELPER */
|
3682
Projekt_test/src/SOIL/stb_image_aug.c
Normal file
354
Projekt_test/src/SOIL/stb_image_aug.h
Normal file
@ -0,0 +1,354 @@
|
||||
/* stbi-1.16 - public domain JPEG/PNG reader - http://nothings.org/stb_image.c
|
||||
when you control the images you're loading
|
||||
|
||||
QUICK NOTES:
|
||||
Primarily of interest to game developers and other people who can
|
||||
avoid problematic images and only need the trivial interface
|
||||
|
||||
JPEG baseline (no JPEG progressive, no oddball channel decimations)
|
||||
PNG non-interlaced
|
||||
BMP non-1bpp, non-RLE
|
||||
TGA (not sure what subset, if a subset)
|
||||
PSD (composited view only, no extra channels)
|
||||
HDR (radiance rgbE format)
|
||||
writes BMP,TGA (define STBI_NO_WRITE to remove code)
|
||||
decoded from memory or through stdio FILE (define STBI_NO_STDIO to remove code)
|
||||
supports installable dequantizing-IDCT, YCbCr-to-RGB conversion (define STBI_SIMD)
|
||||
|
||||
TODO:
|
||||
stbi_info_*
|
||||
|
||||
history:
|
||||
1.16 major bugfix - convert_format converted one too many pixels
|
||||
1.15 initialize some fields for thread safety
|
||||
1.14 fix threadsafe conversion bug; header-file-only version (#define STBI_HEADER_FILE_ONLY before including)
|
||||
1.13 threadsafe
|
||||
1.12 const qualifiers in the API
|
||||
1.11 Support installable IDCT, colorspace conversion routines
|
||||
1.10 Fixes for 64-bit (don't use "unsigned long")
|
||||
optimized upsampling by Fabian "ryg" Giesen
|
||||
1.09 Fix format-conversion for PSD code (bad global variables!)
|
||||
1.08 Thatcher Ulrich's PSD code integrated by Nicolas Schulz
|
||||
1.07 attempt to fix C++ warning/errors again
|
||||
1.06 attempt to fix C++ warning/errors again
|
||||
1.05 fix TGA loading to return correct *comp and use good luminance calc
|
||||
1.04 default float alpha is 1, not 255; use 'void *' for stbi_image_free
|
||||
1.03 bugfixes to STBI_NO_STDIO, STBI_NO_HDR
|
||||
1.02 support for (subset of) HDR files, float interface for preferred access to them
|
||||
1.01 fix bug: possible bug in handling right-side up bmps... not sure
|
||||
fix bug: the stbi_bmp_load() and stbi_tga_load() functions didn't work at all
|
||||
1.00 interface to zlib that skips zlib header
|
||||
0.99 correct handling of alpha in palette
|
||||
0.98 TGA loader by lonesock; dynamically add loaders (untested)
|
||||
0.97 jpeg errors on too large a file; also catch another malloc failure
|
||||
0.96 fix detection of invalid v value - particleman@mollyrocket forum
|
||||
0.95 during header scan, seek to markers in case of padding
|
||||
0.94 STBI_NO_STDIO to disable stdio usage; rename all #defines the same
|
||||
0.93 handle jpegtran output; verbose errors
|
||||
0.92 read 4,8,16,24,32-bit BMP files of several formats
|
||||
0.91 output 24-bit Windows 3.0 BMP files
|
||||
0.90 fix a few more warnings; bump version number to approach 1.0
|
||||
0.61 bugfixes due to Marc LeBlanc, Christopher Lloyd
|
||||
0.60 fix compiling as c++
|
||||
0.59 fix warnings: merge Dave Moore's -Wall fixes
|
||||
0.58 fix bug: zlib uncompressed mode len/nlen was wrong endian
|
||||
0.57 fix bug: jpg last huffman symbol before marker was >9 bits but less
|
||||
than 16 available
|
||||
0.56 fix bug: zlib uncompressed mode len vs. nlen
|
||||
0.55 fix bug: restart_interval not initialized to 0
|
||||
0.54 allow NULL for 'int *comp'
|
||||
0.53 fix bug in png 3->4; speedup png decoding
|
||||
0.52 png handles req_comp=3,4 directly; minor cleanup; jpeg comments
|
||||
0.51 obey req_comp requests, 1-component jpegs return as 1-component,
|
||||
on 'test' only check type, not whether we support this variant
|
||||
*/
|
||||
|
||||
#ifndef HEADER_STB_IMAGE_AUGMENTED
|
||||
#define HEADER_STB_IMAGE_AUGMENTED
|
||||
|
||||
//// begin header file ////////////////////////////////////////////////////
|
||||
//
|
||||
// Limitations:
|
||||
// - no progressive/interlaced support (jpeg, png)
|
||||
// - 8-bit samples only (jpeg, png)
|
||||
// - not threadsafe
|
||||
// - channel subsampling of at most 2 in each dimension (jpeg)
|
||||
// - no delayed line count (jpeg) -- IJG doesn't support either
|
||||
//
|
||||
// Basic usage (see HDR discussion below):
|
||||
// int x,y,n;
|
||||
// unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
|
||||
// // ... process data if not NULL ...
|
||||
// // ... x = width, y = height, n = # 8-bit components per pixel ...
|
||||
// // ... replace '0' with '1'..'4' to force that many components per pixel
|
||||
// stbi_image_free(data)
|
||||
//
|
||||
// Standard parameters:
|
||||
// int *x -- outputs image width in pixels
|
||||
// int *y -- outputs image height in pixels
|
||||
// int *comp -- outputs # of image components in image file
|
||||
// int req_comp -- if non-zero, # of image components requested in result
|
||||
//
|
||||
// The return value from an image loader is an 'unsigned char *' which points
|
||||
// to the pixel data. The pixel data consists of *y scanlines of *x pixels,
|
||||
// with each pixel consisting of N interleaved 8-bit components; the first
|
||||
// pixel pointed to is top-left-most in the image. There is no padding between
|
||||
// image scanlines or between pixels, regardless of format. The number of
|
||||
// components N is 'req_comp' if req_comp is non-zero, or *comp otherwise.
|
||||
// If req_comp is non-zero, *comp has the number of components that _would_
|
||||
// have been output otherwise. E.g. if you set req_comp to 4, you will always
|
||||
// get RGBA output, but you can check *comp to easily see if it's opaque.
|
||||
//
|
||||
// An output image with N components has the following components interleaved
|
||||
// in this order in each pixel:
|
||||
//
|
||||
// N=#comp components
|
||||
// 1 grey
|
||||
// 2 grey, alpha
|
||||
// 3 red, green, blue
|
||||
// 4 red, green, blue, alpha
|
||||
//
|
||||
// If image loading fails for any reason, the return value will be NULL,
|
||||
// and *x, *y, *comp will be unchanged. The function stbi_failure_reason()
|
||||
// can be queried for an extremely brief, end-user unfriendly explanation
|
||||
// of why the load failed. Define STBI_NO_FAILURE_STRINGS to avoid
|
||||
// compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly
|
||||
// more user-friendly ones.
|
||||
//
|
||||
// Paletted PNG and BMP images are automatically depalettized.
|
||||
//
|
||||
//
|
||||
// ===========================================================================
|
||||
//
|
||||
// HDR image support (disable by defining STBI_NO_HDR)
|
||||
//
|
||||
// stb_image now supports loading HDR images in general, and currently
|
||||
// the Radiance .HDR file format, although the support is provided
|
||||
// generically. You can still load any file through the existing interface;
|
||||
// if you attempt to load an HDR file, it will be automatically remapped to
|
||||
// LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
|
||||
// both of these constants can be reconfigured through this interface:
|
||||
//
|
||||
// stbi_hdr_to_ldr_gamma(2.2f);
|
||||
// stbi_hdr_to_ldr_scale(1.0f);
|
||||
//
|
||||
// (note, do not use _inverse_ constants; stbi_image will invert them
|
||||
// appropriately).
|
||||
//
|
||||
// Additionally, there is a new, parallel interface for loading files as
|
||||
// (linear) floats to preserve the full dynamic range:
|
||||
//
|
||||
// float *data = stbi_loadf(filename, &x, &y, &n, 0);
|
||||
//
|
||||
// If you load LDR images through this interface, those images will
|
||||
// be promoted to floating point values, run through the inverse of
|
||||
// constants corresponding to the above:
|
||||
//
|
||||
// stbi_ldr_to_hdr_scale(1.0f);
|
||||
// stbi_ldr_to_hdr_gamma(2.2f);
|
||||
//
|
||||
// Finally, given a filename (or an open file or memory block--see header
|
||||
// file for details) containing image data, you can query for the "most
|
||||
// appropriate" interface to use (that is, whether the image is HDR or
|
||||
// not), using:
|
||||
//
|
||||
// stbi_is_hdr(char *filename);
|
||||
|
||||
#ifndef STBI_NO_STDIO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define STBI_VERSION 1
|
||||
|
||||
enum
|
||||
{
|
||||
STBI_default = 0, // only used for req_comp
|
||||
|
||||
STBI_grey = 1,
|
||||
STBI_grey_alpha = 2,
|
||||
STBI_rgb = 3,
|
||||
STBI_rgb_alpha = 4,
|
||||
};
|
||||
|
||||
typedef unsigned char stbi_uc;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// WRITING API
|
||||
|
||||
#if !defined(STBI_NO_WRITE) && !defined(STBI_NO_STDIO)
|
||||
// write a BMP/TGA file given tightly packed 'comp' channels (no padding, nor bmp-stride-padding)
|
||||
// (you must include the appropriate extension in the filename).
|
||||
// returns TRUE on success, FALSE if couldn't open file, error writing file
|
||||
extern int stbi_write_bmp (char const *filename, int x, int y, int comp, void *data);
|
||||
extern int stbi_write_tga (char const *filename, int x, int y, int comp, void *data);
|
||||
#endif
|
||||
|
||||
// PRIMARY API - works on images of any type
|
||||
|
||||
// load image by filename, open file, or memory buffer
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern stbi_uc *stbi_load (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
extern int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
|
||||
#endif
|
||||
extern stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
// for stbi_load_from_file, file pointer is left pointing immediately after image
|
||||
|
||||
#ifndef STBI_NO_HDR
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern float *stbi_loadf (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
#endif
|
||||
extern float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
|
||||
extern void stbi_hdr_to_ldr_gamma(float gamma);
|
||||
extern void stbi_hdr_to_ldr_scale(float scale);
|
||||
|
||||
extern void stbi_ldr_to_hdr_gamma(float gamma);
|
||||
extern void stbi_ldr_to_hdr_scale(float scale);
|
||||
|
||||
#endif // STBI_NO_HDR
|
||||
|
||||
// get a VERY brief reason for failure
|
||||
// NOT THREADSAFE
|
||||
extern char *stbi_failure_reason (void);
|
||||
|
||||
// free the loaded image -- this is just free()
|
||||
extern void stbi_image_free (void *retval_from_stbi_load);
|
||||
|
||||
// get image dimensions & components without fully decoding
|
||||
extern int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
|
||||
extern int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern int stbi_info (char const *filename, int *x, int *y, int *comp);
|
||||
extern int stbi_is_hdr (char const *filename);
|
||||
extern int stbi_is_hdr_from_file(FILE *f);
|
||||
#endif
|
||||
|
||||
// ZLIB client - used by PNG, available for other purposes
|
||||
|
||||
extern char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
|
||||
extern char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);
|
||||
extern int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
|
||||
|
||||
extern char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
|
||||
extern int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
|
||||
|
||||
// TYPE-SPECIFIC ACCESS
|
||||
|
||||
// is it a jpeg?
|
||||
extern int stbi_jpeg_test_memory (stbi_uc const *buffer, int len);
|
||||
extern stbi_uc *stbi_jpeg_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
extern int stbi_jpeg_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
|
||||
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern stbi_uc *stbi_jpeg_load (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern int stbi_jpeg_test_file (FILE *f);
|
||||
extern stbi_uc *stbi_jpeg_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
|
||||
extern int stbi_jpeg_info (char const *filename, int *x, int *y, int *comp);
|
||||
extern int stbi_jpeg_info_from_file (FILE *f, int *x, int *y, int *comp);
|
||||
#endif
|
||||
|
||||
// is it a png?
|
||||
extern int stbi_png_test_memory (stbi_uc const *buffer, int len);
|
||||
extern stbi_uc *stbi_png_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
extern int stbi_png_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp);
|
||||
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern stbi_uc *stbi_png_load (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern int stbi_png_info (char const *filename, int *x, int *y, int *comp);
|
||||
extern int stbi_png_test_file (FILE *f);
|
||||
extern stbi_uc *stbi_png_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
extern int stbi_png_info_from_file (FILE *f, int *x, int *y, int *comp);
|
||||
#endif
|
||||
|
||||
// is it a bmp?
|
||||
extern int stbi_bmp_test_memory (stbi_uc const *buffer, int len);
|
||||
|
||||
extern stbi_uc *stbi_bmp_load (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern stbi_uc *stbi_bmp_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern int stbi_bmp_test_file (FILE *f);
|
||||
extern stbi_uc *stbi_bmp_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
#endif
|
||||
|
||||
// is it a tga?
|
||||
extern int stbi_tga_test_memory (stbi_uc const *buffer, int len);
|
||||
|
||||
extern stbi_uc *stbi_tga_load (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern stbi_uc *stbi_tga_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern int stbi_tga_test_file (FILE *f);
|
||||
extern stbi_uc *stbi_tga_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
#endif
|
||||
|
||||
// is it a psd?
|
||||
extern int stbi_psd_test_memory (stbi_uc const *buffer, int len);
|
||||
|
||||
extern stbi_uc *stbi_psd_load (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern stbi_uc *stbi_psd_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern int stbi_psd_test_file (FILE *f);
|
||||
extern stbi_uc *stbi_psd_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
#endif
|
||||
|
||||
// is it an hdr?
|
||||
extern int stbi_hdr_test_memory (stbi_uc const *buffer, int len);
|
||||
|
||||
extern float * stbi_hdr_load (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern float * stbi_hdr_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
extern stbi_uc *stbi_hdr_load_rgbe (char const *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern float * stbi_hdr_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern int stbi_hdr_test_file (FILE *f);
|
||||
extern float * stbi_hdr_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
extern stbi_uc *stbi_hdr_load_rgbe_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
#endif
|
||||
|
||||
// define new loaders
|
||||
typedef struct
|
||||
{
|
||||
int (*test_memory)(stbi_uc const *buffer, int len);
|
||||
stbi_uc * (*load_from_memory)(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
#ifndef STBI_NO_STDIO
|
||||
int (*test_file)(FILE *f);
|
||||
stbi_uc * (*load_from_file)(FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
#endif
|
||||
} stbi_loader;
|
||||
|
||||
// register a loader by filling out the above structure (you must defined ALL functions)
|
||||
// returns 1 if added or already added, 0 if not added (too many loaders)
|
||||
// NOT THREADSAFE
|
||||
extern int stbi_register_loader(stbi_loader *loader);
|
||||
|
||||
// define faster low-level operations (typically SIMD support)
|
||||
#if STBI_SIMD
|
||||
typedef void (*stbi_idct_8x8)(uint8 *out, int out_stride, short data[64], unsigned short *dequantize);
|
||||
// compute an integer IDCT on "input"
|
||||
// input[x] = data[x] * dequantize[x]
|
||||
// write results to 'out': 64 samples, each run of 8 spaced by 'out_stride'
|
||||
// CLAMP results to 0..255
|
||||
typedef void (*stbi_YCbCr_to_RGB_run)(uint8 *output, uint8 const *y, uint8 const *cb, uint8 const *cr, int count, int step);
|
||||
// compute a conversion from YCbCr to RGB
|
||||
// 'count' pixels
|
||||
// write pixels to 'output'; each pixel is 'step' bytes (either 3 or 4; if 4, write '255' as 4th), order R,G,B
|
||||
// y: Y input channel
|
||||
// cb: Cb input channel; scale/biased to be 0..255
|
||||
// cr: Cr input channel; scale/biased to be 0..255
|
||||
|
||||
extern void stbi_install_idct(stbi_idct_8x8 func);
|
||||
extern void stbi_install_YCbCr_to_RGB(stbi_YCbCr_to_RGB_run func);
|
||||
#endif // STBI_SIMD
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
//
|
||||
//// end header file /////////////////////////////////////////////////////
|
||||
#endif // STBI_INCLUDE_STB_IMAGE_H
|
21
Projekt_test/src/SOIL/stbi_DDS_aug.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
adding DDS loading support to stbi
|
||||
*/
|
||||
|
||||
#ifndef HEADER_STB_IMAGE_DDS_AUGMENTATION
|
||||
#define HEADER_STB_IMAGE_DDS_AUGMENTATION
|
||||
|
||||
// is it a DDS file?
|
||||
extern int stbi_dds_test_memory (stbi_uc const *buffer, int len);
|
||||
|
||||
extern stbi_uc *stbi_dds_load (char *filename, int *x, int *y, int *comp, int req_comp);
|
||||
extern stbi_uc *stbi_dds_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
||||
#ifndef STBI_NO_STDIO
|
||||
extern int stbi_dds_test_file (FILE *f);
|
||||
extern stbi_uc *stbi_dds_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
||||
#endif
|
||||
|
||||
//
|
||||
//
|
||||
//// end header file /////////////////////////////////////////////////////
|
||||
#endif // HEADER_STB_IMAGE_DDS_AUGMENTATION
|
511
Projekt_test/src/SOIL/stbi_DDS_aug_c.h
Normal file
@ -0,0 +1,511 @@
|
||||
|
||||
/// DDS file support, does decoding, _not_ direct uploading
|
||||
/// (use SOIL for that ;-)
|
||||
|
||||
/// A bunch of DirectDraw Surface structures and flags
|
||||
typedef struct {
|
||||
unsigned int dwMagic;
|
||||
unsigned int dwSize;
|
||||
unsigned int dwFlags;
|
||||
unsigned int dwHeight;
|
||||
unsigned int dwWidth;
|
||||
unsigned int dwPitchOrLinearSize;
|
||||
unsigned int dwDepth;
|
||||
unsigned int dwMipMapCount;
|
||||
unsigned int dwReserved1[ 11 ];
|
||||
|
||||
// DDPIXELFORMAT
|
||||
struct {
|
||||
unsigned int dwSize;
|
||||
unsigned int dwFlags;
|
||||
unsigned int dwFourCC;
|
||||
unsigned int dwRGBBitCount;
|
||||
unsigned int dwRBitMask;
|
||||
unsigned int dwGBitMask;
|
||||
unsigned int dwBBitMask;
|
||||
unsigned int dwAlphaBitMask;
|
||||
} sPixelFormat;
|
||||
|
||||
// DDCAPS2
|
||||
struct {
|
||||
unsigned int dwCaps1;
|
||||
unsigned int dwCaps2;
|
||||
unsigned int dwDDSX;
|
||||
unsigned int dwReserved;
|
||||
} sCaps;
|
||||
unsigned int dwReserved2;
|
||||
} DDS_header ;
|
||||
|
||||
// the following constants were copied directly off the MSDN website
|
||||
|
||||
// The dwFlags member of the original DDSURFACEDESC2 structure
|
||||
// can be set to one or more of the following values.
|
||||
#define DDSD_CAPS 0x00000001
|
||||
#define DDSD_HEIGHT 0x00000002
|
||||
#define DDSD_WIDTH 0x00000004
|
||||
#define DDSD_PITCH 0x00000008
|
||||
#define DDSD_PIXELFORMAT 0x00001000
|
||||
#define DDSD_MIPMAPCOUNT 0x00020000
|
||||
#define DDSD_LINEARSIZE 0x00080000
|
||||
#define DDSD_DEPTH 0x00800000
|
||||
|
||||
// DirectDraw Pixel Format
|
||||
#define DDPF_ALPHAPIXELS 0x00000001
|
||||
#define DDPF_FOURCC 0x00000004
|
||||
#define DDPF_RGB 0x00000040
|
||||
|
||||
// The dwCaps1 member of the DDSCAPS2 structure can be
|
||||
// set to one or more of the following values.
|
||||
#define DDSCAPS_COMPLEX 0x00000008
|
||||
#define DDSCAPS_TEXTURE 0x00001000
|
||||
#define DDSCAPS_MIPMAP 0x00400000
|
||||
|
||||
// The dwCaps2 member of the DDSCAPS2 structure can be
|
||||
// set to one or more of the following values.
|
||||
#define DDSCAPS2_CUBEMAP 0x00000200
|
||||
#define DDSCAPS2_CUBEMAP_POSITIVEX 0x00000400
|
||||
#define DDSCAPS2_CUBEMAP_NEGATIVEX 0x00000800
|
||||
#define DDSCAPS2_CUBEMAP_POSITIVEY 0x00001000
|
||||
#define DDSCAPS2_CUBEMAP_NEGATIVEY 0x00002000
|
||||
#define DDSCAPS2_CUBEMAP_POSITIVEZ 0x00004000
|
||||
#define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000
|
||||
#define DDSCAPS2_VOLUME 0x00200000
|
||||
|
||||
static int dds_test(stbi *s)
|
||||
{
|
||||
// check the magic number
|
||||
if (get8(s) != 'D') return 0;
|
||||
if (get8(s) != 'D') return 0;
|
||||
if (get8(s) != 'S') return 0;
|
||||
if (get8(s) != ' ') return 0;
|
||||
// check header size
|
||||
if (get32le(s) != 124) return 0;
|
||||
return 1;
|
||||
}
|
||||
#ifndef STBI_NO_STDIO
|
||||
int stbi_dds_test_file (FILE *f)
|
||||
{
|
||||
stbi s;
|
||||
int r,n = ftell(f);
|
||||
start_file(&s,f);
|
||||
r = dds_test(&s);
|
||||
fseek(f,n,SEEK_SET);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
int stbi_dds_test_memory (stbi_uc const *buffer, int len)
|
||||
{
|
||||
stbi s;
|
||||
start_mem(&s,buffer, len);
|
||||
return dds_test(&s);
|
||||
}
|
||||
|
||||
// helper functions
|
||||
int stbi_convert_bit_range( int c, int from_bits, int to_bits )
|
||||
{
|
||||
int b = (1 << (from_bits - 1)) + c * ((1 << to_bits) - 1);
|
||||
return (b + (b >> from_bits)) >> from_bits;
|
||||
}
|
||||
void stbi_rgb_888_from_565( unsigned int c, int *r, int *g, int *b )
|
||||
{
|
||||
*r = stbi_convert_bit_range( (c >> 11) & 31, 5, 8 );
|
||||
*g = stbi_convert_bit_range( (c >> 05) & 63, 6, 8 );
|
||||
*b = stbi_convert_bit_range( (c >> 00) & 31, 5, 8 );
|
||||
}
|
||||
void stbi_decode_DXT1_block(
|
||||
unsigned char uncompressed[16*4],
|
||||
unsigned char compressed[8] )
|
||||
{
|
||||
int next_bit = 4*8;
|
||||
int i, r, g, b;
|
||||
int c0, c1;
|
||||
unsigned char decode_colors[4*4];
|
||||
// find the 2 primary colors
|
||||
c0 = compressed[0] + (compressed[1] << 8);
|
||||
c1 = compressed[2] + (compressed[3] << 8);
|
||||
stbi_rgb_888_from_565( c0, &r, &g, &b );
|
||||
decode_colors[0] = r;
|
||||
decode_colors[1] = g;
|
||||
decode_colors[2] = b;
|
||||
decode_colors[3] = 255;
|
||||
stbi_rgb_888_from_565( c1, &r, &g, &b );
|
||||
decode_colors[4] = r;
|
||||
decode_colors[5] = g;
|
||||
decode_colors[6] = b;
|
||||
decode_colors[7] = 255;
|
||||
if( c0 > c1 )
|
||||
{
|
||||
// no alpha, 2 interpolated colors
|
||||
decode_colors[8] = (2*decode_colors[0] + decode_colors[4]) / 3;
|
||||
decode_colors[9] = (2*decode_colors[1] + decode_colors[5]) / 3;
|
||||
decode_colors[10] = (2*decode_colors[2] + decode_colors[6]) / 3;
|
||||
decode_colors[11] = 255;
|
||||
decode_colors[12] = (decode_colors[0] + 2*decode_colors[4]) / 3;
|
||||
decode_colors[13] = (decode_colors[1] + 2*decode_colors[5]) / 3;
|
||||
decode_colors[14] = (decode_colors[2] + 2*decode_colors[6]) / 3;
|
||||
decode_colors[15] = 255;
|
||||
} else
|
||||
{
|
||||
// 1 interpolated color, alpha
|
||||
decode_colors[8] = (decode_colors[0] + decode_colors[4]) / 2;
|
||||
decode_colors[9] = (decode_colors[1] + decode_colors[5]) / 2;
|
||||
decode_colors[10] = (decode_colors[2] + decode_colors[6]) / 2;
|
||||
decode_colors[11] = 255;
|
||||
decode_colors[12] = 0;
|
||||
decode_colors[13] = 0;
|
||||
decode_colors[14] = 0;
|
||||
decode_colors[15] = 0;
|
||||
}
|
||||
// decode the block
|
||||
for( i = 0; i < 16*4; i += 4 )
|
||||
{
|
||||
int idx = ((compressed[next_bit>>3] >> (next_bit & 7)) & 3) * 4;
|
||||
next_bit += 2;
|
||||
uncompressed[i+0] = decode_colors[idx+0];
|
||||
uncompressed[i+1] = decode_colors[idx+1];
|
||||
uncompressed[i+2] = decode_colors[idx+2];
|
||||
uncompressed[i+3] = decode_colors[idx+3];
|
||||
}
|
||||
// done
|
||||
}
|
||||
void stbi_decode_DXT23_alpha_block(
|
||||
unsigned char uncompressed[16*4],
|
||||
unsigned char compressed[8] )
|
||||
{
|
||||
int i, next_bit = 0;
|
||||
// each alpha value gets 4 bits
|
||||
for( i = 3; i < 16*4; i += 4 )
|
||||
{
|
||||
uncompressed[i] = stbi_convert_bit_range(
|
||||
(compressed[next_bit>>3] >> (next_bit&7)) & 15,
|
||||
4, 8 );
|
||||
next_bit += 4;
|
||||
}
|
||||
}
|
||||
void stbi_decode_DXT45_alpha_block(
|
||||
unsigned char uncompressed[16*4],
|
||||
unsigned char compressed[8] )
|
||||
{
|
||||
int i, next_bit = 8*2;
|
||||
unsigned char decode_alpha[8];
|
||||
// each alpha value gets 3 bits, and the 1st 2 bytes are the range
|
||||
decode_alpha[0] = compressed[0];
|
||||
decode_alpha[1] = compressed[1];
|
||||
if( decode_alpha[0] > decode_alpha[1] )
|
||||
{
|
||||
// 6 step intermediate
|
||||
decode_alpha[2] = (6*decode_alpha[0] + 1*decode_alpha[1]) / 7;
|
||||
decode_alpha[3] = (5*decode_alpha[0] + 2*decode_alpha[1]) / 7;
|
||||
decode_alpha[4] = (4*decode_alpha[0] + 3*decode_alpha[1]) / 7;
|
||||
decode_alpha[5] = (3*decode_alpha[0] + 4*decode_alpha[1]) / 7;
|
||||
decode_alpha[6] = (2*decode_alpha[0] + 5*decode_alpha[1]) / 7;
|
||||
decode_alpha[7] = (1*decode_alpha[0] + 6*decode_alpha[1]) / 7;
|
||||
} else
|
||||
{
|
||||
// 4 step intermediate, pluss full and none
|
||||
decode_alpha[2] = (4*decode_alpha[0] + 1*decode_alpha[1]) / 5;
|
||||
decode_alpha[3] = (3*decode_alpha[0] + 2*decode_alpha[1]) / 5;
|
||||
decode_alpha[4] = (2*decode_alpha[0] + 3*decode_alpha[1]) / 5;
|
||||
decode_alpha[5] = (1*decode_alpha[0] + 4*decode_alpha[1]) / 5;
|
||||
decode_alpha[6] = 0;
|
||||
decode_alpha[7] = 255;
|
||||
}
|
||||
for( i = 3; i < 16*4; i += 4 )
|
||||
{
|
||||
int idx = 0, bit;
|
||||
bit = (compressed[next_bit>>3] >> (next_bit&7)) & 1;
|
||||
idx += bit << 0;
|
||||
++next_bit;
|
||||
bit = (compressed[next_bit>>3] >> (next_bit&7)) & 1;
|
||||
idx += bit << 1;
|
||||
++next_bit;
|
||||
bit = (compressed[next_bit>>3] >> (next_bit&7)) & 1;
|
||||
idx += bit << 2;
|
||||
++next_bit;
|
||||
uncompressed[i] = decode_alpha[idx & 7];
|
||||
}
|
||||
// done
|
||||
}
|
||||
void stbi_decode_DXT_color_block(
|
||||
unsigned char uncompressed[16*4],
|
||||
unsigned char compressed[8] )
|
||||
{
|
||||
int next_bit = 4*8;
|
||||
int i, r, g, b;
|
||||
int c0, c1;
|
||||
unsigned char decode_colors[4*3];
|
||||
// find the 2 primary colors
|
||||
c0 = compressed[0] + (compressed[1] << 8);
|
||||
c1 = compressed[2] + (compressed[3] << 8);
|
||||
stbi_rgb_888_from_565( c0, &r, &g, &b );
|
||||
decode_colors[0] = r;
|
||||
decode_colors[1] = g;
|
||||
decode_colors[2] = b;
|
||||
stbi_rgb_888_from_565( c1, &r, &g, &b );
|
||||
decode_colors[3] = r;
|
||||
decode_colors[4] = g;
|
||||
decode_colors[5] = b;
|
||||
// Like DXT1, but no choicees:
|
||||
// no alpha, 2 interpolated colors
|
||||
decode_colors[6] = (2*decode_colors[0] + decode_colors[3]) / 3;
|
||||
decode_colors[7] = (2*decode_colors[1] + decode_colors[4]) / 3;
|
||||
decode_colors[8] = (2*decode_colors[2] + decode_colors[5]) / 3;
|
||||
decode_colors[9] = (decode_colors[0] + 2*decode_colors[3]) / 3;
|
||||
decode_colors[10] = (decode_colors[1] + 2*decode_colors[4]) / 3;
|
||||
decode_colors[11] = (decode_colors[2] + 2*decode_colors[5]) / 3;
|
||||
// decode the block
|
||||
for( i = 0; i < 16*4; i += 4 )
|
||||
{
|
||||
int idx = ((compressed[next_bit>>3] >> (next_bit & 7)) & 3) * 3;
|
||||
next_bit += 2;
|
||||
uncompressed[i+0] = decode_colors[idx+0];
|
||||
uncompressed[i+1] = decode_colors[idx+1];
|
||||
uncompressed[i+2] = decode_colors[idx+2];
|
||||
}
|
||||
// done
|
||||
}
|
||||
static stbi_uc *dds_load(stbi *s, int *x, int *y, int *comp, int req_comp)
|
||||
{
|
||||
// all variables go up front
|
||||
stbi_uc *dds_data = NULL;
|
||||
stbi_uc block[16*4];
|
||||
stbi_uc compressed[8];
|
||||
int flags, DXT_family;
|
||||
int has_alpha, has_mipmap;
|
||||
int is_compressed, cubemap_faces;
|
||||
int block_pitch, num_blocks;
|
||||
DDS_header header;
|
||||
int i, sz, cf;
|
||||
// load the header
|
||||
if( sizeof( DDS_header ) != 128 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
getn( s, (stbi_uc*)(&header), 128 );
|
||||
// and do some checking
|
||||
if( header.dwMagic != (('D' << 0) | ('D' << 8) | ('S' << 16) | (' ' << 24)) ) return NULL;
|
||||
if( header.dwSize != 124 ) return NULL;
|
||||
flags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
|
||||
if( (header.dwFlags & flags) != flags ) return NULL;
|
||||
/* According to the MSDN spec, the dwFlags should contain
|
||||
DDSD_LINEARSIZE if it's compressed, or DDSD_PITCH if
|
||||
uncompressed. Some DDS writers do not conform to the
|
||||
spec, so I need to make my reader more tolerant */
|
||||
if( header.sPixelFormat.dwSize != 32 ) return NULL;
|
||||
flags = DDPF_FOURCC | DDPF_RGB;
|
||||
if( (header.sPixelFormat.dwFlags & flags) == 0 ) return NULL;
|
||||
if( (header.sCaps.dwCaps1 & DDSCAPS_TEXTURE) == 0 ) return NULL;
|
||||
// get the image data
|
||||
s->img_x = header.dwWidth;
|
||||
s->img_y = header.dwHeight;
|
||||
s->img_n = 4;
|
||||
is_compressed = (header.sPixelFormat.dwFlags & DDPF_FOURCC) / DDPF_FOURCC;
|
||||
has_alpha = (header.sPixelFormat.dwFlags & DDPF_ALPHAPIXELS) / DDPF_ALPHAPIXELS;
|
||||
has_mipmap = (header.sCaps.dwCaps1 & DDSCAPS_MIPMAP) && (header.dwMipMapCount > 1);
|
||||
cubemap_faces = (header.sCaps.dwCaps2 & DDSCAPS2_CUBEMAP) / DDSCAPS2_CUBEMAP;
|
||||
/* I need cubemaps to have square faces */
|
||||
cubemap_faces &= (s->img_x == s->img_y);
|
||||
cubemap_faces *= 5;
|
||||
cubemap_faces += 1;
|
||||
block_pitch = (s->img_x+3) >> 2;
|
||||
num_blocks = block_pitch * ((s->img_y+3) >> 2);
|
||||
/* let the user know what's going on */
|
||||
*x = s->img_x;
|
||||
*y = s->img_y;
|
||||
*comp = s->img_n;
|
||||
/* is this uncompressed? */
|
||||
if( is_compressed )
|
||||
{
|
||||
/* compressed */
|
||||
// note: header.sPixelFormat.dwFourCC is something like (('D'<<0)|('X'<<8)|('T'<<16)|('1'<<24))
|
||||
DXT_family = 1 + (header.sPixelFormat.dwFourCC >> 24) - '1';
|
||||
if( (DXT_family < 1) || (DXT_family > 5) ) return NULL;
|
||||
/* check the expected size...oops, nevermind...
|
||||
those non-compliant writers leave
|
||||
dwPitchOrLinearSize == 0 */
|
||||
// passed all the tests, get the RAM for decoding
|
||||
sz = (s->img_x)*(s->img_y)*4*cubemap_faces;
|
||||
dds_data = (unsigned char*)malloc( sz );
|
||||
/* do this once for each face */
|
||||
for( cf = 0; cf < cubemap_faces; ++ cf )
|
||||
{
|
||||
// now read and decode all the blocks
|
||||
for( i = 0; i < num_blocks; ++i )
|
||||
{
|
||||
// where are we?
|
||||
int bx, by, bw=4, bh=4;
|
||||
int ref_x = 4 * (i % block_pitch);
|
||||
int ref_y = 4 * (i / block_pitch);
|
||||
// get the next block's worth of compressed data, and decompress it
|
||||
if( DXT_family == 1 )
|
||||
{
|
||||
// DXT1
|
||||
getn( s, compressed, 8 );
|
||||
stbi_decode_DXT1_block( block, compressed );
|
||||
} else if( DXT_family < 4 )
|
||||
{
|
||||
// DXT2/3
|
||||
getn( s, compressed, 8 );
|
||||
stbi_decode_DXT23_alpha_block ( block, compressed );
|
||||
getn( s, compressed, 8 );
|
||||
stbi_decode_DXT_color_block ( block, compressed );
|
||||
} else
|
||||
{
|
||||
// DXT4/5
|
||||
getn( s, compressed, 8 );
|
||||
stbi_decode_DXT45_alpha_block ( block, compressed );
|
||||
getn( s, compressed, 8 );
|
||||
stbi_decode_DXT_color_block ( block, compressed );
|
||||
}
|
||||
// is this a partial block?
|
||||
if( ref_x + 4 > s->img_x )
|
||||
{
|
||||
bw = s->img_x - ref_x;
|
||||
}
|
||||
if( ref_y + 4 > s->img_y )
|
||||
{
|
||||
bh = s->img_y - ref_y;
|
||||
}
|
||||
// now drop our decompressed data into the buffer
|
||||
for( by = 0; by < bh; ++by )
|
||||
{
|
||||
int idx = 4*((ref_y+by+cf*s->img_x)*s->img_x + ref_x);
|
||||
for( bx = 0; bx < bw*4; ++bx )
|
||||
{
|
||||
|
||||
dds_data[idx+bx] = block[by*16+bx];
|
||||
}
|
||||
}
|
||||
}
|
||||
/* done reading and decoding the main image...
|
||||
skip MIPmaps if present */
|
||||
if( has_mipmap )
|
||||
{
|
||||
int block_size = 16;
|
||||
if( DXT_family == 1 )
|
||||
{
|
||||
block_size = 8;
|
||||
}
|
||||
for( i = 1; i < header.dwMipMapCount; ++i )
|
||||
{
|
||||
int mx = s->img_x >> (i + 2);
|
||||
int my = s->img_y >> (i + 2);
|
||||
if( mx < 1 )
|
||||
{
|
||||
mx = 1;
|
||||
}
|
||||
if( my < 1 )
|
||||
{
|
||||
my = 1;
|
||||
}
|
||||
skip( s, mx*my*block_size );
|
||||
}
|
||||
}
|
||||
}/* per cubemap face */
|
||||
} else
|
||||
{
|
||||
/* uncompressed */
|
||||
DXT_family = 0;
|
||||
s->img_n = 3;
|
||||
if( has_alpha )
|
||||
{
|
||||
s->img_n = 4;
|
||||
}
|
||||
*comp = s->img_n;
|
||||
sz = s->img_x*s->img_y*s->img_n*cubemap_faces;
|
||||
dds_data = (unsigned char*)malloc( sz );
|
||||
/* do this once for each face */
|
||||
for( cf = 0; cf < cubemap_faces; ++ cf )
|
||||
{
|
||||
/* read the main image for this face */
|
||||
getn( s, &dds_data[cf*s->img_x*s->img_y*s->img_n], s->img_x*s->img_y*s->img_n );
|
||||
/* done reading and decoding the main image...
|
||||
skip MIPmaps if present */
|
||||
if( has_mipmap )
|
||||
{
|
||||
for( i = 1; i < header.dwMipMapCount; ++i )
|
||||
{
|
||||
int mx = s->img_x >> i;
|
||||
int my = s->img_y >> i;
|
||||
if( mx < 1 )
|
||||
{
|
||||
mx = 1;
|
||||
}
|
||||
if( my < 1 )
|
||||
{
|
||||
my = 1;
|
||||
}
|
||||
skip( s, mx*my*s->img_n );
|
||||
}
|
||||
}
|
||||
}
|
||||
/* data was BGR, I need it RGB */
|
||||
for( i = 0; i < sz; i += s->img_n )
|
||||
{
|
||||
unsigned char temp = dds_data[i];
|
||||
dds_data[i] = dds_data[i+2];
|
||||
dds_data[i+2] = temp;
|
||||
}
|
||||
}
|
||||
/* finished decompressing into RGBA,
|
||||
adjust the y size if we have a cubemap
|
||||
note: sz is already up to date */
|
||||
s->img_y *= cubemap_faces;
|
||||
*y = s->img_y;
|
||||
// did the user want something else, or
|
||||
// see if all the alpha values are 255 (i.e. no transparency)
|
||||
has_alpha = 0;
|
||||
if( s->img_n == 4)
|
||||
{
|
||||
for( i = 3; (i < sz) && (has_alpha == 0); i += 4 )
|
||||
{
|
||||
has_alpha |= (dds_data[i] < 255);
|
||||
}
|
||||
}
|
||||
if( (req_comp <= 4) && (req_comp >= 1) )
|
||||
{
|
||||
// user has some requirements, meet them
|
||||
if( req_comp != s->img_n )
|
||||
{
|
||||
dds_data = convert_format( dds_data, s->img_n, req_comp, s->img_x, s->img_y );
|
||||
*comp = s->img_n;
|
||||
}
|
||||
} else
|
||||
{
|
||||
// user had no requirements, only drop to RGB is no alpha
|
||||
if( (has_alpha == 0) && (s->img_n == 4) )
|
||||
{
|
||||
dds_data = convert_format( dds_data, 4, 3, s->img_x, s->img_y );
|
||||
*comp = 3;
|
||||
}
|
||||
}
|
||||
// OK, done
|
||||
return dds_data;
|
||||
}
|
||||
|
||||
#ifndef STBI_NO_STDIO
|
||||
stbi_uc *stbi_dds_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp)
|
||||
{
|
||||
stbi s;
|
||||
start_file(&s,f);
|
||||
return dds_load(&s,x,y,comp,req_comp);
|
||||
}
|
||||
|
||||
stbi_uc *stbi_dds_load (char *filename, int *x, int *y, int *comp, int req_comp)
|
||||
{
|
||||
stbi_uc *data;
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (!f) return NULL;
|
||||
data = stbi_dds_load_from_file(f,x,y,comp,req_comp);
|
||||
fclose(f);
|
||||
return data;
|
||||
}
|
||||
#endif
|
||||
|
||||
stbi_uc *stbi_dds_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
|
||||
{
|
||||
stbi s;
|
||||
start_mem(&s,buffer, len);
|
||||
return dds_load(&s,x,y,comp,req_comp);
|
||||
}
|
102
Projekt_test/src/Shader_Loader.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
#include "Shader_Loader.h"
|
||||
#include<iostream>
|
||||
#include<fstream>
|
||||
#include<vector>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
Shader_Loader::Shader_Loader(void) {}
|
||||
Shader_Loader::~Shader_Loader(void) {}
|
||||
|
||||
std::string Shader_Loader::ReadShader(const char* filename)
|
||||
{
|
||||
|
||||
std::string shaderCode;
|
||||
std::ifstream file(filename, std::ios::in);
|
||||
|
||||
if (!file.good())
|
||||
{
|
||||
std::cout << "Can't read file " << filename << std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
file.seekg(0, std::ios::end);
|
||||
shaderCode.resize((unsigned int)file.tellg());
|
||||
file.seekg(0, std::ios::beg);
|
||||
file.read(&shaderCode[0], shaderCode.size());
|
||||
file.close();
|
||||
return shaderCode;
|
||||
}
|
||||
|
||||
GLuint Shader_Loader::CreateShader(GLenum shaderType, std::string
|
||||
source, const char* shaderName)
|
||||
{
|
||||
|
||||
int compile_result = 0;
|
||||
|
||||
GLuint shader = glCreateShader(shaderType);
|
||||
const char* shader_code_ptr = source.c_str();
|
||||
const int shader_code_size = source.size();
|
||||
|
||||
glShaderSource(shader, 1, &shader_code_ptr, &shader_code_size);
|
||||
glCompileShader(shader);
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_result);
|
||||
|
||||
//sprawdz bledy
|
||||
if (compile_result == GL_FALSE)
|
||||
{
|
||||
|
||||
int info_log_length = 0;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);
|
||||
std::vector<char> shader_log(info_log_length);
|
||||
glGetShaderInfoLog(shader, info_log_length, NULL, &shader_log[0]);
|
||||
std::cout << "ERROR compiling shader: " << shaderName << std::endl << &shader_log[0] << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint Shader_Loader::CreateProgram(const char* vertexShaderFilename,
|
||||
const char* fragmentShaderFilename)
|
||||
{
|
||||
|
||||
//wczytaj shadery
|
||||
std::string vertex_shader_code = ReadShader(vertexShaderFilename);
|
||||
std::string fragment_shader_code = ReadShader(fragmentShaderFilename);
|
||||
|
||||
GLuint vertex_shader = CreateShader(GL_VERTEX_SHADER, vertex_shader_code, "vertex shader");
|
||||
GLuint fragment_shader = CreateShader(GL_FRAGMENT_SHADER, fragment_shader_code, "fragment shader");
|
||||
|
||||
int link_result = 0;
|
||||
//stworz shader
|
||||
GLuint program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
|
||||
glLinkProgram(program);
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &link_result);
|
||||
//sprawdz bledy w linkerze
|
||||
if (link_result == GL_FALSE)
|
||||
{
|
||||
|
||||
int info_log_length = 0;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length);
|
||||
std::vector<char> program_log(info_log_length);
|
||||
glGetProgramInfoLog(program, info_log_length, NULL, &program_log[0]);
|
||||
std::cout << "Shader Loader : LINK ERROR" << std::endl << &program_log[0] << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
glDetachShader(program, vertex_shader);
|
||||
glDetachShader(program, fragment_shader);
|
||||
glDeleteShader(vertex_shader);
|
||||
glDeleteShader(fragment_shader);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
void Shader_Loader::DeleteProgram(GLuint program)
|
||||
{
|
||||
glDeleteProgram(program);
|
||||
}
|
29
Projekt_test/src/Shader_Loader.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "glew.h"
|
||||
#include "freeglut.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace Core
|
||||
{
|
||||
|
||||
class Shader_Loader
|
||||
{
|
||||
private:
|
||||
|
||||
std::string ReadShader(const char* filename);
|
||||
GLuint CreateShader(GLenum shaderType,
|
||||
std::string source,
|
||||
const char* shaderName);
|
||||
|
||||
public:
|
||||
|
||||
Shader_Loader(void);
|
||||
~Shader_Loader(void);
|
||||
GLuint CreateProgram(const char* VertexShaderFilename,
|
||||
const char* FragmentShaderFilename);
|
||||
|
||||
void DeleteProgram(GLuint program);
|
||||
|
||||
};
|
||||
}
|
37
Projekt_test/src/Texture.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "Texture.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
#include "SOIL/SOIL.h"
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
GLuint Core::LoadTexture( const char * filepath )
|
||||
{
|
||||
GLuint id;
|
||||
glGenTextures(1, &id);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
int w, h;
|
||||
unsigned char* image = SOIL_load_image(filepath, &w, &h, 0, SOIL_LOAD_RGBA);
|
||||
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
SOIL_free_image_data(image);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void Core::SetActiveTexture(GLuint textureID, const char * shaderVariableName, GLuint programID, int textureUnit)
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(programID, shaderVariableName), textureUnit);
|
||||
glActiveTexture(GL_TEXTURE0 + textureUnit);
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
}
|
15
Projekt_test/src/Texture.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "glew.h"
|
||||
#include "freeglut.h"
|
||||
|
||||
namespace Core
|
||||
{
|
||||
GLuint LoadTexture(const char * filepath);
|
||||
|
||||
// textureID - identyfikator tekstury otrzymany z funkcji LoadTexture
|
||||
// shaderVariableName - nazwa zmiennej typu 'sampler2D' w shaderze, z ktora ma zostac powiazana tekstura
|
||||
// programID - identyfikator aktualnego programu karty graficznej
|
||||
// textureUnit - indeks jednostki teksturujacej - liczba od 0 do 7. Jezeli uzywa sie wielu tekstur w jednym shaderze, to kazda z nich nalezy powiazac z inna jednostka.
|
||||
void SetActiveTexture(GLuint textureID, const char * shaderVariableName, GLuint programID, int textureUnit);
|
||||
}
|
58
Projekt_test/src/main.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "glew.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <sstream> // Do formatowania stringa
|
||||
|
||||
#include "project.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// inicjalizacja glfw
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
#endif
|
||||
|
||||
// tworzenie okna za pomoca glfw
|
||||
GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL);
|
||||
if (window == NULL)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
// ladowanie OpenGL za pomoca glew
|
||||
glewInit();
|
||||
glViewport(0, 0, 500, 500);
|
||||
|
||||
init(window);
|
||||
|
||||
// Zapisz pocz¹tkowy czas
|
||||
|
||||
|
||||
// Modyfikacja g³ównej pêtli
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Obliczanie up³ywaj¹cego czasu
|
||||
|
||||
|
||||
// Reszta twojej pêtli renderowania
|
||||
renderLoop(window);
|
||||
|
||||
// Poll for and process events
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
shutdown(window);
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
291
Projekt_test/src/objload.h
Normal file
@ -0,0 +1,291 @@
|
||||
/* Copyright (c) 2012, Gerhard Reitmayr
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
||||
|
||||
#ifndef OBJLOAD_H_
|
||||
#define OBJLOAD_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace obj {
|
||||
|
||||
struct Model {
|
||||
std::vector<float> vertex; //< 3 * N entries
|
||||
std::vector<float> texCoord; //< 2 * N entries
|
||||
std::vector<float> normal; //< 3 * N entries
|
||||
|
||||
std::map<std::string, std::vector<unsigned short> > faces; //< assume triangels and uniform indexing
|
||||
};
|
||||
|
||||
struct ObjModel {
|
||||
struct FaceVertex {
|
||||
FaceVertex() : v(-1), t(-1), n(-1) {}
|
||||
int v, t, n;
|
||||
|
||||
bool operator<( const FaceVertex & other ) const;
|
||||
bool operator==( const FaceVertex & other ) const;
|
||||
};
|
||||
|
||||
typedef std::pair<std::vector<FaceVertex>, std::vector<unsigned> > FaceList;
|
||||
|
||||
std::vector<float> vertex; //< 3 * N entries
|
||||
std::vector<float> texCoord; //< 2 * N entries
|
||||
std::vector<float> normal; //< 3 * N entries
|
||||
|
||||
std::map<std::string, FaceList > faces;
|
||||
};
|
||||
|
||||
inline ObjModel parseObjModel( std::istream & in);
|
||||
inline void tesselateObjModel( ObjModel & obj);
|
||||
inline ObjModel tesselateObjModel( const ObjModel & obj );
|
||||
inline Model convertToModel( const ObjModel & obj );
|
||||
|
||||
inline Model loadModel( std::istream & in );
|
||||
inline Model loadModelFromString( const std::string & in );
|
||||
inline Model loadModelFromFile( const std::string & in );
|
||||
|
||||
inline std::ostream & operator<<( std::ostream & out, const Model & m );
|
||||
inline std::ostream & operator<<( std::ostream & out, const ObjModel::FaceVertex & f);
|
||||
|
||||
// ---------------------------- Implementation starts here -----------------------
|
||||
|
||||
inline bool ObjModel::FaceVertex::operator<( const ObjModel::FaceVertex & other ) const {
|
||||
return (v < other.v) || (v == other.v && t < other.t ) || (v == other.v && t == other.t && n < other.n);
|
||||
}
|
||||
|
||||
inline bool ObjModel::FaceVertex::operator==( const ObjModel::FaceVertex & other ) const {
|
||||
return (v == other.v && t == other.t && n == other.n);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::istream & operator>>(std::istream & in, std::vector<T> & vec ){
|
||||
T temp;
|
||||
if(in >> temp)
|
||||
vec.push_back(temp);
|
||||
return in;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::istream & operator>>(std::istream & in, std::set<T> & vec ){
|
||||
T temp;
|
||||
if(in >> temp)
|
||||
vec.insert(temp);
|
||||
return in;
|
||||
}
|
||||
|
||||
inline std::istream & operator>>( std::istream & in, ObjModel::FaceVertex & f){
|
||||
if(in >> f.v){
|
||||
if(in.peek() == '/'){
|
||||
in.get();
|
||||
in >> f.t;
|
||||
in.clear();
|
||||
if(in.peek() == '/'){
|
||||
in.get();
|
||||
in >> f.n;
|
||||
in.clear();
|
||||
}
|
||||
}
|
||||
in.clear();
|
||||
--f.v;
|
||||
--f.t;
|
||||
--f.n;
|
||||
}
|
||||
// std::cout << f << std::endl;
|
||||
return in;
|
||||
}
|
||||
|
||||
ObjModel parseObjModel( std::istream & in ){
|
||||
char line[1024];
|
||||
std::string op;
|
||||
std::istringstream line_in;
|
||||
std::set<std::string> groups;
|
||||
groups.insert("default");
|
||||
|
||||
ObjModel data;
|
||||
|
||||
while(in.good()){
|
||||
in.getline(line, 1023);
|
||||
line_in.clear();
|
||||
line_in.str(line);
|
||||
|
||||
if(!(line_in >> op))
|
||||
continue;
|
||||
if(op == "v")
|
||||
line_in >> data.vertex >> data.vertex >> data.vertex;
|
||||
else if(op == "vt")
|
||||
line_in >> data.texCoord >> data.texCoord >> data.texCoord;
|
||||
else if(op == "vn")
|
||||
line_in >> data.normal >> data.normal >> data.normal;
|
||||
else if(op == "g"){
|
||||
groups.clear();
|
||||
while(line_in >> groups) ;
|
||||
groups.insert("default");
|
||||
}
|
||||
else if(op == "f") {
|
||||
std::vector<ObjModel::FaceVertex> list;
|
||||
while(line_in >> list) ;
|
||||
|
||||
for(std::set<std::string>::const_iterator g = groups.begin(); g != groups.end(); ++g){
|
||||
ObjModel::FaceList & fl = data.faces[*g];
|
||||
fl.second.push_back(fl.first.size());
|
||||
fl.first.insert(fl.first.end(), list.begin(), list.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
for(std::map<std::string, ObjModel::FaceList>::iterator g = data.faces.begin(); g != data.faces.end(); ++g){
|
||||
ObjModel::FaceList & fl = g->second;
|
||||
fl.second.push_back(fl.first.size());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
inline void tesselateObjModel( std::vector<ObjModel::FaceVertex> & input, std::vector<unsigned> & input_start){
|
||||
std::vector<ObjModel::FaceVertex> output;
|
||||
std::vector<unsigned> output_start;
|
||||
output.reserve(input.size());
|
||||
output_start.reserve(input_start.size());
|
||||
|
||||
for(std::vector<unsigned>::const_iterator s = input_start.begin(); s != input_start.end() - 1; ++s){
|
||||
const unsigned size = *(s+1) - *s;
|
||||
if(size > 3){
|
||||
const ObjModel::FaceVertex & start_vertex = input[*s];
|
||||
for( int i = 1; i < (int)size-1; ++i){
|
||||
output_start.push_back(output.size());
|
||||
output.push_back(start_vertex);
|
||||
output.push_back(input[*s+i]);
|
||||
output.push_back(input[*s+i+1]);
|
||||
}
|
||||
} else {
|
||||
output_start.push_back(output.size());
|
||||
output.insert(output.end(), input.begin() + *s, input.begin() + *(s+1));
|
||||
}
|
||||
}
|
||||
output_start.push_back(output.size());
|
||||
input.swap(output);
|
||||
input_start.swap(output_start);
|
||||
}
|
||||
|
||||
void tesselateObjModel( ObjModel & obj){
|
||||
for(std::map<std::string, ObjModel::FaceList>::iterator g = obj.faces.begin(); g != obj.faces.end(); ++g){
|
||||
ObjModel::FaceList & fl = g->second;
|
||||
tesselateObjModel(fl.first, fl.second);
|
||||
}
|
||||
}
|
||||
|
||||
Model convertToModel( const ObjModel & obj ) {
|
||||
// insert all face vertices into a vector and make unique
|
||||
std::vector<ObjModel::FaceVertex> unique(obj.faces.find("default")->second.first);
|
||||
std::sort(unique.begin(), unique.end());
|
||||
unique.erase( std::unique(unique.begin(), unique.end()), unique.end());
|
||||
|
||||
// build a new model with repeated vertices/texcoords/normals to have single indexing
|
||||
Model model;
|
||||
for(std::vector<ObjModel::FaceVertex>::const_iterator f = unique.begin(); f != unique.end(); ++f){
|
||||
model.vertex.insert(model.vertex.end(), obj.vertex.begin() + 3*f->v, obj.vertex.begin() + 3*f->v + 3);
|
||||
if(!obj.texCoord.empty()){
|
||||
const int index = (f->t > -1) ? f->t : f->v;
|
||||
model.texCoord.insert(model.texCoord.end(), obj.texCoord.begin() + 2*index, obj.texCoord.begin() + 2*index + 2);
|
||||
}
|
||||
if(!obj.normal.empty()){
|
||||
const int index = (f->n > -1) ? f->n : f->v;
|
||||
model.normal.insert(model.normal.end(), obj.normal.begin() + 3*index, obj.normal.begin() + 3*index + 3);
|
||||
}
|
||||
}
|
||||
// look up unique index and transform face descriptions
|
||||
for(std::map<std::string, ObjModel::FaceList>::const_iterator g = obj.faces.begin(); g != obj.faces.end(); ++g){
|
||||
const std::string & name = g->first;
|
||||
const ObjModel::FaceList & fl = g->second;
|
||||
std::vector<unsigned short> & v = model.faces[g->first];
|
||||
v.reserve(fl.first.size());
|
||||
for(std::vector<ObjModel::FaceVertex>::const_iterator f = fl.first.begin(); f != fl.first.end(); ++f){
|
||||
const unsigned short index = std::distance(unique.begin(), std::lower_bound(unique.begin(), unique.end(), *f));
|
||||
v.push_back(index);
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
ObjModel tesselateObjModel( const ObjModel & obj ){
|
||||
ObjModel result = obj;
|
||||
tesselateObjModel(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Model loadModel( std::istream & in ){
|
||||
ObjModel model = parseObjModel(in);
|
||||
tesselateObjModel(model);
|
||||
return convertToModel(model);
|
||||
}
|
||||
|
||||
Model loadModelFromString( const std::string & str ){
|
||||
std::istringstream in(str);
|
||||
return loadModel(in);
|
||||
}
|
||||
|
||||
Model loadModelFromFile( const std::string & str) {
|
||||
std::ifstream in(str.c_str());
|
||||
return loadModel(in);
|
||||
}
|
||||
|
||||
inline std::ostream & operator<<( std::ostream & out, const ObjModel::FaceVertex & f){
|
||||
out << f.v << "\t" << f.t << "\t" << f.n;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream & operator<<( std::ostream & out, const Model & m ){
|
||||
if(!m.vertex.empty()){
|
||||
out << "vertex\n";
|
||||
for(int i = 0; i < (int)m.vertex.size(); ++i)
|
||||
out << m.vertex[i] << (((i % 3) == 2)?"\n":"\t");
|
||||
}
|
||||
if(!m.texCoord.empty()){
|
||||
out << "texCoord\n";
|
||||
for(int i = 0; i < (int)m.texCoord.size(); ++i)
|
||||
out << m.texCoord[i] << (((i % 2) == 1)?"\n":"\t");
|
||||
}
|
||||
if(!m.normal.empty()){
|
||||
out << "normal\n";
|
||||
for(int i = 0; i < (int)m.normal.size(); ++i)
|
||||
out << m.normal[i] << (((i % 3) == 2)?"\n":"\t");
|
||||
}
|
||||
if(!m.faces.empty()){
|
||||
out << "faces\t";
|
||||
for(std::map<std::string, std::vector<unsigned short> >::const_iterator g = m.faces.begin(); g != m.faces.end(); ++g){
|
||||
out << g->first << " ";
|
||||
}
|
||||
out << "\n";
|
||||
// for(int i = 0; i < m.face.size(); ++i)
|
||||
// out << m.face[i] << (((i % 3) == 2)?"\n":"\t");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace obj
|
||||
|
||||
#endif // OBJLOAD_H_
|
610
Projekt_test/src/project.hpp
Normal file
@ -0,0 +1,610 @@
|
||||
#include "glew.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <list>
|
||||
|
||||
#include "Shader_Loader.h"
|
||||
#include "Render_Utils.h"
|
||||
#include "Texture.h"
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
|
||||
#include "Box.cpp"
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <string>
|
||||
#include "objload.h"
|
||||
#include "SOIL/stb_image_aug.h"
|
||||
#include <Windows.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include "SOIL/SOIL.h"
|
||||
using namespace std;
|
||||
|
||||
bool rKeyWasPressed = false;
|
||||
|
||||
|
||||
|
||||
namespace texture {
|
||||
GLuint earth;
|
||||
GLuint mars;
|
||||
GLuint jupiter;
|
||||
GLuint neptune;
|
||||
GLuint saturn;
|
||||
GLuint mercury;
|
||||
GLuint venus;
|
||||
GLuint uranus;
|
||||
GLuint moon;
|
||||
GLuint ship;
|
||||
GLuint asteroid;
|
||||
GLuint sun;
|
||||
GLuint metal;
|
||||
GLuint earth_nmap;
|
||||
}
|
||||
|
||||
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
GLuint programTex;
|
||||
GLuint programEarth;
|
||||
GLuint programProcTex;
|
||||
GLuint programSkybox;
|
||||
GLuint cubemapTexture;
|
||||
GLuint programUnmap;
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
Core::RenderContext shipContext;
|
||||
Core::RenderContext stationContext;
|
||||
Core::RenderContext sphereContext;
|
||||
Core::RenderContext cubeContext;
|
||||
GLuint empty_nmap_texture = -1;
|
||||
glm::vec3 cameraPos = glm::vec3(-4.f, 0, 0);
|
||||
glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
|
||||
|
||||
glm::vec3 spaceshipPos = glm::vec3(-25.f, 0.5f, 0.f);
|
||||
glm::vec3 spaceshipDir = glm::vec3(1.f, 0.f, 0.f);
|
||||
GLuint VAO, VBO;
|
||||
|
||||
float aspectRatio = 1.777777777777778f;
|
||||
glm::vec3 lightColor = glm::vec3(0.9, 0.7, 0.8);
|
||||
|
||||
std::vector<glm::vec3> asteroidPositions;
|
||||
|
||||
const double totalTime = 90.0;
|
||||
double remainingTime = totalTime;
|
||||
|
||||
struct Planet {
|
||||
glm::vec3 startPosition;
|
||||
glm::vec3 modelScale;
|
||||
bool isActivated;
|
||||
GLuint textureID;
|
||||
std::string name;
|
||||
glm::vec3 currentPlanetPos;
|
||||
bool interacted;
|
||||
GLuint nmap_texture;
|
||||
bool isNmap;
|
||||
|
||||
};
|
||||
|
||||
std::vector<Planet> planets;
|
||||
std::vector<Planet*> targetPlanets;
|
||||
|
||||
struct Asteroid {
|
||||
glm::vec3 startPosition;
|
||||
glm::vec3 modelScale;
|
||||
glm::vec3 currentAsteroidPos;
|
||||
bool interacted;
|
||||
|
||||
};
|
||||
|
||||
std::vector<Asteroid> asteroids;
|
||||
|
||||
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraDir));
|
||||
glm::mat4 cameraRotrationMatrix = glm::mat4({
|
||||
cameraSide.x,cameraSide.y,cameraSide.z,0,
|
||||
cameraUp.x,cameraUp.y,cameraUp.z ,0,
|
||||
-cameraDir.x,-cameraDir.y,-cameraDir.z,0,
|
||||
0.,0.,0.,1.,
|
||||
});
|
||||
cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix);
|
||||
glm::mat4 cameraMatrix = cameraRotrationMatrix * glm::translate(-cameraPos);
|
||||
|
||||
return cameraMatrix;
|
||||
}
|
||||
|
||||
glm::mat4 createPerspectiveMatrix()
|
||||
{
|
||||
|
||||
glm::mat4 perspectiveMatrix;
|
||||
float n = 0.05;
|
||||
float f = 20.;
|
||||
float a1 = glm::min(aspectRatio, 1.f);
|
||||
float a2 = glm::min(1 / aspectRatio, 1.f);
|
||||
perspectiveMatrix = glm::mat4({
|
||||
1,0.,0.,0.,
|
||||
0.,aspectRatio,0.,0.,
|
||||
0.,0.,(f + n) / (n - f),2 * f * n / (n - f),
|
||||
0.,0.,-1.,0.,
|
||||
});
|
||||
|
||||
|
||||
perspectiveMatrix = glm::transpose(perspectiveMatrix);
|
||||
|
||||
return perspectiveMatrix;
|
||||
}
|
||||
|
||||
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, bool isHighlighted) {
|
||||
glUseProgram(programTex);
|
||||
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, glm::value_ptr(transformation));
|
||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
|
||||
glUniform3f(glGetUniformLocation(programTex, "lightPos"), 0, 0, 0);
|
||||
Core::SetActiveTexture(textureID, "colorTexture", programTex, 0);
|
||||
glUniform1i(glGetUniformLocation(programTex, "isHighlighted"), isHighlighted ? GL_TRUE : GL_FALSE);
|
||||
glm::vec3 highlightColor = isHighlighted ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
glUniform3fv(glGetUniformLocation(programTex, "highlightColor"), 1, glm::value_ptr(highlightColor));
|
||||
// Ustawianie uniformów dla shadera
|
||||
glUniform1f(glGetUniformLocation(programTex, "metallic"), 0.5);
|
||||
glUniform1f(glGetUniformLocation(programTex, "roughness"), 0.5);
|
||||
glUniform3fv(glGetUniformLocation(programTex, "albedo"), 1, glm::value_ptr(glm::vec3(1.0, 0.5, 0.31)));
|
||||
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
|
||||
void drawObjectTextureWithNMAP(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, bool isHighlighted, GLuint nmap_texture) {
|
||||
glUseProgram(programUnmap);
|
||||
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(programUnmap, "transformation"), 1, GL_FALSE, glm::value_ptr(transformation));
|
||||
glUniformMatrix4fv(glGetUniformLocation(programUnmap, "modelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
|
||||
glUniform3f(glGetUniformLocation(programUnmap, "lightPos"), 0, 0, 0);
|
||||
Core::SetActiveTexture(textureID, "colorTexture", programUnmap, 0);
|
||||
glUniform1i(glGetUniformLocation(programUnmap, "isHighlighted"), isHighlighted ? GL_TRUE : GL_FALSE);
|
||||
glm::vec3 highlightColor = isHighlighted ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
glUniform3fv(glGetUniformLocation(programUnmap, "highlightColor"), 1, glm::value_ptr(highlightColor));
|
||||
|
||||
glUniform1f(glGetUniformLocation(programUnmap, "metallic"), 0.3);
|
||||
glUniform1f(glGetUniformLocation(programUnmap, "roughness"), 0.5);
|
||||
glUniform3fv(glGetUniformLocation(programUnmap, "albedo"), 1, glm::value_ptr(glm::vec3(1.0, 0.5, 0.31)));
|
||||
glUniform1i(glGetUniformLocation(programUnmap, "normalMap"), 1);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, nmap_texture);
|
||||
|
||||
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
|
||||
void drawSunTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, bool isHighlighted) {
|
||||
glUseProgram(programSun);
|
||||
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, glm::value_ptr(transformation));
|
||||
glUniformMatrix4fv(glGetUniformLocation(programSun, "modelMatrix"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
glUniform3f(glGetUniformLocation(programSun, "lightPos"), 0, 0, 0);
|
||||
Core::SetActiveTexture(textureID, "colorTexture", programSun, 0);
|
||||
glUniform1i(glGetUniformLocation(programSun, "isHighlighted"), isHighlighted ? GL_TRUE : GL_FALSE);
|
||||
glm::vec3 highlightColor = isHighlighted ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
glUniform3fv(glGetUniformLocation(programSun, "highlightColor"), 1, glm::value_ptr(highlightColor));
|
||||
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
void drawObjectSkybox(Core::RenderContext& context) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glUseProgram(programSkybox);
|
||||
glm::mat4 view = createCameraMatrix();
|
||||
glm::mat4 projection = createPerspectiveMatrix();
|
||||
glm::mat4 viewProjectionMatrix = projection * glm::mat4(glm::mat3(view));
|
||||
glUniformMatrix4fv(glGetUniformLocation(programSkybox, "transformation"), 1, GL_FALSE, glm::value_ptr(viewProjectionMatrix));
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
|
||||
Core::DrawContext(cubeContext);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void renderScene(GLFWwindow* window)
|
||||
{
|
||||
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glm::mat4 transformation;
|
||||
float time = glfwGetTime();
|
||||
|
||||
drawObjectSkybox(cubeContext);
|
||||
//sun
|
||||
drawSunTexture(sphereContext, glm::mat4(), texture::sun, FALSE);
|
||||
|
||||
float rot = 1.f;
|
||||
|
||||
|
||||
for (auto& planet : planets) {
|
||||
|
||||
|
||||
|
||||
glm::mat4 modelMatrix = glm::eulerAngleY(time / rot) * glm::translate(planet.startPosition) * glm::eulerAngleY(time) * glm::scale(planet.modelScale);
|
||||
drawObjectTextureWithNMAP(sphereContext, modelMatrix, planet.textureID, planet.isActivated, texture::earth_nmap);
|
||||
planet.currentPlanetPos = glm::vec3(modelMatrix * glm::vec4(0, 0, 0, 1.0f));
|
||||
rot += 0.5f;
|
||||
}
|
||||
|
||||
drawObjectTexture(sphereContext,
|
||||
glm::eulerAngleY(time / 2.0f) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), texture::moon, FALSE);
|
||||
|
||||
drawObjectTexture(stationContext,
|
||||
glm::translate(glm::vec3(-25.f, -0.f, 0)) * glm::scale(glm::vec3(0.005f)),
|
||||
texture::metal, FALSE
|
||||
);
|
||||
|
||||
|
||||
for (auto& asteroid : asteroids) {
|
||||
glm::mat4 modelMatrix = glm::translate(asteroid.startPosition) * glm::scale(asteroid.modelScale);
|
||||
drawObjectTexture(sphereContext, modelMatrix, texture::asteroid, FALSE);
|
||||
}
|
||||
|
||||
|
||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
||||
glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
|
||||
spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
|
||||
spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
|
||||
-spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0,
|
||||
0.,0.,0.,1.,
|
||||
});
|
||||
|
||||
// This rotation matrix will rotate the spaceship by 90 degrees around the Y-axis.
|
||||
glm::mat4 rotationMatrix = glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(0, 1, 0));
|
||||
glm::mat4 rotationMatrix2 = glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(1, 0, 0));
|
||||
// Apply the rotation to the spaceship's current transformation matrix.
|
||||
glm::mat4 spaceshipModelMatrix = glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * rotationMatrix * rotationMatrix2 * glm::scale(glm::vec3(0.0003f));
|
||||
|
||||
// Now draw the spaceship with the updated model matrix.
|
||||
drawObjectTexture(shipContext, spaceshipModelMatrix, texture::ship, FALSE);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
glUseProgram(0);
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
}
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
aspectRatio = width / float(height);
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
void loadModelToContext(std::string path, Core::RenderContext& context)
|
||||
{
|
||||
Assimp::Importer import;
|
||||
const aiScene * scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace);
|
||||
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
|
||||
{
|
||||
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
|
||||
return;
|
||||
}
|
||||
context.initFromAssimpMesh(scene->mMeshes[0]);
|
||||
}
|
||||
|
||||
|
||||
void initializePlanets() {
|
||||
|
||||
planets.push_back(Planet{ glm::vec3(1.5f, 0, 0), glm::vec3(0.1f), false, texture::mercury, "Mercury", glm::vec3(1.5f, 0, 0), false, empty_nmap_texture, FALSE });
|
||||
planets.push_back(Planet{ glm::vec3(2.3f, 0, 0), glm::vec3(0.15f), false, texture::venus, "Venus", glm::vec3(2.3f, 0, 0), false, empty_nmap_texture, FALSE });
|
||||
planets.push_back(Planet{ glm::vec3(4.f, 0, 0), glm::vec3(0.25f), false, texture::earth, "Earth", glm::vec3(4.f, 0, 0), false, texture::earth_nmap, TRUE });
|
||||
planets.push_back(Planet{ glm::vec3(6.6f, 0, 0), glm::vec3(0.27f), false, texture::mars, "Mars", glm::vec3(6.6f, 0, 0), false, empty_nmap_texture, FALSE });
|
||||
planets.push_back(Planet{ glm::vec3(7.4f, 0, 0), glm::vec3(0.43f), false, texture::jupiter, "Jupiter", glm::vec3(7.4f, 0, 0), false, empty_nmap_texture, FALSE });
|
||||
planets.push_back(Planet{ glm::vec3(11.f, 0, 0), glm::vec3(0.47f), false, texture::saturn, "Saturn", glm::vec3(11.f, 0, 0), false, empty_nmap_texture, FALSE });
|
||||
planets.push_back(Planet{ glm::vec3(12.f, 0, 0), glm::vec3(0.32f), false, texture::uranus, "Uranus", glm::vec3(12.f, 0, 0), false, empty_nmap_texture, FALSE });
|
||||
planets.push_back(Planet{ glm::vec3(14.f, 0, 0), glm::vec3(0.3f), false, texture::neptune, "Neptune", glm::vec3(14.f, 0, 0), false, empty_nmap_texture, FALSE });
|
||||
}
|
||||
|
||||
void selectRandomPlanets() {
|
||||
srand(static_cast<unsigned int>(time(nullptr)));
|
||||
std::vector<int> selectedIndexes;
|
||||
|
||||
while (targetPlanets.size() < 4) {
|
||||
int randIndex = rand() % planets.size();
|
||||
|
||||
if (std::find(selectedIndexes.begin(), selectedIndexes.end(), randIndex) == selectedIndexes.end()) {
|
||||
selectedIndexes.push_back(randIndex);
|
||||
planets[randIndex].isActivated = true;
|
||||
targetPlanets.push_back(&planets[randIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initializeAsteroids() {
|
||||
asteroids.clear();
|
||||
int numberOfAsteroids = 100;
|
||||
float minX = -19.2f;
|
||||
float maxX = -16.0f;
|
||||
float minY = -2.0f;
|
||||
float maxY = 2.0f;
|
||||
float minZ = -6.0f;
|
||||
float maxZ = 6.0f;
|
||||
|
||||
for (size_t i = 0; i < numberOfAsteroids; i++) {
|
||||
float x = minX + static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / (maxX - minX)));
|
||||
float y = minY + static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / (maxY - minY)));
|
||||
float z = minZ + static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / (maxZ - minZ)));
|
||||
glm::vec3 startPos = glm::vec3(x, y, z);
|
||||
glm::vec3 scale = glm::vec3(0.07f);
|
||||
asteroids.push_back(Asteroid{ startPos, scale, startPos, false });
|
||||
}
|
||||
}
|
||||
|
||||
GLuint loadCubemap(std::vector<std::string> faces)
|
||||
{
|
||||
GLuint textureID;
|
||||
glGenTextures(1, &textureID);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
|
||||
|
||||
int width, height;
|
||||
unsigned char* image;
|
||||
|
||||
for (GLuint i = 0; i < faces.size(); i++)
|
||||
{
|
||||
image = SOIL_load_image(faces[i].c_str(), &width, &height, 0, SOIL_LOAD_RGB);
|
||||
if (image)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
||||
SOIL_free_image_data(image);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "failed: " << faces[i] << std::endl;
|
||||
SOIL_free_image_data(image);
|
||||
}
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
|
||||
return textureID;
|
||||
}
|
||||
|
||||
void init(GLFWwindow* window){
|
||||
|
||||
|
||||
std::vector<std::string> faces
|
||||
{
|
||||
"./textures/skybox/space_bk.png",
|
||||
"./textures/skybox/space_dn.png",
|
||||
"./textures/skybox/space_ft.png",
|
||||
"./textures/skybox/space_lf.png",
|
||||
"./textures/skybox/space_rt.png",
|
||||
"./textures/skybox/space_up.png"
|
||||
};
|
||||
cubemapTexture = loadCubemap(faces);
|
||||
|
||||
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
program = shaderLoader.CreateProgram("shaders/shader.vert", "shaders/shader.frag");
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||
programEarth = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||
programProcTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
|
||||
programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||
|
||||
programUnmap = shaderLoader.CreateProgram("shaders/shader_unmap.vert", "shaders/shader_unmap.frag");
|
||||
|
||||
texture::earth = Core::LoadTexture("textures/earth.png");
|
||||
texture::ship = Core::LoadTexture("textures/ship.jpg");
|
||||
texture::moon = Core::LoadTexture("textures/moon.jpg");
|
||||
texture::jupiter = Core::LoadTexture("textures/jupiter.jpg");
|
||||
texture::mars = Core::LoadTexture("textures/mars.jpg");
|
||||
texture::neptune = Core::LoadTexture("textures/neptune.jpg");
|
||||
texture::uranus = Core::LoadTexture("textures/uranus.jpg");
|
||||
texture::mercury = Core::LoadTexture("textures/mercury.jpg");
|
||||
texture::saturn = Core::LoadTexture("textures/saturn.jpg");
|
||||
texture::venus = Core::LoadTexture("textures/venus.jpg");
|
||||
texture::asteroid = Core::LoadTexture("textures/asteroid.jpg");
|
||||
texture::sun = Core::LoadTexture("textures/sun.jpg");
|
||||
texture::metal = Core::LoadTexture("textures/metal.jpg");
|
||||
|
||||
texture::earth_nmap = Core::LoadTexture("textures/earth_normalmap.png");
|
||||
|
||||
|
||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
||||
loadModelToContext("./models/spaceship.obj", shipContext);
|
||||
loadModelToContext("./models/spaceship_station.obj", stationContext);
|
||||
loadModelToContext("./models/cube.obj", cubeContext);
|
||||
|
||||
initializePlanets();
|
||||
selectRandomPlanets();
|
||||
initializeAsteroids();
|
||||
}
|
||||
|
||||
bool checkAllPlanetsDeactivated() {
|
||||
for (const auto& planet : planets) {
|
||||
if (planet.isActivated) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void shutdown(GLFWwindow* window)
|
||||
{
|
||||
shaderLoader.DeleteProgram(program);
|
||||
}
|
||||
|
||||
|
||||
//obsluga wejscia
|
||||
void processInput(GLFWwindow* window)
|
||||
{
|
||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
|
||||
float angleSpeed = 0.003f;
|
||||
float moveSpeed = 0.007f;
|
||||
static bool rKeyPressedLastFrame = false;
|
||||
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipDir * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipDir * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipSide * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipSide * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipUp * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipUp * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
|
||||
bool rKeyPressedThisFrame = glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS;
|
||||
|
||||
if (rKeyPressedThisFrame && !rKeyPressedLastFrame) {
|
||||
rKeyWasPressed = true;
|
||||
}
|
||||
else {
|
||||
rKeyWasPressed = false;
|
||||
}
|
||||
|
||||
rKeyPressedLastFrame = rKeyPressedThisFrame;
|
||||
const float interactionDistance = 1.2f;
|
||||
if (rKeyPressedLastFrame) {
|
||||
for (auto& planet : planets) {
|
||||
float planetRadius = std::max(std::max(planet.modelScale.x, planet.modelScale.y), planet.modelScale.z);
|
||||
float collisionDistance = interactionDistance + planetRadius;
|
||||
if (glm::distance(spaceshipPos, planet.currentPlanetPos) < collisionDistance && planet.isActivated) {
|
||||
planet.isActivated = false;
|
||||
remainingTime += 10.0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
||||
if (checkAllPlanetsDeactivated() && remainingTime > 0) {
|
||||
const glm::vec3 stationPos = glm::vec3(-25.f, 0, 0);
|
||||
float stationRadius = std::max(std::max(glm::vec3(1.3f).x, glm::vec3(1.3f).y), glm::vec3(1.3f).z);
|
||||
float distanceTostation = glm::distance(spaceshipPos, stationPos);
|
||||
if (distanceTostation < 1.5f) {
|
||||
MessageBox(NULL, TEXT("You won!"), TEXT("Congratulations"), MB_OK);
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cameraPos = spaceshipPos - 1.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.5f;
|
||||
cameraDir = spaceshipDir;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void updateWindowTitle(GLFWwindow* window, double remainingTime) {
|
||||
int minutes = static_cast<int>(remainingTime) / 60;
|
||||
int seconds = static_cast<int>(remainingTime) % 60;
|
||||
|
||||
std::stringstream title;
|
||||
title << "Remaining time: ";
|
||||
title << std::setw(2) << std::setfill('0') << minutes;
|
||||
title << ":";
|
||||
title << std::setw(2) << std::setfill('0') << seconds << " s";
|
||||
|
||||
glfwSetWindowTitle(window, title.str().c_str());
|
||||
}
|
||||
|
||||
void ShowLoseDialog(GLFWwindow* window) {
|
||||
int msgboxID = MessageBox(
|
||||
NULL,
|
||||
TEXT("You lose! Game Over."),
|
||||
TEXT("Game Over"),
|
||||
MB_ICONWARNING | MB_OK
|
||||
);
|
||||
|
||||
if (msgboxID == IDOK) {
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// funkcja jest glowna petla
|
||||
void renderLoop(GLFWwindow* window) {
|
||||
double lastTime = glfwGetTime();
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
double currentTime = glfwGetTime();
|
||||
double deltaTime = currentTime - lastTime;
|
||||
lastTime = currentTime;
|
||||
|
||||
remainingTime -= deltaTime;
|
||||
if (remainingTime <= 0) {
|
||||
ShowLoseDialog(window);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
for (auto& planet : planets) {
|
||||
float planetRadius = std::max(std::max(planet.modelScale.x, planet.modelScale.y), planet.modelScale.z);
|
||||
float collisionDistance = 0.2f + planetRadius;
|
||||
float safeDistance = collisionDistance + 0.5f;
|
||||
|
||||
if (glm::distance(spaceshipPos, planet.currentPlanetPos) < collisionDistance && !planet.interacted) {
|
||||
remainingTime -= 20.0;
|
||||
planet.interacted = true;
|
||||
break;
|
||||
}
|
||||
else if (glm::distance(spaceshipPos, planet.currentPlanetPos) > safeDistance && planet.interacted) {
|
||||
planet.interacted = false;
|
||||
}
|
||||
}
|
||||
for (auto& asteroid : asteroids) {
|
||||
float asteroidRadius = std::max(std::max(asteroid.modelScale.x, asteroid.modelScale.y), asteroid.modelScale.z);
|
||||
float collisionDistance = 0.1f + asteroidRadius;
|
||||
float safeDistance = collisionDistance + 0.2f;
|
||||
|
||||
if (glm::distance(spaceshipPos, asteroid.currentAsteroidPos) < collisionDistance && !asteroid.interacted) {
|
||||
remainingTime -= 10.0;
|
||||
asteroid.interacted = true;
|
||||
break;
|
||||
}
|
||||
else if (glm::distance(spaceshipPos, asteroid.currentAsteroidPos) > safeDistance && asteroid.interacted) {
|
||||
asteroid.interacted = false;
|
||||
}
|
||||
}
|
||||
|
||||
updateWindowTitle(window, remainingTime);
|
||||
}
|
||||
|
||||
processInput(window);
|
||||
|
||||
renderScene(window);
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
107
Projekt_test/style.css
Normal file
@ -0,0 +1,107 @@
|
||||
html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
|
||||
|
||||
body{
|
||||
color:#444;
|
||||
font-family:Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
|
||||
font-size:12px;
|
||||
line-height:1.5em;
|
||||
padding:1em;
|
||||
margin:auto;
|
||||
max-width:42em;
|
||||
background:#fefefe;
|
||||
}
|
||||
|
||||
a{ color: #0645ad; text-decoration:none;}
|
||||
a:visited{ color: #0b0080; }
|
||||
a:hover{ color: #06e; }
|
||||
a:active{ color:#faa700; }
|
||||
a:focus{ outline: thin dotted; }
|
||||
a:hover, a:active{ outline: 0; }
|
||||
|
||||
::-moz-selection{background:rgba(255,255,0,0.3);color:#000}
|
||||
::selection{background:rgba(255,255,0,0.3);color:#000}
|
||||
|
||||
a::-moz-selection{background:rgba(255,255,0,0.3);color:#0645ad}
|
||||
a::selection{background:rgba(255,255,0,0.3);color:#0645ad}
|
||||
|
||||
p{
|
||||
margin:1em 0;
|
||||
}
|
||||
|
||||
img{
|
||||
max-width:100%;
|
||||
}
|
||||
|
||||
h1,h2,h3,h4,h5,h6{
|
||||
font-weight:normal;
|
||||
color:#111;
|
||||
line-height:1em;
|
||||
}
|
||||
h4,h5,h6{ font-weight: bold; }
|
||||
h1{ font-size:2.5em; }
|
||||
h2{ font-size:2em; }
|
||||
h3{ font-size:1.5em; }
|
||||
h4{ font-size:1.2em; }
|
||||
h5{ font-size:1em; }
|
||||
h6{ font-size:0.9em; }
|
||||
|
||||
blockquote{
|
||||
color:#666666;
|
||||
margin:0;
|
||||
padding-left: 3em;
|
||||
border-left: 0.5em #EEE solid;
|
||||
}
|
||||
hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa;border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; }
|
||||
pre, code, kbd, samp { color: #000; font-family: monospace, monospace; _font-family: 'courier new', monospace; font-size: 0.98em; }
|
||||
pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; }
|
||||
|
||||
b, strong { font-weight: bold; }
|
||||
|
||||
dfn { font-style: italic; }
|
||||
|
||||
ins { background: #ff9; color: #000; text-decoration: none; }
|
||||
|
||||
mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; }
|
||||
|
||||
sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
|
||||
sup { top: -0.5em; }
|
||||
sub { bottom: -0.25em; }
|
||||
|
||||
ul, ol { margin: 1em 0; padding: 0 0 0 2em; }
|
||||
li p:last-child { margin:0 }
|
||||
dd { margin: 0 0 0 2em; }
|
||||
|
||||
img { border: 0; -ms-interpolation-mode: bicubic; vertical-align: middle; }
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
width: 100%;
|
||||
}
|
||||
th { border-bottom: 1px solid black; }
|
||||
td { vertical-align: top; }
|
||||
|
||||
@media only screen and (min-width: 480px) {
|
||||
body{font-size:14px;}
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 768px) {
|
||||
body{font-size:16px;}
|
||||
}
|
||||
|
||||
@media print {
|
||||
* { background: transparent !important; color: black !important; filter:none !important; -ms-filter: none !important; }
|
||||
body{font-size:12pt; max-width:100%;}
|
||||
a, a:visited { text-decoration: underline; }
|
||||
hr { height: 1px; border:0; border-bottom:1px solid black; }
|
||||
a[href]:after { content: " (" attr(href) ")"; }
|
||||
abbr[title]:after { content: " (" attr(title) ")"; }
|
||||
.ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
|
||||
pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; }
|
||||
tr, img { page-break-inside: avoid; }
|
||||
img { max-width: 100% !important; }
|
||||
@page :left { margin: 15mm 20mm 15mm 10mm; }
|
||||
@page :right { margin: 15mm 10mm 15mm 20mm; }
|
||||
p, h2, h3 { orphans: 3; widows: 3; }
|
||||
h2, h3 { page-break-after: avoid; }
|
||||
}
|
BIN
Projekt_test/textures/asteroid.jpg
Normal file
After Width: | Height: | Size: 879 KiB |
BIN
Projekt_test/textures/earth.png
Normal file
After Width: | Height: | Size: 148 KiB |
BIN
Projekt_test/textures/earth2_normals.png
Normal file
After Width: | Height: | Size: 3.0 MiB |
BIN
Projekt_test/textures/earth_normalmap.png
Normal file
After Width: | Height: | Size: 163 KiB |
BIN
Projekt_test/textures/jupiter.jpg
Normal file
After Width: | Height: | Size: 487 KiB |
BIN
Projekt_test/textures/mars.jpg
Normal file
After Width: | Height: | Size: 733 KiB |
BIN
Projekt_test/textures/mercury.jpg
Normal file
After Width: | Height: | Size: 852 KiB |
BIN
Projekt_test/textures/metal.jpg
Normal file
After Width: | Height: | Size: 16 MiB |
BIN
Projekt_test/textures/moon.jpg
Normal file
After Width: | Height: | Size: 70 KiB |
BIN
Projekt_test/textures/moon_normal.jpg
Normal file
After Width: | Height: | Size: 374 KiB |
BIN
Projekt_test/textures/neptune.jpg
Normal file
After Width: | Height: | Size: 236 KiB |
BIN
Projekt_test/textures/rust_normal.jpg
Normal file
After Width: | Height: | Size: 3.3 MiB |
BIN
Projekt_test/textures/saturn.jpg
Normal file
After Width: | Height: | Size: 195 KiB |
BIN
Projekt_test/textures/ship.jpg
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
Projekt_test/textures/ship.png
Normal file
After Width: | Height: | Size: 2.6 MiB |