some old changes

This commit is contained in:
Hartmut Seichter 2023-06-05 11:15:47 +02:00
parent 623f21aedd
commit 7d17df39b3
5 changed files with 59 additions and 18 deletions

View file

@ -1,3 +1,4 @@
{ {
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureOnOpen": true
} }

View file

@ -9,7 +9,7 @@ project(pixwerx)
# #
# pixwerx ist C++17 # pixwerx ist C++17
# #
set (CMAKE_CXX_STANDARD 17) set (CMAKE_CXX_STANDARD 23)
# internal cmake modules # internal cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake ${CMAKE_MODULE_PATH})

View file

@ -39,7 +39,7 @@ struct matrix_transform {
} }
inline static inline static
matrix_<4,4,T> perspective_frustum(const T &left,const T &right, matrix_<4,4,T> perspective_frustum_rh(const T &left,const T &right,
const T &bottom,const T &top, const T &bottom,const T &top,
const T &z_near,const T &z_far) const T &z_near,const T &z_far)
{ {
@ -58,6 +58,46 @@ struct matrix_transform {
return frustum; return frustum;
} }
// /// creates a projection from a frustum planes with a reversed depth mapped to [0..1]
// pub fn make_projection_rh_from_frustum_reversed(
// left: f32,
// right: f32,
// bottom: f32,
// top: f32,
// z_near: f32,
// z_far: f32,
// ) -> Mat4 {
// assert!(z_near > 0.0 && z_far > 0.0);
// // info!("near {:?}", z_near);
// //
// // reversed z 0..1 projection
// //
// let a = (right + left) / (right - left); // position in frame horizontal
// let b = (top + bottom) / (top - bottom); // position in frame vertical
// let c = z_near / (z_far - z_near); // lower bound
// let d = z_far * z_near / (z_far - z_near); // upper bound
// let sx = 2.0 * z_near / (right - left); // scale x
// let sy = 2.0 * z_near / (top - bottom); // scale y
// // reverse z 0..1
// // --------------
// // sx 0 a 0
// // 0 sy b 0
// // 0 0 c d
// // 0 0 -1 0
// Mat4::from_cols(
// Vec4::new(sx, 0.0, 0.0, 0.0),
// Vec4::new(0.0, sy, 0.0, 0.0),
// Vec4::new(a, b, c, -1.0),
// Vec4::new(0.0, 0.0, d, 0.0),
// )
// }
inline static inline static
matrix_<4,4,T> perspective_projection(const T &field_of_view, matrix_<4,4,T> perspective_projection(const T &field_of_view,
const T &aspect_ratio, const T &aspect_ratio,
@ -69,7 +109,7 @@ struct matrix_transform {
const auto top = right / aspect_ratio; const auto top = right / aspect_ratio;
const auto bottom = -top; const auto bottom = -top;
return perspective_frustum(left,right, return perspective_frustum_rh(left,right,
bottom,top, bottom,top,
z_near,z_far); z_near,z_far);
} }

View file

@ -1,10 +1,9 @@
set(GLFW_BUILD_EXAMPLES TRUE CACHE BOOL "Build the GLFW example programs" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build the GLFW example programs" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation" FORCE) set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "Generate installation target" FORCE) set(GLFW_INSTALL OFF CACHE BOOL "Generate installation target" FORCE)
#add_subdirectory(glfw-3.2.1)
add_subdirectory(glfw-3.3.5) add_subdirectory(glfw-3.3.5)
add_subdirectory(lua-5.4.2) add_subdirectory(lua-5.4.2)

View file

@ -54,9 +54,14 @@ g.texture_coordinates = { {
{ 0.0, 1.0 } { 0.0, 1.0 }
} } } }
z = -5.0 z = 0
s = 1 s = 1
-- 0 --- 3
-- | \ |
-- 1 --- 2
-- indices -- indices
g.indices = { g.indices = {
0, 1, 2, -- triangle #1 0, 1, 2, -- triangle #1
@ -74,10 +79,6 @@ g.vertices = {
{ -s, s, z } { -s, s, z }
} }
-- 0 --- 3
-- | \ |
-- 1 --- 2
g:compute_normals() g:compute_normals()
@ -131,7 +132,7 @@ end
local renderer = pw.renderer() local renderer = pw.renderer()
-- camera position -- camera position
local cam_pos = pw.vector3(0,0,0) local cam_pos = pw.vector3(0,0,5)
-- model position -- model position
local model_pos = pw.vector3(0,0,0) local model_pos = pw.vector3(0,0,0)
@ -197,7 +198,7 @@ w.on_update = function(self)
s:set_uniform_vec4("color",cl) s:set_uniform_vec4("color",cl)
-- specific to our shader -- specific to our shader
s:set_uniform_int("tex_color",0) s:set_uniform_int("tex_color",0) -- unit 0
-- bind the texture -- bind the texture
tx:bind() tx:bind()
@ -228,7 +229,7 @@ while w:update() do
if pw.input.get().has_input then if pw.input.get().has_input then
-- somehow works -- somehow (depending on X11/Wayland) works
if pw.input.get().input_string == 'f' then if pw.input.get().input_string == 'f' then
w.fullscreen = not w.fullscreen w.fullscreen = not w.fullscreen
end end