Started Meinkraft project
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
#include "Block.h"
|
||||
|
||||
|
||||
|
||||
Block::Block()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Block::~Block()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
class Block
|
||||
{
|
||||
public:
|
||||
Block();
|
||||
~Block();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "Chunk.h"
|
||||
|
||||
|
||||
|
||||
Chunk::Chunk()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Chunk::~Chunk()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
class Chunk
|
||||
{
|
||||
public:
|
||||
Chunk();
|
||||
~Chunk();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "Entity.h"
|
||||
#include "cmath"
|
||||
#include <GL/freeglut.h>
|
||||
#include "Model.h"
|
||||
|
||||
|
||||
Entity::Entity()
|
||||
{
|
||||
model = NULL;
|
||||
scale = 1;
|
||||
canCollide = true;
|
||||
}
|
||||
|
||||
|
||||
Entity::~Entity()
|
||||
{
|
||||
if(model)
|
||||
Model::unload(model);
|
||||
}
|
||||
|
||||
|
||||
void Entity::draw()
|
||||
{
|
||||
if (model)
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
glRotatef(rotation.x, 1, 0, 0);
|
||||
glRotatef(rotation.y, 0, 1, 0);
|
||||
glRotatef(rotation.z, 0, 0, 1);
|
||||
glScalef(scale, scale, scale);
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
model->draw();
|
||||
glCullFace(GL_FRONT);
|
||||
model->draw();
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Entity::inObject(const Vec3f & point)
|
||||
{
|
||||
if (!model)
|
||||
return false;
|
||||
Vec3f center = position + model->center;
|
||||
float distance = ((point.x - center.x) * (point.x - center.x) + (point.z - center.z)*(point.z - center.z));
|
||||
if (distance < model->radius*scale*model->radius*scale)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "Vector.h"
|
||||
class Model;
|
||||
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
Entity();
|
||||
~Entity();
|
||||
|
||||
Model* model;
|
||||
|
||||
virtual void draw();
|
||||
virtual void update(float elapsedTime) {};
|
||||
Vec3f position;
|
||||
Vec3f rotation;
|
||||
float scale;
|
||||
|
||||
bool canCollide;
|
||||
bool inObject(const Vec3f &position);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#include <GL/freeglut.h>
|
||||
|
||||
#include "Meinkraft.h"
|
||||
#include <stdio.h>
|
||||
#include "Vector.h"
|
||||
|
||||
void configureOpenGL(void);
|
||||
|
||||
Meinkraft* app;
|
||||
|
||||
bool justMoved = false;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
app = new Meinkraft();
|
||||
glutInit(&argc, argv);
|
||||
|
||||
configureOpenGL();
|
||||
|
||||
app->init();
|
||||
|
||||
glutDisplayFunc([]() { app->draw(); } );
|
||||
glutIdleFunc([]() { app->update(); } );
|
||||
glutReshapeFunc([](int w, int h) { Meinkraft::width = w; Meinkraft::height = h; glViewport(0, 0, w, h); });
|
||||
|
||||
//Keyboard
|
||||
glutKeyboardFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = true; });
|
||||
glutKeyboardUpFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = false; });
|
||||
glutSpecialFunc([](int c, int, int) { app->keyboardState.special[c] = true; });
|
||||
glutSpecialUpFunc([](int c, int, int) { app->keyboardState.special[c] = false; });
|
||||
|
||||
auto mousemotion = [](int x, int y)
|
||||
{
|
||||
if (justMoved)
|
||||
{
|
||||
justMoved = false;
|
||||
return;
|
||||
}
|
||||
int dx = x - app->width / 2;
|
||||
int dy = y - app->height / 2;
|
||||
if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400)
|
||||
{
|
||||
app->mouseOffset = app->mouseOffset + Vec2f(dx, dy);
|
||||
glutWarpPointer(app->width / 2, app->height / 2);
|
||||
justMoved = true;
|
||||
}
|
||||
};
|
||||
|
||||
//Mouse
|
||||
glutPassiveMotionFunc(mousemotion);
|
||||
glutMotionFunc(mousemotion);
|
||||
|
||||
Meinkraft::height = GLUT_WINDOW_HEIGHT;
|
||||
Meinkraft::width = GLUT_WINDOW_WIDTH;
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
delete app;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void configureOpenGL()
|
||||
{
|
||||
//Init window and glut display mode
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(800, 600);
|
||||
glutCreateWindow("Meinkraft Bèta 0.1");
|
||||
//glutFullScreen();
|
||||
|
||||
//Depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
//Alpha blending
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//Alpha testing
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_GREATER, 0.01f);
|
||||
|
||||
//Lighting
|
||||
GLfloat mat_specular[] = { 0.2, 0.2, 0.2, 0 };
|
||||
//GLfloat mat_shininess[] = { 5.0 };
|
||||
GLfloat light_position[] = { 0.0, 2.0, 1.0, 0 };
|
||||
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 0 };
|
||||
GLfloat light_ambient[] = { 0.3, 0.3, 0.3, 0 };
|
||||
glClearColor(0.7, 0.7, 1.0, 1.0);
|
||||
|
||||
//glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
||||
//glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
||||
//glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
//glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
|
||||
#include "Meinkraft.h"
|
||||
#include <GL/freeglut.h>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include "Player.h"
|
||||
#include "StateHandler.h"
|
||||
|
||||
int Meinkraft::width = 0;
|
||||
int Meinkraft::height = 0;
|
||||
|
||||
void Meinkraft::init()
|
||||
{
|
||||
player = Player::getInstance();
|
||||
statehandler = StateHandler::getInstance();
|
||||
//cursor = Cursor::getInstance();
|
||||
|
||||
lastFrameTime = 0;
|
||||
|
||||
glClearColor(0.7f, 0.7f, 1.0f, 1.0f);
|
||||
|
||||
mousePosition = Vec2f(width / 2, height / 2);
|
||||
}
|
||||
|
||||
|
||||
void Meinkraft::draw()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//Draw world
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(70, width / (float)height, 0.1f, 500);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
statehandler->draw();
|
||||
|
||||
//cursor->draw();
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
void Meinkraft::update()
|
||||
{
|
||||
float frameTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
|
||||
float deltaTime = frameTime - lastFrameTime;
|
||||
lastFrameTime = frameTime;
|
||||
|
||||
if (keyboardState.keys[27])
|
||||
exit(0);
|
||||
|
||||
Player* player = Player::getInstance();
|
||||
|
||||
player->rotation.y += mouseOffset.x / 10.0f;
|
||||
player->rotation.x += mouseOffset.y / 10.0f;
|
||||
if (player->rotation.x > 90)
|
||||
player->rotation.x = 90;
|
||||
if (player->rotation.x < -90)
|
||||
player->rotation.x = -90;
|
||||
|
||||
float speed = 10;
|
||||
|
||||
Vec3f oldPosition = player->position;
|
||||
if (keyboardState.keys['a']) player->setPosition(0, deltaTime*speed, false);
|
||||
if (keyboardState.keys['d']) player->setPosition(180, deltaTime*speed, false);
|
||||
if (keyboardState.keys['w']) player->setPosition(90, deltaTime*speed, false);
|
||||
if (keyboardState.keys['s']) player->setPosition(270, deltaTime*speed, false);
|
||||
if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
|
||||
if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
|
||||
|
||||
//if (!worldhandler->isPlayerPositionValid())
|
||||
// player->position = oldPosition;
|
||||
|
||||
//player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f;
|
||||
|
||||
statehandler->update(deltaTime);
|
||||
|
||||
mousePosition = mousePosition + mouseOffset;
|
||||
//cursor->update(mousePosition);
|
||||
|
||||
mouseOffset = Vec2f(0, 0);
|
||||
prevKeyboardState = keyboardState;
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
KeyboardState::KeyboardState()
|
||||
{
|
||||
memset(keys, 0, sizeof(keys));
|
||||
memset(special, 0, sizeof(special));
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
class Player;
|
||||
class StateHandler;
|
||||
#include "Vector.h"
|
||||
|
||||
class KeyboardState
|
||||
{
|
||||
public:
|
||||
bool keys[256];
|
||||
bool special[256];
|
||||
bool control, shift, alt;
|
||||
|
||||
KeyboardState();
|
||||
};
|
||||
|
||||
class Meinkraft
|
||||
{
|
||||
public:
|
||||
void init();
|
||||
void draw();
|
||||
void update();
|
||||
|
||||
Player* player;
|
||||
StateHandler* statehandler;
|
||||
|
||||
static int width, height;
|
||||
KeyboardState keyboardState;
|
||||
KeyboardState prevKeyboardState;
|
||||
|
||||
Vec2f mouseOffset;
|
||||
Vec2f mousePosition;
|
||||
|
||||
float lastFrameTime;
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Meinkraft", "Meinkraft.vcxproj", "{05A43DED-C24F-41E3-93C3-AB634336B0A2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{05A43DED-C24F-41E3-93C3-AB634336B0A2}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{05A43DED-C24F-41E3-93C3-AB634336B0A2}.Debug|x64.Build.0 = Debug|x64
|
||||
{05A43DED-C24F-41E3-93C3-AB634336B0A2}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{05A43DED-C24F-41E3-93C3-AB634336B0A2}.Debug|x86.Build.0 = Debug|Win32
|
||||
{05A43DED-C24F-41E3-93C3-AB634336B0A2}.Release|x64.ActiveCfg = Release|x64
|
||||
{05A43DED-C24F-41E3-93C3-AB634336B0A2}.Release|x64.Build.0 = Release|x64
|
||||
{05A43DED-C24F-41E3-93C3-AB634336B0A2}.Release|x86.ActiveCfg = Release|Win32
|
||||
{05A43DED-C24F-41E3-93C3-AB634336B0A2}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,191 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{05A43DED-C24F-41E3-93C3-AB634336B0A2}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>Meinkraft</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>freeglut/include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>freeglut/lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>freeglut/include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>freeglut/lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>freeglut/include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>freeglut/lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>freeglut/include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>freeglut/lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Block.cpp" />
|
||||
<ClCompile Include="Chunk.cpp" />
|
||||
<ClCompile Include="Meinkraft.cpp" />
|
||||
<ClCompile Include="Entity.cpp" />
|
||||
<ClCompile Include="json.cpp" />
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="MenuState.cpp" />
|
||||
<ClCompile Include="Model.cpp" />
|
||||
<ClCompile Include="Player.cpp" />
|
||||
<ClCompile Include="State.cpp" />
|
||||
<ClCompile Include="StateHandler.cpp" />
|
||||
<ClCompile Include="Vector.cpp" />
|
||||
<ClCompile Include="Vertex.cpp" />
|
||||
<ClCompile Include="World.cpp" />
|
||||
<ClCompile Include="WorldState.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Block.h" />
|
||||
<ClInclude Include="Chunk.h" />
|
||||
<ClInclude Include="Meinkraft.h" />
|
||||
<ClInclude Include="Entity.h" />
|
||||
<ClInclude Include="json.h" />
|
||||
<ClInclude Include="Main.h" />
|
||||
<ClInclude Include="MenuState.h" />
|
||||
<ClInclude Include="Model.h" />
|
||||
<ClInclude Include="Player.h" />
|
||||
<ClInclude Include="State.h" />
|
||||
<ClInclude Include="StateHandler.h" />
|
||||
<ClInclude Include="stb_image.h" />
|
||||
<ClInclude Include="stb_perlin.h" />
|
||||
<ClInclude Include="Vector.h" />
|
||||
<ClInclude Include="Vertex.h" />
|
||||
<ClInclude Include="World.h" />
|
||||
<ClInclude Include="WorldState.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\World">
|
||||
<UniqueIdentifier>{087c1e25-9bb6-45a3-9612-6773babfbbed}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\State">
|
||||
<UniqueIdentifier>{27bdcbff-0967-4c9a-904d-b7784c5b87d1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="json.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Vector.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Vertex.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Player.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Meinkraft.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Chunk.cpp">
|
||||
<Filter>Source Files\World</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Block.cpp">
|
||||
<Filter>Source Files\World</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Entity.cpp">
|
||||
<Filter>Source Files\World</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Model.cpp">
|
||||
<Filter>Source Files\World</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="World.cpp">
|
||||
<Filter>Source Files\World</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StateHandler.cpp">
|
||||
<Filter>Source Files\State</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="WorldState.cpp">
|
||||
<Filter>Source Files\State</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MenuState.cpp">
|
||||
<Filter>Source Files\State</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="State.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Entity.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="json.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Main.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Model.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Vector.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Vertex.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Player.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Meinkraft.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="World.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Chunk.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Block.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="stb_image.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="stb_perlin.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="State.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StateHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MenuState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="WorldState.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "MenuState.h"
|
||||
|
||||
|
||||
|
||||
MenuState::MenuState()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MenuState::~MenuState()
|
||||
{
|
||||
}
|
||||
|
||||
void MenuState::init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void MenuState::exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
void MenuState::draw(void)
|
||||
{
|
||||
}
|
||||
|
||||
void MenuState::update(float deltaTime)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "State.h"
|
||||
|
||||
class MenuState : public State
|
||||
{
|
||||
public:
|
||||
MenuState();
|
||||
~MenuState();
|
||||
|
||||
void init(void);
|
||||
void exit(void);
|
||||
|
||||
void draw(void);
|
||||
void update(float deltaTime);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,385 @@
|
||||
#include "Model.h"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
//Prototypes
|
||||
std::vector<std::string> split(std::string str, std::string sep);
|
||||
std::string replace(std::string str, std::string toReplace, std::string replacement);
|
||||
std::string toLower(std::string data);
|
||||
|
||||
Model::Model(std::string fileName)
|
||||
{
|
||||
std::string dirName = fileName;
|
||||
if (dirName.rfind("/") != std::string::npos)
|
||||
dirName = dirName.substr(0, dirName.rfind("/"));
|
||||
if (dirName.rfind("\\") != std::string::npos)
|
||||
dirName = dirName.substr(0, dirName.rfind("\\"));
|
||||
if (fileName == dirName)
|
||||
dirName = "";
|
||||
|
||||
|
||||
std::ifstream pFile(fileName.c_str());
|
||||
|
||||
if (!pFile.is_open())
|
||||
{
|
||||
std::cout << "Could not open file " << fileName << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ObjGroup* currentGroup = new ObjGroup();
|
||||
currentGroup->materialIndex = -1;
|
||||
|
||||
|
||||
while (!pFile.eof())
|
||||
{
|
||||
std::string line;
|
||||
std::getline(pFile, line);
|
||||
|
||||
line = replace(line, "\t", " ");
|
||||
while (line.find(" ") != std::string::npos)
|
||||
line = replace(line, " ", " ");
|
||||
if (line == "")
|
||||
continue;
|
||||
if (line[0] == ' ')
|
||||
line = line.substr(1);
|
||||
if (line == "")
|
||||
continue;
|
||||
if (line[line.length() - 1] == ' ')
|
||||
line = line.substr(0, line.length() - 1);
|
||||
if (line == "")
|
||||
continue;
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
|
||||
std::vector<std::string> params = split(line, " ");
|
||||
params[0] = toLower(params[0]);
|
||||
|
||||
if (params[0] == "v")
|
||||
vertices.push_back(Vec3f((float)atof(params[1].c_str()), (float)atof(params[2].c_str()), (float)atof(params[3].c_str())));
|
||||
else if (params[0] == "vn")
|
||||
normals.push_back(Vec3f((float)atof(params[1].c_str()), (float)atof(params[2].c_str()), (float)atof(params[3].c_str())));
|
||||
else if (params[0] == "vt")
|
||||
texcoords.push_back(Vec2f((float)atof(params[1].c_str()), (float)atof(params[2].c_str())));
|
||||
else if (params[0] == "f")
|
||||
{
|
||||
for (size_t ii = 4; ii <= params.size(); ii++)
|
||||
{
|
||||
Face face;
|
||||
|
||||
for (size_t i = ii - 3; i < ii; i++) //magische forlus om van quads triangles te maken ;)
|
||||
{
|
||||
VertexIndex vertex;
|
||||
std::vector<std::string> indices = split(params[i == (ii - 3) ? 1 : i], "/");
|
||||
if (indices.size() >= 1) //er is een positie
|
||||
vertex.position = atoi(indices[0].c_str()) - 1;
|
||||
if (indices.size() == 2) //alleen texture
|
||||
vertex.texcoord = atoi(indices[1].c_str()) - 1;
|
||||
if (indices.size() == 3) //v/t/n of v//n
|
||||
{
|
||||
if (indices[1] != "")
|
||||
vertex.texcoord = atoi(indices[1].c_str()) - 1;
|
||||
vertex.normal = atoi(indices[2].c_str()) - 1;
|
||||
}
|
||||
face.vertices.push_back(vertex);
|
||||
}
|
||||
currentGroup->faces.push_back(face);
|
||||
}
|
||||
}
|
||||
else if (params[0] == "s")
|
||||
{//smoothing
|
||||
}
|
||||
else if (params[0] == "mtllib")
|
||||
{
|
||||
loadMaterialFile(dirName + "/" + params[1], dirName);
|
||||
}
|
||||
else if (params[0] == "usemtl")
|
||||
{
|
||||
if (currentGroup->faces.size() != 0)
|
||||
groups.push_back(currentGroup);
|
||||
currentGroup = new ObjGroup();
|
||||
currentGroup->materialIndex = -1;
|
||||
|
||||
for (size_t i = 0; i < materials.size(); i++)
|
||||
{
|
||||
MaterialInfo* info = materials[i];
|
||||
if (info->name == params[1])
|
||||
{
|
||||
currentGroup->materialIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentGroup->materialIndex == -1)
|
||||
std::cout << "Could not find material name " << params[1] << std::endl;
|
||||
}
|
||||
}
|
||||
groups.push_back(currentGroup);
|
||||
|
||||
minVertex = vertices[0];
|
||||
maxVertex = vertices[0];
|
||||
for (auto v : vertices)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
minVertex[i] = fmin(minVertex[i], v[i]);
|
||||
maxVertex[i] = fmax(maxVertex[i], v[i]);
|
||||
}
|
||||
}
|
||||
center = (minVertex + maxVertex) / 2.0f;
|
||||
radius = 0;
|
||||
for (auto v : vertices)
|
||||
radius = fmax(radius, (center.x - v.x) * (center.x - v.x) + (center.z - v.z) * (center.z - v.z));
|
||||
radius = sqrt(radius);
|
||||
|
||||
for each(ObjGroup *group in groups)
|
||||
{
|
||||
Optimise(group);
|
||||
}
|
||||
}
|
||||
|
||||
void Model::Optimise(ObjGroup *t)
|
||||
{
|
||||
for (Face &face : t->faces)
|
||||
{
|
||||
for each(auto &vertex in face.vertices)
|
||||
{
|
||||
t->VertexArray.push_back(Vertex(vertices[vertex.position].x, vertices[vertex.position].y, vertices[vertex.position].z,
|
||||
normals[vertex.normal].x, normals[vertex.normal].y, normals[vertex.normal].z,
|
||||
texcoords[vertex.texcoord].x, texcoords[vertex.texcoord].y));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Model::draw()
|
||||
{
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_NORMAL_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
for (auto &g : groups)
|
||||
{
|
||||
if (materials[g->materialIndex]->hasTexture)
|
||||
{
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
materials[g->materialIndex]->texture->bind();
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
float color[4] = { 1, 0, 0, 1 };
|
||||
|
||||
if (materials[g->materialIndex]->hasDiffuse)
|
||||
{
|
||||
memcpy(color, materials[g->materialIndex]->diffuseColor.v, 3 * sizeof(float));
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
|
||||
}
|
||||
else if (materials[g->materialIndex]->hasAmbient)
|
||||
{
|
||||
memcpy(color, materials[g->materialIndex]->ambientColor.v, 3 * sizeof(float));
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
|
||||
}
|
||||
else if (materials[g->materialIndex]->hasSpecular)
|
||||
{
|
||||
memcpy(color, materials[g->materialIndex]->specularColor.v, 3 * sizeof(float));
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
|
||||
}
|
||||
}
|
||||
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 0);
|
||||
glNormalPointer(GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 3);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), ((float*)g->VertexArray.data()) + 6);
|
||||
glDrawArrays(GL_TRIANGLES, 0, g->VertexArray.size());
|
||||
}
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
void Model::loadMaterialFile(std::string fileName, std::string dirName)
|
||||
{
|
||||
std::ifstream pFile(fileName.c_str());
|
||||
if (!pFile.is_open())
|
||||
{
|
||||
std::cout << "Could not open file " << fileName << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
MaterialInfo* currentMaterial = NULL;
|
||||
|
||||
while (!pFile.eof())
|
||||
{
|
||||
std::string line;
|
||||
std::getline(pFile, line);
|
||||
|
||||
line = replace(line, "\t", " ");
|
||||
while (line.find(" ") != std::string::npos)
|
||||
line = replace(line, " ", " ");
|
||||
if (line == "")
|
||||
continue;
|
||||
if (line[0] == ' ')
|
||||
line = line.substr(1);
|
||||
if (line == "")
|
||||
continue;
|
||||
if (line[line.length() - 1] == ' ')
|
||||
line = line.substr(0, line.length() - 1);
|
||||
if (line == "")
|
||||
continue;
|
||||
if (line[0] == '#')
|
||||
continue;
|
||||
|
||||
std::vector<std::string> params = split(line, " ");
|
||||
params[0] = toLower(params[0]);
|
||||
|
||||
if (params[0] == "newmtl")
|
||||
{
|
||||
if (currentMaterial != NULL)
|
||||
{
|
||||
materials.push_back(currentMaterial);
|
||||
}
|
||||
currentMaterial = new MaterialInfo();
|
||||
currentMaterial->name = params[1];
|
||||
}
|
||||
else if (params[0] == "map_kd")
|
||||
{
|
||||
currentMaterial->hasTexture = true;
|
||||
currentMaterial->texture = new Texture(dirName + "/" + params[1]);
|
||||
}
|
||||
else if (params[0] == "kd")
|
||||
{
|
||||
currentMaterial->hasDiffuse = true;
|
||||
currentMaterial->diffuseColor = Vec3f(atof(params[1].c_str()), atof(params[2].c_str()), atof(params[3].c_str()));
|
||||
}
|
||||
else if (params[0] == "ka")
|
||||
{
|
||||
currentMaterial->hasAmbient = true;
|
||||
currentMaterial->ambientColor = Vec3f(atof(params[1].c_str()), atof(params[2].c_str()), atof(params[3].c_str()));
|
||||
}
|
||||
else if (params[0] == "ks")
|
||||
{
|
||||
currentMaterial->hasSpecular = true;
|
||||
currentMaterial->specularColor = Vec3f(atof(params[1].c_str()), atof(params[2].c_str()), atof(params[3].c_str()));
|
||||
}
|
||||
else
|
||||
std::cout << "Didn't parse " << params[0] << " in material file" << std::endl;
|
||||
}
|
||||
if (currentMaterial != NULL)
|
||||
materials.push_back(currentMaterial);
|
||||
|
||||
}
|
||||
|
||||
Model::MaterialInfo::MaterialInfo()
|
||||
{
|
||||
hasTexture = false;
|
||||
}
|
||||
|
||||
Model::Texture::Texture(const std::string & fileName)
|
||||
{
|
||||
int width, height, bpp;
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
unsigned char* imgData = stbi_load(fileName.c_str(), &width, &height, &bpp, 4);
|
||||
|
||||
glGenTextures(1, &index);
|
||||
glBindTexture(GL_TEXTURE_2D, index);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0, //level
|
||||
GL_RGBA, //internal format
|
||||
width, //width
|
||||
height, //height
|
||||
0, //border
|
||||
GL_RGBA, //data format
|
||||
GL_UNSIGNED_BYTE, //data type
|
||||
imgData); //data
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
||||
stbi_image_free(imgData);
|
||||
}
|
||||
|
||||
void Model::Texture::bind()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, index);
|
||||
}
|
||||
|
||||
std::string replace(std::string str, std::string toReplace, std::string replacement)
|
||||
{
|
||||
size_t index = 0;
|
||||
while (true)
|
||||
{
|
||||
index = str.find(toReplace, index);
|
||||
if (index == std::string::npos)
|
||||
break;
|
||||
str.replace(index, toReplace.length(), replacement);
|
||||
++index;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::vector<std::string> split(std::string str, std::string sep)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
size_t index;
|
||||
while (true)
|
||||
{
|
||||
index = str.find(sep);
|
||||
if (index == std::string::npos)
|
||||
break;
|
||||
ret.push_back(str.substr(0, index));
|
||||
str = str.substr(index + 1);
|
||||
}
|
||||
ret.push_back(str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline std::string toLower(std::string data)
|
||||
{
|
||||
std::transform(data.begin(), data.end(), data.begin(), ::tolower);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::map<std::string, std::pair<Model*, int>> Model::cache;
|
||||
|
||||
Model* Model::load(const std::string &fileName)
|
||||
{
|
||||
if (cache.find(fileName) == cache.end())
|
||||
cache[fileName] = std::pair<Model*, int>(new Model(fileName), 0);
|
||||
cache[fileName].second++;
|
||||
return cache[fileName].first;
|
||||
}
|
||||
|
||||
void Model::unload(Model* model)
|
||||
{
|
||||
for (auto m : cache)
|
||||
{
|
||||
if (m.second.first == model)
|
||||
{
|
||||
m.second.second--;
|
||||
if (m.second.second == 0)
|
||||
{
|
||||
delete m.second.first;
|
||||
cache.erase(cache.find(m.first));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Model::~Model(void)
|
||||
{
|
||||
for (auto m : cache)
|
||||
{
|
||||
delete m.second.first;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include <GL/freeglut.h>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "Vector.h"
|
||||
#include "Vertex.h"
|
||||
|
||||
class Model
|
||||
{
|
||||
private:
|
||||
|
||||
class VertexIndex
|
||||
{
|
||||
public:
|
||||
int position;
|
||||
int normal;
|
||||
int texcoord;
|
||||
};
|
||||
|
||||
class Face
|
||||
{
|
||||
public:
|
||||
std::list<VertexIndex> vertices;
|
||||
};
|
||||
|
||||
class Texture
|
||||
{
|
||||
GLuint index;
|
||||
public:
|
||||
Texture(const std::string &fileName);
|
||||
void bind();
|
||||
};
|
||||
|
||||
class MaterialInfo
|
||||
{
|
||||
public:
|
||||
MaterialInfo();
|
||||
std::string name;
|
||||
Texture* texture;
|
||||
bool hasTexture;
|
||||
|
||||
bool hasDiffuse;
|
||||
Vec3f diffuseColor;
|
||||
bool hasAmbient;
|
||||
Vec3f ambientColor;
|
||||
bool hasSpecular;
|
||||
Vec3f specularColor;
|
||||
|
||||
};
|
||||
|
||||
class ObjGroup
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
int materialIndex;
|
||||
std::list<Face> faces;
|
||||
std::vector<Vertex> VertexArray;
|
||||
};
|
||||
|
||||
std::vector<Vec3f> vertices;
|
||||
std::vector<Vec3f> normals;
|
||||
std::vector<Vec2f> texcoords;
|
||||
std::vector<ObjGroup*> groups;
|
||||
std::vector<MaterialInfo*> materials;
|
||||
|
||||
void loadMaterialFile(std::string fileName, std::string dirName);
|
||||
|
||||
Model(std::string filename);
|
||||
~Model(void);
|
||||
|
||||
public:
|
||||
|
||||
static std::map<std::string, std::pair<Model*, int> > cache;
|
||||
static Model* load(const std::string &fileName);
|
||||
static void unload(Model* model);
|
||||
|
||||
void draw();
|
||||
void Optimise(ObjGroup *t);
|
||||
|
||||
Vec3f minVertex;
|
||||
Vec3f maxVertex;
|
||||
|
||||
Vec3f center;
|
||||
float radius;
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
#include "Player.h"
|
||||
#include <GL/freeglut.h>
|
||||
|
||||
Player* Player::instance = NULL;
|
||||
|
||||
Player::Player()
|
||||
{
|
||||
speed = 10;
|
||||
health = 50;
|
||||
xp = 75;
|
||||
level = 10;
|
||||
}
|
||||
|
||||
Player* Player::getInstance()
|
||||
{
|
||||
if (instance == nullptr)
|
||||
instance = new Player();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Player::init()
|
||||
{
|
||||
instance = new Player();
|
||||
}
|
||||
|
||||
Player::~Player()
|
||||
{
|
||||
if (leftWeapon)
|
||||
delete leftWeapon;
|
||||
|
||||
if (rightWeapon)
|
||||
delete rightWeapon;
|
||||
}
|
||||
|
||||
void Player::setCamera()
|
||||
{
|
||||
glRotatef(rotation.x, 1, 0, 0);
|
||||
glRotatef(rotation.y, 0, 1, 0);
|
||||
glTranslatef(-position.x, -position.y, -position.z);
|
||||
|
||||
}
|
||||
|
||||
void Player::setPosition(float angle, float fac, bool height)
|
||||
{
|
||||
if (height)
|
||||
position.y += angle*fac;
|
||||
else
|
||||
{
|
||||
position.x -= (float)cos((rotation.y + angle) / 180 * M_PI) * fac;
|
||||
position.z -= (float)sin((rotation.y + angle) / 180 * M_PI) * fac;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include "Vector.h"
|
||||
|
||||
class Model;
|
||||
|
||||
class Player
|
||||
{
|
||||
private:
|
||||
static Player* instance;
|
||||
public:
|
||||
Player();
|
||||
~Player();
|
||||
|
||||
void setCamera();
|
||||
void setPosition(float angle, float fac, bool height);
|
||||
|
||||
static Player* getInstance(void);
|
||||
static void init(void);
|
||||
|
||||
Vec3f position;
|
||||
Vec2f rotation;
|
||||
|
||||
Model* leftWeapon;
|
||||
Model* rightWeapon;
|
||||
|
||||
float health;
|
||||
float xp;
|
||||
int level;
|
||||
|
||||
float speed;
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "State.h"
|
||||
|
||||
State::State()
|
||||
{
|
||||
}
|
||||
|
||||
State::~State()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
class State
|
||||
{
|
||||
public:
|
||||
State();
|
||||
~State();
|
||||
|
||||
virtual void init(void) = 0;
|
||||
virtual void exit(void) = 0;
|
||||
|
||||
virtual void draw(void) = 0;
|
||||
virtual void update(float deltaTime) = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "StateHandler.h"
|
||||
#include "MenuState.h"
|
||||
#include "WorldState.h"
|
||||
|
||||
StateHandler* StateHandler::instance = nullptr;
|
||||
|
||||
StateHandler::StateHandler()
|
||||
{
|
||||
available = false;
|
||||
CState = MENU;
|
||||
CurrentState = new MenuState();
|
||||
CurrentState->init();
|
||||
available = true;
|
||||
}
|
||||
|
||||
StateHandler::~StateHandler()
|
||||
{
|
||||
delete CurrentState;
|
||||
}
|
||||
|
||||
StateHandler* StateHandler::getInstance()
|
||||
{
|
||||
if (instance == nullptr)
|
||||
instance = new StateHandler();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void StateHandler::update(float deltaTime)
|
||||
{
|
||||
if(available)
|
||||
CurrentState->update(deltaTime);
|
||||
}
|
||||
void StateHandler::draw()
|
||||
{
|
||||
if(available)
|
||||
CurrentState->draw();
|
||||
}
|
||||
|
||||
void StateHandler::changeState(EState newState)
|
||||
{
|
||||
if (CState == newState)
|
||||
return;
|
||||
|
||||
available = false;
|
||||
|
||||
CurrentState->exit();
|
||||
|
||||
switch (newState)
|
||||
{
|
||||
case WORLD:
|
||||
CurrentState = new WorldState();
|
||||
case MENU:
|
||||
CurrentState = new MenuState();
|
||||
}
|
||||
|
||||
CState = newState;
|
||||
CurrentState->init();
|
||||
|
||||
available = true;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "State.h"
|
||||
|
||||
class StateHandler
|
||||
{
|
||||
public:
|
||||
~StateHandler();
|
||||
|
||||
static StateHandler* getInstance(void);
|
||||
|
||||
enum EState { WORLD, MENU };
|
||||
|
||||
void changeState(EState newState);
|
||||
|
||||
void draw(void);
|
||||
void update(float deltaTime);
|
||||
private:
|
||||
StateHandler();
|
||||
static StateHandler* instance;
|
||||
|
||||
State* CurrentState;
|
||||
EState CState;
|
||||
bool available;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
#include "Vector.h"
|
||||
|
||||
Vec3f::Vec3f(float x, float y, float z)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
/*The length of the vector*/
|
||||
float Vec3f::Length()
|
||||
{
|
||||
return (float)sqrt(x*x+y*y+z*z);
|
||||
}
|
||||
|
||||
void Vec3f::Normalize()
|
||||
{
|
||||
float length = this->Length();
|
||||
|
||||
if (length != 0)
|
||||
{
|
||||
x = x / length;
|
||||
y = y / length;
|
||||
z = z / length;
|
||||
}
|
||||
}
|
||||
|
||||
float Vec3f::Distance(const Vec3f &other)
|
||||
{
|
||||
return (float)sqrt(pow(other.x - x, 2)+pow(other.y - y, 2)+pow(other.z - z, 2));
|
||||
}
|
||||
|
||||
Vec3f::Vec3f()
|
||||
{
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
this->z = 0;
|
||||
}
|
||||
Vec3f::Vec3f(const Vec3f &other)
|
||||
{
|
||||
this->x = other.x;
|
||||
this->y = other.y;
|
||||
this->z = other.z;
|
||||
}
|
||||
|
||||
float& Vec3f::operator [](int index)
|
||||
{
|
||||
return v[index];
|
||||
}
|
||||
|
||||
Vec3f Vec3f::operator+(const Vec3f & other)
|
||||
{
|
||||
return Vec3f(x + other.x, y + other.y, z + other.z);
|
||||
}
|
||||
|
||||
Vec3f Vec3f::operator-(const Vec3f & other)
|
||||
{
|
||||
return Vec3f(x - other.x, y - other.y, z - other.z);
|
||||
}
|
||||
|
||||
Vec3f Vec3f::operator/(float value)
|
||||
{
|
||||
return Vec3f(x / value, y / value, z / value);
|
||||
}
|
||||
|
||||
bool Vec3f::operator==(const Vec3f & other)
|
||||
{
|
||||
/*bool xb, yb,zb;
|
||||
xb = x == other.x;
|
||||
yb = y == other.y;
|
||||
zb = z == other.z;
|
||||
if (xb & yb & zb)
|
||||
return true;*/
|
||||
return x == other.x & y == other.y & z == other.z;
|
||||
}
|
||||
|
||||
bool Vec3f::operator!=(const Vec3f & other)
|
||||
{
|
||||
return x != other.x & y != other.y & z != other.z;
|
||||
}
|
||||
|
||||
Vec3f Vec3f::operator*(const float & other)
|
||||
{
|
||||
return Vec3f(x*other, y*other, z*other);
|
||||
}
|
||||
|
||||
Vec3f Vec3f::cross(const Vec3f & other)
|
||||
{
|
||||
return Vec3f(
|
||||
y*other.z - other.y*z,
|
||||
z*other.x - other.z*x,
|
||||
x*other.y - other.x*y
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vec2f::Vec2f(float x, float y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
Vec2f::Vec2f()
|
||||
{
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
}
|
||||
Vec2f::Vec2f(const Vec2f &other)
|
||||
{
|
||||
this->x = other.x;
|
||||
this->y = other.y;
|
||||
}
|
||||
|
||||
float& Vec2f::operator [](int index)
|
||||
{
|
||||
return v[index];
|
||||
}
|
||||
|
||||
Vec2f Vec2f::operator+(const Vec2f & other)
|
||||
{
|
||||
return Vec2f(x + other.x, y+other.y);
|
||||
}
|
||||
|
||||
float Vec2f::length()
|
||||
{
|
||||
return (float)sqrt(x*x + y*y);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
class Vec3f
|
||||
{
|
||||
public:
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
float x, y, z;
|
||||
};
|
||||
float v[3];
|
||||
};
|
||||
Vec3f();
|
||||
Vec3f(const Vec3f &other);
|
||||
Vec3f(float x, float y, float z);
|
||||
float Length();
|
||||
void Normalize();
|
||||
float Distance(const Vec3f &);
|
||||
float& operator [](int);
|
||||
Vec3f operator + (const Vec3f &other);
|
||||
Vec3f operator -(const Vec3f &other);
|
||||
Vec3f operator / (float value);
|
||||
bool operator ==(const Vec3f &other);
|
||||
bool operator !=(const Vec3f &other);
|
||||
Vec3f operator *(const float &other);
|
||||
|
||||
Vec3f cross(const Vec3f &other);
|
||||
|
||||
};
|
||||
|
||||
class Vec2f
|
||||
{
|
||||
public:
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
float x, y;
|
||||
};
|
||||
float v[2];
|
||||
};
|
||||
Vec2f();
|
||||
Vec2f(float x, float y);
|
||||
Vec2f(const Vec2f &other);
|
||||
float& operator [](int);
|
||||
Vec2f operator + (const Vec2f &other);
|
||||
float length();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "Vertex.h"
|
||||
|
||||
Vertex::Vertex(float x, float y, float z, float nx, float ny, float nz, float tx, float ty)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
|
||||
this->normalX = nx;
|
||||
this->normalY = ny;
|
||||
this->normalZ = nz;
|
||||
|
||||
this->texX = tx;
|
||||
this->texY = ty;
|
||||
}
|
||||
|
||||
Vertex::~Vertex()
|
||||
{
|
||||
}
|
||||
|
||||
Vertex Vertex::operator/(float &other)
|
||||
{
|
||||
return Vertex(x / other, y / other, z / other, normalX, normalY, normalZ, texX, texY);
|
||||
}
|
||||
|
||||
Vertex Vertex::operator*(Vertex & other)
|
||||
{
|
||||
return Vertex(x*other.x, y*other.y, z*other.z, normalX, normalY, normalZ, texX, texY);
|
||||
}
|
||||
|
||||
Vertex Vertex::operator*(float & other)
|
||||
{
|
||||
return Vertex(x*other, y*other, z*other, normalX, normalY, normalZ, texX, texY);
|
||||
}
|
||||
|
||||
Vertex Vertex::operator+(Vertex & other)
|
||||
{
|
||||
return Vertex(x+other.x, y+other.y, z+other.z, normalX, normalY, normalZ, texX, texY);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
class Vertex
|
||||
{
|
||||
public:
|
||||
Vertex(float x, float y, float z, float nx, float ny, float nz, float tx, float ty);
|
||||
~Vertex();
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
float normalX;
|
||||
float normalY;
|
||||
float normalZ;
|
||||
|
||||
float texX;
|
||||
float texY;
|
||||
|
||||
Vertex operator/(float &other);
|
||||
Vertex operator*(Vertex &other);
|
||||
Vertex operator*(float &other);
|
||||
Vertex operator+(Vertex &other);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "World.h"
|
||||
|
||||
|
||||
|
||||
World::World()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
World::~World()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
class World
|
||||
{
|
||||
public:
|
||||
World();
|
||||
~World();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "WorldState.h"
|
||||
|
||||
|
||||
|
||||
WorldState::WorldState()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
WorldState::~WorldState()
|
||||
{
|
||||
}
|
||||
|
||||
void WorldState::init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void WorldState::exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
void WorldState::draw(void)
|
||||
{
|
||||
}
|
||||
|
||||
void WorldState::update(float deltaTime)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "State.h"
|
||||
|
||||
class WorldState : public State
|
||||
{
|
||||
public:
|
||||
WorldState();
|
||||
~WorldState();
|
||||
|
||||
void init(void);
|
||||
void exit(void);
|
||||
|
||||
void draw(void);
|
||||
void update(float deltaTime);
|
||||
};
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,106 @@
|
||||
freeglut 3.0.0-1.mp for MSVC
|
||||
|
||||
This package contains freeglut import libraries, headers, and Windows DLLs.
|
||||
These allow 32 and 64 bit GLUT applications to be compiled on Windows using
|
||||
Microsoft Visual C++.
|
||||
|
||||
For more information on freeglut, visit http://freeglut.sourceforge.net/.
|
||||
|
||||
|
||||
Installation
|
||||
|
||||
Create a folder on your PC which is readable by all users, for example
|
||||
“C:\Program Files\Common Files\MSVC\freeglut\” on a typical Windows system. Copy
|
||||
the “lib\” and “include\” folders from this zip archive to that location.
|
||||
|
||||
The appropriate freeglut DLL can either be placed in the same folder as your
|
||||
application, or can be installed in a system-wide folder which appears in your
|
||||
%PATH% environment variable. Be careful not to mix the 32 bit DLL up with the 64
|
||||
bit DLL, as they are not interchangeable.
|
||||
|
||||
|
||||
Compiling 32 bit Applications
|
||||
|
||||
To create a 32 bit freeglut application, create a new Win32 C++ project in MSVC.
|
||||
From the “Win32 Application Wizard”, choose a “Windows application”, check the
|
||||
“Empty project” box, and submit.
|
||||
|
||||
You’ll now need to configure the compiler and linker settings. Open up the
|
||||
project properties, and select “All Configurations” (this is necessary to ensure
|
||||
our changes are applied for both debug and release builds). Open up the
|
||||
“general” section under “C/C++”, and configure the “include\” folder you created
|
||||
above as an “Additional Include Directory”. If you have more than one GLUT
|
||||
package which contains a “glut.h” file, it’s important to ensure that the
|
||||
freeglut include folder appears above all other GLUT include folders.
|
||||
|
||||
Now open up the “general” section under “Linker”, and configure the “lib\”
|
||||
folder you created above as an “Additional Library Directory”. A freeglut
|
||||
application depends on the import libraries “freeglut.lib” and “opengl32.lib”,
|
||||
which can be configured under the “Input” section. However, it shouldn’t be
|
||||
necessary to explicitly state these dependencies, since the freeglut headers
|
||||
handle this for you. Now open the “Advanced” section, and enter “mainCRTStartup”
|
||||
as the “Entry Point” for your application. This is necessary because GLUT
|
||||
applications use “main” as the application entry point, not “WinMain”—without it
|
||||
you’ll get an undefined reference when you try to link your application.
|
||||
|
||||
That’s all of your project properties configured, so you can now add source
|
||||
files to your project and build the application. If you want your application to
|
||||
be compatible with GLUT, you should “#include <GL/glut.h>”. If you want to use
|
||||
freeglut specific extensions, you should “#include <GL/freeglut.h>” instead.
|
||||
|
||||
Don’t forget to either include the freeglut DLL when distributing applications,
|
||||
or provide your users with some method of obtaining it if they don’t already
|
||||
have it!
|
||||
|
||||
|
||||
Compiling 64 bit Applications
|
||||
|
||||
Building 64 bit applications is almost identical to building 32 bit applications.
|
||||
When you use the configuration manager to add the x64 platform, it’s easiest to
|
||||
copy the settings from the Win32 platform. If you do so, it’s then only necessary
|
||||
to change the “Additional Library Directories” configuration so that it
|
||||
references the directory containing the 64 bit import library rather
|
||||
than the 32 bit one.
|
||||
|
||||
|
||||
Problems?
|
||||
|
||||
If you have problems using this package (compiler / linker errors etc.), please
|
||||
check that you have followed all of the steps in this readme file correctly.
|
||||
Almost all of the problems which are reported with these packages are due to
|
||||
missing a step or not doing it correctly, for example trying to build a 32 bit
|
||||
app against the 64 bit import library. If you have followed all of the steps
|
||||
correctly but your application still fails to build, try building a very simple
|
||||
but functional program (the example at
|
||||
http://www.transmissionzero.co.uk/computing/using-glut-with-mingw/ works fine
|
||||
with MSVC). A lot of people try to build very complex applications after
|
||||
installing these packages, and often the error is with the application code or
|
||||
other library dependencies rather than freeglut.
|
||||
|
||||
If you still can’t get it working after trying to compile a simple application,
|
||||
then please get in touch via http://www.transmissionzero.co.uk/contact/,
|
||||
providing as much detail as you can. Please don’t complain to the freeglut guys
|
||||
unless you’re sure it’s a freeglut bug, and have reproduced the issue after
|
||||
compiling freeglut from the latest SVN version—if that’s still the case, I’m
|
||||
sure they would appreciate a bug report or a patch.
|
||||
|
||||
|
||||
Changelog
|
||||
|
||||
2015–07–22: Release 3.0.0-2.mp
|
||||
|
||||
• Modified the freeglut_std.h file so that it doesn’t try to link against the
|
||||
freeglutd.lib import library.
|
||||
|
||||
2015–03–15: Release 3.0.0-1.mp
|
||||
|
||||
• First 3.0.0 MSVC release. I’ve built the package using Visual Studio 2013,
|
||||
and the only change I’ve made is to the DLL version resource—I’ve changed
|
||||
the description so that my MinGW and MSVC builds are distinguishable from
|
||||
each other (and other builds) using Windows Explorer.
|
||||
|
||||
|
||||
Transmission Zero
|
||||
2015–07–22
|
||||
|
||||
http://www.transmissionzero.co.uk/
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef __FREEGLUT_H__
|
||||
#define __FREEGLUT_H__
|
||||
|
||||
/*
|
||||
* freeglut.h
|
||||
*
|
||||
* The freeglut library include file
|
||||
*
|
||||
* THE SOFTWARE IS 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
|
||||
* PAWEL W. OLSZTA 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "freeglut_std.h"
|
||||
#include "freeglut_ext.h"
|
||||
|
||||
/*** END OF FILE ***/
|
||||
|
||||
#endif /* __FREEGLUT_H__ */
|
||||
@@ -0,0 +1,271 @@
|
||||
#ifndef __FREEGLUT_EXT_H__
|
||||
#define __FREEGLUT_EXT_H__
|
||||
|
||||
/*
|
||||
* freeglut_ext.h
|
||||
*
|
||||
* The non-GLUT-compatible extensions to the freeglut library include file
|
||||
*
|
||||
* Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
|
||||
* Written by Pawel W. Olszta, <olszta@sourceforge.net>
|
||||
* Creation date: Thu Dec 2 1999
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is 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 Software.
|
||||
*
|
||||
* THE SOFTWARE IS 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
|
||||
* PAWEL W. OLSZTA 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Additional GLUT Key definitions for the Special key function
|
||||
*/
|
||||
#define GLUT_KEY_NUM_LOCK 0x006D
|
||||
#define GLUT_KEY_BEGIN 0x006E
|
||||
#define GLUT_KEY_DELETE 0x006F
|
||||
#define GLUT_KEY_SHIFT_L 0x0070
|
||||
#define GLUT_KEY_SHIFT_R 0x0071
|
||||
#define GLUT_KEY_CTRL_L 0x0072
|
||||
#define GLUT_KEY_CTRL_R 0x0073
|
||||
#define GLUT_KEY_ALT_L 0x0074
|
||||
#define GLUT_KEY_ALT_R 0x0075
|
||||
|
||||
/*
|
||||
* GLUT API Extension macro definitions -- behaviour when the user clicks on an "x" to close a window
|
||||
*/
|
||||
#define GLUT_ACTION_EXIT 0
|
||||
#define GLUT_ACTION_GLUTMAINLOOP_RETURNS 1
|
||||
#define GLUT_ACTION_CONTINUE_EXECUTION 2
|
||||
|
||||
/*
|
||||
* Create a new rendering context when the user opens a new window?
|
||||
*/
|
||||
#define GLUT_CREATE_NEW_CONTEXT 0
|
||||
#define GLUT_USE_CURRENT_CONTEXT 1
|
||||
|
||||
/*
|
||||
* Direct/Indirect rendering context options (has meaning only in Unix/X11)
|
||||
*/
|
||||
#define GLUT_FORCE_INDIRECT_CONTEXT 0
|
||||
#define GLUT_ALLOW_DIRECT_CONTEXT 1
|
||||
#define GLUT_TRY_DIRECT_CONTEXT 2
|
||||
#define GLUT_FORCE_DIRECT_CONTEXT 3
|
||||
|
||||
/*
|
||||
* GLUT API Extension macro definitions -- the glutGet parameters
|
||||
*/
|
||||
#define GLUT_INIT_STATE 0x007C
|
||||
|
||||
#define GLUT_ACTION_ON_WINDOW_CLOSE 0x01F9
|
||||
|
||||
#define GLUT_WINDOW_BORDER_WIDTH 0x01FA
|
||||
#define GLUT_WINDOW_BORDER_HEIGHT 0x01FB
|
||||
#define GLUT_WINDOW_HEADER_HEIGHT 0x01FB /* Docs say it should always have been GLUT_WINDOW_BORDER_HEIGHT, keep this for backward compatibility */
|
||||
|
||||
#define GLUT_VERSION 0x01FC
|
||||
|
||||
#define GLUT_RENDERING_CONTEXT 0x01FD
|
||||
#define GLUT_DIRECT_RENDERING 0x01FE
|
||||
|
||||
#define GLUT_FULL_SCREEN 0x01FF
|
||||
|
||||
#define GLUT_SKIP_STALE_MOTION_EVENTS 0x0204
|
||||
|
||||
#define GLUT_GEOMETRY_VISUALIZE_NORMALS 0x0205
|
||||
|
||||
#define GLUT_STROKE_FONT_DRAW_JOIN_DOTS 0x0206 /* Draw dots between line segments of stroke fonts? */
|
||||
|
||||
/*
|
||||
* New tokens for glutInitDisplayMode.
|
||||
* Only one GLUT_AUXn bit may be used at a time.
|
||||
* Value 0x0400 is defined in OpenGLUT.
|
||||
*/
|
||||
#define GLUT_AUX 0x1000
|
||||
|
||||
#define GLUT_AUX1 0x1000
|
||||
#define GLUT_AUX2 0x2000
|
||||
#define GLUT_AUX3 0x4000
|
||||
#define GLUT_AUX4 0x8000
|
||||
|
||||
/*
|
||||
* Context-related flags, see fg_state.c
|
||||
* Set the requested OpenGL version
|
||||
*/
|
||||
#define GLUT_INIT_MAJOR_VERSION 0x0200
|
||||
#define GLUT_INIT_MINOR_VERSION 0x0201
|
||||
#define GLUT_INIT_FLAGS 0x0202
|
||||
#define GLUT_INIT_PROFILE 0x0203
|
||||
|
||||
/*
|
||||
* Flags for glutInitContextFlags, see fg_init.c
|
||||
*/
|
||||
#define GLUT_DEBUG 0x0001
|
||||
#define GLUT_FORWARD_COMPATIBLE 0x0002
|
||||
|
||||
|
||||
/*
|
||||
* Flags for glutInitContextProfile, see fg_init.c
|
||||
*/
|
||||
#define GLUT_CORE_PROFILE 0x0001
|
||||
#define GLUT_COMPATIBILITY_PROFILE 0x0002
|
||||
|
||||
/*
|
||||
* Process loop function, see fg_main.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutMainLoopEvent( void );
|
||||
FGAPI void FGAPIENTRY glutLeaveMainLoop( void );
|
||||
FGAPI void FGAPIENTRY glutExit ( void );
|
||||
|
||||
/*
|
||||
* Window management functions, see fg_window.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutFullScreenToggle( void );
|
||||
FGAPI void FGAPIENTRY glutLeaveFullScreen( void );
|
||||
|
||||
/*
|
||||
* Menu functions
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutSetMenuFont( int menuID, void* font );
|
||||
|
||||
/*
|
||||
* Window-specific callback functions, see fg_callbacks.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutMouseWheelFunc( void (* callback)( int, int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutPositionFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutCloseFunc( void (* callback)( void ) );
|
||||
FGAPI void FGAPIENTRY glutWMCloseFunc( void (* callback)( void ) );
|
||||
/* And also a destruction callback for menus */
|
||||
FGAPI void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) );
|
||||
|
||||
/*
|
||||
* State setting and retrieval functions, see fg_state.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutSetOption ( GLenum option_flag, int value );
|
||||
FGAPI int * FGAPIENTRY glutGetModeValues(GLenum mode, int * size);
|
||||
/* A.Donev: User-data manipulation */
|
||||
FGAPI void* FGAPIENTRY glutGetWindowData( void );
|
||||
FGAPI void FGAPIENTRY glutSetWindowData(void* data);
|
||||
FGAPI void* FGAPIENTRY glutGetMenuData( void );
|
||||
FGAPI void FGAPIENTRY glutSetMenuData(void* data);
|
||||
|
||||
/*
|
||||
* Font stuff, see fg_font.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutBitmapHeight( void* font );
|
||||
FGAPI GLfloat FGAPIENTRY glutStrokeHeight( void* font );
|
||||
FGAPI void FGAPIENTRY glutBitmapString( void* font, const unsigned char *string );
|
||||
FGAPI void FGAPIENTRY glutStrokeString( void* font, const unsigned char *string );
|
||||
|
||||
/*
|
||||
* Geometry functions, see fg_geometry.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutWireRhombicDodecahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidRhombicDodecahedron( void );
|
||||
FGAPI void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, double offset[3], double scale );
|
||||
FGAPI void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, double offset[3], double scale );
|
||||
FGAPI void FGAPIENTRY glutWireCylinder( double radius, double height, GLint slices, GLint stacks);
|
||||
FGAPI void FGAPIENTRY glutSolidCylinder( double radius, double height, GLint slices, GLint stacks);
|
||||
|
||||
/*
|
||||
* Rest of functions for rendering Newell's teaset, found in fg_teapot.c
|
||||
* NB: front facing polygons have clockwise winding, not counter clockwise
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutWireTeacup( double size );
|
||||
FGAPI void FGAPIENTRY glutSolidTeacup( double size );
|
||||
FGAPI void FGAPIENTRY glutWireTeaspoon( double size );
|
||||
FGAPI void FGAPIENTRY glutSolidTeaspoon( double size );
|
||||
|
||||
/*
|
||||
* Extension functions, see fg_ext.c
|
||||
*/
|
||||
typedef void (*GLUTproc)();
|
||||
FGAPI GLUTproc FGAPIENTRY glutGetProcAddress( const char *procName );
|
||||
|
||||
/*
|
||||
* Multi-touch/multi-pointer extensions
|
||||
*/
|
||||
|
||||
#define GLUT_HAS_MULTI 1
|
||||
|
||||
/* TODO: add device_id parameter,
|
||||
cf. http://sourceforge.net/mailarchive/forum.php?thread_name=20120518071314.GA28061%40perso.beuc.net&forum_name=freeglut-developer */
|
||||
FGAPI void FGAPIENTRY glutMultiEntryFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutMultiButtonFunc( void (* callback)( int, int, int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutMultiMotionFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutMultiPassiveFunc( void (* callback)( int, int, int ) );
|
||||
|
||||
/*
|
||||
* Joystick functions, see fg_joystick.c
|
||||
*/
|
||||
/* USE OF THESE FUNCTIONS IS DEPRECATED !!!!! */
|
||||
/* If you have a serious need for these functions in your application, please either
|
||||
* contact the "freeglut" developer community at freeglut-developer@lists.sourceforge.net,
|
||||
* switch to the OpenGLUT library, or else port your joystick functionality over to PLIB's
|
||||
* "js" library.
|
||||
*/
|
||||
int glutJoystickGetNumAxes( int ident );
|
||||
int glutJoystickGetNumButtons( int ident );
|
||||
int glutJoystickNotWorking( int ident );
|
||||
float glutJoystickGetDeadBand( int ident, int axis );
|
||||
void glutJoystickSetDeadBand( int ident, int axis, float db );
|
||||
float glutJoystickGetSaturation( int ident, int axis );
|
||||
void glutJoystickSetSaturation( int ident, int axis, float st );
|
||||
void glutJoystickSetMinRange( int ident, float *axes );
|
||||
void glutJoystickSetMaxRange( int ident, float *axes );
|
||||
void glutJoystickSetCenter( int ident, float *axes );
|
||||
void glutJoystickGetMinRange( int ident, float *axes );
|
||||
void glutJoystickGetMaxRange( int ident, float *axes );
|
||||
void glutJoystickGetCenter( int ident, float *axes );
|
||||
|
||||
/*
|
||||
* Initialization functions, see fg_init.c
|
||||
*/
|
||||
/* to get the typedef for va_list */
|
||||
#include <stdarg.h>
|
||||
FGAPI void FGAPIENTRY glutInitContextVersion( int majorVersion, int minorVersion );
|
||||
FGAPI void FGAPIENTRY glutInitContextFlags( int flags );
|
||||
FGAPI void FGAPIENTRY glutInitContextProfile( int profile );
|
||||
FGAPI void FGAPIENTRY glutInitErrorFunc( void (* callback)( const char *fmt, va_list ap ) );
|
||||
FGAPI void FGAPIENTRY glutInitWarningFunc( void (* callback)( const char *fmt, va_list ap ) );
|
||||
|
||||
/* OpenGL >= 2.0 support */
|
||||
FGAPI void FGAPIENTRY glutSetVertexAttribCoord3(GLint attrib);
|
||||
FGAPI void FGAPIENTRY glutSetVertexAttribNormal(GLint attrib);
|
||||
FGAPI void FGAPIENTRY glutSetVertexAttribTexCoord2(GLint attrib);
|
||||
|
||||
/* Mobile platforms lifecycle */
|
||||
FGAPI void FGAPIENTRY glutInitContextFunc(void (* callback)());
|
||||
FGAPI void FGAPIENTRY glutAppStatusFunc(void (* callback)(int));
|
||||
/* state flags that can be passed to callback set by glutAppStatusFunc */
|
||||
#define GLUT_APPSTATUS_PAUSE 0x0001
|
||||
#define GLUT_APPSTATUS_RESUME 0x0002
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the display mode definitions
|
||||
*/
|
||||
#define GLUT_CAPTIONLESS 0x0400
|
||||
#define GLUT_BORDERLESS 0x0800
|
||||
#define GLUT_SRGB 0x1000
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*** END OF FILE ***/
|
||||
|
||||
#endif /* __FREEGLUT_EXT_H__ */
|
||||
@@ -0,0 +1,638 @@
|
||||
#ifndef __FREEGLUT_STD_H__
|
||||
#define __FREEGLUT_STD_H__
|
||||
|
||||
/*
|
||||
* freeglut_std.h
|
||||
*
|
||||
* The GLUT-compatible part of the freeglut library include file
|
||||
*
|
||||
* Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
|
||||
* Written by Pawel W. Olszta, <olszta@sourceforge.net>
|
||||
* Creation date: Thu Dec 2 1999
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is 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 Software.
|
||||
*
|
||||
* THE SOFTWARE IS 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
|
||||
* PAWEL W. OLSZTA 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Under windows, we have to differentiate between static and dynamic libraries
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
/* #pragma may not be supported by some compilers.
|
||||
* Discussion by FreeGLUT developers suggests that
|
||||
* Visual C++ specific code involving pragmas may
|
||||
* need to move to a separate header. 24th Dec 2003
|
||||
*/
|
||||
|
||||
/* Define FREEGLUT_LIB_PRAGMAS to 1 to include library
|
||||
* pragmas or to 0 to exclude library pragmas.
|
||||
* The default behavior depends on the compiler/platform.
|
||||
*/
|
||||
# ifndef FREEGLUT_LIB_PRAGMAS
|
||||
# if ( defined(_MSC_VER) || defined(__WATCOMC__) ) && !defined(_WIN32_WCE)
|
||||
# define FREEGLUT_LIB_PRAGMAS 1
|
||||
# else
|
||||
# define FREEGLUT_LIB_PRAGMAS 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN 1
|
||||
# endif
|
||||
# ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
# endif
|
||||
# include <windows.h>
|
||||
|
||||
/* Windows static library */
|
||||
# ifdef FREEGLUT_STATIC
|
||||
|
||||
#error Static linking is not supported with this build. Please remove the FREEGLUT_STATIC preprocessor directive, or download the source code from http://freeglut.sf.net/ and build against that.
|
||||
|
||||
/* Windows shared library (DLL) */
|
||||
# else
|
||||
|
||||
# define FGAPIENTRY __stdcall
|
||||
# if defined(FREEGLUT_EXPORTS)
|
||||
# define FGAPI __declspec(dllexport)
|
||||
# else
|
||||
# define FGAPI __declspec(dllimport)
|
||||
|
||||
/* Link with Win32 shared freeglut lib */
|
||||
# if FREEGLUT_LIB_PRAGMAS
|
||||
# pragma comment (lib, "freeglut.lib")
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
/* Drag in other Windows libraries as required by FreeGLUT */
|
||||
# if FREEGLUT_LIB_PRAGMAS
|
||||
# pragma comment (lib, "glu32.lib") /* link OpenGL Utility lib */
|
||||
# pragma comment (lib, "opengl32.lib") /* link Microsoft OpenGL lib */
|
||||
# pragma comment (lib, "gdi32.lib") /* link Windows GDI lib */
|
||||
# pragma comment (lib, "winmm.lib") /* link Windows MultiMedia lib */
|
||||
# pragma comment (lib, "user32.lib") /* link Windows user lib */
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
/* Non-Windows definition of FGAPI and FGAPIENTRY */
|
||||
# define FGAPI
|
||||
# define FGAPIENTRY
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The freeglut and GLUT API versions
|
||||
*/
|
||||
#define FREEGLUT 1
|
||||
#define GLUT_API_VERSION 4
|
||||
#define GLUT_XLIB_IMPLEMENTATION 13
|
||||
/* Deprecated:
|
||||
cf. http://sourceforge.net/mailarchive/forum.php?thread_name=CABcAi1hw7cr4xtigckaGXB5X8wddLfMcbA_rZ3NAuwMrX_zmsw%40mail.gmail.com&forum_name=freeglut-developer */
|
||||
#define FREEGLUT_VERSION_2_0 1
|
||||
|
||||
/*
|
||||
* Always include OpenGL and GLU headers
|
||||
*/
|
||||
/* Note: FREEGLUT_GLES is only used to cleanly bootstrap headers
|
||||
inclusion here; use GLES constants directly
|
||||
(e.g. GL_ES_VERSION_2_0) for all other needs */
|
||||
#ifdef FREEGLUT_GLES
|
||||
# include <EGL/egl.h>
|
||||
# include <GLES/gl.h>
|
||||
# include <GLES2/gl2.h>
|
||||
#elif __APPLE__
|
||||
# include <OpenGL/gl.h>
|
||||
# include <OpenGL/glu.h>
|
||||
#else
|
||||
# include <GL/gl.h>
|
||||
# include <GL/glu.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the special key codes:
|
||||
*/
|
||||
#define GLUT_KEY_F1 0x0001
|
||||
#define GLUT_KEY_F2 0x0002
|
||||
#define GLUT_KEY_F3 0x0003
|
||||
#define GLUT_KEY_F4 0x0004
|
||||
#define GLUT_KEY_F5 0x0005
|
||||
#define GLUT_KEY_F6 0x0006
|
||||
#define GLUT_KEY_F7 0x0007
|
||||
#define GLUT_KEY_F8 0x0008
|
||||
#define GLUT_KEY_F9 0x0009
|
||||
#define GLUT_KEY_F10 0x000A
|
||||
#define GLUT_KEY_F11 0x000B
|
||||
#define GLUT_KEY_F12 0x000C
|
||||
#define GLUT_KEY_LEFT 0x0064
|
||||
#define GLUT_KEY_UP 0x0065
|
||||
#define GLUT_KEY_RIGHT 0x0066
|
||||
#define GLUT_KEY_DOWN 0x0067
|
||||
#define GLUT_KEY_PAGE_UP 0x0068
|
||||
#define GLUT_KEY_PAGE_DOWN 0x0069
|
||||
#define GLUT_KEY_HOME 0x006A
|
||||
#define GLUT_KEY_END 0x006B
|
||||
#define GLUT_KEY_INSERT 0x006C
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- mouse state definitions
|
||||
*/
|
||||
#define GLUT_LEFT_BUTTON 0x0000
|
||||
#define GLUT_MIDDLE_BUTTON 0x0001
|
||||
#define GLUT_RIGHT_BUTTON 0x0002
|
||||
#define GLUT_DOWN 0x0000
|
||||
#define GLUT_UP 0x0001
|
||||
#define GLUT_LEFT 0x0000
|
||||
#define GLUT_ENTERED 0x0001
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the display mode definitions
|
||||
*/
|
||||
#define GLUT_RGB 0x0000
|
||||
#define GLUT_RGBA 0x0000
|
||||
#define GLUT_INDEX 0x0001
|
||||
#define GLUT_SINGLE 0x0000
|
||||
#define GLUT_DOUBLE 0x0002
|
||||
#define GLUT_ACCUM 0x0004
|
||||
#define GLUT_ALPHA 0x0008
|
||||
#define GLUT_DEPTH 0x0010
|
||||
#define GLUT_STENCIL 0x0020
|
||||
#define GLUT_MULTISAMPLE 0x0080
|
||||
#define GLUT_STEREO 0x0100
|
||||
#define GLUT_LUMINANCE 0x0200
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- windows and menu related definitions
|
||||
*/
|
||||
#define GLUT_MENU_NOT_IN_USE 0x0000
|
||||
#define GLUT_MENU_IN_USE 0x0001
|
||||
#define GLUT_NOT_VISIBLE 0x0000
|
||||
#define GLUT_VISIBLE 0x0001
|
||||
#define GLUT_HIDDEN 0x0000
|
||||
#define GLUT_FULLY_RETAINED 0x0001
|
||||
#define GLUT_PARTIALLY_RETAINED 0x0002
|
||||
#define GLUT_FULLY_COVERED 0x0003
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- fonts definitions
|
||||
*
|
||||
* Steve Baker suggested to make it binary compatible with GLUT:
|
||||
*/
|
||||
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__WATCOMC__)
|
||||
# define GLUT_STROKE_ROMAN ((void *)0x0000)
|
||||
# define GLUT_STROKE_MONO_ROMAN ((void *)0x0001)
|
||||
# define GLUT_BITMAP_9_BY_15 ((void *)0x0002)
|
||||
# define GLUT_BITMAP_8_BY_13 ((void *)0x0003)
|
||||
# define GLUT_BITMAP_TIMES_ROMAN_10 ((void *)0x0004)
|
||||
# define GLUT_BITMAP_TIMES_ROMAN_24 ((void *)0x0005)
|
||||
# define GLUT_BITMAP_HELVETICA_10 ((void *)0x0006)
|
||||
# define GLUT_BITMAP_HELVETICA_12 ((void *)0x0007)
|
||||
# define GLUT_BITMAP_HELVETICA_18 ((void *)0x0008)
|
||||
#else
|
||||
/*
|
||||
* I don't really know if it's a good idea... But here it goes:
|
||||
*/
|
||||
extern void* glutStrokeRoman;
|
||||
extern void* glutStrokeMonoRoman;
|
||||
extern void* glutBitmap9By15;
|
||||
extern void* glutBitmap8By13;
|
||||
extern void* glutBitmapTimesRoman10;
|
||||
extern void* glutBitmapTimesRoman24;
|
||||
extern void* glutBitmapHelvetica10;
|
||||
extern void* glutBitmapHelvetica12;
|
||||
extern void* glutBitmapHelvetica18;
|
||||
|
||||
/*
|
||||
* Those pointers will be used by following definitions:
|
||||
*/
|
||||
# define GLUT_STROKE_ROMAN ((void *) &glutStrokeRoman)
|
||||
# define GLUT_STROKE_MONO_ROMAN ((void *) &glutStrokeMonoRoman)
|
||||
# define GLUT_BITMAP_9_BY_15 ((void *) &glutBitmap9By15)
|
||||
# define GLUT_BITMAP_8_BY_13 ((void *) &glutBitmap8By13)
|
||||
# define GLUT_BITMAP_TIMES_ROMAN_10 ((void *) &glutBitmapTimesRoman10)
|
||||
# define GLUT_BITMAP_TIMES_ROMAN_24 ((void *) &glutBitmapTimesRoman24)
|
||||
# define GLUT_BITMAP_HELVETICA_10 ((void *) &glutBitmapHelvetica10)
|
||||
# define GLUT_BITMAP_HELVETICA_12 ((void *) &glutBitmapHelvetica12)
|
||||
# define GLUT_BITMAP_HELVETICA_18 ((void *) &glutBitmapHelvetica18)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutGet parameters
|
||||
*/
|
||||
#define GLUT_WINDOW_X 0x0064
|
||||
#define GLUT_WINDOW_Y 0x0065
|
||||
#define GLUT_WINDOW_WIDTH 0x0066
|
||||
#define GLUT_WINDOW_HEIGHT 0x0067
|
||||
#define GLUT_WINDOW_BUFFER_SIZE 0x0068
|
||||
#define GLUT_WINDOW_STENCIL_SIZE 0x0069
|
||||
#define GLUT_WINDOW_DEPTH_SIZE 0x006A
|
||||
#define GLUT_WINDOW_RED_SIZE 0x006B
|
||||
#define GLUT_WINDOW_GREEN_SIZE 0x006C
|
||||
#define GLUT_WINDOW_BLUE_SIZE 0x006D
|
||||
#define GLUT_WINDOW_ALPHA_SIZE 0x006E
|
||||
#define GLUT_WINDOW_ACCUM_RED_SIZE 0x006F
|
||||
#define GLUT_WINDOW_ACCUM_GREEN_SIZE 0x0070
|
||||
#define GLUT_WINDOW_ACCUM_BLUE_SIZE 0x0071
|
||||
#define GLUT_WINDOW_ACCUM_ALPHA_SIZE 0x0072
|
||||
#define GLUT_WINDOW_DOUBLEBUFFER 0x0073
|
||||
#define GLUT_WINDOW_RGBA 0x0074
|
||||
#define GLUT_WINDOW_PARENT 0x0075
|
||||
#define GLUT_WINDOW_NUM_CHILDREN 0x0076
|
||||
#define GLUT_WINDOW_COLORMAP_SIZE 0x0077
|
||||
#define GLUT_WINDOW_NUM_SAMPLES 0x0078
|
||||
#define GLUT_WINDOW_STEREO 0x0079
|
||||
#define GLUT_WINDOW_CURSOR 0x007A
|
||||
|
||||
#define GLUT_SCREEN_WIDTH 0x00C8
|
||||
#define GLUT_SCREEN_HEIGHT 0x00C9
|
||||
#define GLUT_SCREEN_WIDTH_MM 0x00CA
|
||||
#define GLUT_SCREEN_HEIGHT_MM 0x00CB
|
||||
#define GLUT_MENU_NUM_ITEMS 0x012C
|
||||
#define GLUT_DISPLAY_MODE_POSSIBLE 0x0190
|
||||
#define GLUT_INIT_WINDOW_X 0x01F4
|
||||
#define GLUT_INIT_WINDOW_Y 0x01F5
|
||||
#define GLUT_INIT_WINDOW_WIDTH 0x01F6
|
||||
#define GLUT_INIT_WINDOW_HEIGHT 0x01F7
|
||||
#define GLUT_INIT_DISPLAY_MODE 0x01F8
|
||||
#define GLUT_ELAPSED_TIME 0x02BC
|
||||
#define GLUT_WINDOW_FORMAT_ID 0x007B
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutDeviceGet parameters
|
||||
*/
|
||||
#define GLUT_HAS_KEYBOARD 0x0258
|
||||
#define GLUT_HAS_MOUSE 0x0259
|
||||
#define GLUT_HAS_SPACEBALL 0x025A
|
||||
#define GLUT_HAS_DIAL_AND_BUTTON_BOX 0x025B
|
||||
#define GLUT_HAS_TABLET 0x025C
|
||||
#define GLUT_NUM_MOUSE_BUTTONS 0x025D
|
||||
#define GLUT_NUM_SPACEBALL_BUTTONS 0x025E
|
||||
#define GLUT_NUM_BUTTON_BOX_BUTTONS 0x025F
|
||||
#define GLUT_NUM_DIALS 0x0260
|
||||
#define GLUT_NUM_TABLET_BUTTONS 0x0261
|
||||
#define GLUT_DEVICE_IGNORE_KEY_REPEAT 0x0262
|
||||
#define GLUT_DEVICE_KEY_REPEAT 0x0263
|
||||
#define GLUT_HAS_JOYSTICK 0x0264
|
||||
#define GLUT_OWNS_JOYSTICK 0x0265
|
||||
#define GLUT_JOYSTICK_BUTTONS 0x0266
|
||||
#define GLUT_JOYSTICK_AXES 0x0267
|
||||
#define GLUT_JOYSTICK_POLL_RATE 0x0268
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutLayerGet parameters
|
||||
*/
|
||||
#define GLUT_OVERLAY_POSSIBLE 0x0320
|
||||
#define GLUT_LAYER_IN_USE 0x0321
|
||||
#define GLUT_HAS_OVERLAY 0x0322
|
||||
#define GLUT_TRANSPARENT_INDEX 0x0323
|
||||
#define GLUT_NORMAL_DAMAGED 0x0324
|
||||
#define GLUT_OVERLAY_DAMAGED 0x0325
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutVideoResizeGet parameters
|
||||
*/
|
||||
#define GLUT_VIDEO_RESIZE_POSSIBLE 0x0384
|
||||
#define GLUT_VIDEO_RESIZE_IN_USE 0x0385
|
||||
#define GLUT_VIDEO_RESIZE_X_DELTA 0x0386
|
||||
#define GLUT_VIDEO_RESIZE_Y_DELTA 0x0387
|
||||
#define GLUT_VIDEO_RESIZE_WIDTH_DELTA 0x0388
|
||||
#define GLUT_VIDEO_RESIZE_HEIGHT_DELTA 0x0389
|
||||
#define GLUT_VIDEO_RESIZE_X 0x038A
|
||||
#define GLUT_VIDEO_RESIZE_Y 0x038B
|
||||
#define GLUT_VIDEO_RESIZE_WIDTH 0x038C
|
||||
#define GLUT_VIDEO_RESIZE_HEIGHT 0x038D
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutUseLayer parameters
|
||||
*/
|
||||
#define GLUT_NORMAL 0x0000
|
||||
#define GLUT_OVERLAY 0x0001
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutGetModifiers parameters
|
||||
*/
|
||||
#define GLUT_ACTIVE_SHIFT 0x0001
|
||||
#define GLUT_ACTIVE_CTRL 0x0002
|
||||
#define GLUT_ACTIVE_ALT 0x0004
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- the glutSetCursor parameters
|
||||
*/
|
||||
#define GLUT_CURSOR_RIGHT_ARROW 0x0000
|
||||
#define GLUT_CURSOR_LEFT_ARROW 0x0001
|
||||
#define GLUT_CURSOR_INFO 0x0002
|
||||
#define GLUT_CURSOR_DESTROY 0x0003
|
||||
#define GLUT_CURSOR_HELP 0x0004
|
||||
#define GLUT_CURSOR_CYCLE 0x0005
|
||||
#define GLUT_CURSOR_SPRAY 0x0006
|
||||
#define GLUT_CURSOR_WAIT 0x0007
|
||||
#define GLUT_CURSOR_TEXT 0x0008
|
||||
#define GLUT_CURSOR_CROSSHAIR 0x0009
|
||||
#define GLUT_CURSOR_UP_DOWN 0x000A
|
||||
#define GLUT_CURSOR_LEFT_RIGHT 0x000B
|
||||
#define GLUT_CURSOR_TOP_SIDE 0x000C
|
||||
#define GLUT_CURSOR_BOTTOM_SIDE 0x000D
|
||||
#define GLUT_CURSOR_LEFT_SIDE 0x000E
|
||||
#define GLUT_CURSOR_RIGHT_SIDE 0x000F
|
||||
#define GLUT_CURSOR_TOP_LEFT_CORNER 0x0010
|
||||
#define GLUT_CURSOR_TOP_RIGHT_CORNER 0x0011
|
||||
#define GLUT_CURSOR_BOTTOM_RIGHT_CORNER 0x0012
|
||||
#define GLUT_CURSOR_BOTTOM_LEFT_CORNER 0x0013
|
||||
#define GLUT_CURSOR_INHERIT 0x0064
|
||||
#define GLUT_CURSOR_NONE 0x0065
|
||||
#define GLUT_CURSOR_FULL_CROSSHAIR 0x0066
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- RGB color component specification definitions
|
||||
*/
|
||||
#define GLUT_RED 0x0000
|
||||
#define GLUT_GREEN 0x0001
|
||||
#define GLUT_BLUE 0x0002
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- additional keyboard and joystick definitions
|
||||
*/
|
||||
#define GLUT_KEY_REPEAT_OFF 0x0000
|
||||
#define GLUT_KEY_REPEAT_ON 0x0001
|
||||
#define GLUT_KEY_REPEAT_DEFAULT 0x0002
|
||||
|
||||
#define GLUT_JOYSTICK_BUTTON_A 0x0001
|
||||
#define GLUT_JOYSTICK_BUTTON_B 0x0002
|
||||
#define GLUT_JOYSTICK_BUTTON_C 0x0004
|
||||
#define GLUT_JOYSTICK_BUTTON_D 0x0008
|
||||
|
||||
/*
|
||||
* GLUT API macro definitions -- game mode definitions
|
||||
*/
|
||||
#define GLUT_GAME_MODE_ACTIVE 0x0000
|
||||
#define GLUT_GAME_MODE_POSSIBLE 0x0001
|
||||
#define GLUT_GAME_MODE_WIDTH 0x0002
|
||||
#define GLUT_GAME_MODE_HEIGHT 0x0003
|
||||
#define GLUT_GAME_MODE_PIXEL_DEPTH 0x0004
|
||||
#define GLUT_GAME_MODE_REFRESH_RATE 0x0005
|
||||
#define GLUT_GAME_MODE_DISPLAY_CHANGED 0x0006
|
||||
|
||||
/*
|
||||
* Initialization functions, see fglut_init.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutInit( int* pargc, char** argv );
|
||||
FGAPI void FGAPIENTRY glutInitWindowPosition( int x, int y );
|
||||
FGAPI void FGAPIENTRY glutInitWindowSize( int width, int height );
|
||||
FGAPI void FGAPIENTRY glutInitDisplayMode( unsigned int displayMode );
|
||||
FGAPI void FGAPIENTRY glutInitDisplayString( const char* displayMode );
|
||||
|
||||
/*
|
||||
* Process loop function, see fg_main.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutMainLoop( void );
|
||||
|
||||
/*
|
||||
* Window management functions, see fg_window.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutCreateWindow( const char* title );
|
||||
FGAPI int FGAPIENTRY glutCreateSubWindow( int window, int x, int y, int width, int height );
|
||||
FGAPI void FGAPIENTRY glutDestroyWindow( int window );
|
||||
FGAPI void FGAPIENTRY glutSetWindow( int window );
|
||||
FGAPI int FGAPIENTRY glutGetWindow( void );
|
||||
FGAPI void FGAPIENTRY glutSetWindowTitle( const char* title );
|
||||
FGAPI void FGAPIENTRY glutSetIconTitle( const char* title );
|
||||
FGAPI void FGAPIENTRY glutReshapeWindow( int width, int height );
|
||||
FGAPI void FGAPIENTRY glutPositionWindow( int x, int y );
|
||||
FGAPI void FGAPIENTRY glutShowWindow( void );
|
||||
FGAPI void FGAPIENTRY glutHideWindow( void );
|
||||
FGAPI void FGAPIENTRY glutIconifyWindow( void );
|
||||
FGAPI void FGAPIENTRY glutPushWindow( void );
|
||||
FGAPI void FGAPIENTRY glutPopWindow( void );
|
||||
FGAPI void FGAPIENTRY glutFullScreen( void );
|
||||
|
||||
/*
|
||||
* Display-related functions, see fg_display.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutPostWindowRedisplay( int window );
|
||||
FGAPI void FGAPIENTRY glutPostRedisplay( void );
|
||||
FGAPI void FGAPIENTRY glutSwapBuffers( void );
|
||||
|
||||
/*
|
||||
* Mouse cursor functions, see fg_cursor.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutWarpPointer( int x, int y );
|
||||
FGAPI void FGAPIENTRY glutSetCursor( int cursor );
|
||||
|
||||
/*
|
||||
* Overlay stuff, see fg_overlay.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutEstablishOverlay( void );
|
||||
FGAPI void FGAPIENTRY glutRemoveOverlay( void );
|
||||
FGAPI void FGAPIENTRY glutUseLayer( GLenum layer );
|
||||
FGAPI void FGAPIENTRY glutPostOverlayRedisplay( void );
|
||||
FGAPI void FGAPIENTRY glutPostWindowOverlayRedisplay( int window );
|
||||
FGAPI void FGAPIENTRY glutShowOverlay( void );
|
||||
FGAPI void FGAPIENTRY glutHideOverlay( void );
|
||||
|
||||
/*
|
||||
* Menu stuff, see fg_menu.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutCreateMenu( void (* callback)( int menu ) );
|
||||
FGAPI void FGAPIENTRY glutDestroyMenu( int menu );
|
||||
FGAPI int FGAPIENTRY glutGetMenu( void );
|
||||
FGAPI void FGAPIENTRY glutSetMenu( int menu );
|
||||
FGAPI void FGAPIENTRY glutAddMenuEntry( const char* label, int value );
|
||||
FGAPI void FGAPIENTRY glutAddSubMenu( const char* label, int subMenu );
|
||||
FGAPI void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value );
|
||||
FGAPI void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, int value );
|
||||
FGAPI void FGAPIENTRY glutRemoveMenuItem( int item );
|
||||
FGAPI void FGAPIENTRY glutAttachMenu( int button );
|
||||
FGAPI void FGAPIENTRY glutDetachMenu( int button );
|
||||
|
||||
/*
|
||||
* Global callback functions, see fg_callbacks.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutTimerFunc( unsigned int time, void (* callback)( int ), int value );
|
||||
FGAPI void FGAPIENTRY glutIdleFunc( void (* callback)( void ) );
|
||||
|
||||
/*
|
||||
* Window-specific callback functions, see fg_callbacks.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutKeyboardFunc( void (* callback)( unsigned char, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutSpecialFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutReshapeFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutVisibilityFunc( void (* callback)( int ) );
|
||||
FGAPI void FGAPIENTRY glutDisplayFunc( void (* callback)( void ) );
|
||||
FGAPI void FGAPIENTRY glutMouseFunc( void (* callback)( int, int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutMotionFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutPassiveMotionFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutEntryFunc( void (* callback)( int ) );
|
||||
|
||||
FGAPI void FGAPIENTRY glutKeyboardUpFunc( void (* callback)( unsigned char, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutSpecialUpFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutJoystickFunc( void (* callback)( unsigned int, int, int, int ), int pollInterval );
|
||||
FGAPI void FGAPIENTRY glutMenuStateFunc( void (* callback)( int ) );
|
||||
FGAPI void FGAPIENTRY glutMenuStatusFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutOverlayDisplayFunc( void (* callback)( void ) );
|
||||
FGAPI void FGAPIENTRY glutWindowStatusFunc( void (* callback)( int ) );
|
||||
|
||||
FGAPI void FGAPIENTRY glutSpaceballMotionFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutSpaceballRotateFunc( void (* callback)( int, int, int ) );
|
||||
FGAPI void FGAPIENTRY glutSpaceballButtonFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutButtonBoxFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutDialsFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutTabletMotionFunc( void (* callback)( int, int ) );
|
||||
FGAPI void FGAPIENTRY glutTabletButtonFunc( void (* callback)( int, int, int, int ) );
|
||||
|
||||
/*
|
||||
* State setting and retrieval functions, see fg_state.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutGet( GLenum query );
|
||||
FGAPI int FGAPIENTRY glutDeviceGet( GLenum query );
|
||||
FGAPI int FGAPIENTRY glutGetModifiers( void );
|
||||
FGAPI int FGAPIENTRY glutLayerGet( GLenum query );
|
||||
|
||||
/*
|
||||
* Font stuff, see fg_font.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutBitmapCharacter( void* font, int character );
|
||||
FGAPI int FGAPIENTRY glutBitmapWidth( void* font, int character );
|
||||
FGAPI void FGAPIENTRY glutStrokeCharacter( void* font, int character );
|
||||
FGAPI int FGAPIENTRY glutStrokeWidth( void* font, int character );
|
||||
FGAPI GLfloat FGAPIENTRY glutStrokeWidthf( void* font, int character ); /* GLUT 3.8 */
|
||||
FGAPI int FGAPIENTRY glutBitmapLength( void* font, const unsigned char* string );
|
||||
FGAPI int FGAPIENTRY glutStrokeLength( void* font, const unsigned char* string );
|
||||
FGAPI GLfloat FGAPIENTRY glutStrokeLengthf( void* font, const unsigned char *string ); /* GLUT 3.8 */
|
||||
|
||||
/*
|
||||
* Geometry functions, see fg_geometry.c
|
||||
*/
|
||||
|
||||
FGAPI void FGAPIENTRY glutWireCube( double size );
|
||||
FGAPI void FGAPIENTRY glutSolidCube( double size );
|
||||
FGAPI void FGAPIENTRY glutWireSphere( double radius, GLint slices, GLint stacks );
|
||||
FGAPI void FGAPIENTRY glutSolidSphere( double radius, GLint slices, GLint stacks );
|
||||
FGAPI void FGAPIENTRY glutWireCone( double base, double height, GLint slices, GLint stacks );
|
||||
FGAPI void FGAPIENTRY glutSolidCone( double base, double height, GLint slices, GLint stacks );
|
||||
FGAPI void FGAPIENTRY glutWireTorus( double innerRadius, double outerRadius, GLint sides, GLint rings );
|
||||
FGAPI void FGAPIENTRY glutSolidTorus( double innerRadius, double outerRadius, GLint sides, GLint rings );
|
||||
FGAPI void FGAPIENTRY glutWireDodecahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidDodecahedron( void );
|
||||
FGAPI void FGAPIENTRY glutWireOctahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidOctahedron( void );
|
||||
FGAPI void FGAPIENTRY glutWireTetrahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidTetrahedron( void );
|
||||
FGAPI void FGAPIENTRY glutWireIcosahedron( void );
|
||||
FGAPI void FGAPIENTRY glutSolidIcosahedron( void );
|
||||
|
||||
/*
|
||||
* Teapot rendering functions, found in fg_teapot.c
|
||||
* NB: front facing polygons have clockwise winding, not counter clockwise
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutWireTeapot( double size );
|
||||
FGAPI void FGAPIENTRY glutSolidTeapot( double size );
|
||||
|
||||
/*
|
||||
* Game mode functions, see fg_gamemode.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutGameModeString( const char* string );
|
||||
FGAPI int FGAPIENTRY glutEnterGameMode( void );
|
||||
FGAPI void FGAPIENTRY glutLeaveGameMode( void );
|
||||
FGAPI int FGAPIENTRY glutGameModeGet( GLenum query );
|
||||
|
||||
/*
|
||||
* Video resize functions, see fg_videoresize.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutVideoResizeGet( GLenum query );
|
||||
FGAPI void FGAPIENTRY glutSetupVideoResizing( void );
|
||||
FGAPI void FGAPIENTRY glutStopVideoResizing( void );
|
||||
FGAPI void FGAPIENTRY glutVideoResize( int x, int y, int width, int height );
|
||||
FGAPI void FGAPIENTRY glutVideoPan( int x, int y, int width, int height );
|
||||
|
||||
/*
|
||||
* Colormap functions, see fg_misc.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutSetColor( int color, GLfloat red, GLfloat green, GLfloat blue );
|
||||
FGAPI GLfloat FGAPIENTRY glutGetColor( int color, int component );
|
||||
FGAPI void FGAPIENTRY glutCopyColormap( int window );
|
||||
|
||||
/*
|
||||
* Misc keyboard and joystick functions, see fg_misc.c
|
||||
*/
|
||||
FGAPI void FGAPIENTRY glutIgnoreKeyRepeat( int ignore );
|
||||
FGAPI void FGAPIENTRY glutSetKeyRepeat( int repeatMode );
|
||||
FGAPI void FGAPIENTRY glutForceJoystickFunc( void );
|
||||
|
||||
/*
|
||||
* Misc functions, see fg_misc.c
|
||||
*/
|
||||
FGAPI int FGAPIENTRY glutExtensionSupported( const char* extension );
|
||||
FGAPI void FGAPIENTRY glutReportErrors( void );
|
||||
|
||||
/* Comment from glut.h of classic GLUT:
|
||||
|
||||
Win32 has an annoying issue where there are multiple C run-time
|
||||
libraries (CRTs). If the executable is linked with a different CRT
|
||||
from the GLUT DLL, the GLUT DLL will not share the same CRT static
|
||||
data seen by the executable. In particular, atexit callbacks registered
|
||||
in the executable will not be called if GLUT calls its (different)
|
||||
exit routine). GLUT is typically built with the
|
||||
"/MD" option (the CRT with multithreading DLL support), but the Visual
|
||||
C++ linker default is "/ML" (the single threaded CRT).
|
||||
|
||||
One workaround to this issue is requiring users to always link with
|
||||
the same CRT as GLUT is compiled with. That requires users supply a
|
||||
non-standard option. GLUT 3.7 has its own built-in workaround where
|
||||
the executable's "exit" function pointer is covertly passed to GLUT.
|
||||
GLUT then calls the executable's exit function pointer to ensure that
|
||||
any "atexit" calls registered by the application are called if GLUT
|
||||
needs to exit.
|
||||
|
||||
Note that the __glut*WithExit routines should NEVER be called directly.
|
||||
To avoid the atexit workaround, #define GLUT_DISABLE_ATEXIT_HACK. */
|
||||
|
||||
/* to get the prototype for exit() */
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK) && !defined(__WATCOMC__)
|
||||
FGAPI void FGAPIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int));
|
||||
FGAPI int FGAPIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int));
|
||||
FGAPI int FGAPIENTRY __glutCreateMenuWithExit(void (* func)(int), void (__cdecl *exitfunc)(int));
|
||||
#ifndef FREEGLUT_BUILDING_LIB
|
||||
#if defined(__GNUC__)
|
||||
#define FGUNUSED __attribute__((unused))
|
||||
#else
|
||||
#define FGUNUSED
|
||||
#endif
|
||||
static void FGAPIENTRY FGUNUSED glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }
|
||||
#define glutInit glutInit_ATEXIT_HACK
|
||||
static int FGAPIENTRY FGUNUSED glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); }
|
||||
#define glutCreateWindow glutCreateWindow_ATEXIT_HACK
|
||||
static int FGAPIENTRY FGUNUSED glutCreateMenu_ATEXIT_HACK(void (* func)(int)) { return __glutCreateMenuWithExit(func, exit); }
|
||||
#define glutCreateMenu glutCreateMenu_ATEXIT_HACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*** END OF FILE ***/
|
||||
|
||||
#endif /* __FREEGLUT_STD_H__ */
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef __GLUT_H__
|
||||
#define __GLUT_H__
|
||||
|
||||
/*
|
||||
* glut.h
|
||||
*
|
||||
* The freeglut library include file
|
||||
*
|
||||
* THE SOFTWARE IS 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
|
||||
* PAWEL W. OLSZTA 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "freeglut_std.h"
|
||||
|
||||
/*** END OF FILE ***/
|
||||
|
||||
#endif /* __GLUT_H__ */
|
||||
Binary file not shown.
@@ -0,0 +1,730 @@
|
||||
#include "json.h"
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <cfloat>
|
||||
#include <set>
|
||||
#include <cstdlib>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace json
|
||||
{
|
||||
|
||||
Value Value::null;
|
||||
//constructors
|
||||
Value::Value()
|
||||
{
|
||||
type = Type::nullValue;
|
||||
value.objectValue = NULL;
|
||||
}
|
||||
|
||||
Value::Value(Type type)
|
||||
{
|
||||
this->type = type;
|
||||
if (type == Type::stringValue)
|
||||
value.stringValue = new std::string();
|
||||
if (type == Type::arrayValue)
|
||||
value.arrayValue = new std::vector<Value>();
|
||||
if (type == Type::objectValue)
|
||||
value.objectValue = new std::map<std::string, Value>();
|
||||
}
|
||||
|
||||
Value::Value(int value)
|
||||
{
|
||||
type = Type::intValue;
|
||||
this->value.intValue = value;
|
||||
}
|
||||
|
||||
Value::Value(float value)
|
||||
{
|
||||
type = Type::floatValue;
|
||||
this->value.floatValue = value;
|
||||
}
|
||||
|
||||
Value::Value(bool value)
|
||||
{
|
||||
type = Type::boolValue;
|
||||
this->value.boolValue = value;
|
||||
}
|
||||
|
||||
Value::Value(const std::string &value)
|
||||
{
|
||||
type = Type::stringValue;
|
||||
this->value.stringValue = new std::string();
|
||||
this->value.stringValue->assign(value);
|
||||
}
|
||||
Value::Value(const char* value)
|
||||
{
|
||||
type = Type::stringValue;
|
||||
this->value.stringValue = new std::string();
|
||||
this->value.stringValue->assign(value);
|
||||
}
|
||||
|
||||
Value::Value(const Value& other) : Value(other.type)
|
||||
{
|
||||
if (type == Type::objectValue)
|
||||
*this->value.objectValue = *other.value.objectValue;
|
||||
else if (type == Type::arrayValue)
|
||||
*this->value.arrayValue = *other.value.arrayValue;
|
||||
else if (type == Type::stringValue)
|
||||
this->value.stringValue->assign(*other.value.stringValue);
|
||||
else
|
||||
this->value = other.value;
|
||||
}
|
||||
|
||||
void Value::operator=(const Value& other)
|
||||
{
|
||||
if (type != other.type)
|
||||
{
|
||||
if (type == Type::stringValue)
|
||||
delete value.stringValue;
|
||||
if (type == Type::arrayValue)
|
||||
delete value.arrayValue;
|
||||
if (type == Type::objectValue)
|
||||
delete value.objectValue;
|
||||
this->type = other.type;
|
||||
if (type == Type::stringValue)
|
||||
value.stringValue = new std::string();
|
||||
if (type == Type::arrayValue)
|
||||
value.arrayValue = new std::vector<Value>();
|
||||
if (type == Type::objectValue)
|
||||
value.objectValue = new std::map<std::string, Value>();
|
||||
}
|
||||
|
||||
if (type == Type::objectValue)
|
||||
*this->value.objectValue = *other.value.objectValue;
|
||||
else if (type == Type::arrayValue)
|
||||
*this->value.arrayValue = *other.value.arrayValue;
|
||||
else if (type == Type::stringValue)
|
||||
this->value.stringValue->assign(*other.value.stringValue);
|
||||
else
|
||||
this->value = other.value;
|
||||
}
|
||||
|
||||
Value::~Value()
|
||||
{
|
||||
if (type == Type::stringValue)
|
||||
delete value.stringValue;
|
||||
else if (type == Type::arrayValue)
|
||||
delete value.arrayValue;
|
||||
else if (type == Type::objectValue)
|
||||
delete value.objectValue;
|
||||
}
|
||||
|
||||
size_t Value::size() const
|
||||
{
|
||||
assert(type == Type::arrayValue || type == Type::objectValue);
|
||||
if (type == Type::arrayValue)
|
||||
return value.arrayValue->size();
|
||||
else if (type == Type::objectValue)
|
||||
return value.objectValue->size();
|
||||
throw "Unsupported";
|
||||
}
|
||||
|
||||
void Value::push_back(const Value& value)
|
||||
{
|
||||
assert(type == Type::arrayValue || type == Type::nullValue);
|
||||
if (type == Type::nullValue)
|
||||
{
|
||||
type = Type::arrayValue;
|
||||
this->value.arrayValue = new std::vector<Value>();
|
||||
}
|
||||
this->value.arrayValue->push_back(value);
|
||||
}
|
||||
|
||||
|
||||
Value& Value::operator[](const std::string &key)
|
||||
{
|
||||
assert(type == Type::objectValue);
|
||||
return (*value.objectValue)[key];
|
||||
}
|
||||
Value& Value::operator[](const std::string &key) const
|
||||
{
|
||||
assert(type == Type::objectValue);
|
||||
return (*value.objectValue)[key];
|
||||
}
|
||||
|
||||
Value& Value::operator[](const char* key)
|
||||
{
|
||||
assert(type == Type::objectValue || type == Type::nullValue);
|
||||
if (type == Type::nullValue)
|
||||
{
|
||||
type = Type::objectValue;
|
||||
value.objectValue = new std::map<std::string, Value>();
|
||||
}
|
||||
return (*value.objectValue)[std::string(key)];
|
||||
}
|
||||
|
||||
Value& Value::operator[](const char* key) const
|
||||
{
|
||||
assert(type == Type::objectValue);
|
||||
return (*value.objectValue)[std::string(key)];
|
||||
}
|
||||
|
||||
Value& Value::operator[](size_t index)
|
||||
{
|
||||
assert(type == Type::arrayValue);
|
||||
return (*value.arrayValue)[index];
|
||||
}
|
||||
Value& Value::operator[](size_t index) const
|
||||
{
|
||||
assert(type == Type::arrayValue);
|
||||
return (*value.arrayValue)[index];
|
||||
}
|
||||
Value& Value::operator[](int index)
|
||||
{
|
||||
assert(type == Type::arrayValue);
|
||||
return (*value.arrayValue)[index];
|
||||
}
|
||||
Value& Value::operator[](int index) const
|
||||
{
|
||||
assert(type == Type::arrayValue);
|
||||
return (*value.arrayValue)[index];
|
||||
}
|
||||
|
||||
void Value::erase(size_t index)
|
||||
{
|
||||
throw "Cannot cast";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Value::Iterator Value::end() const
|
||||
{
|
||||
if (type == Type::objectValue)
|
||||
return Iterator(value.objectValue->end());
|
||||
else if (type == Type::arrayValue)
|
||||
return Iterator(value.arrayValue->end());
|
||||
throw "oops";
|
||||
}
|
||||
|
||||
Value::Iterator Value::begin() const
|
||||
{
|
||||
if (type == Type::objectValue)
|
||||
return Iterator(value.objectValue->begin());
|
||||
else if (type == Type::arrayValue)
|
||||
return Iterator(value.arrayValue->begin());
|
||||
throw "oops";
|
||||
}
|
||||
|
||||
///iterator stuff
|
||||
|
||||
Value Value::Iterator::operator*()
|
||||
{
|
||||
if (type == Type::objectValue)
|
||||
return this->objectIterator->second;
|
||||
else if (type == Type::arrayValue)
|
||||
return *arrayIterator;
|
||||
throw "Oops";
|
||||
}
|
||||
|
||||
bool Value::Iterator::operator!=(const Iterator &other)
|
||||
{
|
||||
if (type == Type::objectValue)
|
||||
return this->objectIterator != other.objectIterator;
|
||||
else if (type == Type::arrayValue)
|
||||
return this->arrayIterator != other.arrayIterator;
|
||||
throw "Oops";
|
||||
}
|
||||
|
||||
void Value::Iterator::operator++()
|
||||
{
|
||||
if (type == Type::objectValue)
|
||||
this->objectIterator++;
|
||||
else if (type == Type::arrayValue)
|
||||
this->arrayIterator++;
|
||||
}
|
||||
void Value::Iterator::operator++(int)
|
||||
{
|
||||
if (type == Type::objectValue)
|
||||
this->objectIterator++;
|
||||
else if (type == Type::arrayValue)
|
||||
this->arrayIterator++;
|
||||
}
|
||||
|
||||
Value::Iterator::Iterator(const std::vector<Value>::iterator& arrayIterator)
|
||||
{
|
||||
type = Type::arrayValue;
|
||||
this->arrayIterator = arrayIterator;
|
||||
}
|
||||
|
||||
Value::Iterator::Iterator(const std::map<std::string, Value>::iterator& objectIterator)
|
||||
{
|
||||
type = Type::objectValue;
|
||||
this->objectIterator = objectIterator;
|
||||
}
|
||||
|
||||
std::string Value::Iterator::key()
|
||||
{
|
||||
assert(type == Type::objectValue);
|
||||
return this->objectIterator->first;
|
||||
}
|
||||
Value& Value::Iterator::value()
|
||||
{
|
||||
assert(type == Type::objectValue);
|
||||
return this->objectIterator->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void ltrim(std::istream& stream);
|
||||
static void eatComment(std::istream& stream);
|
||||
static Value eatString(std::istream& stream);
|
||||
static Value eatObject(std::istream& stream);
|
||||
static Value eatArray(std::istream& stream);
|
||||
static Value eatNumeric(std::istream& stream, char firstChar);
|
||||
static Value eatBool(std::istream& stream);
|
||||
static Value eatNull(std::istream& stream);
|
||||
static Value eatValue(std::istream& stream);
|
||||
|
||||
//reading
|
||||
static void ltrim(std::istream& stream)
|
||||
{
|
||||
char c = stream.peek();
|
||||
while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
|
||||
{
|
||||
stream.get();
|
||||
c = stream.peek();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static Value eatString(std::istream& stream)
|
||||
{
|
||||
std::string value = "";
|
||||
bool escaped = false;
|
||||
while (!stream.eof())
|
||||
{
|
||||
char c = stream.get();
|
||||
if (c == '\\' && !escaped)
|
||||
escaped = !escaped;
|
||||
else if (c == '\"' && !escaped)
|
||||
return Value(value);
|
||||
else
|
||||
{
|
||||
value += c;
|
||||
escaped = false;
|
||||
}
|
||||
}
|
||||
return Value(value);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
static Value eatObject(std::istream& stream)
|
||||
{
|
||||
Value obj(Type::objectValue);
|
||||
while (!stream.eof())
|
||||
{
|
||||
ltrim(stream);
|
||||
char token = stream.get();
|
||||
if (token == '}')
|
||||
break; //empty object
|
||||
if (token == '/')
|
||||
{
|
||||
eatComment(stream);
|
||||
token = stream.get();
|
||||
}
|
||||
|
||||
assert(token == '"');
|
||||
Value key = eatString(stream);
|
||||
ltrim(stream);
|
||||
token = stream.get();
|
||||
assert(token == ':');
|
||||
ltrim(stream);
|
||||
Value val = eatValue(stream);
|
||||
obj[key.asString()] = val;
|
||||
ltrim(stream);
|
||||
|
||||
token = stream.get();
|
||||
if (token == '}')
|
||||
break;
|
||||
assert(token == ',');
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
static Value eatArray(std::istream& stream)
|
||||
{
|
||||
Value obj(Type::arrayValue);
|
||||
while (!stream.eof())
|
||||
{
|
||||
ltrim(stream);
|
||||
if (stream.peek() == ']')
|
||||
{
|
||||
stream.get();
|
||||
break;
|
||||
}
|
||||
obj.push_back(eatValue(stream));
|
||||
ltrim(stream);
|
||||
char token = stream.get();
|
||||
if (token == '/')
|
||||
{
|
||||
eatComment(stream);
|
||||
token = stream.get();
|
||||
}
|
||||
if (token == ']')
|
||||
break;
|
||||
assert(token == ',');
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
static Value eatNumeric(std::istream& stream, char firstChar)
|
||||
{
|
||||
std::string numeric(1, firstChar);
|
||||
while (!stream.eof())
|
||||
{
|
||||
char token = stream.peek();
|
||||
if ((token >= '0' && token <= '9') || token == '.' || token == '-')
|
||||
numeric += stream.get();
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (numeric.find('.') == std::string::npos)
|
||||
return Value(atoi(numeric.c_str()));
|
||||
else
|
||||
return Value((float)atof(numeric.c_str()));
|
||||
};
|
||||
|
||||
static Value eatBool(std::istream& stream)
|
||||
{
|
||||
char token = stream.get();
|
||||
if (token == 'a') //fAlse
|
||||
{
|
||||
stream.get(); //l
|
||||
stream.get(); //s
|
||||
stream.get(); //e
|
||||
return false;
|
||||
}
|
||||
else if (token == 'r') //tRue
|
||||
{
|
||||
stream.get(); // u
|
||||
stream.get(); // e
|
||||
return true;
|
||||
}
|
||||
return Value(Type::nullValue);
|
||||
};
|
||||
static Value eatNull(std::istream& stream)
|
||||
{
|
||||
return Value(Type::nullValue);
|
||||
};
|
||||
|
||||
//precondition: / is already eaten
|
||||
static void eatComment(std::istream& stream)
|
||||
{
|
||||
char token = stream.get();
|
||||
assert(token == '/' || token == '*');
|
||||
if (token == '*')
|
||||
{
|
||||
char last = token;
|
||||
while ((last != '*' || token != '/') && !stream.eof())
|
||||
{
|
||||
last = token;
|
||||
token = stream.get();
|
||||
}
|
||||
}
|
||||
else if (token == '/')
|
||||
while (token != '\n' && !stream.eof())
|
||||
token = stream.get();
|
||||
ltrim(stream);
|
||||
}
|
||||
|
||||
|
||||
static Value eatValue(std::istream& stream)
|
||||
{
|
||||
ltrim(stream);
|
||||
char token = stream.get();
|
||||
if (token == '{')
|
||||
return eatObject(stream);
|
||||
if (token == '[')
|
||||
return eatArray(stream);
|
||||
if ((token >= '0' && token <= '9') || token == '.' || token == '-')
|
||||
return eatNumeric(stream, token);
|
||||
if (token == '"')
|
||||
return eatString(stream);
|
||||
if (token == 't' || token == 'f')
|
||||
return eatBool(stream);
|
||||
if (token == 'n')
|
||||
return eatNull(stream);
|
||||
if (token == '/')
|
||||
{
|
||||
eatComment(stream);
|
||||
return eatValue(stream);
|
||||
}
|
||||
throw "Unable to parse json";
|
||||
};
|
||||
|
||||
|
||||
Value readJson(const std::string &data)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << data;
|
||||
printf("%s", "test");
|
||||
|
||||
return eatValue(stream);
|
||||
}
|
||||
|
||||
Value readJson(std::istream &stream)
|
||||
{
|
||||
return eatValue(stream);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::ostream& indent(std::ostream& stream, int level)
|
||||
{
|
||||
for (int i = 0; i < level; i++)
|
||||
stream << '\t';
|
||||
return stream;
|
||||
}
|
||||
|
||||
std::ostream& Value::prettyPrint(std::ostream& stream, json::Value& printConfig, int level) const
|
||||
{
|
||||
stream << std::fixed << std::setprecision(6);
|
||||
switch (type)
|
||||
{
|
||||
case Type::intValue:
|
||||
stream << value.intValue;
|
||||
break;
|
||||
case Type::floatValue:
|
||||
assert(!isnan(value.floatValue));
|
||||
//assert(isnormal(value.floatValue));
|
||||
if (value.floatValue >= 0)
|
||||
stream << " ";
|
||||
stream << value.floatValue;
|
||||
break;
|
||||
case Type::boolValue:
|
||||
stream << (value.boolValue ? "true" : "false");
|
||||
break;
|
||||
case Type::stringValue:
|
||||
stream << "\"" << *value.stringValue << "\""; //TODO: escape \'s
|
||||
break;
|
||||
case Type::arrayValue:
|
||||
{
|
||||
stream << "[";
|
||||
int wrap = 99999;
|
||||
if (value.arrayValue->size() > 10)
|
||||
wrap = 1;
|
||||
if (value.arrayValue->at(0).isArray() || value.arrayValue->at(0).isObject())
|
||||
wrap = 1;
|
||||
else
|
||||
wrap = 3;
|
||||
|
||||
std::string seperator = " ";
|
||||
|
||||
if (!printConfig.isNull() && printConfig.isMember("wrap"))
|
||||
wrap = printConfig["wrap"];
|
||||
if (!printConfig.isNull() && printConfig.isMember("seperator"))
|
||||
seperator = printConfig["seperator"].asString();
|
||||
|
||||
|
||||
int index = 0;
|
||||
|
||||
if ((long)size() > wrap)
|
||||
{
|
||||
stream << "\n";
|
||||
indent(stream, level + 1);
|
||||
}
|
||||
for (auto v : *this)
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
stream << "," << seperator;
|
||||
if (index % wrap == 0)
|
||||
{
|
||||
stream << "\n";
|
||||
indent(stream, level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
json::Value childPrintConfig = json::Value::null;
|
||||
if (!printConfig.isNull())
|
||||
{
|
||||
if (printConfig.isMember("elements"))
|
||||
childPrintConfig = printConfig["elements"];
|
||||
else if (printConfig.isMember("recursive") && printConfig["recursive"].asBool() == true)
|
||||
childPrintConfig = printConfig;
|
||||
}
|
||||
|
||||
v.prettyPrint(stream, childPrintConfig, level + 1);
|
||||
index++;
|
||||
}
|
||||
if ((long)size() > wrap)
|
||||
{
|
||||
stream << "\n";
|
||||
indent(stream, level);
|
||||
}
|
||||
stream << "]";
|
||||
break;
|
||||
}
|
||||
case Type::objectValue:
|
||||
{
|
||||
stream << "{\n";
|
||||
int wrap = 99999;
|
||||
if (value.arrayValue->size() > 10)
|
||||
wrap = 1;
|
||||
if (value.arrayValue->at(0).isArray() || value.arrayValue->at(0).isObject())
|
||||
wrap = 1;
|
||||
else
|
||||
wrap = 3;
|
||||
|
||||
std::string seperator = " ";
|
||||
|
||||
if (!printConfig.isNull() && printConfig.isMember("wrap"))
|
||||
wrap = printConfig["wrap"];
|
||||
if (!printConfig.isNull() && printConfig.isMember("seperator"))
|
||||
seperator = printConfig["seperator"].asString();
|
||||
|
||||
|
||||
int index = 0;
|
||||
indent(stream, level + 1);
|
||||
|
||||
|
||||
|
||||
//for (auto v : *value.objectValue)
|
||||
auto printEl = [&](const std::pair<const std::string&, const Value&> v)
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
stream << "," << seperator;
|
||||
if (index % wrap == 0)
|
||||
{
|
||||
stream << "\n";
|
||||
indent(stream, level + 1);
|
||||
}
|
||||
}
|
||||
stream << "\"" << v.first << "\" : ";
|
||||
if (
|
||||
(v.second.isArray() || v.second.isObject()) &&
|
||||
(printConfig.isNull() ||
|
||||
(
|
||||
printConfig.isMember(v.first) &&
|
||||
printConfig[v.first].isObject() &&
|
||||
printConfig[v.first].isMember("wrap") &&
|
||||
printConfig[v.first]["wrap"].asInt() < (int)v.second.size())
|
||||
)
|
||||
)
|
||||
{
|
||||
stream << "\n";
|
||||
indent(stream, level + 1);
|
||||
}
|
||||
|
||||
json::Value childPrintConfig = json::Value::null;
|
||||
if (!printConfig.isNull())
|
||||
{
|
||||
if (printConfig.isMember(v.first))
|
||||
childPrintConfig = printConfig[v.first];
|
||||
else if (printConfig.isMember("recursive") && printConfig["recursive"].asBool() == true)
|
||||
childPrintConfig = printConfig;
|
||||
}
|
||||
|
||||
v.second.prettyPrint(stream, childPrintConfig, level + 1);;
|
||||
index++;
|
||||
};
|
||||
|
||||
|
||||
|
||||
std::set<std::string> printed;
|
||||
if (!printConfig.isNull())
|
||||
{
|
||||
if (printConfig.isMember("sort"))
|
||||
{
|
||||
for (std::string el : printConfig["sort"])
|
||||
{
|
||||
if (isMember(el))
|
||||
{
|
||||
printEl(std::pair<const std::string&, const Value&>(el, (*value.objectValue)[el]));
|
||||
printed.insert(el);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto v : *value.objectValue)
|
||||
if (printed.find(v.first) == printed.end())
|
||||
printEl(v);
|
||||
|
||||
stream << "\n";
|
||||
indent(stream, level);
|
||||
stream << "}";
|
||||
break;
|
||||
}
|
||||
case Type::nullValue:
|
||||
stream << "null";
|
||||
break;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
std::ostream & operator<<(std::ostream &stream, const Value& value)
|
||||
{
|
||||
stream << std::fixed<< std::setprecision(6);
|
||||
switch (value.type)
|
||||
{
|
||||
case Type::intValue:
|
||||
stream << value.value.intValue;
|
||||
break;
|
||||
case Type::floatValue:
|
||||
assert(!isnan(value.value.floatValue));
|
||||
//assert(isnormal(value.value.floatValue));
|
||||
stream << value.value.floatValue;
|
||||
break;
|
||||
case Type::boolValue:
|
||||
stream << (value.value.boolValue ? "true" : "false");
|
||||
break;
|
||||
case Type::stringValue:
|
||||
stream << "\"" << *value.value.stringValue << "\""; //TODO: escape \'s
|
||||
break;
|
||||
case Type::arrayValue:
|
||||
{
|
||||
stream << "[";
|
||||
bool first = true;
|
||||
for (auto v : value)
|
||||
{
|
||||
if (!first)
|
||||
stream << ", ";
|
||||
stream << v;
|
||||
first = false;
|
||||
}
|
||||
stream << "]";
|
||||
break;
|
||||
}
|
||||
case Type::objectValue:
|
||||
{
|
||||
stream << "{";
|
||||
bool first = true;
|
||||
for (auto v : *value.value.objectValue)
|
||||
{
|
||||
if (!first)
|
||||
stream << ", ";
|
||||
stream << "\"" << v.first << "\" : " << v.second << std::endl;
|
||||
first = false;
|
||||
}
|
||||
stream << "}";
|
||||
break;
|
||||
}
|
||||
case Type::nullValue:
|
||||
stream << "null";
|
||||
break;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
|
||||
namespace json
|
||||
{
|
||||
enum class Type
|
||||
{
|
||||
intValue,
|
||||
floatValue,
|
||||
boolValue,
|
||||
stringValue,
|
||||
arrayValue,
|
||||
objectValue,
|
||||
nullValue
|
||||
};
|
||||
|
||||
class Value
|
||||
{
|
||||
public:
|
||||
Type type;
|
||||
union ValueHolder
|
||||
{
|
||||
int intValue;
|
||||
float floatValue;
|
||||
bool boolValue;
|
||||
std::string* stringValue;
|
||||
std::vector<Value>* arrayValue;
|
||||
std::map<std::string, Value>* objectValue;
|
||||
} value;
|
||||
|
||||
static Value null;
|
||||
|
||||
Value();
|
||||
Value(Type type);
|
||||
Value(int value);
|
||||
Value(float value);
|
||||
Value(bool value);
|
||||
Value(const std::string &value);
|
||||
Value(const char* value);
|
||||
Value(const Value& other);
|
||||
virtual ~Value();
|
||||
|
||||
void operator = (const Value& other);
|
||||
|
||||
|
||||
|
||||
|
||||
inline operator int() const { return asInt(); }
|
||||
inline operator float() const { return asFloat(); }
|
||||
inline operator bool() const { return asBool(); }
|
||||
inline operator const std::string&() const { return asString(); }
|
||||
|
||||
|
||||
inline int asInt() const { assert(type == Type::intValue); return value.intValue; }
|
||||
inline float asFloat() const { assert(type == Type::floatValue || type == Type::intValue); return type == Type::floatValue ? value.floatValue : value.intValue; }
|
||||
inline bool asBool() const { assert(type == Type::boolValue); return value.boolValue; }
|
||||
inline const std::string& asString() const { assert(type == Type::stringValue); return *value.stringValue; }
|
||||
inline bool isNull() const { return type == Type::nullValue; }
|
||||
inline bool isString() const { return type == Type::stringValue; }
|
||||
inline bool isInt() const { return type == Type::intValue; }
|
||||
inline bool isBool() const { return type == Type::boolValue; }
|
||||
inline bool isFloat() const { return type == Type::floatValue; }
|
||||
inline bool isObject() const { return type == Type::objectValue; }
|
||||
inline bool isArray() const { return type == Type::arrayValue; }
|
||||
inline bool isMember(const std::string &name) const { assert(type == Type::objectValue); return value.objectValue->find(name) != value.objectValue->end(); }
|
||||
//array/object
|
||||
virtual size_t size() const;
|
||||
//array
|
||||
virtual void push_back(const Value& value);
|
||||
virtual void erase(size_t index);
|
||||
virtual Value& operator [] (size_t index);
|
||||
virtual Value& operator [] (int index);
|
||||
virtual Value& operator [] (size_t index) const;
|
||||
virtual Value& operator [] (int index) const;
|
||||
|
||||
virtual Value& operator [] (const std::string &key);
|
||||
virtual Value& operator [] (const char* key);
|
||||
virtual Value& operator [] (const std::string &key) const;
|
||||
virtual Value& operator [] (const char* key) const;
|
||||
|
||||
virtual bool operator == (const std::string &other) { return asString() == other; }
|
||||
virtual bool operator == (const int other) { return asInt() == other; }
|
||||
virtual bool operator == (const float other) { return asFloat() == other; }
|
||||
|
||||
|
||||
std::ostream& prettyPrint(std::ostream& stream, json::Value& printConfig = null, int level = 0) const;
|
||||
|
||||
class Iterator;
|
||||
Iterator begin() const;
|
||||
Iterator end() const;
|
||||
};
|
||||
|
||||
class Value::Iterator
|
||||
{
|
||||
private:
|
||||
Type type;
|
||||
std::map<std::string, Value>::iterator objectIterator;
|
||||
std::vector<Value>::iterator arrayIterator;
|
||||
public:
|
||||
Iterator(const std::map<std::string, Value>::iterator& objectIterator);
|
||||
Iterator(const std::vector<Value>::iterator& arrayIterator);
|
||||
|
||||
void operator ++();
|
||||
void operator ++(int);
|
||||
bool operator != (const Iterator &other);
|
||||
Value operator*();
|
||||
|
||||
std::string key();
|
||||
Value& value();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Value readJson(const std::string &data);
|
||||
Value readJson(std::istream &stream);
|
||||
std::ostream &operator << (std::ostream &stream, const Value& value); //serializes json data
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,182 @@
|
||||
// stb_perlin.h - v0.2 - perlin noise
|
||||
// public domain single-file C implementation by Sean Barrett
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// This software is dual-licensed to the public domain and under the following
|
||||
// license: you are granted a perpetual, irrevocable license to copy, modify,
|
||||
// publish, and distribute this file as you see fit.
|
||||
//
|
||||
//
|
||||
// to create the implementation,
|
||||
// #define STB_PERLIN_IMPLEMENTATION
|
||||
// in *one* C/CPP file that includes this file.
|
||||
|
||||
|
||||
// Documentation:
|
||||
//
|
||||
// float stb_perlin_noise3( float x,
|
||||
// float y,
|
||||
// float z,
|
||||
// int x_wrap=0,
|
||||
// int y_wrap=0,
|
||||
// int z_wrap=0)
|
||||
//
|
||||
// This function computes a random value at the coordinate (x,y,z).
|
||||
// Adjacent random values are continuous but the noise fluctuates
|
||||
// its randomness with period 1, i.e. takes on wholly unrelated values
|
||||
// at integer points. Specifically, this implements Ken Perlin's
|
||||
// revised noise function from 2002.
|
||||
//
|
||||
// The "wrap" parameters can be used to create wraparound noise that
|
||||
// wraps at powers of two. The numbers MUST be powers of two. Specify
|
||||
// 0 to mean "don't care". (The noise always wraps every 256 due
|
||||
// details of the implementation, even if you ask for larger or no
|
||||
// wrapping.)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" float stb_perlin_noise3(float x, float y, float z, int x_wrap=0, int y_wrap=0, int z_wrap=0);
|
||||
#else
|
||||
extern float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap);
|
||||
#endif
|
||||
|
||||
#ifdef STB_PERLIN_IMPLEMENTATION
|
||||
|
||||
#include <math.h> // floor()
|
||||
|
||||
// not same permutation table as Perlin's reference to avoid copyright issues;
|
||||
// Perlin's table can be found at http://mrl.nyu.edu/~perlin/noise/
|
||||
// @OPTIMIZE: should this be unsigned char instead of int for cache?
|
||||
static int stb__perlin_randtab[512] =
|
||||
{
|
||||
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
||||
152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72,
|
||||
175, 63, 77, 90, 181, 16, 96, 111, 133, 104, 75, 162, 93, 56, 66, 240,
|
||||
8, 50, 84, 229, 49, 210, 173, 239, 141, 1, 87, 18, 2, 198, 143, 57,
|
||||
225, 160, 58, 217, 168, 206, 245, 204, 199, 6, 73, 60, 20, 230, 211, 233,
|
||||
94, 200, 88, 9, 74, 155, 33, 15, 219, 130, 226, 202, 83, 236, 42, 172,
|
||||
165, 218, 55, 222, 46, 107, 98, 154, 109, 67, 196, 178, 127, 158, 13, 243,
|
||||
65, 79, 166, 248, 25, 224, 115, 80, 68, 51, 184, 128, 232, 208, 151, 122,
|
||||
26, 212, 105, 43, 179, 213, 235, 148, 146, 89, 14, 195, 28, 78, 112, 76,
|
||||
250, 47, 24, 251, 140, 108, 186, 190, 228, 170, 183, 139, 39, 188, 244, 246,
|
||||
132, 48, 119, 144, 180, 138, 134, 193, 82, 182, 120, 121, 86, 220, 209, 3,
|
||||
91, 241, 149, 85, 205, 150, 113, 216, 31, 100, 41, 164, 177, 214, 153, 231,
|
||||
38, 71, 185, 174, 97, 201, 29, 95, 7, 92, 54, 254, 191, 118, 34, 221,
|
||||
131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62,
|
||||
27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135,
|
||||
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
||||
|
||||
// and a second copy so we don't need an extra mask or static initializer
|
||||
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
||||
152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72,
|
||||
175, 63, 77, 90, 181, 16, 96, 111, 133, 104, 75, 162, 93, 56, 66, 240,
|
||||
8, 50, 84, 229, 49, 210, 173, 239, 141, 1, 87, 18, 2, 198, 143, 57,
|
||||
225, 160, 58, 217, 168, 206, 245, 204, 199, 6, 73, 60, 20, 230, 211, 233,
|
||||
94, 200, 88, 9, 74, 155, 33, 15, 219, 130, 226, 202, 83, 236, 42, 172,
|
||||
165, 218, 55, 222, 46, 107, 98, 154, 109, 67, 196, 178, 127, 158, 13, 243,
|
||||
65, 79, 166, 248, 25, 224, 115, 80, 68, 51, 184, 128, 232, 208, 151, 122,
|
||||
26, 212, 105, 43, 179, 213, 235, 148, 146, 89, 14, 195, 28, 78, 112, 76,
|
||||
250, 47, 24, 251, 140, 108, 186, 190, 228, 170, 183, 139, 39, 188, 244, 246,
|
||||
132, 48, 119, 144, 180, 138, 134, 193, 82, 182, 120, 121, 86, 220, 209, 3,
|
||||
91, 241, 149, 85, 205, 150, 113, 216, 31, 100, 41, 164, 177, 214, 153, 231,
|
||||
38, 71, 185, 174, 97, 201, 29, 95, 7, 92, 54, 254, 191, 118, 34, 221,
|
||||
131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62,
|
||||
27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135,
|
||||
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
||||
};
|
||||
|
||||
static float stb__perlin_lerp(float a, float b, float t)
|
||||
{
|
||||
return a + (b-a) * t;
|
||||
}
|
||||
|
||||
// different grad function from Perlin's, but easy to modify to match reference
|
||||
static float stb__perlin_grad(int hash, float x, float y, float z)
|
||||
{
|
||||
static float basis[12][4] =
|
||||
{
|
||||
{ 1, 1, 0 },
|
||||
{ -1, 1, 0 },
|
||||
{ 1,-1, 0 },
|
||||
{ -1,-1, 0 },
|
||||
{ 1, 0, 1 },
|
||||
{ -1, 0, 1 },
|
||||
{ 1, 0,-1 },
|
||||
{ -1, 0,-1 },
|
||||
{ 0, 1, 1 },
|
||||
{ 0,-1, 1 },
|
||||
{ 0, 1,-1 },
|
||||
{ 0,-1,-1 },
|
||||
};
|
||||
|
||||
// perlin's gradient has 12 cases so some get used 1/16th of the time
|
||||
// and some 2/16ths. We reduce bias by changing those fractions
|
||||
// to 5/16ths and 6/16ths, and the same 4 cases get the extra weight.
|
||||
static unsigned char indices[64] =
|
||||
{
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
0,9,1,11,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
||||
};
|
||||
|
||||
// if you use reference permutation table, change 63 below to 15 to match reference
|
||||
float *grad = basis[indices[hash & 63]];
|
||||
return grad[0]*x + grad[1]*y + grad[2]*z;
|
||||
}
|
||||
|
||||
float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap)
|
||||
{
|
||||
float u,v,w;
|
||||
float n000,n001,n010,n011,n100,n101,n110,n111;
|
||||
float n00,n01,n10,n11;
|
||||
float n0,n1;
|
||||
|
||||
unsigned int x_mask = (x_wrap-1) & 255;
|
||||
unsigned int y_mask = (y_wrap-1) & 255;
|
||||
unsigned int z_mask = (z_wrap-1) & 255;
|
||||
int px = (int) floor(x);
|
||||
int py = (int) floor(y);
|
||||
int pz = (int) floor(z);
|
||||
int x0 = px & x_mask, x1 = (px+1) & x_mask;
|
||||
int y0 = py & y_mask, y1 = (py+1) & y_mask;
|
||||
int z0 = pz & z_mask, z1 = (pz+1) & z_mask;
|
||||
int r0,r1, r00,r01,r10,r11;
|
||||
|
||||
#define stb__perlin_ease(a) (((a*6-15)*a + 10) * a * a * a)
|
||||
|
||||
x -= px; u = stb__perlin_ease(x);
|
||||
y -= py; v = stb__perlin_ease(y);
|
||||
z -= pz; w = stb__perlin_ease(z);
|
||||
|
||||
r0 = stb__perlin_randtab[x0];
|
||||
r1 = stb__perlin_randtab[x1];
|
||||
|
||||
r00 = stb__perlin_randtab[r0+y0];
|
||||
r01 = stb__perlin_randtab[r0+y1];
|
||||
r10 = stb__perlin_randtab[r1+y0];
|
||||
r11 = stb__perlin_randtab[r1+y1];
|
||||
|
||||
n000 = stb__perlin_grad(stb__perlin_randtab[r00+z0], x , y , z );
|
||||
n001 = stb__perlin_grad(stb__perlin_randtab[r00+z1], x , y , z-1 );
|
||||
n010 = stb__perlin_grad(stb__perlin_randtab[r01+z0], x , y-1, z );
|
||||
n011 = stb__perlin_grad(stb__perlin_randtab[r01+z1], x , y-1, z-1 );
|
||||
n100 = stb__perlin_grad(stb__perlin_randtab[r10+z0], x-1, y , z );
|
||||
n101 = stb__perlin_grad(stb__perlin_randtab[r10+z1], x-1, y , z-1 );
|
||||
n110 = stb__perlin_grad(stb__perlin_randtab[r11+z0], x-1, y-1, z );
|
||||
n111 = stb__perlin_grad(stb__perlin_randtab[r11+z1], x-1, y-1, z-1 );
|
||||
|
||||
n00 = stb__perlin_lerp(n000,n001,w);
|
||||
n01 = stb__perlin_lerp(n010,n011,w);
|
||||
n10 = stb__perlin_lerp(n100,n101,w);
|
||||
n11 = stb__perlin_lerp(n110,n111,w);
|
||||
|
||||
n0 = stb__perlin_lerp(n00,n01,v);
|
||||
n1 = stb__perlin_lerp(n10,n11,v);
|
||||
|
||||
return stb__perlin_lerp(n0,n1,u);
|
||||
}
|
||||
#endif // STB_PERLIN_IMPLEMENTATION
|
||||
Reference in New Issue
Block a user