Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gamedev/fggl
  • onuralpsezer/fggl
2 results
Show changes
Showing
with 279 additions and 18 deletions
cmake_minimum_required(VERSION 3.16)
project(demo)
# Executable
add_executable(FgglDemo main.cpp)
target_link_libraries(FgglDemo fggl)
target_include_directories(FgglDemo PUBLIC ${PROJECT_BINARY_DIR})
add_executable(demo
demo/main.cpp
demo/GameScene.cpp
demo/rollball.cpp
demo/topdown.cpp
demo/grid.cpp
demo/robot/programmer.cpp
demo/models/viewer.cpp
demo/hexboard/board.cpp
demo/hexboard/camera.cpp
)
# set build flags
target_compile_options( demo PRIVATE -Wall -Wextra -Wodr -Wdouble-promotion -fno-strict-aliasing -fno-strict-overflow )
set_property(TARGET demo PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
target_include_directories(demo
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries( demo fggl )
#target_link_libraries(demo fggl fgglbt)
if ( FGGL_EXT_LUA )
target_link_libraries( demo fggl-lua )
endif()
# rssources
find_package(spdlog)
target_link_libraries(demo spdlog::spdlog)
#target_include_directories(FgglDemo PUBLIC ${PROJECT_BINARY_DIR})
#find_package(Lua)
#target_link_libraries(demo ${LUA_LIBRARIES})
# resources
file(GLOB_RECURSE data data/*)
file(COPY ${data} DESTINATION data )
\ No newline at end of file
file(COPY ${data} DESTINATION data )
include(GNUInstallDirs)
install(
TARGETS demo
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
DIRECTORY data/
DESTINATION ${CMAKE_INSTALL_DATADIR}/fggl-demo
)
# Linux Desktop Entries
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(FILES aux/com.fossgalaxy.fggl.Demo.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications )
install(FILES aux/com.fossgalaxy.fggl.Demo.metainfo.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo )
endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
[Desktop Entry]
Name=FGGL Demo
Exec=demo
Type=Application
Categories=Game
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>com.fossgalaxy.fggl.Demo</id>
<name>FGGL Demo</name>
<summary>An application for testing FGGL features</summary>
<metadata_license>CC-BY-4.0</metadata_license>
<project_license>GPL-3.0-or-later</project_license>
<description>
<p>
Test application for the FOSS Galaxy Game Library (FGGL)
</p>
</description>
<launchable type="desktop-id">com.fossgalaxy.fggl.Demo.desktop</launchable>
</component>
packs/
File added
demo/data/backpack/ao.jpg

132 B

source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
demo/data/backpack/diffuse.jpg

132 B

image diff could not be displayed: it is too large. Options to address this: view the blob.
demo/data/backpack/roughness.jpg

132 B

Model by Berk Gedik, from: https://sketchfab.com/3d-models/survival-guitar-backpack-low-poly-799f8c4511f84fab8c3f12887f7e6b36
Modified material assignment (Joey de Vries) for easier load in OpenGL model loading chapter, and renamed albedo to diffuse and metallic to specular to match non-PBR lighting setup.
\ No newline at end of file
demo/data/backpack/specular.jpg

132 B

File added
#version 150
in vec4 v_Color;
out vec4 out_FragColor;
void main()
{
out_FragColor = v_Color;
}
\ No newline at end of file
#version 150
in vec3 in_Position;
in vec4 in_ColorPointSize;
out vec4 v_Color;
uniform mat4 u_MvpMatrix;
void main()
{
gl_Position = u_MvpMatrix * vec4(in_Position, 1.0);
gl_PointSize = in_ColorPointSize.w;
v_Color = vec4(in_ColorPointSize.xyz, 1.0);
}
\ No newline at end of file
---
- define: label
attrs:
value: """
- define: button
children:
- template: label
- define: textinput
children:
- template: label
- define: checkbox
attrs:
state: False
- define: radio
attrs:
state: False
- define: frame
/**
* OpenGL phong lighting model.
* Adapted from LearnOpenGL.com, by Joey de Vries, CC BY-NC 4.0
*/
struct Material {
sampler2D diffuse;
sample2D specular;
float shininess;
};
struct DirectionalLight {
vec3 direction;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
struct PointLight {
vec3 position;
vec3 ambient;
vec3 diffuse;
vec3 specular;
float constant;
float linear;
float quadratic;
};
struct SpotLight {
vec3 position;
vec3 direction;
vec3 ambient;
vec3 diffuse;
vec3 specular;
float constant;
float linear;
float quadratic;
float cutOff;
float outerCutOff;
};
vec3 CalcDirectionalLight(DirectionalLight light, vec3 normal, vec3 viewDir) {
vec3 lightDir = normalize(-light.direction);
// diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// combine results
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords));
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoords));
return (ambient + diffuse + specular);
}
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir) {
vec3 lightDir = normalize(light.position - fragPos);
// diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// attenuation
float distance = length(light.position - fragPos);
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
// combine results
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords));
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoords));
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;
return (ambient + diffuse + specular);
}
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir) {
vec3 lightDir = normalize(light.position - fragPos);
// diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// attenuation
float distance = length(light.position - fragPos);
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
// spotlight intensity
float theta = dot(lightDir, normalize(-light.direction));
float epsilon = light.cutOff - light.outerCutOff;
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0, 1.0);
// combine results
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords));
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoords));
ambient *= attenuation * intensity;
diffuse *= attenuation * intensity;
specular *= attenuation * intensity;
return (ambient + diffuse + specular);
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ uniform mat4 model;
void main()
{
gl_Position = view * model * vec4(aPos, 1.0);
gl_Position = view * model * vec4(aPos, 1.0);
mat3 normalMatrix = mat3(transpose(inverse(view * model)));
vs_out.normal = normalize(vec3(vec4(normalMatrix * aNormal, 0.0)));
}
#version 330 core
#extension GL_ARB_shading_language_include : require
// based on http://www.opengl-tutorial.org, WTFPL
// features lighting additions from https://learnopengl.com/, CC BY-NC 4.0
struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};
uniform Material material;
uniform vec3 lightPos;
uniform vec3 objColour;
in vec3 normal;
......@@ -15,15 +26,9 @@ out vec4 FragColor;
void main()
{
vec3 lightColour = vec3( 1.0, 1.0, 1.0 );
vec3 objColour = vec3(1.0f, 0.6f, 0.2f);
vec3 lightColour = vec3(1, 1, 1);
float lightPower = 200.0;
// material colours
vec3 matDiff = vec3(1.0, 0.6, 0.2 );
vec3 matAmb = vec3(0.1) * matDiff;
vec3 matSpec = vec3(0.3);
vec3 n = normalize( normal_cs );
vec3 l = normalize( lightdir_cs );
float distance = length( lightPos - pos_ws );
......@@ -31,12 +36,12 @@ void main()
vec3 e = normalize( eyedir_cs );
vec3 r = reflect( -l, n );
float cosAlpha = clamp( dot(e, r), 0, 1);
float cosTheta = clamp( dot( n, l ), 0, 1 );
vec3 colour =
( matAmb ) +
( matDiff * lightColour * lightPower * cosTheta / ( distance*distance ) ) +
( matSpec * lightColour * lightPower * pow( cosAlpha, 5 ) / (distance*distance) );
vec3 colour =
( material.ambient * vec3(0.1) ) +
( material.diffuse * vec3(0.5) * lightColour * lightPower * cosTheta / ( distance*distance ) ) +
( material.specular * lightColour * lightPower * pow( cosAlpha, material.shininess * 128 ) / (distance*distance) );
FragColor = vec4(colour, 1);
}