work in progress, cleaned up the directories and split them up into folder which make more sense, Still need to compile libvitaboy and all the tools

This commit is contained in:
Jip 2024-05-13 18:38:21 +02:00
parent 66ce473514
commit 948bd8474c
1786 changed files with 571812 additions and 15332 deletions

View file

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 2.6...3.29)
project(libgldemo)
if(WIN32)
set(GLDEMO_EXE WIN32)
set(GLDEMO_LINK mingw32 libgldemo_static opengl32 glu32)
else()
set(GLDEMO_EXE "")
set(GLDEMO_LINK libgldemo_static Xxf86vm rt Xext X11 GL GLU)
endif()
if(WIN32)
set(LIBGLDEMO_SOURCES wgl.c)
else()
set(LIBGLDEMO_SOURCES glx.c)
add_definitions(-D_POSIX_C_SOURCE=200112)
endif()
add_library(libgldemo_static STATIC ${LIBGLDEMO_SOURCES})
set_target_properties(libgldemo_static PROPERTIES
OUTPUT_NAME "gldemo"
CLEAN_DIRECT_OUTPUT 1)

234
examples/gldemo/glx.c Normal file
View file

@ -0,0 +1,234 @@
/*
libgldemo - General-purpose OpenGL demo backend
glx.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libgldemo.h"
static Display *display = NULL;
static int screen = 0;
static Window window = 0;
static GLXContext hrc = 0;
static uint8_t keys[256] = {0};
static uint8_t f11_pressed = 0;
static uint16_t WndWidth, WndHeight;
static uint16_t ResWidth, ResHeight;
static int fullscreen = 0;
void KillGLWindow()
{
if(hrc){
glXMakeCurrent(display, None, NULL);
glXDestroyContext(display, hrc);
hrc = 0;
}
if(window){
XDestroyWindow(display, window);
window = 0;
}
}
static int CreateGLWindow(const char *__restrict title, uint16_t width, uint16_t height)
{
int attlist[] = {
GLX_RGBA,
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_DEPTH_SIZE, 16,
GLX_DOUBLEBUFFER,
None
};
XVisualInfo *visualinfo;
Colormap cmap;
Atom wmDelete;
XSetWindowAttributes attr;
int (APIENTRY *glXSwapIntervalSGIptr)(int);
visualinfo = glXChooseVisual(display, screen, attlist);
if(visualinfo == NULL){
KillGLWindow();
DemoErrorBox("Can't find a suitable pixel format.");
return 0;
}
/* create a color map */
cmap = XCreateColormap(display, RootWindow(display, visualinfo->screen), visualinfo->visual, AllocNone);
attr.colormap = cmap;
attr.border_pixel = 0;
hrc = glXCreateContext(display, visualinfo, NULL, GL_TRUE);
if(hrc == NULL){
KillGLWindow();
DemoErrorBox("Failed to create an OpenGL rendering context.");
return 0;
}
attr.event_mask = KeyPressMask | KeyReleaseMask | StructureNotifyMask;
if(fullscreen){
attr.override_redirect = True;
width = ResWidth;
height = ResHeight;
XWarpPointer(display, None, window, 0, 0, 0, 0, 0, 0);
}else{
attr.override_redirect = False;
}
if(!(window = XCreateWindow(display, XRootWindow(display, visualinfo->screen),
(ResWidth - width)>>1,
(ResHeight - height)>>1,
width,
height,
0, visualinfo->depth, InputOutput, visualinfo->visual,
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr)
)){
KillGLWindow();
DemoErrorBox("Window creation error.");
return 0;
}
WndWidth = width;
WndHeight = height;
XSetStandardProperties(display, window, title, title, None, NULL, 0, NULL);
XMapRaised(display, window);
XGrabKeyboard(display, window, True, GrabModeAsync, GrabModeAsync, CurrentTime);
wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
XSetWMProtocols(display, window, &wmDelete, 1);
/* connect the glx-context to the window */
glXMakeCurrent(display, window, hrc);
XFlush(display);
if(!Demo.InitGL()){
KillGLWindow();
DemoErrorBox("Initialization failed.");
return 0;
}
if(!Demo.ResizeScene(width&&height ? width : 1, width&&height ? height : 1)){
KillGLWindow();
DemoErrorBox("Scene resize failed.");
return 0;
}
glXSwapIntervalSGIptr = (int (APIENTRY *)(int)) glXGetProcAddressARB((const GLubyte *) "glXSwapIntervalSGI");
if(glXSwapIntervalSGIptr) glXSwapIntervalSGIptr(1);
return 1;
}
int main()
{
int dotclock;
XF86VidModeModeLine modeline;
struct timespec time1;
display = XOpenDisplay(0);
if(display == NULL){
KillGLWindow();
DemoErrorBox("Failed to obtain the X11 display context.");
return 0;
}
XkbSetDetectableAutoRepeat(display, True, 0);
screen = XDefaultScreen(display);
XF86VidModeGetModeLine(display, screen, &dotclock, &modeline);
ResWidth = modeline.hdisplay;
ResHeight = modeline.vdisplay;
if(Demo.Startup && !Demo.Startup())
return -1;
if(!CreateGLWindow(Demo.Title, Demo.Width, Demo.Height))
return -1;
clock_gettime(CLOCK_REALTIME, &time1);
while(1){
struct timespec time2;
float TimeDelta;
while(XPending(display)){
XEvent event;
XNextEvent(display, &event);
switch(event.type){
case ConfigureNotify:
if(((unsigned)event.xconfigure.width != WndWidth) ||
((unsigned)event.xconfigure.height != WndHeight)){
WndWidth = event.xconfigure.width;
WndHeight = event.xconfigure.height;
Demo.ResizeScene(event.xconfigure.width, event.xconfigure.height);
}
break;
case KeyPress: {
KeySym key = XLookupKeysym(&event.xkey, 0);
if(key <= 255)
keys[(key + 'A' - 'a') & 255] = 1;
else if(key == XK_Left) keys[KEY_LEFT] = 1;
else if(key == XK_Up) keys[KEY_UP] = 1;
else if(key == XK_Right) keys[KEY_RIGHT] = 1;
else if(key == XK_Down) keys[KEY_DOWN] = 1;
else{
if(key == XK_Escape){
KillGLWindow();
XCloseDisplay(display);
return (!Demo.Shutdown || Demo.Shutdown()) ? 0 : -1;
}
if(key == XK_F11 && !f11_pressed){
KillGLWindow();
fullscreen = !fullscreen;
CreateGLWindow(Demo.Title, Demo.Width, Demo.Height);
f11_pressed = 1;
}
}
break;
}
case KeyRelease: {
KeySym key = XLookupKeysym(&event.xkey, 0);
if(key <= 255)
keys[(key + 'A' - 'a') & 255] = 0;
else if(key == XK_Left) keys[KEY_LEFT] = 0;
else if(key == XK_Up) keys[KEY_UP] = 0;
else if(key == XK_Right) keys[KEY_RIGHT] = 0;
else if(key == XK_Down) keys[KEY_DOWN] = 0;
else if(key == XK_F11) f11_pressed = 0;
break;
}
case ClientMessage:
if (XGetAtomName(display, event.xclient.message_type)[0] == 'W'){
KillGLWindow();
XCloseDisplay(display);
return (!Demo.Shutdown || Demo.Shutdown()) ? 0 : -1;
}
}
}
/* Find the timedelta */
clock_gettime(CLOCK_REALTIME, &time2);
TimeDelta = (float)(time2.tv_sec - time1.tv_sec) + ((float)(time2.tv_nsec - time1.tv_nsec)) * 1e-9;
if(TimeDelta < 0) TimeDelta = 0; /* Safe-guard in case of system delay */
time1 = time2;
/* Draw */
Demo.DrawScene(TimeDelta, keys);
glXSwapBuffers(display, window);
}
}

