Skip to content

Commit

Permalink
vGizmo3D v4.0 WiP - new features: this is a 3.1 beta release, going t…
Browse files Browse the repository at this point in the history
…oward v4.0 (to unify imguizmo_quat version)
  • Loading branch information
BrutPitt committed Jan 10, 2025
1 parent 62f62f9 commit a964fba
Show file tree
Hide file tree
Showing 13 changed files with 3,320 additions and 0 deletions.
231 changes: 231 additions & 0 deletions easy_examples/commons/shadersAndModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
//------------------------------------------------------------------------------
// Copyright (c) 2018-2025 Michele Morrone
// All rights reserved.
//
// https://michelemorrone.eu - https://brutpitt.com
//
// X: https://x.com/BrutPitt - GitHub: https://github.com/BrutPitt
//
// direct mail: brutpitt(at)gmail.com - me(at)michelemorrone.eu
//
// This software is distributed under the terms of the BSD 2-Clause license
//------------------------------------------------------------------------------
#pragma once

#define GLSL_VERSION "#version 450\n"
const char* vertex_code = GLSL_VERSION R"(
layout(std140) uniform;
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 inColor;
layout (location = 2) uniform mat4 mvp;
layout (location = 0) out vec4 outColor;
out vec3 vsPos;
void main()
{
outColor = inColor;
gl_Position = mvp * pos;
}
)";
const char* vertex_instanced = GLSL_VERSION R"(
layout(std140) uniform;
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 inColor;
layout (location = 2) uniform mat4 mvp;
layout (location = 3) uniform mat4 light;
layout (location = 0) out vec4 outColor;
out vec3 vsPos;
void main()
{
if(gl_InstanceID==1) {
outColor = inColor;
gl_Position = mvp * pos;
}
else {
outColor = vec4(1.0, 1.0, 0.5, 1.0);
gl_Position = light * pos ;
}
}
)";

const char* vk_vertex_code = R"(
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (std140, binding = 0) uniform buffer
{
mat4 mvp;
} uniformBuffer;
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 inColor;
layout (location = 0) out vec4 outColor;
void main()
{
outColor = inColor;
gl_Position = uniformBuffer.mvp * pos;
}
)";

const char* vk_vertex_instanced = R"(
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (std140, binding = 0) uniform buffer
{
mat4 mvp;
mat4 light;
} uniformBuffer;
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 inColor;
layout (location = 0) out vec4 outColor;
void main()
{
if(gl_InstanceIndex==1) {
outColor = inColor;
gl_Position = uniformBuffer.mvp * pos;
}
else {
outColor = vec4(1.0, 1.0, 0.5, 1.0);
gl_Position = uniformBuffer.light * pos;
}
}
)";
// fragment shader with (C)olor in and (C)olor out
const char* fragment_code = GLSL_VERSION R"(
layout (location = 0) in vec4 color;
layout (location = 0) out vec4 outColor;
void main()
{
outColor = color;
}
)";

const char* vk_vert_inv_z = R"(
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (std140, binding = 0) uniform buffer
{
mat4 mvp;
mat4 light;
} uniformBuffer;
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 inColor;
layout (location = 0) out vec4 outColor;
layout (location = 1) out vec4 vPos;
void main()
{
if(gl_InstanceIndex==1) {
outColor = inColor;
gl_Position = uniformBuffer.mvp * pos;
}
else {
outColor = vec4(1.0, 1.0, 0.5, 1.0);
gl_Position = uniformBuffer.light * pos;
}
vPos = gl_Position;
}
)";

const char* vk_frag_inv_z = GLSL_VERSION R"(
layout (location = 0) in vec4 color;
layout (location = 1) in vec4 vPos;
layout (location = 0) out vec4 outColor;
// far & near values are the same of perspective() call and can be passed to shader
float far = 100.0; // copied here for simplicity
float near = .1;
float linearizeDepth(float d) // draw in zNDC [0, 1]
{
return near * far / (far + d * (near - far));
}
void main()
{
outColor = color;
// invert depth value
gl_FragDepth = 1.0 - linearizeDepth(vPos.z);
}
)";


struct VertexPC
{
float x, y, z, w; // Position
float r, g, b, a; // Color
};

