Merge branch 'master' of https://github.com/erwincoumans/bullet3
This commit is contained in:
@@ -13,7 +13,7 @@ addons:
|
|||||||
script:
|
script:
|
||||||
- echo "CXX="$CXX
|
- echo "CXX="$CXX
|
||||||
- echo "CC="$CC
|
- echo "CC="$CC
|
||||||
- cmake . -DBUILD_PYBULLET=OFF -G"Unix Makefiles" #-DCMAKE_CXX_FLAGS=-Werror
|
- cmake . -DBUILD_PYBULLET=ON -G"Unix Makefiles" #-DCMAKE_CXX_FLAGS=-Werror
|
||||||
- make -j8
|
- make -j8
|
||||||
- ctest -j8 --output-on-failure
|
- ctest -j8 --output-on-failure
|
||||||
# Build again with double precision
|
# Build again with double precision
|
||||||
|
|||||||
@@ -303,30 +303,15 @@ ENDIF()
|
|||||||
OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON)
|
OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON)
|
||||||
|
|
||||||
OPTION(BUILD_PYBULLET "Set when you want to build pybullet (Python bindings for Bullet)" OFF)
|
OPTION(BUILD_PYBULLET "Set when you want to build pybullet (Python bindings for Bullet)" OFF)
|
||||||
IF(BUILD_PYBULLET)
|
|
||||||
# Optional Python configuration
|
|
||||||
# builds pybullet automatically if all the requirements are met
|
|
||||||
SET(PYTHON_VERSION_PYBULLET "2.7" CACHE STRING "Python version pybullet will use.")
|
|
||||||
SET(Python_ADDITIONAL_VERSIONS 2.7 2.7.3 3 3.0 3.1 3.2 3.3 3.4 3.5 3.6)
|
|
||||||
SET_PROPERTY(CACHE PYTHON_VERSION_PYBULLET PROPERTY STRINGS ${Python_ADDITIONAL_VERSIONS})
|
|
||||||
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build3/cmake ${CMAKE_MODULE_PATH})
|
|
||||||
OPTION(EXACT_PYTHON_VERSION "Require Python and match PYTHON_VERSION_PYBULLET exactly, e.g. 2.7.3" OFF)
|
|
||||||
IF(EXACT_PYTHON_VERSION)
|
|
||||||
set(EXACT_PYTHON_VERSION_FLAG EXACT REQUIRED)
|
|
||||||
ENDIF(EXACT_PYTHON_VERSION)
|
|
||||||
# first find the python interpreter
|
|
||||||
FIND_PACKAGE(PythonInterp ${PYTHON_VERSION_PYBULLET} ${EXACT_PYTHON_VERSION_FLAG})
|
|
||||||
# python library should exactly match that of the interpreter
|
|
||||||
FIND_PACKAGE(PythonLibs ${PYTHON_VERSION_STRING} EXACT)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
OPTION(BUILD_ENET "Set when you want to build apps with enet UDP networking support" ON)
|
OPTION(BUILD_ENET "Set when you want to build apps with enet UDP networking support" ON)
|
||||||
OPTION(BUILD_CLSOCKET "Set when you want to build apps with enet TCP networking support" ON)
|
OPTION(BUILD_CLSOCKET "Set when you want to build apps with enet TCP networking support" ON)
|
||||||
|
|
||||||
|
|
||||||
IF(BUILD_PYBULLET)
|
IF(BUILD_PYBULLET)
|
||||||
|
FIND_PACKAGE(PythonLibs)
|
||||||
OPTION(BUILD_PYBULLET_NUMPY "Set when you want to build pybullet with NumPy support" ON)
|
|
||||||
|
OPTION(BUILD_PYBULLET_NUMPY "Set when you want to build pybullet with NumPy support" OFF)
|
||||||
OPTION(BUILD_PYBULLET_ENET "Set when you want to build pybullet with enet UDP networking support" ON)
|
OPTION(BUILD_PYBULLET_ENET "Set when you want to build pybullet with enet UDP networking support" ON)
|
||||||
OPTION(BUILD_PYBULLET_CLSOCKET "Set when you want to build pybullet with enet TCP networking support" ON)
|
OPTION(BUILD_PYBULLET_CLSOCKET "Set when you want to build pybullet with enet TCP networking support" ON)
|
||||||
|
|
||||||
|
|||||||
@@ -238,6 +238,9 @@ end
|
|||||||
targetdir( _OPTIONS["targetdir"] or "../bin" )
|
targetdir( _OPTIONS["targetdir"] or "../bin" )
|
||||||
location("./" .. act .. postfix)
|
location("./" .. act .. postfix)
|
||||||
|
|
||||||
|
projectRootDir = os.getcwd() .. "/../"
|
||||||
|
print("Project root directory: " .. projectRootDir);
|
||||||
|
|
||||||
if not _OPTIONS["python_include_dir"] then
|
if not _OPTIONS["python_include_dir"] then
|
||||||
_OPTIONS["python_include_dir"] = default_python_include_dir
|
_OPTIONS["python_include_dir"] = default_python_include_dir
|
||||||
end
|
end
|
||||||
@@ -245,22 +248,109 @@ end
|
|||||||
if not _OPTIONS["python_lib_dir"] then
|
if not _OPTIONS["python_lib_dir"] then
|
||||||
_OPTIONS["python_lib_dir"] = default_python_lib_dir
|
_OPTIONS["python_lib_dir"] = default_python_lib_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
projectRootDir = os.getcwd() .. "/../"
|
if os.is("Linux") then
|
||||||
print("Project root directory: " .. projectRootDir);
|
default_glfw_include_dir = "usr/local/include/GLFW"
|
||||||
|
default_glfw_lib_dir = "/usr/local/lib/"
|
||||||
|
default_glfw_lib_name = "glfw3"
|
||||||
|
end
|
||||||
|
|
||||||
|
if os.is("macosx") then
|
||||||
|
default_glfw_include_dir = "/usr/local/Cellar/glfw/3.2.1/include"
|
||||||
|
default_glfw_lib_dir = "/usr/local/Cellar/glfw/3.2.1/lib"
|
||||||
|
default_glfw_lib_name = "glfw"
|
||||||
|
end
|
||||||
|
|
||||||
|
if os.is("Windows") then
|
||||||
|
default_glfw_include_dir = "c:/glfw/include"
|
||||||
|
default_glfw_lib_dir = "c:/glfw/lib"
|
||||||
|
default_glfw_lib_name = "glfw3"
|
||||||
|
end
|
||||||
|
|
||||||
|
if not _OPTIONS["glfw_lib_dir"] then
|
||||||
|
_OPTIONS["glfw_lib_dir"] = default_glfw_lib_dir
|
||||||
|
end
|
||||||
|
if not _OPTIONS["glfw_include_dir"] then
|
||||||
|
_OPTIONS["glfw_include_dir"] = default_glfw_include_dir
|
||||||
|
end
|
||||||
|
if not _OPTIONS["glfw_lib_name"] then
|
||||||
|
_OPTIONS["glfw_lib_name"] = default_glfw_lib_name
|
||||||
|
end
|
||||||
|
newoption
|
||||||
|
{
|
||||||
|
trigger = "glfw_include_dir",
|
||||||
|
value = default_glfw_include_dir,
|
||||||
|
description = "GLFW 3.x include directory"
|
||||||
|
}
|
||||||
|
|
||||||
|
newoption
|
||||||
|
{
|
||||||
|
trigger = "glfw_lib_name",
|
||||||
|
value = default_glfw_lib_name,
|
||||||
|
description = "GLFW 3.x library name (glfw, glfw3)"
|
||||||
|
}
|
||||||
|
|
||||||
|
newoption
|
||||||
|
{
|
||||||
|
trigger = "glfw_lib_dir",
|
||||||
|
value = default_glfw_lib_dir,
|
||||||
|
description = "(optional) GLFW 3.x library directory "
|
||||||
|
}
|
||||||
|
|
||||||
|
newoption
|
||||||
|
{
|
||||||
|
trigger = "enable_glfw",
|
||||||
|
value = false,
|
||||||
|
description = "(optional) use GLFW 3.x library"
|
||||||
|
}
|
||||||
|
|
||||||
|
if _OPTIONS["enable_glfw"] then
|
||||||
|
defines {"B3_USE_GLFW"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function initOpenGL()
|
||||||
|
includedirs {
|
||||||
|
projectRootDir .. "examples/ThirdPartyLibs/glad"
|
||||||
|
}
|
||||||
|
|
||||||
|
includedirs {
|
||||||
|
_OPTIONS["glfw_include_dir"],
|
||||||
|
}
|
||||||
|
|
||||||
|
libdirs {
|
||||||
|
_OPTIONS["glfw_lib_dir"]
|
||||||
|
}
|
||||||
|
links { _OPTIONS["glfw_lib_name"]}
|
||||||
|
files { projectRootDir .. "examples/ThirdPartyLibs/glad/glad.c" }
|
||||||
|
end
|
||||||
|
function findOpenGL3()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
function initGlew()
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
dofile ("findOpenGLGlewGlut.lua")
|
||||||
|
if (not findOpenGL3()) then
|
||||||
|
defines {"NO_OPENGL3"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dofile ("findOpenCL.lua")
|
dofile ("findOpenCL.lua")
|
||||||
dofile ("findDirectX11.lua")
|
dofile ("findDirectX11.lua")
|
||||||
dofile ("findOpenGLGlewGlut.lua")
|
|
||||||
|
|
||||||
if (not findOpenGL3()) then
|
|
||||||
defines {"NO_OPENGL3"}
|
|
||||||
end
|
|
||||||
|
|
||||||
language "C++"
|
language "C++"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if _OPTIONS["audio"] then
|
if _OPTIONS["audio"] then
|
||||||
include "../examples/TinyAudio"
|
include "../examples/TinyAudio"
|
||||||
end
|
end
|
||||||
|
|||||||
Binary file not shown.
@@ -909,7 +909,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
|||||||
|
|
||||||
#ifndef NO_OPENGL3
|
#ifndef NO_OPENGL3
|
||||||
SimpleOpenGL3App* simpleApp=0;
|
SimpleOpenGL3App* simpleApp=0;
|
||||||
sUseOpenGL2 =args.CheckCmdLineFlag("opengl2");
|
sUseOpenGL2 = args.CheckCmdLineFlag("opengl2");
|
||||||
#else
|
#else
|
||||||
sUseOpenGL2 = true;
|
sUseOpenGL2 = true;
|
||||||
#endif
|
#endif
|
||||||
@@ -920,10 +920,16 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
|||||||
const char* optMode = "Release build";
|
const char* optMode = "Release build";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
const char* glContext = "[glfw]";
|
||||||
|
#else
|
||||||
|
const char* glContext = "[btgl]";
|
||||||
|
#endif
|
||||||
|
|
||||||
if (sUseOpenGL2 )
|
if (sUseOpenGL2 )
|
||||||
{
|
{
|
||||||
char title[1024];
|
char title[1024];
|
||||||
sprintf(title,"%s using limited OpenGL2 fallback. %s", appTitle,optMode);
|
sprintf(title,"%s using limited OpenGL2 fallback %s %s", appTitle,glContext, optMode);
|
||||||
s_app = new SimpleOpenGL2App(title,width,height);
|
s_app = new SimpleOpenGL2App(title,width,height);
|
||||||
s_app->m_renderer = new SimpleOpenGL2Renderer(width,height);
|
s_app->m_renderer = new SimpleOpenGL2Renderer(width,height);
|
||||||
}
|
}
|
||||||
@@ -932,7 +938,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
char title[1024];
|
char title[1024];
|
||||||
sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode);
|
sprintf(title,"%s using OpenGL3+ %s %s", appTitle,glContext, optMode);
|
||||||
simpleApp = new SimpleOpenGL3App(title,width,height, gAllowRetina);
|
simpleApp = new SimpleOpenGL3App(title,width,height, gAllowRetina);
|
||||||
s_app = simpleApp;
|
s_app = simpleApp;
|
||||||
}
|
}
|
||||||
@@ -1001,7 +1007,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
|||||||
|
|
||||||
if (sUseOpenGL2)
|
if (sUseOpenGL2)
|
||||||
{
|
{
|
||||||
m_internalData->m_gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
m_internalData->m_gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(s_window->getRetinaScale());
|
||||||
}
|
}
|
||||||
#ifndef NO_OPENGL3
|
#ifndef NO_OPENGL3
|
||||||
else
|
else
|
||||||
@@ -1341,7 +1347,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
|||||||
if (sUseOpenGL2)
|
if (sUseOpenGL2)
|
||||||
{
|
{
|
||||||
|
|
||||||
saveOpenGLState(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
|
saveOpenGLState(s_instancingRenderer->getScreenWidth()*s_window->getRetinaScale(), s_instancingRenderer->getScreenHeight()*s_window->getRetinaScale());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_internalData->m_gui)
|
if (m_internalData->m_gui)
|
||||||
|
|||||||
499
examples/OpenGLWindow/GLFWOpenGLWindow.cpp
Normal file
499
examples/OpenGLWindow/GLFWOpenGLWindow.cpp
Normal file
@@ -0,0 +1,499 @@
|
|||||||
|
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
#include "GLFWOpenGLWindow.h"
|
||||||
|
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "LinearMath/btScalar.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct GLFWOpenGLWindowInternalData
|
||||||
|
{
|
||||||
|
bool m_requestedExit;
|
||||||
|
bool m_hasCursorPos;
|
||||||
|
bool m_altPressed;
|
||||||
|
bool m_shiftPressed;
|
||||||
|
bool m_ctrlPressed;
|
||||||
|
float m_cursorXPos;
|
||||||
|
float m_cursorYPos;
|
||||||
|
b3MouseMoveCallback m_mouseMoveCallback;
|
||||||
|
b3MouseButtonCallback m_mouseButtonCallback;
|
||||||
|
b3ResizeCallback m_resizeCallback;
|
||||||
|
b3WheelCallback m_wheelCallback;
|
||||||
|
b3KeyboardCallback m_keyboardCallback;
|
||||||
|
b3RenderCallback m_renderCallback;
|
||||||
|
int m_width;
|
||||||
|
int m_height;
|
||||||
|
float m_retinaScaleFactor;
|
||||||
|
|
||||||
|
GLFWwindow* m_glfwWindow;
|
||||||
|
|
||||||
|
GLFWOpenGLWindowInternalData()
|
||||||
|
:m_requestedExit(false),
|
||||||
|
m_hasCursorPos(false),
|
||||||
|
m_altPressed(false),
|
||||||
|
m_shiftPressed(false),
|
||||||
|
m_ctrlPressed(false),
|
||||||
|
m_cursorXPos(0),
|
||||||
|
m_cursorYPos(0),
|
||||||
|
m_mouseMoveCallback(0),
|
||||||
|
m_mouseButtonCallback(0),
|
||||||
|
m_resizeCallback(0),
|
||||||
|
m_wheelCallback(0),
|
||||||
|
m_keyboardCallback(0),
|
||||||
|
m_renderCallback(0),
|
||||||
|
m_width(0),
|
||||||
|
m_height(0),
|
||||||
|
m_retinaScaleFactor(1),
|
||||||
|
m_glfwWindow(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static void GLFWErrorCallback(int error, const char* description)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error: %s\n", description);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLFWMouseButtonCallback(GLFWwindow* window,int button,int glfwState,int)
|
||||||
|
{
|
||||||
|
GLFWOpenGLWindow* wnd = (GLFWOpenGLWindow*) glfwGetWindowUserPointer(window);
|
||||||
|
if (wnd && wnd->getMouseButtonCallback())
|
||||||
|
{
|
||||||
|
int state = (glfwState == GLFW_PRESS)? 1 : 0;
|
||||||
|
wnd->mouseButtonCallbackInternal(button, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLFWScrollCallback(GLFWwindow* window, double deltaX,double deltaY)
|
||||||
|
{
|
||||||
|
GLFWOpenGLWindow* wnd = (GLFWOpenGLWindow*) glfwGetWindowUserPointer(window);
|
||||||
|
if (wnd && wnd->getWheelCallback())
|
||||||
|
{
|
||||||
|
wnd->getWheelCallback()(deltaX*100,deltaY*100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLFWCursorPosCallback(GLFWwindow* window,double xPos,double yPos)
|
||||||
|
{
|
||||||
|
GLFWOpenGLWindow* wnd = (GLFWOpenGLWindow*) glfwGetWindowUserPointer(window);
|
||||||
|
if (wnd && wnd->getMouseMoveCallback())
|
||||||
|
{
|
||||||
|
wnd->mouseCursorCallbackInternal(xPos,yPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void GLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
|
GLFWOpenGLWindow* wnd = (GLFWOpenGLWindow*) glfwGetWindowUserPointer(window);
|
||||||
|
if (wnd)
|
||||||
|
{
|
||||||
|
wnd->keyboardCallbackInternal(key,action);
|
||||||
|
}
|
||||||
|
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void GLFWSizeCallback(GLFWwindow* window,int width,int height)
|
||||||
|
{
|
||||||
|
GLFWOpenGLWindow* wnd = (GLFWOpenGLWindow*) glfwGetWindowUserPointer(window);
|
||||||
|
{
|
||||||
|
wnd->resizeInternal(width,height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GLFWOpenGLWindow::GLFWOpenGLWindow()
|
||||||
|
{
|
||||||
|
m_data = new GLFWOpenGLWindowInternalData();
|
||||||
|
}
|
||||||
|
|
||||||
|
GLFWOpenGLWindow::~GLFWOpenGLWindow()
|
||||||
|
{
|
||||||
|
if (m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
closeWindow();
|
||||||
|
}
|
||||||
|
delete m_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int getBulletKeyFromGLFWKeycode(int glfwKeyCode)
|
||||||
|
{
|
||||||
|
int keycode = -1;
|
||||||
|
if (glfwKeyCode >= 'A' && glfwKeyCode <= 'Z')
|
||||||
|
{
|
||||||
|
return glfwKeyCode+32;//todo: fix the ascii A vs a input
|
||||||
|
}
|
||||||
|
if (glfwKeyCode >= '0' && glfwKeyCode <= '9')
|
||||||
|
{
|
||||||
|
return glfwKeyCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (glfwKeyCode)
|
||||||
|
{
|
||||||
|
case GLFW_KEY_ENTER: {keycode = B3G_RETURN; break; };
|
||||||
|
case GLFW_KEY_ESCAPE: {keycode = B3G_ESCAPE; break; };
|
||||||
|
case GLFW_KEY_F1: {keycode = B3G_F1; break;}
|
||||||
|
case GLFW_KEY_F2: {keycode = B3G_F2; break;}
|
||||||
|
case GLFW_KEY_F3: {keycode = B3G_F3; break;}
|
||||||
|
case GLFW_KEY_F4: {keycode = B3G_F4; break;}
|
||||||
|
case GLFW_KEY_F5: {keycode = B3G_F5; break;}
|
||||||
|
case GLFW_KEY_F6: {keycode = B3G_F6; break;}
|
||||||
|
case GLFW_KEY_F7: {keycode = B3G_F7; break;}
|
||||||
|
case GLFW_KEY_F8: {keycode = B3G_F8; break;}
|
||||||
|
case GLFW_KEY_F9: {keycode = B3G_F9; break;}
|
||||||
|
case GLFW_KEY_F10: {keycode= B3G_F10; break;}
|
||||||
|
|
||||||
|
//case GLFW_KEY_SPACE: {keycode= ' '; break;}
|
||||||
|
|
||||||
|
case GLFW_KEY_PAGE_DOWN: {keycode= B3G_PAGE_DOWN; break;}
|
||||||
|
case GLFW_KEY_PAGE_UP: {keycode= B3G_PAGE_UP; break;}
|
||||||
|
|
||||||
|
case GLFW_KEY_INSERT: {keycode= B3G_INSERT; break;}
|
||||||
|
case GLFW_KEY_BACKSPACE: {keycode= B3G_BACKSPACE; break;}
|
||||||
|
case GLFW_KEY_DELETE: {keycode= B3G_DELETE; break;}
|
||||||
|
|
||||||
|
case GLFW_KEY_END:{keycode= B3G_END; break;}
|
||||||
|
case GLFW_KEY_HOME:{keycode= B3G_HOME; break;}
|
||||||
|
case GLFW_KEY_LEFT:{keycode= B3G_LEFT_ARROW; break;}
|
||||||
|
case GLFW_KEY_UP:{keycode= B3G_UP_ARROW; break;}
|
||||||
|
case GLFW_KEY_RIGHT:{keycode= B3G_RIGHT_ARROW; break;}
|
||||||
|
case GLFW_KEY_DOWN:{keycode= B3G_DOWN_ARROW; break;}
|
||||||
|
case GLFW_KEY_RIGHT_SHIFT:{keycode=B3G_SHIFT;break;}
|
||||||
|
case GLFW_KEY_LEFT_SHIFT:{keycode=B3G_SHIFT;break;}
|
||||||
|
case GLFW_KEY_MENU:{keycode=B3G_ALT;break;}
|
||||||
|
case GLFW_KEY_RIGHT_CONTROL:{keycode=B3G_CONTROL;break;}
|
||||||
|
case GLFW_KEY_LEFT_CONTROL:{keycode=B3G_CONTROL;break;}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
//keycode = MapVirtualKey( virtualKeyCode, MAPGLFW_KEY_GLFW_KEY_TO_CHAR ) & 0x0000FFFF;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return keycode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::keyboardCallbackInternal(int key, int state)
|
||||||
|
{
|
||||||
|
if (getKeyboardCallback())
|
||||||
|
{
|
||||||
|
//convert keyboard codes from glfw to bullet
|
||||||
|
int btcode = getBulletKeyFromGLFWKeycode(key);
|
||||||
|
int btstate = (state == GLFW_RELEASE)? 0 : 1;
|
||||||
|
|
||||||
|
switch (btcode)
|
||||||
|
{
|
||||||
|
case B3G_SHIFT:
|
||||||
|
{
|
||||||
|
m_data->m_shiftPressed = state!=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case B3G_ALT:
|
||||||
|
{
|
||||||
|
m_data->m_altPressed = state!=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case B3G_CONTROL:
|
||||||
|
{
|
||||||
|
m_data->m_ctrlPressed = state!=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getKeyboardCallback()(btcode,btstate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::mouseButtonCallbackInternal(int button, int state)
|
||||||
|
{
|
||||||
|
if (getMouseButtonCallback() && m_data->m_hasCursorPos)
|
||||||
|
{
|
||||||
|
getMouseButtonCallback()(button,state,m_data->m_cursorXPos,m_data->m_cursorYPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::mouseCursorCallbackInternal(double xPos, double yPos)
|
||||||
|
{
|
||||||
|
if (getMouseMoveCallback())
|
||||||
|
{
|
||||||
|
m_data->m_hasCursorPos = true;
|
||||||
|
m_data->m_cursorXPos = xPos;
|
||||||
|
m_data->m_cursorYPos = yPos;
|
||||||
|
getMouseMoveCallback()(xPos,yPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::resizeInternal(int width,int height)
|
||||||
|
{
|
||||||
|
|
||||||
|
glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height);
|
||||||
|
glViewport (0,0,m_data->m_width,m_data->m_height);
|
||||||
|
|
||||||
|
if (getResizeCallback())
|
||||||
|
{
|
||||||
|
getResizeCallback()(m_data->m_width/m_data->m_retinaScaleFactor,m_data->m_height / m_data->m_retinaScaleFactor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::createDefaultWindow(int width, int height, const char* title)
|
||||||
|
{
|
||||||
|
b3gWindowConstructionInfo ci;
|
||||||
|
ci.m_width = width;
|
||||||
|
ci.m_height = height;
|
||||||
|
ci.m_title = title;
|
||||||
|
|
||||||
|
createWindow(ci);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
||||||
|
{
|
||||||
|
|
||||||
|
btAssert(m_data->m_glfwWindow==0);
|
||||||
|
if (m_data->m_glfwWindow==0)
|
||||||
|
{
|
||||||
|
glfwSetErrorCallback(GLFWErrorCallback);
|
||||||
|
|
||||||
|
if (!glfwInit())
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
if (ci.m_openglVersion==2)
|
||||||
|
{
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
m_data->m_glfwWindow = glfwCreateWindow(ci.m_width, ci.m_height, ci.m_title, NULL, NULL);
|
||||||
|
|
||||||
|
if (!m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
glfwTerminate();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwSetKeyCallback(m_data->m_glfwWindow,GLFWKeyCallback);
|
||||||
|
glfwSetMouseButtonCallback(m_data->m_glfwWindow,GLFWMouseButtonCallback);
|
||||||
|
|
||||||
|
glfwSetCursorPosCallback(m_data->m_glfwWindow,GLFWCursorPosCallback);
|
||||||
|
glfwSetScrollCallback(m_data->m_glfwWindow, GLFWScrollCallback);
|
||||||
|
|
||||||
|
|
||||||
|
glfwSetWindowSizeCallback(m_data->m_glfwWindow, GLFWSizeCallback);
|
||||||
|
glfwSetWindowUserPointer(m_data->m_glfwWindow,this);
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(m_data->m_glfwWindow);
|
||||||
|
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||||
|
glfwSwapInterval(0);//1);
|
||||||
|
glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height);
|
||||||
|
int windowWidth, windowHeight;
|
||||||
|
glfwGetWindowSize(m_data->m_glfwWindow, &windowWidth, &windowHeight);
|
||||||
|
m_data->m_retinaScaleFactor = float(m_data->m_width)/float(windowWidth);
|
||||||
|
glViewport(0,0,m_data->m_width, m_data->m_height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::closeWindow()
|
||||||
|
{
|
||||||
|
if (m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
glfwDestroyWindow(m_data->m_glfwWindow);
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
|
m_data->m_glfwWindow = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::runMainLoop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
float GLFWOpenGLWindow::getTimeInSeconds()
|
||||||
|
{
|
||||||
|
return 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GLFWOpenGLWindow::requestedExit() const
|
||||||
|
{
|
||||||
|
bool shouldClose = m_data->m_requestedExit;
|
||||||
|
|
||||||
|
if (m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
shouldClose = shouldClose || glfwWindowShouldClose(m_data->m_glfwWindow);
|
||||||
|
}
|
||||||
|
return shouldClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::setRequestExit()
|
||||||
|
{
|
||||||
|
if (m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
glfwSetWindowShouldClose(m_data->m_glfwWindow, GLFW_TRUE);
|
||||||
|
}
|
||||||
|
m_data->m_requestedExit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::startRendering()
|
||||||
|
{
|
||||||
|
if (m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::endRendering()
|
||||||
|
{
|
||||||
|
glfwPollEvents();
|
||||||
|
glfwSwapBuffers(m_data->m_glfwWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GLFWOpenGLWindow::isModifierKeyPressed(int key)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case B3G_SHIFT:
|
||||||
|
{
|
||||||
|
result = m_data->m_shiftPressed;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case B3G_ALT:
|
||||||
|
{
|
||||||
|
result = m_data->m_altPressed;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case B3G_CONTROL:
|
||||||
|
{
|
||||||
|
result = m_data->m_ctrlPressed;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::setMouseMoveCallback(b3MouseMoveCallback mouseCallback)
|
||||||
|
{
|
||||||
|
m_data->m_mouseMoveCallback = mouseCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
b3MouseMoveCallback GLFWOpenGLWindow::getMouseMoveCallback()
|
||||||
|
{
|
||||||
|
return m_data->m_mouseMoveCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::setMouseButtonCallback(b3MouseButtonCallback mouseCallback)
|
||||||
|
{
|
||||||
|
m_data->m_mouseButtonCallback = mouseCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
b3MouseButtonCallback GLFWOpenGLWindow::getMouseButtonCallback()
|
||||||
|
{
|
||||||
|
return m_data->m_mouseButtonCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::setResizeCallback(b3ResizeCallback resizeCallback)
|
||||||
|
{
|
||||||
|
m_data->m_resizeCallback = resizeCallback;
|
||||||
|
getResizeCallback()(m_data->m_width/getRetinaScale(),m_data->m_height/getRetinaScale());
|
||||||
|
}
|
||||||
|
|
||||||
|
b3ResizeCallback GLFWOpenGLWindow::getResizeCallback()
|
||||||
|
{
|
||||||
|
return m_data->m_resizeCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::setWheelCallback(b3WheelCallback wheelCallback)
|
||||||
|
{
|
||||||
|
m_data->m_wheelCallback = wheelCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
b3WheelCallback GLFWOpenGLWindow::getWheelCallback()
|
||||||
|
{
|
||||||
|
return m_data->m_wheelCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::setKeyboardCallback( b3KeyboardCallback keyboardCallback)
|
||||||
|
{
|
||||||
|
m_data->m_keyboardCallback = keyboardCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
b3KeyboardCallback GLFWOpenGLWindow::getKeyboardCallback()
|
||||||
|
{
|
||||||
|
return m_data->m_keyboardCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::setRenderCallback( b3RenderCallback renderCallback)
|
||||||
|
{
|
||||||
|
m_data->m_renderCallback = renderCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLFWOpenGLWindow::setWindowTitle(const char* title)
|
||||||
|
{
|
||||||
|
if (m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
glfwSetWindowTitle(m_data->m_glfwWindow,title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float GLFWOpenGLWindow::getRetinaScale() const
|
||||||
|
{
|
||||||
|
return m_data->m_retinaScaleFactor;
|
||||||
|
}
|
||||||
|
void GLFWOpenGLWindow::setAllowRetina(bool allow)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int GLFWOpenGLWindow::getWidth() const
|
||||||
|
{
|
||||||
|
if (m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height);
|
||||||
|
}
|
||||||
|
int width = m_data->m_width/m_data->m_retinaScaleFactor;
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
int GLFWOpenGLWindow::getHeight() const
|
||||||
|
{
|
||||||
|
if (m_data->m_glfwWindow)
|
||||||
|
{
|
||||||
|
glfwGetFramebufferSize(m_data->m_glfwWindow, &m_data->m_width, &m_data->m_height);
|
||||||
|
}
|
||||||
|
return m_data->m_height/m_data->m_retinaScaleFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GLFWOpenGLWindow::fileOpenDialog(char* fileName, int maxFileNameLength)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
78
examples/OpenGLWindow/GLFWOpenGLWindow.h
Normal file
78
examples/OpenGLWindow/GLFWOpenGLWindow.h
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
#ifndef GLFW_OPENGL_WINDOW_H
|
||||||
|
#define GLFW_OPENGL_WINDOW_H
|
||||||
|
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
|
||||||
|
#include "../CommonInterfaces/CommonWindowInterface.h"
|
||||||
|
|
||||||
|
#define b3gDefaultOpenGLWindow GLFWOpenGLWindow
|
||||||
|
|
||||||
|
|
||||||
|
class GLFWOpenGLWindow : public CommonWindowInterface
|
||||||
|
{
|
||||||
|
struct GLFWOpenGLWindowInternalData* m_data;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
GLFWOpenGLWindow();
|
||||||
|
|
||||||
|
virtual ~GLFWOpenGLWindow();
|
||||||
|
|
||||||
|
virtual void createDefaultWindow(int width, int height, const char* title);
|
||||||
|
|
||||||
|
virtual void createWindow(const b3gWindowConstructionInfo& ci);
|
||||||
|
|
||||||
|
virtual void closeWindow();
|
||||||
|
|
||||||
|
virtual void runMainLoop();
|
||||||
|
virtual float getTimeInSeconds();
|
||||||
|
|
||||||
|
virtual bool requestedExit() const;
|
||||||
|
virtual void setRequestExit();
|
||||||
|
|
||||||
|
virtual void startRendering();
|
||||||
|
|
||||||
|
virtual void endRendering();
|
||||||
|
|
||||||
|
virtual bool isModifierKeyPressed(int key);
|
||||||
|
|
||||||
|
virtual void setMouseMoveCallback(b3MouseMoveCallback mouseCallback);
|
||||||
|
virtual b3MouseMoveCallback getMouseMoveCallback();
|
||||||
|
|
||||||
|
virtual void setMouseButtonCallback(b3MouseButtonCallback mouseCallback);
|
||||||
|
virtual b3MouseButtonCallback getMouseButtonCallback();
|
||||||
|
|
||||||
|
virtual void setResizeCallback(b3ResizeCallback resizeCallback);
|
||||||
|
virtual b3ResizeCallback getResizeCallback();
|
||||||
|
|
||||||
|
virtual void setWheelCallback(b3WheelCallback wheelCallback);
|
||||||
|
virtual b3WheelCallback getWheelCallback();
|
||||||
|
|
||||||
|
virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback);
|
||||||
|
virtual b3KeyboardCallback getKeyboardCallback();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
virtual void setRenderCallback( b3RenderCallback renderCallback);
|
||||||
|
|
||||||
|
virtual void setWindowTitle(const char* title);
|
||||||
|
|
||||||
|
virtual float getRetinaScale() const;
|
||||||
|
virtual void setAllowRetina(bool allow);
|
||||||
|
|
||||||
|
virtual int getWidth() const;
|
||||||
|
virtual int getHeight() const;
|
||||||
|
|
||||||
|
virtual int fileOpenDialog(char* fileName, int maxFileNameLength);
|
||||||
|
|
||||||
|
void keyboardCallbackInternal(int key, int state);
|
||||||
|
void mouseButtonCallbackInternal(int button, int state);
|
||||||
|
void mouseCursorCallbackInternal(double xPos, double yPos);
|
||||||
|
void resizeInternal(int width,int height);
|
||||||
|
};
|
||||||
|
#endif//B3_USE_GLFW
|
||||||
|
#endif//GLFW_OPENGL_WINDOW_H
|
||||||
@@ -28,7 +28,9 @@ float shadowMapWorldSize=10;
|
|||||||
#include "OpenGLInclude.h"
|
#include "OpenGLInclude.h"
|
||||||
#include "../CommonInterfaces/CommonWindowInterface.h"
|
#include "../CommonInterfaces/CommonWindowInterface.h"
|
||||||
//#include "Bullet3Common/b3MinMax.h"
|
//#include "Bullet3Common/b3MinMax.h"
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
|
||||||
|
#else
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
#ifndef glVertexAttribDivisor
|
#ifndef glVertexAttribDivisor
|
||||||
#ifndef NO_GLEW
|
#ifndef NO_GLEW
|
||||||
@@ -44,6 +46,7 @@ float shadowMapWorldSize=10;
|
|||||||
#endif //NO_GLEW
|
#endif //NO_GLEW
|
||||||
#endif
|
#endif
|
||||||
#endif //__APPLE__
|
#endif //__APPLE__
|
||||||
|
#endif//B3_USE_GLFW
|
||||||
#include "GLInstancingRenderer.h"
|
#include "GLInstancingRenderer.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#ifndef B3_USE_GLFW
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
||||||
#include "MacOpenGLWindow.h"
|
#include "MacOpenGLWindow.h"
|
||||||
@@ -190,6 +191,6 @@ void MacOpenGLWindow::setAllowRetina(bool allow)
|
|||||||
|
|
||||||
|
|
||||||
#endif //__APPLE__
|
#endif //__APPLE__
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#ifndef B3_USE_GLFW
|
||||||
|
|
||||||
#include "MacOpenGLWindowObjC.h"
|
#include "MacOpenGLWindowObjC.h"
|
||||||
|
|
||||||
#define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
|
#define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
|
||||||
@@ -1231,3 +1233,5 @@ b3ResizeCallback Mac_getResizeCallback(struct MacOpenGLWindowInternalData* m_int
|
|||||||
{
|
{
|
||||||
return [m_internalData->m_myview getResizeCallback];
|
return [m_internalData->m_myview getResizeCallback];
|
||||||
}
|
}
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ subject to the following restrictions:
|
|||||||
#ifndef __OPENGL_INCLUDE_H
|
#ifndef __OPENGL_INCLUDE_H
|
||||||
#define __OPENGL_INCLUDE_H
|
#define __OPENGL_INCLUDE_H
|
||||||
|
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
#include "glad/glad.h"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#else
|
||||||
//think different
|
//think different
|
||||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||||
#include <OpenGL/OpenGL.h>
|
#include <OpenGL/OpenGL.h>
|
||||||
@@ -45,7 +48,7 @@ subject to the following restrictions:
|
|||||||
//#include <GL/glu.h>
|
//#include <GL/glu.h>
|
||||||
#endif //_WINDOWS
|
#endif //_WINDOWS
|
||||||
#endif //APPLE
|
#endif //APPLE
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
//disable glGetError
|
//disable glGetError
|
||||||
//#undef glGetError
|
//#undef glGetError
|
||||||
//#define glGetError MyGetError
|
//#define glGetError MyGetError
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ subject to the following restrictions:
|
|||||||
#ifndef __OPENGL_INCLUDE_H
|
#ifndef __OPENGL_INCLUDE_H
|
||||||
#define __OPENGL_INCLUDE_H
|
#define __OPENGL_INCLUDE_H
|
||||||
|
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#else
|
||||||
//think different
|
//think different
|
||||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||||
#include <OpenGL/OpenGL.h>
|
#include <OpenGL/OpenGL.h>
|
||||||
@@ -31,6 +34,7 @@ subject to the following restrictions:
|
|||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
#ifdef GLEW_STATIC
|
#ifdef GLEW_STATIC
|
||||||
#include "CustomGL/glew.h"
|
#include "CustomGL/glew.h"
|
||||||
#else
|
#else
|
||||||
@@ -52,7 +56,7 @@ subject to the following restrictions:
|
|||||||
//#include <GL/glu.h>
|
//#include <GL/glu.h>
|
||||||
#endif //_WINDOWS
|
#endif //_WINDOWS
|
||||||
#endif //APPLE
|
#endif //APPLE
|
||||||
|
#endif
|
||||||
//disable glGetError
|
//disable glGetError
|
||||||
//#undef glGetError
|
//#undef glGetError
|
||||||
//#define glGetError MyGetError
|
//#define glGetError MyGetError
|
||||||
|
|||||||
@@ -13,6 +13,11 @@
|
|||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "TwFonts.h"
|
#include "TwFonts.h"
|
||||||
#include "SimpleOpenGL2Renderer.h"
|
#include "SimpleOpenGL2Renderer.h"
|
||||||
|
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
#include "GLFWOpenGLWindow.h"
|
||||||
|
#else
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "MacOpenGLWindow.h"
|
#include "MacOpenGLWindow.h"
|
||||||
#else
|
#else
|
||||||
@@ -30,6 +35,8 @@
|
|||||||
#endif //BT_USE_EGL
|
#endif //BT_USE_EGL
|
||||||
#endif //_WIN32
|
#endif //_WIN32
|
||||||
#endif//__APPLE__
|
#endif//__APPLE__
|
||||||
|
#endif //#ifdef B3_USE_GLFW
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "../CommonInterfaces/CommonRenderInterface.h"
|
#include "../CommonInterfaces/CommonRenderInterface.h"
|
||||||
|
|
||||||
@@ -39,9 +46,9 @@ static void Simple2ResizeCallback( float widthf, float heightf)
|
|||||||
{
|
{
|
||||||
int width = (int)widthf;
|
int width = (int)widthf;
|
||||||
int height = (int)heightf;
|
int height = (int)heightf;
|
||||||
if (gApp2->m_renderer)
|
if (gApp2->m_renderer && gApp2->m_window)
|
||||||
gApp2->m_renderer->resize(width,height);
|
gApp2->m_renderer->resize(width,height);//*gApp2->m_window->getRetinaScale(),height*gApp2->m_window->getRetinaScale());
|
||||||
//gApp2->m_renderer->setScreenSize(width,height);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,11 +65,18 @@ static void Simple2KeyboardCallback(int key, int state)
|
|||||||
|
|
||||||
void Simple2MouseButtonCallback( int button, int state, float x, float y)
|
void Simple2MouseButtonCallback( int button, int state, float x, float y)
|
||||||
{
|
{
|
||||||
gApp2->defaultMouseButtonCallback(button,state,x,y);
|
if (gApp2 && gApp2->m_window)
|
||||||
|
{
|
||||||
|
gApp2->defaultMouseButtonCallback(button,state,x,y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void Simple2MouseMoveCallback( float x, float y)
|
void Simple2MouseMoveCallback( float x, float y)
|
||||||
{
|
{
|
||||||
gApp2->defaultMouseMoveCallback(x,y);
|
|
||||||
|
if (gApp2 && gApp2->m_window)
|
||||||
|
{
|
||||||
|
gApp2->defaultMouseMoveCallback(x,y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simple2WheelCallback( float deltax, float deltay)
|
void Simple2WheelCallback( float deltax, float deltay)
|
||||||
@@ -129,7 +143,7 @@ SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height)
|
|||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
#endif //_WIN32
|
#endif //_WIN32
|
||||||
|
|
||||||
|
#ifndef B3_USE_GLFW
|
||||||
if (glewInit() != GLEW_OK)
|
if (glewInit() != GLEW_OK)
|
||||||
{
|
{
|
||||||
b3Error("glewInit failed");
|
b3Error("glewInit failed");
|
||||||
@@ -140,7 +154,7 @@ SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height)
|
|||||||
b3Error("GLEW_VERSION_2_1 needs to support 2_1");
|
b3Error("GLEW_VERSION_2_1 needs to support 2_1");
|
||||||
exit(1); // or handle the error in a nicer way
|
exit(1); // or handle the error in a nicer way
|
||||||
}
|
}
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
#endif //__APPLE__
|
#endif //__APPLE__
|
||||||
#endif //NO_GLEW
|
#endif //NO_GLEW
|
||||||
|
|
||||||
@@ -580,4 +594,4 @@ int SimpleOpenGL2App::registerCubeShape(float halfExtentsX,float halfExtentsY, f
|
|||||||
|
|
||||||
int shapeId = m_renderer->registerShape(&verts[0].xyzw[0],numVertices,cube_indices,numIndices,B3_GL_TRIANGLES,textureIndex);
|
int shapeId = m_renderer->registerShape(&verts[0].xyzw[0],numVertices,cube_indices,numIndices,B3_GL_TRIANGLES,textureIndex);
|
||||||
return shapeId;
|
return shapeId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
#include "SimpleOpenGL3App.h"
|
#include "SimpleOpenGL3App.h"
|
||||||
#include "ShapeData.h"
|
#include "ShapeData.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
#include "GLFWOpenGLWindow.h"
|
||||||
|
#else
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "MacOpenGLWindow.h"
|
#include "MacOpenGLWindow.h"
|
||||||
#else
|
#else
|
||||||
@@ -19,6 +24,8 @@
|
|||||||
#endif //BT_USE_EGL
|
#endif //BT_USE_EGL
|
||||||
#endif //_WIN32
|
#endif //_WIN32
|
||||||
#endif//__APPLE__
|
#endif//__APPLE__
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "GLPrimitiveRenderer.h"
|
#include "GLPrimitiveRenderer.h"
|
||||||
@@ -321,12 +328,12 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo
|
|||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
#endif //_WIN32
|
#endif //_WIN32
|
||||||
|
|
||||||
|
#ifndef B3_USE_GLFW
|
||||||
if (glewInit() != GLEW_OK)
|
if (glewInit() != GLEW_OK)
|
||||||
exit(1); // or handle the error in a nicer way
|
exit(1); // or handle the error in a nicer way
|
||||||
if (!GLEW_VERSION_2_1) // check that the machine supports the 2.1 API.
|
if (!GLEW_VERSION_2_1) // check that the machine supports the 2.1 API.
|
||||||
exit(1); // or handle the error in a nicer way
|
exit(1); // or handle the error in a nicer way
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
#endif //__APPLE__
|
#endif //__APPLE__
|
||||||
#endif //NO_GLEW
|
#endif //NO_GLEW
|
||||||
glGetError();//don't remove this call, it is needed for Ubuntu
|
glGetError();//don't remove this call, it is needed for Ubuntu
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#ifndef B3_USE_GLFW
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
Copyright (c) 2012 Advanced Micro Devices, Inc.
|
||||||
@@ -196,5 +197,5 @@ int Win32OpenGLWindow::getHeight() const
|
|||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
@@ -1007,7 +1007,7 @@ void CMainApplication::RenderFrame()
|
|||||||
// We want to make sure the glFinish waits for the entire present to complete, not just the submission
|
// We want to make sure the glFinish waits for the entire present to complete, not just the submission
|
||||||
// of the command. So, we do a clear here right here so the glFinish will wait fully for the swap.
|
// of the command. So, we do a clear here right here so the glFinish will wait fully for the swap.
|
||||||
glClearColor( 0, 0, 0, 1 );
|
glClearColor( 0, 0, 0, 1 );
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
//glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush and wait for swap.
|
// Flush and wait for swap.
|
||||||
@@ -1281,9 +1281,13 @@ bool CMainApplication::SetupTexturemaps()
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
GLfloat fLargest;
|
GLfloat fLargest;
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &fLargest);
|
||||||
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, fLargest);
|
||||||
|
#else
|
||||||
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);
|
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
glBindTexture( GL_TEXTURE_2D, 0 );
|
glBindTexture( GL_TEXTURE_2D, 0 );
|
||||||
|
|
||||||
@@ -1908,7 +1912,7 @@ void CMainApplication::RenderScene( vr::Hmd_Eye nEye )
|
|||||||
{
|
{
|
||||||
B3_PROFILE("RenderScene");
|
B3_PROFILE("RenderScene");
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
if( m_bShowCubes )
|
if( m_bShowCubes )
|
||||||
@@ -2295,9 +2299,14 @@ bool CGLRenderModel::BInit( const vr::RenderModel_t & vrModel, const vr::RenderM
|
|||||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
GLfloat fLargest;
|
GLfloat fLargest;
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY, &fLargest );
|
||||||
|
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, fLargest );
|
||||||
|
#else
|
||||||
glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest );
|
glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest );
|
||||||
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest );
|
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest );
|
||||||
#endif
|
#endif //B3_USE_GLFW
|
||||||
|
#endif//_WIN32
|
||||||
glBindTexture( GL_TEXTURE_2D, 0 );
|
glBindTexture( GL_TEXTURE_2D, 0 );
|
||||||
|
|
||||||
m_unVertexCount = vrModel.unTriangleCount * 3;
|
m_unVertexCount = vrModel.unTriangleCount * 3;
|
||||||
@@ -2388,6 +2397,7 @@ int main(int argc, char *argv[])
|
|||||||
if (gVideoFileName)
|
if (gVideoFileName)
|
||||||
pMainApplication->getApp()->dumpFramesToVideo(gVideoFileName);
|
pMainApplication->getApp()->dumpFramesToVideo(gVideoFileName);
|
||||||
|
|
||||||
|
#ifndef B3_USE_GLFW
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
//request disable VSYNC
|
//request disable VSYNC
|
||||||
typedef bool (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int);
|
typedef bool (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int);
|
||||||
@@ -2397,7 +2407,7 @@ int main(int argc, char *argv[])
|
|||||||
if (wglSwapIntervalEXT)
|
if (wglSwapIntervalEXT)
|
||||||
wglSwapIntervalEXT(0);
|
wglSwapIntervalEXT(0);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
GLint sync = 0;
|
GLint sync = 0;
|
||||||
CGLContextObj ctx = CGLGetCurrentContext();
|
CGLContextObj ctx = CGLGetCurrentContext();
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
#include "Gwen/Texture.h"
|
#include "Gwen/Texture.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
#include "glad/glad.h"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#else
|
||||||
|
|
||||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||||
#include <OpenGL/OpenGL.h>
|
#include <OpenGL/OpenGL.h>
|
||||||
@@ -22,6 +26,7 @@
|
|||||||
#endif //NO_GLEW
|
#endif //NO_GLEW
|
||||||
#endif //GLEW_STATIC
|
#endif //GLEW_STATIC
|
||||||
#endif//(__APPLE__)
|
#endif//(__APPLE__)
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "FontData.h"
|
#include "FontData.h"
|
||||||
|
|
||||||
@@ -148,7 +153,9 @@ namespace Gwen
|
|||||||
{
|
{
|
||||||
namespace Renderer
|
namespace Renderer
|
||||||
{
|
{
|
||||||
OpenGL_DebugFont::OpenGL_DebugFont()
|
|
||||||
|
OpenGL_DebugFont::OpenGL_DebugFont(float retinaScale)
|
||||||
|
:m_retinaScale(retinaScale)
|
||||||
{
|
{
|
||||||
m_iVertNum = 0;
|
m_iVertNum = 0;
|
||||||
|
|
||||||
@@ -255,8 +262,8 @@ namespace Gwen
|
|||||||
Flush();
|
Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Vertices[ m_iVertNum ].x = (float)x;
|
m_Vertices[ m_iVertNum ].x = (float)x*m_retinaScale;
|
||||||
m_Vertices[ m_iVertNum ].y = (float)y;
|
m_Vertices[ m_iVertNum ].y = (float)y*m_retinaScale;
|
||||||
m_Vertices[ m_iVertNum ].u = u;
|
m_Vertices[ m_iVertNum ].u = u;
|
||||||
m_Vertices[ m_iVertNum ].v = v;
|
m_Vertices[ m_iVertNum ].v = v;
|
||||||
|
|
||||||
@@ -301,16 +308,19 @@ namespace Gwen
|
|||||||
Flush();
|
Flush();
|
||||||
Gwen::Rect rect = ClipRegion();
|
Gwen::Rect rect = ClipRegion();
|
||||||
|
|
||||||
// OpenGL's coords are from the bottom left
|
float retinaScale = m_retinaScale;
|
||||||
// so we need to translate them here.
|
// OpenGL's coords are from the bottom left
|
||||||
{
|
// so we need to translate them here.
|
||||||
GLint view[4];
|
{
|
||||||
glGetIntegerv( GL_VIEWPORT, &view[0] );
|
GLint view[4];
|
||||||
rect.y = view[3] - (rect.y + rect.h);
|
glGetIntegerv( GL_VIEWPORT, &view[0] );
|
||||||
}
|
rect.y = view[3]/retinaScale - (rect.y + rect.h);
|
||||||
|
}
|
||||||
glScissor( rect.x * Scale(), rect.y * Scale(), rect.w * Scale(), rect.h * Scale() );
|
|
||||||
glEnable( GL_SCISSOR_TEST );
|
glScissor( retinaScale * rect.x * Scale(), retinaScale * rect.y * Scale(), retinaScale * rect.w * Scale(), retinaScale * rect.h * Scale() );
|
||||||
|
glEnable( GL_SCISSOR_TEST );
|
||||||
|
//glDisable( GL_SCISSOR_TEST );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void OpenGL_DebugFont::EndClip()
|
void OpenGL_DebugFont::EndClip()
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ namespace Gwen
|
|||||||
|
|
||||||
class OpenGL_DebugFont : public Gwen::Renderer::Base
|
class OpenGL_DebugFont : public Gwen::Renderer::Base
|
||||||
{
|
{
|
||||||
|
float m_retinaScale;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
@@ -32,8 +34,8 @@ namespace Gwen
|
|||||||
|
|
||||||
|
|
||||||
static const int MaxVerts = 1024;
|
static const int MaxVerts = 1024;
|
||||||
|
|
||||||
OpenGL_DebugFont();
|
OpenGL_DebugFont(float retinaScale);
|
||||||
~OpenGL_DebugFont();
|
~OpenGL_DebugFont();
|
||||||
|
|
||||||
void RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString& text );
|
void RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString& text );
|
||||||
|
|||||||
284
examples/ThirdPartyLibs/glad/KHR/khrplatform.h
Normal file
284
examples/ThirdPartyLibs/glad/KHR/khrplatform.h
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
#ifndef __khrplatform_h_
|
||||||
|
#define __khrplatform_h_
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2008-2009 The Khronos Group Inc.
|
||||||
|
**
|
||||||
|
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
** copy of this software and/or associated documentation files (the
|
||||||
|
** "Materials"), to deal in the Materials without restriction, including
|
||||||
|
** without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
** permit persons to whom the Materials are furnished to do so, subject to
|
||||||
|
** the following conditions:
|
||||||
|
**
|
||||||
|
** The above copyright notice and this permission notice shall be included
|
||||||
|
** in all copies or substantial portions of the Materials.
|
||||||
|
**
|
||||||
|
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Khronos platform-specific types and definitions.
|
||||||
|
*
|
||||||
|
* $Revision: 32517 $ on $Date: 2016-03-11 02:41:19 -0800 (Fri, 11 Mar 2016) $
|
||||||
|
*
|
||||||
|
* Adopters may modify this file to suit their platform. Adopters are
|
||||||
|
* encouraged to submit platform specific modifications to the Khronos
|
||||||
|
* group so that they can be included in future versions of this file.
|
||||||
|
* Please submit changes by sending them to the public Khronos Bugzilla
|
||||||
|
* (http://khronos.org/bugzilla) by filing a bug against product
|
||||||
|
* "Khronos (general)" component "Registry".
|
||||||
|
*
|
||||||
|
* A predefined template which fills in some of the bug fields can be
|
||||||
|
* reached using http://tinyurl.com/khrplatform-h-bugreport, but you
|
||||||
|
* must create a Bugzilla login first.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* See the Implementer's Guidelines for information about where this file
|
||||||
|
* should be located on your system and for more details of its use:
|
||||||
|
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||||
|
*
|
||||||
|
* This file should be included as
|
||||||
|
* #include <KHR/khrplatform.h>
|
||||||
|
* by Khronos client API header files that use its types and defines.
|
||||||
|
*
|
||||||
|
* The types in khrplatform.h should only be used to define API-specific types.
|
||||||
|
*
|
||||||
|
* Types defined in khrplatform.h:
|
||||||
|
* khronos_int8_t signed 8 bit
|
||||||
|
* khronos_uint8_t unsigned 8 bit
|
||||||
|
* khronos_int16_t signed 16 bit
|
||||||
|
* khronos_uint16_t unsigned 16 bit
|
||||||
|
* khronos_int32_t signed 32 bit
|
||||||
|
* khronos_uint32_t unsigned 32 bit
|
||||||
|
* khronos_int64_t signed 64 bit
|
||||||
|
* khronos_uint64_t unsigned 64 bit
|
||||||
|
* khronos_intptr_t signed same number of bits as a pointer
|
||||||
|
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||||
|
* khronos_ssize_t signed size
|
||||||
|
* khronos_usize_t unsigned size
|
||||||
|
* khronos_float_t signed 32 bit floating point
|
||||||
|
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||||
|
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||||
|
* nanoseconds
|
||||||
|
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||||
|
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||||
|
* only be used as a base type when a client API's boolean type is
|
||||||
|
* an enum. Client APIs which use an integer or other type for
|
||||||
|
* booleans cannot use this as the base type for their boolean.
|
||||||
|
*
|
||||||
|
* Tokens defined in khrplatform.h:
|
||||||
|
*
|
||||||
|
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||||
|
*
|
||||||
|
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||||
|
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||||
|
*
|
||||||
|
* Calling convention macros defined in this file:
|
||||||
|
* KHRONOS_APICALL
|
||||||
|
* KHRONOS_APIENTRY
|
||||||
|
* KHRONOS_APIATTRIBUTES
|
||||||
|
*
|
||||||
|
* These may be used in function prototypes as:
|
||||||
|
*
|
||||||
|
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||||
|
* int arg1,
|
||||||
|
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APICALL
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This precedes the return type of the function in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||||
|
# define KHRONOS_APICALL __declspec(dllimport)
|
||||||
|
#elif defined (__SYMBIAN32__)
|
||||||
|
# define KHRONOS_APICALL IMPORT_C
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIENTRY
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the return type of the function and precedes the function
|
||||||
|
* name in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||||
|
/* Win32 but not WinCE */
|
||||||
|
# define KHRONOS_APIENTRY __stdcall
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APIENTRY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIATTRIBUTES
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the closing parenthesis of the function prototype arguments.
|
||||||
|
*/
|
||||||
|
#if defined (__ARMCC_2__)
|
||||||
|
#define KHRONOS_APIATTRIBUTES __softfp
|
||||||
|
#else
|
||||||
|
#define KHRONOS_APIATTRIBUTES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* basic type definitions
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <stdint.h>
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(__VMS ) || defined(__sgi)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <inttypes.h>
|
||||||
|
*/
|
||||||
|
#include <inttypes.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Win32
|
||||||
|
*/
|
||||||
|
typedef __int32 khronos_int32_t;
|
||||||
|
typedef unsigned __int32 khronos_uint32_t;
|
||||||
|
typedef __int64 khronos_int64_t;
|
||||||
|
typedef unsigned __int64 khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(__sun__) || defined(__digital__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sun or Digital
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#if defined(__arch64__) || defined(_LP64)
|
||||||
|
typedef long int khronos_int64_t;
|
||||||
|
typedef unsigned long int khronos_uint64_t;
|
||||||
|
#else
|
||||||
|
typedef long long int khronos_int64_t;
|
||||||
|
typedef unsigned long long int khronos_uint64_t;
|
||||||
|
#endif /* __arch64__ */
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif 0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hypothetical platform with no float or int64 support
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 0
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 0
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic fallback
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that are (so far) the same on all platforms
|
||||||
|
*/
|
||||||
|
typedef signed char khronos_int8_t;
|
||||||
|
typedef unsigned char khronos_uint8_t;
|
||||||
|
typedef signed short int khronos_int16_t;
|
||||||
|
typedef unsigned short int khronos_uint16_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||||
|
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||||
|
* to be the only LLP64 architecture in current use.
|
||||||
|
*/
|
||||||
|
#ifdef _WIN64
|
||||||
|
typedef signed long long int khronos_intptr_t;
|
||||||
|
typedef unsigned long long int khronos_uintptr_t;
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
typedef unsigned long long int khronos_usize_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_intptr_t;
|
||||||
|
typedef unsigned long int khronos_uintptr_t;
|
||||||
|
typedef signed long int khronos_ssize_t;
|
||||||
|
typedef unsigned long int khronos_usize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_FLOAT
|
||||||
|
/*
|
||||||
|
* Float type
|
||||||
|
*/
|
||||||
|
typedef float khronos_float_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_INT64
|
||||||
|
/* Time types
|
||||||
|
*
|
||||||
|
* These types can be used to represent a time interval in nanoseconds or
|
||||||
|
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||||
|
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||||
|
* time the system booted). The Unadjusted System Time is an unsigned
|
||||||
|
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||||
|
* may be either signed or unsigned.
|
||||||
|
*/
|
||||||
|
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||||
|
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dummy value used to pad enum types to 32 bits.
|
||||||
|
*/
|
||||||
|
#ifndef KHRONOS_MAX_ENUM
|
||||||
|
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enumerated boolean type
|
||||||
|
*
|
||||||
|
* Values other than zero should be considered to be true. Therefore
|
||||||
|
* comparisons should not be made against KHRONOS_TRUE.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
KHRONOS_FALSE = 0,
|
||||||
|
KHRONOS_TRUE = 1,
|
||||||
|
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||||
|
} khronos_boolean_enum_t;
|
||||||
|
|
||||||
|
#endif /* __khrplatform_h_ */
|
||||||
2499
examples/ThirdPartyLibs/glad/glad.c
Normal file
2499
examples/ThirdPartyLibs/glad/glad.c
Normal file
File diff suppressed because it is too large
Load Diff
5208
examples/ThirdPartyLibs/glad/glad/glad.h
Normal file
5208
examples/ThirdPartyLibs/glad/glad/glad.h
Normal file
File diff suppressed because it is too large
Load Diff
574
examples/ThirdPartyLibs/glad/linmath.h
Normal file
574
examples/ThirdPartyLibs/glad/linmath.h
Normal file
@@ -0,0 +1,574 @@
|
|||||||
|
#ifndef LINMATH_H
|
||||||
|
#define LINMATH_H
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define inline __inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LINMATH_H_DEFINE_VEC(n) \
|
||||||
|
typedef float vec##n[n]; \
|
||||||
|
static inline void vec##n##_add(vec##n r, vec##n const a, vec##n const b) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for(i=0; i<n; ++i) \
|
||||||
|
r[i] = a[i] + b[i]; \
|
||||||
|
} \
|
||||||
|
static inline void vec##n##_sub(vec##n r, vec##n const a, vec##n const b) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for(i=0; i<n; ++i) \
|
||||||
|
r[i] = a[i] - b[i]; \
|
||||||
|
} \
|
||||||
|
static inline void vec##n##_scale(vec##n r, vec##n const v, float const s) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for(i=0; i<n; ++i) \
|
||||||
|
r[i] = v[i] * s; \
|
||||||
|
} \
|
||||||
|
static inline float vec##n##_mul_inner(vec##n const a, vec##n const b) \
|
||||||
|
{ \
|
||||||
|
float p = 0.; \
|
||||||
|
int i; \
|
||||||
|
for(i=0; i<n; ++i) \
|
||||||
|
p += b[i]*a[i]; \
|
||||||
|
return p; \
|
||||||
|
} \
|
||||||
|
static inline float vec##n##_len(vec##n const v) \
|
||||||
|
{ \
|
||||||
|
return (float) sqrt(vec##n##_mul_inner(v,v)); \
|
||||||
|
} \
|
||||||
|
static inline void vec##n##_norm(vec##n r, vec##n const v) \
|
||||||
|
{ \
|
||||||
|
float k = 1.f / vec##n##_len(v); \
|
||||||
|
vec##n##_scale(r, v, k); \
|
||||||
|
}
|
||||||
|
|
||||||
|
LINMATH_H_DEFINE_VEC(2)
|
||||||
|
LINMATH_H_DEFINE_VEC(3)
|
||||||
|
LINMATH_H_DEFINE_VEC(4)
|
||||||
|
|
||||||
|
static inline void vec3_mul_cross(vec3 r, vec3 const a, vec3 const b)
|
||||||
|
{
|
||||||
|
r[0] = a[1]*b[2] - a[2]*b[1];
|
||||||
|
r[1] = a[2]*b[0] - a[0]*b[2];
|
||||||
|
r[2] = a[0]*b[1] - a[1]*b[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void vec3_reflect(vec3 r, vec3 const v, vec3 const n)
|
||||||
|
{
|
||||||
|
float p = 2.f*vec3_mul_inner(v, n);
|
||||||
|
int i;
|
||||||
|
for(i=0;i<3;++i)
|
||||||
|
r[i] = v[i] - p*n[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void vec4_mul_cross(vec4 r, vec4 a, vec4 b)
|
||||||
|
{
|
||||||
|
r[0] = a[1]*b[2] - a[2]*b[1];
|
||||||
|
r[1] = a[2]*b[0] - a[0]*b[2];
|
||||||
|
r[2] = a[0]*b[1] - a[1]*b[0];
|
||||||
|
r[3] = 1.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void vec4_reflect(vec4 r, vec4 v, vec4 n)
|
||||||
|
{
|
||||||
|
float p = 2.f*vec4_mul_inner(v, n);
|
||||||
|
int i;
|
||||||
|
for(i=0;i<4;++i)
|
||||||
|
r[i] = v[i] - p*n[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef vec4 mat4x4[4];
|
||||||
|
static inline void mat4x4_identity(mat4x4 M)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
for(j=0; j<4; ++j)
|
||||||
|
M[i][j] = i==j ? 1.f : 0.f;
|
||||||
|
}
|
||||||
|
static inline void mat4x4_dup(mat4x4 M, mat4x4 N)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
for(j=0; j<4; ++j)
|
||||||
|
M[i][j] = N[i][j];
|
||||||
|
}
|
||||||
|
static inline void mat4x4_row(vec4 r, mat4x4 M, int i)
|
||||||
|
{
|
||||||
|
int k;
|
||||||
|
for(k=0; k<4; ++k)
|
||||||
|
r[k] = M[k][i];
|
||||||
|
}
|
||||||
|
static inline void mat4x4_col(vec4 r, mat4x4 M, int i)
|
||||||
|
{
|
||||||
|
int k;
|
||||||
|
for(k=0; k<4; ++k)
|
||||||
|
r[k] = M[i][k];
|
||||||
|
}
|
||||||
|
static inline void mat4x4_transpose(mat4x4 M, mat4x4 N)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
for(j=0; j<4; ++j)
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
M[i][j] = N[j][i];
|
||||||
|
}
|
||||||
|
static inline void mat4x4_add(mat4x4 M, mat4x4 a, mat4x4 b)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
vec4_add(M[i], a[i], b[i]);
|
||||||
|
}
|
||||||
|
static inline void mat4x4_sub(mat4x4 M, mat4x4 a, mat4x4 b)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
vec4_sub(M[i], a[i], b[i]);
|
||||||
|
}
|
||||||
|
static inline void mat4x4_scale(mat4x4 M, mat4x4 a, float k)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
vec4_scale(M[i], a[i], k);
|
||||||
|
}
|
||||||
|
static inline void mat4x4_scale_aniso(mat4x4 M, mat4x4 a, float x, float y, float z)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
vec4_scale(M[0], a[0], x);
|
||||||
|
vec4_scale(M[1], a[1], y);
|
||||||
|
vec4_scale(M[2], a[2], z);
|
||||||
|
for(i = 0; i < 4; ++i) {
|
||||||
|
M[3][i] = a[3][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static inline void mat4x4_mul(mat4x4 M, mat4x4 a, mat4x4 b)
|
||||||
|
{
|
||||||
|
mat4x4 temp;
|
||||||
|
int k, r, c;
|
||||||
|
for(c=0; c<4; ++c) for(r=0; r<4; ++r) {
|
||||||
|
temp[c][r] = 0.f;
|
||||||
|
for(k=0; k<4; ++k)
|
||||||
|
temp[c][r] += a[k][r] * b[c][k];
|
||||||
|
}
|
||||||
|
mat4x4_dup(M, temp);
|
||||||
|
}
|
||||||
|
static inline void mat4x4_mul_vec4(vec4 r, mat4x4 M, vec4 v)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
for(j=0; j<4; ++j) {
|
||||||
|
r[j] = 0.f;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
r[j] += M[i][j] * v[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static inline void mat4x4_translate(mat4x4 T, float x, float y, float z)
|
||||||
|
{
|
||||||
|
mat4x4_identity(T);
|
||||||
|
T[3][0] = x;
|
||||||
|
T[3][1] = y;
|
||||||
|
T[3][2] = z;
|
||||||
|
}
|
||||||
|
static inline void mat4x4_translate_in_place(mat4x4 M, float x, float y, float z)
|
||||||
|
{
|
||||||
|
vec4 t = {x, y, z, 0};
|
||||||
|
vec4 r;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 4; ++i) {
|
||||||
|
mat4x4_row(r, M, i);
|
||||||
|
M[3][i] += vec4_mul_inner(r, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static inline void mat4x4_from_vec3_mul_outer(mat4x4 M, vec3 a, vec3 b)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
for(i=0; i<4; ++i) for(j=0; j<4; ++j)
|
||||||
|
M[i][j] = i<3 && j<3 ? a[i] * b[j] : 0.f;
|
||||||
|
}
|
||||||
|
static inline void mat4x4_rotate(mat4x4 R, mat4x4 M, float x, float y, float z, float angle)
|
||||||
|
{
|
||||||
|
float s = sinf(angle);
|
||||||
|
float c = cosf(angle);
|
||||||
|
vec3 u = {x, y, z};
|
||||||
|
|
||||||
|
if(vec3_len(u) > 1e-4) {
|
||||||
|
mat4x4 T, C, S = {{0}};
|
||||||
|
|
||||||
|
vec3_norm(u, u);
|
||||||
|
mat4x4_from_vec3_mul_outer(T, u, u);
|
||||||
|
|
||||||
|
S[1][2] = u[0];
|
||||||
|
S[2][1] = -u[0];
|
||||||
|
S[2][0] = u[1];
|
||||||
|
S[0][2] = -u[1];
|
||||||
|
S[0][1] = u[2];
|
||||||
|
S[1][0] = -u[2];
|
||||||
|
|
||||||
|
mat4x4_scale(S, S, s);
|
||||||
|
|
||||||
|
mat4x4_identity(C);
|
||||||
|
mat4x4_sub(C, C, T);
|
||||||
|
|
||||||
|
mat4x4_scale(C, C, c);
|
||||||
|
|
||||||
|
mat4x4_add(T, T, C);
|
||||||
|
mat4x4_add(T, T, S);
|
||||||
|
|
||||||
|
T[3][3] = 1.;
|
||||||
|
mat4x4_mul(R, M, T);
|
||||||
|
} else {
|
||||||
|
mat4x4_dup(R, M);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static inline void mat4x4_rotate_X(mat4x4 Q, mat4x4 M, float angle)
|
||||||
|
{
|
||||||
|
float s = sinf(angle);
|
||||||
|
float c = cosf(angle);
|
||||||
|
mat4x4 R = {
|
||||||
|
{1.f, 0.f, 0.f, 0.f},
|
||||||
|
{0.f, c, s, 0.f},
|
||||||
|
{0.f, -s, c, 0.f},
|
||||||
|
{0.f, 0.f, 0.f, 1.f}
|
||||||
|
};
|
||||||
|
mat4x4_mul(Q, M, R);
|
||||||
|
}
|
||||||
|
static inline void mat4x4_rotate_Y(mat4x4 Q, mat4x4 M, float angle)
|
||||||
|
{
|
||||||
|
float s = sinf(angle);
|
||||||
|
float c = cosf(angle);
|
||||||
|
mat4x4 R = {
|
||||||
|
{ c, 0.f, s, 0.f},
|
||||||
|
{ 0.f, 1.f, 0.f, 0.f},
|
||||||
|
{ -s, 0.f, c, 0.f},
|
||||||
|
{ 0.f, 0.f, 0.f, 1.f}
|
||||||
|
};
|
||||||
|
mat4x4_mul(Q, M, R);
|
||||||
|
}
|
||||||
|
static inline void mat4x4_rotate_Z(mat4x4 Q, mat4x4 M, float angle)
|
||||||
|
{
|
||||||
|
float s = sinf(angle);
|
||||||
|
float c = cosf(angle);
|
||||||
|
mat4x4 R = {
|
||||||
|
{ c, s, 0.f, 0.f},
|
||||||
|
{ -s, c, 0.f, 0.f},
|
||||||
|
{ 0.f, 0.f, 1.f, 0.f},
|
||||||
|
{ 0.f, 0.f, 0.f, 1.f}
|
||||||
|
};
|
||||||
|
mat4x4_mul(Q, M, R);
|
||||||
|
}
|
||||||
|
static inline void mat4x4_invert(mat4x4 T, mat4x4 M)
|
||||||
|
{
|
||||||
|
float idet;
|
||||||
|
float s[6];
|
||||||
|
float c[6];
|
||||||
|
s[0] = M[0][0]*M[1][1] - M[1][0]*M[0][1];
|
||||||
|
s[1] = M[0][0]*M[1][2] - M[1][0]*M[0][2];
|
||||||
|
s[2] = M[0][0]*M[1][3] - M[1][0]*M[0][3];
|
||||||
|
s[3] = M[0][1]*M[1][2] - M[1][1]*M[0][2];
|
||||||
|
s[4] = M[0][1]*M[1][3] - M[1][1]*M[0][3];
|
||||||
|
s[5] = M[0][2]*M[1][3] - M[1][2]*M[0][3];
|
||||||
|
|
||||||
|
c[0] = M[2][0]*M[3][1] - M[3][0]*M[2][1];
|
||||||
|
c[1] = M[2][0]*M[3][2] - M[3][0]*M[2][2];
|
||||||
|
c[2] = M[2][0]*M[3][3] - M[3][0]*M[2][3];
|
||||||
|
c[3] = M[2][1]*M[3][2] - M[3][1]*M[2][2];
|
||||||
|
c[4] = M[2][1]*M[3][3] - M[3][1]*M[2][3];
|
||||||
|
c[5] = M[2][2]*M[3][3] - M[3][2]*M[2][3];
|
||||||
|
|
||||||
|
/* Assumes it is invertible */
|
||||||
|
idet = 1.0f/( s[0]*c[5]-s[1]*c[4]+s[2]*c[3]+s[3]*c[2]-s[4]*c[1]+s[5]*c[0] );
|
||||||
|
|
||||||
|
T[0][0] = ( M[1][1] * c[5] - M[1][2] * c[4] + M[1][3] * c[3]) * idet;
|
||||||
|
T[0][1] = (-M[0][1] * c[5] + M[0][2] * c[4] - M[0][3] * c[3]) * idet;
|
||||||
|
T[0][2] = ( M[3][1] * s[5] - M[3][2] * s[4] + M[3][3] * s[3]) * idet;
|
||||||
|
T[0][3] = (-M[2][1] * s[5] + M[2][2] * s[4] - M[2][3] * s[3]) * idet;
|
||||||
|
|
||||||
|
T[1][0] = (-M[1][0] * c[5] + M[1][2] * c[2] - M[1][3] * c[1]) * idet;
|
||||||
|
T[1][1] = ( M[0][0] * c[5] - M[0][2] * c[2] + M[0][3] * c[1]) * idet;
|
||||||
|
T[1][2] = (-M[3][0] * s[5] + M[3][2] * s[2] - M[3][3] * s[1]) * idet;
|
||||||
|
T[1][3] = ( M[2][0] * s[5] - M[2][2] * s[2] + M[2][3] * s[1]) * idet;
|
||||||
|
|
||||||
|
T[2][0] = ( M[1][0] * c[4] - M[1][1] * c[2] + M[1][3] * c[0]) * idet;
|
||||||
|
T[2][1] = (-M[0][0] * c[4] + M[0][1] * c[2] - M[0][3] * c[0]) * idet;
|
||||||
|
T[2][2] = ( M[3][0] * s[4] - M[3][1] * s[2] + M[3][3] * s[0]) * idet;
|
||||||
|
T[2][3] = (-M[2][0] * s[4] + M[2][1] * s[2] - M[2][3] * s[0]) * idet;
|
||||||
|
|
||||||
|
T[3][0] = (-M[1][0] * c[3] + M[1][1] * c[1] - M[1][2] * c[0]) * idet;
|
||||||
|
T[3][1] = ( M[0][0] * c[3] - M[0][1] * c[1] + M[0][2] * c[0]) * idet;
|
||||||
|
T[3][2] = (-M[3][0] * s[3] + M[3][1] * s[1] - M[3][2] * s[0]) * idet;
|
||||||
|
T[3][3] = ( M[2][0] * s[3] - M[2][1] * s[1] + M[2][2] * s[0]) * idet;
|
||||||
|
}
|
||||||
|
static inline void mat4x4_orthonormalize(mat4x4 R, mat4x4 M)
|
||||||
|
{
|
||||||
|
float s = 1.;
|
||||||
|
vec3 h;
|
||||||
|
|
||||||
|
mat4x4_dup(R, M);
|
||||||
|
vec3_norm(R[2], R[2]);
|
||||||
|
|
||||||
|
s = vec3_mul_inner(R[1], R[2]);
|
||||||
|
vec3_scale(h, R[2], s);
|
||||||
|
vec3_sub(R[1], R[1], h);
|
||||||
|
vec3_norm(R[2], R[2]);
|
||||||
|
|
||||||
|
s = vec3_mul_inner(R[1], R[2]);
|
||||||
|
vec3_scale(h, R[2], s);
|
||||||
|
vec3_sub(R[1], R[1], h);
|
||||||
|
vec3_norm(R[1], R[1]);
|
||||||
|
|
||||||
|
s = vec3_mul_inner(R[0], R[1]);
|
||||||
|
vec3_scale(h, R[1], s);
|
||||||
|
vec3_sub(R[0], R[0], h);
|
||||||
|
vec3_norm(R[0], R[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void mat4x4_frustum(mat4x4 M, float l, float r, float b, float t, float n, float f)
|
||||||
|
{
|
||||||
|
M[0][0] = 2.f*n/(r-l);
|
||||||
|
M[0][1] = M[0][2] = M[0][3] = 0.f;
|
||||||
|
|
||||||
|
M[1][1] = 2.f*n/(t-b);
|
||||||
|
M[1][0] = M[1][2] = M[1][3] = 0.f;
|
||||||
|
|
||||||
|
M[2][0] = (r+l)/(r-l);
|
||||||
|
M[2][1] = (t+b)/(t-b);
|
||||||
|
M[2][2] = -(f+n)/(f-n);
|
||||||
|
M[2][3] = -1.f;
|
||||||
|
|
||||||
|
M[3][2] = -2.f*(f*n)/(f-n);
|
||||||
|
M[3][0] = M[3][1] = M[3][3] = 0.f;
|
||||||
|
}
|
||||||
|
static inline void mat4x4_ortho(mat4x4 M, float l, float r, float b, float t, float n, float f)
|
||||||
|
{
|
||||||
|
M[0][0] = 2.f/(r-l);
|
||||||
|
M[0][1] = M[0][2] = M[0][3] = 0.f;
|
||||||
|
|
||||||
|
M[1][1] = 2.f/(t-b);
|
||||||
|
M[1][0] = M[1][2] = M[1][3] = 0.f;
|
||||||
|
|
||||||
|
M[2][2] = -2.f/(f-n);
|
||||||
|
M[2][0] = M[2][1] = M[2][3] = 0.f;
|
||||||
|
|
||||||
|
M[3][0] = -(r+l)/(r-l);
|
||||||
|
M[3][1] = -(t+b)/(t-b);
|
||||||
|
M[3][2] = -(f+n)/(f-n);
|
||||||
|
M[3][3] = 1.f;
|
||||||
|
}
|
||||||
|
static inline void mat4x4_perspective(mat4x4 m, float y_fov, float aspect, float n, float f)
|
||||||
|
{
|
||||||
|
/* NOTE: Degrees are an unhandy unit to work with.
|
||||||
|
* linmath.h uses radians for everything! */
|
||||||
|
float const a = 1.f / (float) tan(y_fov / 2.f);
|
||||||
|
|
||||||
|
m[0][0] = a / aspect;
|
||||||
|
m[0][1] = 0.f;
|
||||||
|
m[0][2] = 0.f;
|
||||||
|
m[0][3] = 0.f;
|
||||||
|
|
||||||
|
m[1][0] = 0.f;
|
||||||
|
m[1][1] = a;
|
||||||
|
m[1][2] = 0.f;
|
||||||
|
m[1][3] = 0.f;
|
||||||
|
|
||||||
|
m[2][0] = 0.f;
|
||||||
|
m[2][1] = 0.f;
|
||||||
|
m[2][2] = -((f + n) / (f - n));
|
||||||
|
m[2][3] = -1.f;
|
||||||
|
|
||||||
|
m[3][0] = 0.f;
|
||||||
|
m[3][1] = 0.f;
|
||||||
|
m[3][2] = -((2.f * f * n) / (f - n));
|
||||||
|
m[3][3] = 0.f;
|
||||||
|
}
|
||||||
|
static inline void mat4x4_look_at(mat4x4 m, vec3 eye, vec3 center, vec3 up)
|
||||||
|
{
|
||||||
|
/* Adapted from Android's OpenGL Matrix.java. */
|
||||||
|
/* See the OpenGL GLUT documentation for gluLookAt for a description */
|
||||||
|
/* of the algorithm. We implement it in a straightforward way: */
|
||||||
|
|
||||||
|
/* TODO: The negation of of can be spared by swapping the order of
|
||||||
|
* operands in the following cross products in the right way. */
|
||||||
|
vec3 f;
|
||||||
|
vec3 s;
|
||||||
|
vec3 t;
|
||||||
|
|
||||||
|
vec3_sub(f, center, eye);
|
||||||
|
vec3_norm(f, f);
|
||||||
|
|
||||||
|
vec3_mul_cross(s, f, up);
|
||||||
|
vec3_norm(s, s);
|
||||||
|
|
||||||
|
vec3_mul_cross(t, s, f);
|
||||||
|
|
||||||
|
m[0][0] = s[0];
|
||||||
|
m[0][1] = t[0];
|
||||||
|
m[0][2] = -f[0];
|
||||||
|
m[0][3] = 0.f;
|
||||||
|
|
||||||
|
m[1][0] = s[1];
|
||||||
|
m[1][1] = t[1];
|
||||||
|
m[1][2] = -f[1];
|
||||||
|
m[1][3] = 0.f;
|
||||||
|
|
||||||
|
m[2][0] = s[2];
|
||||||
|
m[2][1] = t[2];
|
||||||
|
m[2][2] = -f[2];
|
||||||
|
m[2][3] = 0.f;
|
||||||
|
|
||||||
|
m[3][0] = 0.f;
|
||||||
|
m[3][1] = 0.f;
|
||||||
|
m[3][2] = 0.f;
|
||||||
|
m[3][3] = 1.f;
|
||||||
|
|
||||||
|
mat4x4_translate_in_place(m, -eye[0], -eye[1], -eye[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef float quat[4];
|
||||||
|
static inline void quat_identity(quat q)
|
||||||
|
{
|
||||||
|
q[0] = q[1] = q[2] = 0.f;
|
||||||
|
q[3] = 1.f;
|
||||||
|
}
|
||||||
|
static inline void quat_add(quat r, quat a, quat b)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
r[i] = a[i] + b[i];
|
||||||
|
}
|
||||||
|
static inline void quat_sub(quat r, quat a, quat b)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
r[i] = a[i] - b[i];
|
||||||
|
}
|
||||||
|
static inline void quat_mul(quat r, quat p, quat q)
|
||||||
|
{
|
||||||
|
vec3 w;
|
||||||
|
vec3_mul_cross(r, p, q);
|
||||||
|
vec3_scale(w, p, q[3]);
|
||||||
|
vec3_add(r, r, w);
|
||||||
|
vec3_scale(w, q, p[3]);
|
||||||
|
vec3_add(r, r, w);
|
||||||
|
r[3] = p[3]*q[3] - vec3_mul_inner(p, q);
|
||||||
|
}
|
||||||
|
static inline void quat_scale(quat r, quat v, float s)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
r[i] = v[i] * s;
|
||||||
|
}
|
||||||
|
static inline float quat_inner_product(quat a, quat b)
|
||||||
|
{
|
||||||
|
float p = 0.f;
|
||||||
|
int i;
|
||||||
|
for(i=0; i<4; ++i)
|
||||||
|
p += b[i]*a[i];
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
static inline void quat_conj(quat r, quat q)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0; i<3; ++i)
|
||||||
|
r[i] = -q[i];
|
||||||
|
r[3] = q[3];
|
||||||
|
}
|
||||||
|
static inline void quat_rotate(quat r, float angle, vec3 axis) {
|
||||||
|
int i;
|
||||||
|
vec3 v;
|
||||||
|
vec3_scale(v, axis, sinf(angle / 2));
|
||||||
|
for(i=0; i<3; ++i)
|
||||||
|
r[i] = v[i];
|
||||||
|
r[3] = cosf(angle / 2);
|
||||||
|
}
|
||||||
|
#define quat_norm vec4_norm
|
||||||
|
static inline void quat_mul_vec3(vec3 r, quat q, vec3 v)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Method by Fabian 'ryg' Giessen (of Farbrausch)
|
||||||
|
t = 2 * cross(q.xyz, v)
|
||||||
|
v' = v + q.w * t + cross(q.xyz, t)
|
||||||
|
*/
|
||||||
|
vec3 t = {q[0], q[1], q[2]};
|
||||||
|
vec3 u = {q[0], q[1], q[2]};
|
||||||
|
|
||||||
|
vec3_mul_cross(t, t, v);
|
||||||
|
vec3_scale(t, t, 2);
|
||||||
|
|
||||||
|
vec3_mul_cross(u, u, t);
|
||||||
|
vec3_scale(t, t, q[3]);
|
||||||
|
|
||||||
|
vec3_add(r, v, t);
|
||||||
|
vec3_add(r, r, u);
|
||||||
|
}
|
||||||
|
static inline void mat4x4_from_quat(mat4x4 M, quat q)
|
||||||
|
{
|
||||||
|
float a = q[3];
|
||||||
|
float b = q[0];
|
||||||
|
float c = q[1];
|
||||||
|
float d = q[2];
|
||||||
|
float a2 = a*a;
|
||||||
|
float b2 = b*b;
|
||||||
|
float c2 = c*c;
|
||||||
|
float d2 = d*d;
|
||||||
|
|
||||||
|
M[0][0] = a2 + b2 - c2 - d2;
|
||||||
|
M[0][1] = 2.f*(b*c + a*d);
|
||||||
|
M[0][2] = 2.f*(b*d - a*c);
|
||||||
|
M[0][3] = 0.f;
|
||||||
|
|
||||||
|
M[1][0] = 2*(b*c - a*d);
|
||||||
|
M[1][1] = a2 - b2 + c2 - d2;
|
||||||
|
M[1][2] = 2.f*(c*d + a*b);
|
||||||
|
M[1][3] = 0.f;
|
||||||
|
|
||||||
|
M[2][0] = 2.f*(b*d + a*c);
|
||||||
|
M[2][1] = 2.f*(c*d - a*b);
|
||||||
|
M[2][2] = a2 - b2 - c2 + d2;
|
||||||
|
M[2][3] = 0.f;
|
||||||
|
|
||||||
|
M[3][0] = M[3][1] = M[3][2] = 0.f;
|
||||||
|
M[3][3] = 1.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void mat4x4o_mul_quat(mat4x4 R, mat4x4 M, quat q)
|
||||||
|
{
|
||||||
|
/* XXX: The way this is written only works for othogonal matrices. */
|
||||||
|
/* TODO: Take care of non-orthogonal case. */
|
||||||
|
quat_mul_vec3(R[0], q, M[0]);
|
||||||
|
quat_mul_vec3(R[1], q, M[1]);
|
||||||
|
quat_mul_vec3(R[2], q, M[2]);
|
||||||
|
|
||||||
|
R[3][0] = R[3][1] = R[3][2] = 0.f;
|
||||||
|
R[3][3] = 1.f;
|
||||||
|
}
|
||||||
|
static inline void quat_from_mat4x4(quat q, mat4x4 M)
|
||||||
|
{
|
||||||
|
float r=0.f;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
int perm[] = { 0, 1, 2, 0, 1 };
|
||||||
|
int *p = perm;
|
||||||
|
|
||||||
|
for(i = 0; i<3; i++) {
|
||||||
|
float m = M[i][i];
|
||||||
|
if( m < r )
|
||||||
|
continue;
|
||||||
|
m = r;
|
||||||
|
p = &perm[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
r = (float) sqrt(1.f + M[p[0]][p[0]] - M[p[1]][p[1]] - M[p[2]][p[2]] );
|
||||||
|
|
||||||
|
if(r < 1e-6) {
|
||||||
|
q[0] = 1.f;
|
||||||
|
q[1] = q[2] = q[3] = 0.f;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
q[0] = r/2.f;
|
||||||
|
q[1] = (M[p[0]][p[1]] - M[p[1]][p[0]])/(2.f*r);
|
||||||
|
q[2] = (M[p[2]][p[0]] - M[p[0]][p[2]])/(2.f*r);
|
||||||
|
q[3] = (M[p[2]][p[1]] - M[p[1]][p[2]])/(2.f*r);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -9,6 +9,10 @@
|
|||||||
extern unsigned char OpenSansData[];
|
extern unsigned char OpenSansData[];
|
||||||
|
|
||||||
#include "Gwen/Renderers/OpenGL_DebugFont.h"
|
#include "Gwen/Renderers/OpenGL_DebugFont.h"
|
||||||
|
|
||||||
|
#ifdef B3_USE_GLFW
|
||||||
|
#include "OpenGLWindow/GLFWOpenGLWindow.h"
|
||||||
|
#else
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "OpenGLWindow/MacOpenGLWindow.h"
|
#include "OpenGLWindow/MacOpenGLWindow.h"
|
||||||
#else
|
#else
|
||||||
@@ -21,7 +25,7 @@ extern unsigned char OpenSansData[];
|
|||||||
#include "OpenGLWindow/X11OpenGLWindow.h"
|
#include "OpenGLWindow/X11OpenGLWindow.h"
|
||||||
#endif //_WIN32
|
#endif //_WIN32
|
||||||
#endif//__APPLE__
|
#endif//__APPLE__
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
#include "OpenGLWindow/opengl_fontstashcallbacks.h"
|
#include "OpenGLWindow/opengl_fontstashcallbacks.h"
|
||||||
#ifndef NO_OPENGL3
|
#ifndef NO_OPENGL3
|
||||||
#include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
|
#include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
|
||||||
@@ -341,11 +345,13 @@ int main()
|
|||||||
sprintf(title,"Gwen with OpenGL %d\n",wci.m_openglVersion);
|
sprintf(title,"Gwen with OpenGL %d\n",wci.m_openglVersion);
|
||||||
}
|
}
|
||||||
window->setWindowTitle(title);
|
window->setWindowTitle(title);
|
||||||
|
|
||||||
|
float retinaScale = window->getRetinaScale();
|
||||||
|
|
||||||
#ifndef NO_OPENGL3
|
#ifndef NO_OPENGL3
|
||||||
if (majorGlVersion>=3 && wci.m_openglVersion>=3)
|
if (majorGlVersion>=3 && wci.m_openglVersion>=3)
|
||||||
{
|
{
|
||||||
float retinaScale = 1.f;
|
#ifndef B3_USE_GLFW
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
//we need glewExperimental on Linux
|
//we need glewExperimental on Linux
|
||||||
@@ -353,7 +359,7 @@ int main()
|
|||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
glewInit();
|
glewInit();
|
||||||
#endif
|
#endif
|
||||||
|
#endif //B3_USE_GLFW
|
||||||
//we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue
|
//we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue
|
||||||
|
|
||||||
GLuint err = glGetError();
|
GLuint err = glGetError();
|
||||||
@@ -361,8 +367,6 @@ int main()
|
|||||||
assert(err==GL_NO_ERROR);
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
retinaScale = window->getRetinaScale();
|
|
||||||
|
|
||||||
primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
|
primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
|
||||||
|
|
||||||
sth_stash* font = initFont(primRenderer );
|
sth_stash* font = initFont(primRenderer );
|
||||||
@@ -374,7 +378,7 @@ int main()
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
//OpenGL 2.x
|
//OpenGL 2.x
|
||||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(retinaScale);
|
||||||
|
|
||||||
|
|
||||||
skin.SetRender( gwenRenderer );
|
skin.SetRender( gwenRenderer );
|
||||||
|
|||||||
@@ -44,6 +44,9 @@
|
|||||||
"**.cpp",
|
"**.cpp",
|
||||||
"**.h",
|
"**.h",
|
||||||
}
|
}
|
||||||
|
files {
|
||||||
|
"../../examples/OpenGLWindow/GLFWOpenGLWindow.cpp",
|
||||||
|
}
|
||||||
if os.is("Windows") then
|
if os.is("Windows") then
|
||||||
files {
|
files {
|
||||||
"../../examples/OpenGLWindow/Win32OpenGLWindow.cpp",
|
"../../examples/OpenGLWindow/Win32OpenGLWindow.cpp",
|
||||||
@@ -62,7 +65,6 @@
|
|||||||
end
|
end
|
||||||
if os.is("MacOSX") then
|
if os.is("MacOSX") then
|
||||||
links{"Cocoa.framework"}
|
links{"Cocoa.framework"}
|
||||||
print("hello!")
|
|
||||||
files{
|
files{
|
||||||
"../../examples/OpenGLWindow/MacOpenGLWindow.cpp",
|
"../../examples/OpenGLWindow/MacOpenGLWindow.cpp",
|
||||||
"../../examples/OpenGLWindow/MacOpenGLWindow.h",
|
"../../examples/OpenGLWindow/MacOpenGLWindow.h",
|
||||||
|
|||||||
Reference in New Issue
Block a user