View file

@ -0,0 +1,68 @@
/*
libgldemo - General-purpose OpenGL demo backend
libgldemo.h - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
typedef struct {
const char *__restrict Title;
uint16_t Width, Height;
int (* Startup)(void);
int (* Shutdown)(void);
int (* InitGL)(void);
int (* ResizeScene)(uint16_t width, uint16_t height);
int (* DrawScene)(float TimeDelta, uint8_t keys[256]);
} DemoConfig;
#ifdef __cplusplus
extern "C" {
#endif
extern const DemoConfig Demo;
#ifdef __cplusplus
}
#endif
#ifdef _WIN32
#include <windows.h>
#define DemoMessageBox(x) MessageBox(NULL, x, NULL, MB_OK)
#define DemoErrorBox(x) MessageBox(NULL, x, NULL, MB_OK | MB_ICONERROR)
#define KEY_LEFT VK_LEFT
#define KEY_UP VK_UP
#define KEY_RIGHT VK_RIGHT
#define KEY_DOWN VK_DOWN
#else
#define POSIX_C_SOURCE 199309L
#include <stdio.h>
#include <time.h>
#include <GL/glx.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/XKBlib.h>
#include <X11/keysym.h>
#define DemoMessageBox(x) fprintf(stdout, "%s\n", x)
#define DemoErrorBox(x) fprintf(stderr, "%s\n", x)
#define KEY_LEFT 0x25
#define KEY_UP 0x26
#define KEY_RIGHT 0x27
#define KEY_DOWN 0x28
#endif

281
examples/gldemo/wgl.c Normal file
View file

@ -0,0 +1,281 @@
/*
libgldemo - General-purpose OpenGL demo backend
wgl.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libgldemo.h"
static HWND hWnd = NULL;
static HDC hDC = NULL;
static HGLRC hRC = NULL;
static HINSTANCE hInst;
static uint8_t keys[256] = {0};
static uint16_t ResWidth, ResHeight, ResDepth;
static int fullscreen = 0;
static float FramePeriod;
static void KillGLWindow()
{
if(fullscreen){
ShowCursor(1);
}
if(hRC){
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
hRC = NULL;
}
if(hDC){
ReleaseDC(hWnd, hDC);
hDC = NULL;
}
if(hWnd){
DestroyWindow(hWnd);
hWnd = NULL;
}
}
static int CreateGLWindow(const char *__restrict title, uint16_t width, uint16_t height)
{
const PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), 1, /* Size and version */
PFD_DRAW_TO_WINDOW | /* dwFlags */
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA, /* iPixelType */
0, /* cColorBits */
0, 0, 0, 0, 0, 0, 0, 0, /* R,G,B,A bits */
0, 0, 0, 0, 0, /* Accumulation buffer bits */
16, /* cDepthBits */
0, /* cStencilBits */
0, /* cAuxBuffers */
PFD_MAIN_PLANE, /* iLayerType */
0, /* Reserved */
0, 0, 0 /* Masks */
};
DWORD dwStyle, dwExStyle;
RECT WindowRect;
int PixelFormat;
BOOL (WINAPI *wglSwapIntervalEXT)(int);
int (WINAPI *wglGetSwapIntervalEXT)(void);
if(fullscreen){
dwExStyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
dwStyle = WS_POPUP;
width = ResWidth;
height = ResHeight;
ShowCursor(0);
}else{
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
WindowRect.left = 0;
WindowRect.right = width;
WindowRect.top = 0;
WindowRect.bottom = height;
AdjustWindowRectEx(&WindowRect, dwStyle, 0, dwExStyle);
width = WindowRect.right - WindowRect.left;
height = WindowRect.bottom - WindowRect.top;
}
if(!(hWnd = CreateWindowEx(dwExStyle, "OpenGL",
title,
dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
(ResWidth - width)>>1,
(ResHeight - height)>>1,
width,
height,
NULL, NULL, hInst, NULL))
){
KillGLWindow();
DemoErrorBox("Window creation error.");
return 0;
}
hDC = GetDC(hWnd);
if(!hDC){
KillGLWindow();
DemoErrorBox("Failed to create an OpenGL device context.");
return 0;
}
PixelFormat = ChoosePixelFormat(hDC, &pfd);
if(!PixelFormat){
KillGLWindow();
DemoErrorBox("Can't find a suitable PixelFormat.");
return 0;
}
if(!SetPixelFormat(hDC, PixelFormat, &pfd)){
KillGLWindow();
DemoErrorBox("Can't set the PixelFormat.");
return 0;
}
hRC = wglCreateContext(hDC);
if(!hRC){
KillGLWindow();
DemoErrorBox("Failed to create an OpenGL rendering context.");
return 0;
}
if(!wglMakeCurrent(hDC, hRC)){
KillGLWindow();
DemoErrorBox("Failed to activate the OpenGL device context.");
return 0;
}
ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
if(!Demo.InitGL()){
KillGLWindow();
DemoErrorBox("Initialization failed.");
return 0;
}
if(!Demo.ResizeScene(width&&height ? width : 1, width&&height ? height : 1)){
KillGLWindow();
DemoErrorBox("Scene resize failed.");
return 0;
}
wglSwapIntervalEXT = (BOOL (WINAPI *)(int)) wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
wglGetSwapIntervalEXT = (int (WINAPI *)(void)) wglGetProcAddress("wglGetSwapIntervalEXT");
if(wglGetSwapIntervalEXT) wglGetSwapIntervalEXT(); /* Seems necessary on some cards */
return 1;
}
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_KEYDOWN:
if(wParam == VK_ESCAPE){
PostQuitMessage(0);
}else if(wParam == VK_F11 && !keys[VK_F11]){
KillGLWindow();
fullscreen = !fullscreen;
if(!CreateGLWindow(Demo.Title, Demo.Width, Demo.Height))
PostQuitMessage(0);
}
case WM_KEYUP:
keys[wParam] = (uMsg == WM_KEYDOWN);
return 0;
case WM_DEVMODECHANGE: {
DEVMODE dm;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
ResWidth = dm.dmPelsWidth;
ResHeight = dm.dmPelsHeight;
ResDepth = dm.dmBitsPerPel;
FramePeriod = 1.0f/dm.dmDisplayFrequency;
}
case WM_SIZE:
Demo.ResizeScene(LOWORD(lParam), HIWORD(lParam));
return 0;
case WM_CLOSE:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc = {
CS_HREDRAW | CS_VREDRAW | CS_OWNDC, /* style */
(WNDPROC) WndProc, /* lpfnWndProc */
0, /* cbClsExtra */
0, /* cbWndExtra */
NULL, /* hInstance */
NULL, /* hIcon */
NULL, /* hCursor */
NULL, /* hbrBackground */
NULL, /* lpszMenuName */
"OpenGL" /* lpszClassName */
};
DEVMODE dm;
LARGE_INTEGER ClockFreq, PreviousTime;
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
wc.hInstance = hInst = hInstance;
wc.hIcon = (HICON) LoadImage(NULL, IDI_WINLOGO, IMAGE_ICON, 0, 0, LR_SHARED);
wc.hCursor = (HCURSOR) LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED | LR_DEFAULTSIZE);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
ResWidth = dm.dmPelsWidth;
ResHeight = dm.dmPelsHeight;
ResDepth = dm.dmBitsPerPel;
FramePeriod = 1.0f/dm.dmDisplayFrequency;
QueryPerformanceFrequency(&ClockFreq);
if(!RegisterClass(&wc)){
MessageBox(NULL, "Failed to register the window class.", NULL, MB_OK | MB_ICONERROR);
return 0;
}
if(Demo.Startup && !Demo.Startup())
return -1;
if(!CreateGLWindow(Demo.Title, Demo.Width, Demo.Height))
return -1;
QueryPerformanceCounter(&PreviousTime);
while(1){
MSG msg;
LARGE_INTEGER CurrentTime;
float TimeDelta;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT){
KillGLWindow();
UnregisterClass("OpenGL", hInstance);
return (!Demo.Shutdown || Demo.Shutdown()) ? 0 : -1;
}
}
/* Find the timedelta */
QueryPerformanceCounter(&CurrentTime);
TimeDelta = (float)(CurrentTime.QuadPart-PreviousTime.QuadPart)/ClockFreq.QuadPart;
PreviousTime = CurrentTime;
if(TimeDelta < 0 || TimeDelta > 5) /* Safe-guard in case of system delay */
continue;
/* Draw */
Demo.DrawScene(TimeDelta, keys);
SwapBuffers(hDC);
/* Sleep for the remainder of the frame */
QueryPerformanceCounter(&CurrentTime);
TimeDelta = (float)(CurrentTime.QuadPart-PreviousTime.QuadPart)/ClockFreq.QuadPart;
TimeDelta = (FramePeriod - TimeDelta) * 1000;
if(TimeDelta > 1 && TimeDelta < 100) Sleep((unsigned) TimeDelta);
}
}