static const VertexPC coloredCubeData[] =
{
// red face
{ -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 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.0f, 1.0f, 0.0f, 0.0f, 1.0f },
{ 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f },
{ 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f },
// magenta face
{ 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f },
{ -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f },
{ -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f },
{ -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f },
// cyan face
{ 1.0f, -1.0f, 1.0f, 1.0f, 0.7f, 1.0f, 0.7f, 1.0f },
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.7f, 1.0f, 0.7f, 1.0f },
{ -1.0f, -1.0f, 1.0f, 1.0f, 0.7f, 1.0f, 0.7f, 1.0f },
{ -1.0f, -1.0f, 1.0f, 1.0f, 0.7f, 1.0f, 0.7f, 1.0f },
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.7f, 1.0f, 0.7f, 1.0f },
{ -1.0f, -1.0f, -1.0f, 1.0f, 0.7f, 1.0f, 0.7f, 1.0f },
};

75 changes: 75 additions & 0 deletions easy_examples/cube_OpenGL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#------------------------------------------------------------------------------
# Copyright (c) 2018-2025 Michele Morrone
# All rights reserved.
#
# https://michelemorrone.eu - https://brutpitt.com
#
# X: https://x.com/BrutPitt - GitHub: https://github.com/BrutPitt
#
# direct mail: brutpitt(at)gmail.com - me(at)michelemorrone.eu
#
# This software is distributed under the terms of the BSD 2-Clause license
#------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.27)
project(oglCubeExamples)

find_package(glm CONFIG)

option(IMGUIZMO_USES_GLM "Use GLM instead of internal vgMath" OFF)
# glm_FOUND OR
if(glm_FOUND OR IMGUIZMO_USES_GLM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVGIZMO_USES_GLM")
endif()

set(CMAKE_CXX_STANDARD 17)

find_package(OpenGL)

if(OPENGL_FOUND)
message(STATUS "OPENGL_INCLUDE_DIRS: ${OPENGL_INCLUDE_DIRS}")
message(STATUS "OPENGL_LIBRARY: ${OPENGL_LIBRARY}")

include_directories(${OPENGL_INCLUDE_DIRS})
else ()
message (FATAL_ERROR "OPENGL not found... REQUIRED!!!!")
endif(OPENGL_FOUND)

find_package(glfw3 CONFIG)
find_package(SDL2 CONFIG)
include_directories(${SDL2_INCLUDE_DIRS})


set(SRC ${CMAKE_SOURCE_DIR})
set(COMMONS_DIR ${SRC}/../commons)
set(TOOLS_DIR ${CMAKE_SOURCE_DIR}/../../libs)
set(VGIZMO_PARENT_DIR ${CMAKE_SOURCE_DIR}/../..)
set(VGIZMO_DIR ${VGIZMO_PARENT_DIR}/vGizmo3D)

include_directories(${TOOLS_DIR})
include_directories(${VGIZMO_PARENT_DIR})
include_directories(${SRC}/../commons)

set(SOURCE_FILES
${SRC}/oglDebug.cpp
${SRC}/oglDebug.h
${COMMONS_DIR}/shadersAndModel.h
${TOOLS_DIR}/glad/glad.cpp
${TOOLS_DIR}/glad/glad.h)


file( GLOB APP_SOURCES ${SRC}/oglCube*.cpp )
foreach( oglCubeSourceFile ${APP_SOURCES} )
get_filename_component( oglCubeName ${oglCubeSourceFile} NAME_WE ) # Cut off the file extension and directory path
project(${oglCubeName})

if(${oglCubeName} MATCHES "SDL")
add_executable( ${PROJECT_NAME} ${oglCubeSourceFile} ${SOURCE_FILES} ${SOURCE_FILES_SDL} ${COMMONS_UI_FILES})
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
else()
add_executable( ${PROJECT_NAME} ${oglCubeSourceFile} ${SOURCE_FILES} ${SOURCE_FILES_GLFW} ${COMMONS_UI_FILES})
target_link_libraries(${PROJECT_NAME} glfw)
endif()

target_link_libraries(${oglCubeName} ${CMAKE_DL_LIBS} ${OPENGL_LIBRARY})
endforeach( oglCubeSourceFile ${APP_SOURCES} )

25 changes: 25 additions & 0 deletions easy_examples/cube_OpenGL/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BSD 2-Clause License

Copyright (c) 2025 Michele Morrone
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 HOLDER 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.
Loading

0 comments on commit a964fba

Please sign in to comment.