View file

@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.2...3.29)
project(rlgldemo)
# Adding Raylib
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # don't build the supplied example games
#set raylib settings
add_compile_definitions(SUPPORT_FILEFORMAT_JPG)
FetchContent_Declare(
raylib
GIT_REPOSITORY "https://github.com/raysan5/raylib.git"
GIT_TAG "master"
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(raylib)
include_directories(${FILEHANDLER_INCLUDE})
include_directories(${VITABOY_INCLUDE})
# Adding our source files
file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/*.cpp") # Define PROJECT_SOURCES as a list of all source files
set(PROJECT_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/*.h") # Define PROJECT_INCLUDE to be the path to the include directory of the project
# Declaring our executable
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE})
target_link_libraries(${PROJECT_NAME} PRIVATE raylib libvitaboy_static FileHandler_static)
# Setting ASSETS_PATH
target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/") # Set the asset path macro to the absolute path on the dev machine
#target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="./assets") # Set the asset path macro in release mode to a relative path that assumes the assets folder is in the same directory as the game executable

669
examples/rlgldemo/main.cpp Normal file
View file

@ -0,0 +1,669 @@
/*
Special thanks to:
libvitaboy - Open source OpenGL TSO character animation library
Renderer.cpp - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
*/
/*
Instructions:
You must have the following files in the same directory as the Renderer binary:
Skeleton:
* skeleton.skel ("adult.skel" in ./avatardata/skeletons/)
Meshes:
* body.mesh (pick one from ./avatardata/bodies/meshes/)
* head.mesh (pick one from ./avatardata/heads/meshes/)
* lhand.mesh (pick one from ./avatardata/hands/meshes/)
* rhand.mesh (pick one from ./avatardata/hands/meshes/)
Textures:
* body.jpg (pick one from ./avatardata/bodies/textures/)
* head.jpg (pick one from ./avatardata/heads/textures/)
* hand.jpg (pick one from ./avatardata/hands/textures/)
Animation:
* animation.anim (pick one from ./avatardata/animations/)
==== Controls ====
1: Toggle skeleton
2: Toggle the mesh
n: Animate the character
*/
#include "raylib.h"
#include "raymath.h" // Required for: Vector3, Quaternion and Matrix functionality
#include "utils.h" // Required for: TRACELOG(), LoadFileData(), LoadFileText(), SaveFileText()
#include "rlgl.h"
#include <cassert>
#include <FileHandler.h>
#include "../libvitaboy/libvitaboy.hpp"
#define SCREEN_WIDTH (800)
#define SCREEN_HEIGHT (600)
#define WINDOW_TITLE "libvitaboy - Renderer - Ray"
struct BasicVertex_t {
float x, y, z;
};
struct CharacterPlacement_t {
BasicVertex_t Translation;
BasicVertex_t Rotation;
};
static CharacterPlacement_t Character = {{0,-3,0}, {0,0,0}};
static Skeleton_t Skeleton;
static Animation_t Animation;
static float AnimationTime = 0;
static void DisplayFileError(const char * Filename){
const char * Message;
switch(File::Error){
case FERR_NOT_FOUND:
Message = "%s does not exist.";
break;
case FERR_OPEN:
Message = "%s could not be opened for reading.";
break;
case FERR_BLANK:
case FERR_UNRECOGNIZED:
case FERR_INVALIDDATA:
Message = "%s is corrupt or invalid.";
break;
case FERR_MEMORY:
Message = "Memory for %s could not be allocated.";
break;
default:
Message = "%s could not be read.";
break;
}
char Buffer[1024];
sprintf(Buffer, Message, Filename);
}
static bool Read(const char* Filename, uint8_t** InData) {
*InData = File::ReadFile(Filename);
if (*InData != NULL) {
VBFile.set(*InData, File::FileSize);
return true;
}
DisplayFileError(Filename);
return false;
}
//textures
static Texture2D textures[3];
enum { Texture_Body, Texture_Head, Texture_Hand };
static const char* const TexturePaths[] = { "body.jpg", "head.jpg", "hand.jpg" };
static bool LoadTextures()
{
for (int i = 0; i < 3; i++)
{
textures[i] = LoadTexture(TexturePaths[i]);
}
return true;
}
static bool UnloadTextures()
{
for (int i = 0; i < 3; i++)
{
UnloadTexture(textures[i]);
}
return true;
}
//meshes
static const unsigned MeshCount = 4;
static Mesh_t Meshes[4];
enum { Mesh_Body, Mesh_Head, Mesh_LHand, Mesh_RHand };
static const char* const MeshPaths[] = { "body.mesh", "head.mesh", "lhand.mesh", "rhand.mesh" };
static const unsigned Mesh_UseTexture[] = { Texture_Body, Texture_Head, Texture_Hand, Texture_Hand };
static const char* const MeshActivate[] = { NULL, "HEAD", "L_HAND", "R_HAND" };
// Generate a simple triangle mesh from code
static Mesh CreateMesh(const Mesh_t& tso_mesh)
{
Mesh ray_mesh = { 0 };
ray_mesh.vertexCount = tso_mesh.RealVertexCount;
ray_mesh.triangleCount = tso_mesh.FaceCount; // Face count (triangulated)
ray_mesh.vertices = (float*)RL_CALLOC(ray_mesh.vertexCount * 3, sizeof(float));
ray_mesh.texcoords = (float*)RL_CALLOC(ray_mesh.vertexCount * 2, sizeof(float));
ray_mesh.normals = (float*)RL_CALLOC(ray_mesh.vertexCount * 3, sizeof(float));
ray_mesh.indices = (unsigned short*)RL_CALLOC(ray_mesh.triangleCount * 3, sizeof(unsigned short));
// Process all mesh faces
//vertex data
for (unsigned j = 0; j < ray_mesh.vertexCount; j++)
{
//vertices?
ray_mesh.vertices[j * 3 + 0] = tso_mesh.TransformedVertexData[j].Coord.x;
ray_mesh.vertices[j * 3 + 1] = tso_mesh.TransformedVertexData[j].Coord.y;
ray_mesh.vertices[j * 3 + 2] = tso_mesh.TransformedVertexData[j].Coord.z;
//coords
ray_mesh.texcoords[j * 2 + 0] = tso_mesh.TransformedVertexData[j].TextureCoord.u;
ray_mesh.texcoords[j * 2 + 1] = -tso_mesh.TransformedVertexData[j].TextureCoord.v;
//normals
ray_mesh.normals[j * 3 + 0] = tso_mesh.TransformedVertexData[j].NormalCoord.x;
ray_mesh.normals[j * 3 + 1] = tso_mesh.TransformedVertexData[j].NormalCoord.y;
ray_mesh.normals[j * 3 + 2] = tso_mesh.TransformedVertexData[j].NormalCoord.z;
}
//indices
for (unsigned j = 0; j < ray_mesh.triangleCount; j++)
{
ray_mesh.indices[j * 3 + 0] = (unsigned short)tso_mesh.FaceData[j].VertexA;
//counter clock wise
ray_mesh.indices[j * 3 + 1] = (unsigned short)tso_mesh.FaceData[j].VertexC;
ray_mesh.indices[j * 3 + 2] = (unsigned short)tso_mesh.FaceData[j].VertexB;
//Clock wise
//ray_mesh.indices[j * 3 + 1] = (unsigned short)tso_mesh.FaceData[j].VertexB;
//ray_mesh.indices[j * 3 + 2] = (unsigned short)tso_mesh.FaceData[j].VertexC;
}
// Upload mesh data from CPU (RAM) to GPU (VRAM) memory
//UploadMesh(&ray_mesh, true); //check the dynamic flag if we have to keep creating the mesh
return ray_mesh;
}
static bool LoadMeshes()
{
uint8_t* InData;
for (unsigned i = 0; i < MeshCount; i++)
{
if (!Read(MeshPaths[i], &InData))
{
return false;
}
ReadMesh(Meshes[i]);
free(InData);
}
return true;
}
static int ResizeScene(uint16_t width, uint16_t height)
{
rlViewport(0, 0, width, height);
rlMatrixMode(RL_PROJECTION);
rlLoadIdentity();
// Calculate The Aspect Ratio Of The Window
//rluPerspective(45.0f, (rlfloat)width/(rlfloat)height, 0.1f, 100.0f);
// rlScalef(-1.0f, 1.0f, 1.0f);
rlMatrixMode(RL_MODELVIEW);
rlLoadIdentity();
return 1;
}
static bool InitRLGL()
{
rlglInit(SCREEN_WIDTH, SCREEN_HEIGHT);
//rlSetCullFace();
//rlEnable(rl_CULL_FACE);
rlDisableBackfaceCulling();
//rlDisable(rl_BLEND);
rlEnableColorBlend();
//rlDepthFunc(rl_LEQUAL); //default
//rlHint(rl_PERSPECTIVE_CORRECTION_HINT, rl_NICEST); //default
//cant change this
//rlFrontFace(rl_CW);
ResizeScene(SCREEN_WIDTH, SCREEN_HEIGHT);
return true;
}
static void TransformVertices(Bone_t& Bone)
{
rlTranslatef(Bone.Translation.x, Bone.Translation.y, Bone.Translation.z);
float matRotation[16];
FindQuaternionMatrix(matRotation, &Bone.Rotation);
rlMultMatrixf(matRotation);
unsigned MeshIndex = 0;
unsigned BoneIndex;
for(unsigned i=1; i<MeshCount; i++){
if(!strcmp(Bone.Name, MeshActivate[i])){
MeshIndex = i;
break;
}
}
Mesh_t& Mesh = Meshes[MeshIndex];
for(BoneIndex=0; BoneIndex<Mesh.BindingCount; BoneIndex++){
if(!strcmp(Bone.Name, Mesh.BoneNames[Mesh.BoneBindings[BoneIndex].BoneIndex]))
break;
}
if(BoneIndex < Mesh.BindingCount){
for(unsigned i=0; i<Mesh.BoneBindings[BoneIndex].RealVertexCount; i++)
{
unsigned VertexIndex = Mesh.BoneBindings[BoneIndex].FirstRealVertex + i;
Vertex_t& RelativeVertex = Mesh.VertexData[VertexIndex];
Vertex_t& AbsoluteVertex = Mesh.TransformedVertexData[VertexIndex];
rlTranslatef(RelativeVertex.Coord.x, RelativeVertex.Coord.y, RelativeVertex.Coord.z);
const Matrix matModelView = rlGetMatrixTransform();
const Vector3 vertex = Vector3Transform(Vector3{ 0.f, 0.f, 0.f }, matModelView);
AbsoluteVertex.Coord.x = vertex.x;
AbsoluteVertex.Coord.y = vertex.y;
AbsoluteVertex.Coord.z = vertex.z;
rlTranslatef(-RelativeVertex.Coord.x, -RelativeVertex.Coord.y, -RelativeVertex.Coord.z);
}
for(unsigned i=0; i<Mesh.BoneBindings[BoneIndex].BlendVertexCount; i++)
{
unsigned VertexIndex = Mesh.RealVertexCount + Mesh.BoneBindings[BoneIndex].FirstBlendVertex + i;
Vertex_t& RelativeVertex = Mesh.VertexData[VertexIndex];
Vertex_t& AbsoluteVertex = Mesh.TransformedVertexData[VertexIndex];
rlTranslatef(RelativeVertex.Coord.x, RelativeVertex.Coord.y, RelativeVertex.Coord.z);
const Matrix matModelView = rlGetMatrixTransform();
const Vector3 vertex = Vector3Transform(Vector3{ 0.f, 0.f, 0.f }, matModelView);
AbsoluteVertex.Coord.x = vertex.x;
AbsoluteVertex.Coord.y = vertex.y;
AbsoluteVertex.Coord.z = vertex.z;
rlTranslatef(-RelativeVertex.Coord.x, -RelativeVertex.Coord.y, -RelativeVertex.Coord.z);
}
}
if(Bone.ChildrenCount == 1){
TransformVertices(*Bone.Children[0]);
}else if(Bone.ChildrenCount > 1){
for(unsigned i=0; i<Bone.ChildrenCount; i++){
rlPushMatrix();
TransformVertices(*Bone.Children[i]);
rlPopMatrix();
}
}
}
static void BlendVertices()
{
for(unsigned i=0; i<MeshCount; i++){
Mesh_t& Mesh = Meshes[i];
for(unsigned i=0; i<Mesh.BlendVertexCount; i++)
{
Vertex_t& BlendVertex = Mesh.TransformedVertexData[Mesh.RealVertexCount + i];
float Weight = BlendVertex.BlendData.Weight;
Vertex_t& RealVertex = Mesh.TransformedVertexData[BlendVertex.BlendData.OtherVertex];
RealVertex.Coord.x =
Weight * BlendVertex.Coord.x +
(1-Weight) * RealVertex.Coord.x;
RealVertex.Coord.y =
Weight * BlendVertex.Coord.y +
(1-Weight) * RealVertex.Coord.y;
RealVertex.Coord.z =
Weight * BlendVertex.Coord.z +
(1-Weight) * RealVertex.Coord.z;
}
}
}
static Mesh ray_meshes[4];
static void CreateMeshes()
{
for (unsigned i = 0; i < MeshCount; i++)
{
ray_meshes[i] = CreateMesh(Meshes[i]);
}
}
static void UpdateMeshes(Model& model)
{
rlPushMatrix();
rlLoadIdentity();
TransformVertices(Skeleton.Bones[0]);
rlPopMatrix();
BlendVertices();
for (unsigned i = 0; i < MeshCount; i++)
{
Mesh& ray_mesh = model.meshes[i];
Mesh_t& tso_mesh = Meshes[i];
//vertex data
for (unsigned j = 0; j < ray_mesh.vertexCount; j++)
{
//vertices?
ray_mesh.vertices[j * 3 + 0] = tso_mesh.TransformedVertexData[j].Coord.x;
ray_mesh.vertices[j * 3 + 1] = tso_mesh.TransformedVertexData[j].Coord.y;
ray_mesh.vertices[j * 3 + 2] = tso_mesh.TransformedVertexData[j].Coord.z;
//coords
ray_mesh.texcoords[j * 2 + 0] = tso_mesh.TransformedVertexData[j].TextureCoord.u;
ray_mesh.texcoords[j * 2 + 1] = -tso_mesh.TransformedVertexData[j].TextureCoord.v;
//normals
ray_mesh.normals[j * 3 + 0] = tso_mesh.TransformedVertexData[j].NormalCoord.x;
ray_mesh.normals[j * 3 + 1] = tso_mesh.TransformedVertexData[j].NormalCoord.y;
ray_mesh.normals[j * 3 + 2] = tso_mesh.TransformedVertexData[j].NormalCoord.z;
}
// from UploadMesh
//mesh->vboId[0] = 0; // Vertex buffer: positions
//mesh->vboId[1] = 0; // Vertex buffer: texcoords
//mesh->vboId[2] = 0; // Vertex buffer: normals
UpdateMeshBuffer(ray_mesh, 0, ray_mesh.vertices, sizeof(float) * ray_mesh.vertexCount * 3, 0);
UpdateMeshBuffer(ray_mesh, 1, ray_mesh.texcoords, sizeof(float) * ray_mesh.vertexCount * 2, 0);
UpdateMeshBuffer(ray_mesh, 2, ray_mesh.normals, sizeof(float) * ray_mesh.vertexCount * 3, 0);
}
rlPopMatrix();
}
static void DrawMeshes()
{
rlPushMatrix();
rlLoadIdentity();
TransformVertices(Skeleton.Bones[0]);
rlPopMatrix();
BlendVertices();
Material material = LoadMaterialDefault();
for (unsigned i = 0; i < MeshCount; i++)
{
material.maps[MATERIAL_MAP_DIFFUSE].texture = textures[Mesh_UseTexture[i]];
DrawMesh(ray_meshes[i], material, MatrixIdentity());
}
rlPopMatrix();
}
static void AdvanceFrame(Skeleton_t& Skeleton, Animation_t& Animation, float TimeDelta)
{
float Duration = (float)Animation.Motions[0].FrameCount/30;
AnimationTime += TimeDelta;
AnimationTime = fmodf(AnimationTime, Duration); //Loop the animation
for(unsigned i=0; i<Animation.MotionsCount; i++){
unsigned BoneIndex = FindBone(Skeleton, Animation.Motions[i].BoneName, Skeleton.BoneCount);
if(BoneIndex == (unsigned)-1) continue;
Bone_t& Bone = Skeleton.Bones[BoneIndex];
unsigned Frame = AnimationTime*30;
float FractionShown = AnimationTime*30 - Frame;
unsigned NextFrame = (Frame+1 != Animation.Motions[0].FrameCount) ? Frame+1 : 0;
if(Animation.Motions[i].HasTranslation){
Translation_t& Translation = Animation.Motions[i].Translations[Frame];
Translation_t& NextTranslation = Animation.Motions[i].Translations[NextFrame];
Bone.Translation.x = (1-FractionShown)*Translation.x + FractionShown*NextTranslation.x;
Bone.Translation.y = (1-FractionShown)*Translation.y + FractionShown*NextTranslation.y;
Bone.Translation.z = (1-FractionShown)*Translation.z + FractionShown*NextTranslation.z;
}
if(Animation.Motions[i].HasRotation){
Rotation_t& Rotation = Animation.Motions[i].Rotations[Frame];
Rotation_t& NextRotation = Animation.Motions[i].Rotations[NextFrame];
//Use nlerp to interpolate
float w1 = 1.0f - FractionShown, w2 = FractionShown;
if(DotProduct(&Rotation, &NextRotation) < 0)
w1 *= -1;
Bone.Rotation.x = w1*Rotation.x + w2*NextRotation.x;
Bone.Rotation.y = w1*Rotation.y + w2*NextRotation.y;
Bone.Rotation.z = w1*Rotation.z + w2*NextRotation.z;
Bone.Rotation.w = w1*Rotation.w + w2*NextRotation.w;
Normalize(&Bone.Rotation);
}
}
}
static void DrawBonesSkeleton(Bone_t& Bone)
{
rlTranslatef(Bone.Translation.x, Bone.Translation.y, Bone.Translation.z);
float RotationMatrix[16];
FindQuaternionMatrix(RotationMatrix, &Bone.Rotation);
rlMultMatrixf(RotationMatrix);
Color color;
if (!strcmp(Bone.Name, "ROOT"))
{
color = RED;
}
else if (!strcmp(Bone.Name, "HEAD"))
{
color = YELLOW;
}
else
{
color = GREEN;
}
DrawCube(Vector3{ 0.f, 0.f, 0.f }, 0.1f, 0.1f, 0.1f, color);
if(Bone.ChildrenCount == 1){
DrawBonesSkeleton(*Bone.Children[0]);
}else if(Bone.ChildrenCount > 1){
for(unsigned i=0; i<Bone.ChildrenCount; i++){
rlPushMatrix();
{
DrawBonesSkeleton(*Bone.Children[i]);
}
rlPopMatrix();
}
}
}
static void DrawSkeleton()
{
rlPushMatrix();
{
DrawBonesSkeleton(Skeleton.Bones[0]);
}
rlPopMatrix();
}
static bool Startup()
{
uint8_t * InData;
if(!Read("skeleton.skel", &InData))
return false;
ReadSkeleton(Skeleton);
free(InData);
for(unsigned i=0; i<MeshCount; i++){
if(!Read(MeshPaths[i], &InData))
return 0;
ReadMesh(Meshes[i]);
free(InData);
}
if(!Read("animation.anim", &InData))
return false;
ReadAnimation(Animation);
free(InData);
AdvanceFrame(Skeleton, Animation, 0);
return true;
}
static Model LoadModelTSO()
{
Model model;
//meshes
model.meshCount = MeshCount;
model.meshes = (Mesh*)RL_CALLOC(model.meshCount, sizeof(Mesh));
//textures
model.materialCount = 3;
model.meshMaterial = (int*)RL_CALLOC(model.meshCount, sizeof(int)); // Material index assigned to each mesh
model.materials = (Material*)RL_CALLOC(model.materialCount, sizeof(Material));
model.meshMaterial[0] = 0; // By default, assign material 0 to each mesh
///load the textures
for (int i = 0; i < model.materialCount; i++)
{
model.materials[i] = LoadMaterialDefault();
model.materials[i].maps[MATERIAL_MAP_DIFFUSE].texture = textures[i];
}
//load meshes
for (int i = 0; i < model.meshCount; i++)
{
Mesh_t& tso_mesh = Meshes[i];
Mesh& ray_mesh = model.meshes[i];
ray_mesh.vertexCount = tso_mesh.RealVertexCount;
ray_mesh.triangleCount = tso_mesh.FaceCount; // Face count (triangulated)
ray_mesh.vertices = (float*)RL_CALLOC(ray_mesh.vertexCount * 3, sizeof(float));
ray_mesh.texcoords = (float*)RL_CALLOC(ray_mesh.vertexCount * 2, sizeof(float));
ray_mesh.normals = (float*)RL_CALLOC(ray_mesh.vertexCount * 3, sizeof(float));
ray_mesh.indices = (unsigned short*)RL_CALLOC(ray_mesh.triangleCount * 3, sizeof(unsigned short));
// Process all mesh faces
// TODO: extract this in seperate function
//vertex data
for (unsigned j = 0; j < ray_mesh.vertexCount; j++)
{
//vertices?
ray_mesh.vertices[j * 3 + 0] = tso_mesh.TransformedVertexData[j].Coord.x;
ray_mesh.vertices[j * 3 + 1] = tso_mesh.TransformedVertexData[j].Coord.y;
ray_mesh.vertices[j * 3 + 2] = tso_mesh.TransformedVertexData[j].Coord.z;
//coords
ray_mesh.texcoords[j * 2 + 0] = tso_mesh.TransformedVertexData[j].TextureCoord.u;
ray_mesh.texcoords[j * 2 + 1] = -tso_mesh.TransformedVertexData[j].TextureCoord.v;
//normals
ray_mesh.normals[j * 3 + 0] = tso_mesh.TransformedVertexData[j].NormalCoord.x;
ray_mesh.normals[j * 3 + 1] = tso_mesh.TransformedVertexData[j].NormalCoord.y;
ray_mesh.normals[j * 3 + 2] = tso_mesh.TransformedVertexData[j].NormalCoord.z;
}
//indices
for (unsigned j = 0; j < ray_mesh.triangleCount; j++)
{
ray_mesh.indices[j * 3 + 0] = (unsigned short)tso_mesh.FaceData[j].VertexA;
//counter clock wise
//ray_mesh.indices[j * 3 + 1] = (unsigned short)tso_mesh.FaceData[j].VertexC;
//ray_mesh.indices[j * 3 + 2] = (unsigned short)tso_mesh.FaceData[j].VertexB;
//Clock wise
ray_mesh.indices[j * 3 + 1] = (unsigned short)tso_mesh.FaceData[j].VertexB;
ray_mesh.indices[j * 3 + 2] = (unsigned short)tso_mesh.FaceData[j].VertexC;
}
//select the textures
model.meshMaterial[i] = Mesh_UseTexture[i];
}
//upload to gpu
// Make sure model transform is set to identity matrix!
model.transform = MatrixIdentity();
if ((model.meshCount != 0) && (model.meshes != NULL))
{
// Upload vertex data to GPU (static meshes)
for (int i = 0; i < model.meshCount; i++)
{
UploadMesh(&model.meshes[i], true);
}
}
else TRACELOG(LOG_WARNING, "MESH: [%s] Failed to load model mesh(es) data", fileName);
if (model.materialCount == 0)
{
TRACELOG(LOG_WARNING, "MATERIAL: [%s] Failed to load model material data, default to white material", fileName);
model.materialCount = 1;
model.materials = (Material*)RL_CALLOC(model.materialCount, sizeof(Material));
model.materials[0] = LoadMaterialDefault();
if (model.meshMaterial == NULL)
{
model.meshMaterial = (int*)RL_CALLOC(model.meshCount, sizeof(int));
}
}
return model;
}
//settings
static bool ShowMesh = true;
static bool ShowSkeleton = true;
int main(void)
{
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_TITLE);
SetTargetFPS(60);
InitRLGL();
// Define the camera to look into our 3d world
Camera camera;
camera.position = Vector3{ 0.0f, 5.0f, 5.0f }; // Camera position
camera.target = Vector3{ 0.0f, 0.0f, 0.0f }; // Camera looking at point
camera.up = Vector3{ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 70.0f; // Camera field-of-view Y
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
assert( Startup() );
assert( LoadTextures() );
assert( LoadMeshes() );
CreateMeshes();
Model model = LoadModelTSO();
printf("======================================\n");
printf("=================RAY==================\n");
printf("======================================\n");
DisableCursor();
while (!WindowShouldClose())
{
const float dt{ GetFrameTime() };
//Handle user interaction
{
UpdateCamera(&camera, CAMERA_FREE);
//if (IsKeyDown(KEY_A)) /*{if(zoom <=-1.0f) zoom+=0.05f; }*/ zoom += 3 * dt;
//if (IsKeyDown(KEY_S)) /*{if(zoom >=-10.0f) zoom-=0.05f; }*/ zoom -= 3 * dt;
if (IsKeyDown(KEY_UP)) { if ((Character.Rotation.x -= 60 * dt) <= -360) Character.Rotation.x += 360; }
if (IsKeyDown(KEY_DOWN)) { if ((Character.Rotation.x += 60 * dt) >= 360) Character.Rotation.x -= 360; }
if (IsKeyDown(KEY_LEFT)) { if ((Character.Rotation.y -= 60 * dt) <= -360) Character.Rotation.y += 360; }
if (IsKeyDown(KEY_RIGHT)) { if ((Character.Rotation.y += 60 * dt) >= 360) Character.Rotation.y -= 360; }
if (IsKeyDown(KEY_X)) { if ((Character.Rotation.z -= 60 * dt) <= -360) Character.Rotation.z += 360; }
if (IsKeyDown(KEY_Z)) { if ((Character.Rotation.z += 60 * dt) >= 360) Character.Rotation.z -= 360; }
if (IsKeyDown(KEY_K)) { Character.Translation.y -= 3 * dt; }
if (IsKeyDown(KEY_I)) { Character.Translation.y += 3 * dt; }
if (IsKeyDown(KEY_J)) { Character.Translation.x -= 3 * dt; }
if (IsKeyDown(KEY_L)) { Character.Translation.x += 3 * dt; }
if (IsKeyPressed(KEY_ONE)){ ShowSkeleton = !ShowSkeleton; }
if (IsKeyPressed(KEY_TWO)) { ShowMesh = !ShowMesh; }
if (IsKeyDown(KEY_N)) { AdvanceFrame(Skeleton, Animation, dt); }
}
rlClearScreenBuffers(); //Clear the screen and the depth buffer
UpdateMeshes(model);
BeginDrawing();
{
ClearBackground(BLACK);
BeginMode3D(camera);
{
DrawGrid(10, 5.0f);
//Avatar
{
if (ShowMesh)
{
// draw the model
const Vector3 position{ 0.0f, 0.0f, 0.0f };
const float scale = 1.f;
DrawModel(model, position, scale, WHITE);
}
if (ShowSkeleton)
{
DrawSkeleton();
}
}
}
EndMode3D();
}
EndDrawing();
}
UnloadTextures();
CloseWindow();
return 0;
}