This commit is contained in:
thatscringebro 2023-02-16 09:26:40 -05:00
parent cffe9490f0
commit 9dfd911bff
200 changed files with 28477 additions and 86 deletions

12
.gitignore vendored Executable file
View File

@ -0,0 +1,12 @@
a.out
pdf/tp01.pdf
tp01.pdf
.vscode
.vscode/settings.json
settings.json
Makefile.dep
mcclone
TheLandOfWildBlocs
CPP/*.o
*.o
SaveFile

12
Build_Run.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash/
# bash script to build, make and run the program
touch Makefile.dep
make -j4 # should be good for most computers that will use the script
./TheLandOfWildBlocs
# Removes the build files after they have been used
rm Makefile.dep
rm TheLandOfWildBlocs
cd CPP
rm *.o

57
CPP/blockinfo.cpp Executable file
View File

@ -0,0 +1,57 @@
#include "../H/blockinfo.h"
#include <iostream>
BlockInfo::BlockInfo(BlockType type, const std::string& name) : m_type(type), m_name(name), m_durability(1)
{
}
BlockInfo::BlockInfo()
{
}
BlockInfo::~BlockInfo()
{
}
BlockType BlockInfo::GetType() const
{
return m_type;
}
void BlockInfo::SetDurability(int durability)
{
m_durability = durability;
}
int BlockInfo::GetDurability() const
{
return m_durability;
}
void BlockInfo::SetUVWH(float u, float v, float w, float h){
m_u = u;
m_v = v;
m_w = w;
m_h = h;
}
float BlockInfo::GetU(){
return m_u;
}
float BlockInfo::GetV(){
return m_v;
}
float BlockInfo::GetW(){
return m_w;
}
float BlockInfo::GetH(){
return m_h;
}
void BlockInfo::Show() const
{
std::cout << "Type: " << m_type << std::endl;
std::cout << "Nom: " << m_name << std::endl;
std::cout << "Durabilite: " << m_durability << std::endl;
}

156
CPP/chunk.cpp Executable file
View File

@ -0,0 +1,156 @@
#include "../H/chunk.h"
#include <climits>
Chunk::Chunk(): m_blocks(Array3d<BlockType>(CHUNK_SIZE_X, CHUNK_SIZE_Y, CHUNK_SIZE_Z)), m_isDirty(true){}
Chunk::Chunk(float x, float z) : m_blocks(Array3d<BlockType>(CHUNK_SIZE_X +1, CHUNK_SIZE_Y, CHUNK_SIZE_Z +1)), m_isDirty(true), m_posx(x), m_posz(z)
{
Perlin perlin(16, 6, 1, 95);
m_blocks.Reset(BTYPE_AIR);
for(int x = 0; x < CHUNK_SIZE_X; ++x)
{
for(int z = 0; z < CHUNK_SIZE_Z; ++z)
{
float val = perlin.Get((float)(m_posx + x) / 2000.f, (float)(m_posz + z) / 2000.f);
if (val < 0)
val *= -1;
val *= CHUNK_SIZE_Y;
val *= 0.4;
for (int i = 0; i < val; i++)
{
SetBlock(x , i, z, (rand()%(BTYPE_LAST - 1)+1));
}
}
}
}
Chunk::~Chunk()
{
}
void Chunk::RemoveBlock(int x, int y, int z)
{
m_blocks.Set(x, y, z, BTYPE_AIR);
m_isDirty = true;
}
void Chunk::SetBlock(int x, int y, int z, BlockType type)
{
m_blocks.Set(x, y, z, type);
m_isDirty = true;
}
BlockType Chunk::GetBlock(int x, int y, int z)
{
return m_blocks.Get(x, y, z);
}
void Chunk::Update(BlockInfo bi[BTYPE_LAST]){
bool front;
bool back;
bool top;
bool bottom;
bool left;
bool right;
// Update mesh
if (m_isDirty)
{
int maxVertexCount = (CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z) * (6 * 4);
VertexBuffer::VertexData * vd = new VertexBuffer::VertexData[maxVertexCount];
int count = 0;
for (int x = 0; x < CHUNK_SIZE_X; ++x)
{
for (int z = 0; z < CHUNK_SIZE_Z; ++z)
{
for (int y = 0; y < CHUNK_SIZE_Y; ++y)
{
if (count > USHRT_MAX)
break;
BlockType bt = GetBlock(x ,y ,z);
if ( bt != BTYPE_AIR )
{
AddBlockToMesh(vd, count, bt, x, y, z, bi);
}
}
}
}
if (count > USHRT_MAX)
{
count = USHRT_MAX;
std::cout << "[ Chunk :: Update ] Chunk data truncaned, too much vertices to have a 16 bit index" << std::endl;
}
m_vertexBuffer.SetMeshData(vd, count);
delete[] vd;
}
m_isDirty = false ;
}
void Chunk::AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, BlockInfo bi[BTYPE_LAST])
{
BlockInfo biCourant = bi[bt];
float u = biCourant.GetU();
float v = biCourant.GetV();
float w = biCourant.GetW();
float h = biCourant.GetH();
//front
if(GetBlock(x,y,z+1) == BTYPE_AIR){
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y - .5f, m_posz + z + .5f, 1.f, 1.f, 1.f, u, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y - .5f, m_posz + z + .5f, 1.f, 1.f, 1.f, u + w, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y + .5f, m_posz + z + .5f, 1.f, 1.f, 1.f, u + w, v + h);
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y + .5f, m_posz + z + .5f, 1.f, 1.f, 1.f, u, v + h);
}
//back
if(GetBlock(x,y,z-1) == BTYPE_AIR){
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y - .5f, m_posz + z - .5f, 1.f, 1.f, 1.f, u, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y + .5f, m_posz + z - .5f, 1.f, 1.f, 1.f, u + w, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y + .5f, m_posz + z - .5f, 1.f, 1.f, 1.f, u + w, v + h);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y - .5f, m_posz + z - .5f, 1.f, 1.f, 1.f, u, v + h);
}
//top
if(GetBlock(x,y+1,z) == BTYPE_AIR){
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y + .5f, m_posz + z - .5f, 0.8f, 0.8f, 0.8f, u, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y + .5f, m_posz + z + .5f, 0.8f, 0.8f, 0.8f, u + w, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y + .5f, m_posz + z + .5f, 0.8f, 0.8f, 0.8f, u + w, v + h);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y + .5f, m_posz + z - .5f, 0.8f, 0.8f, 0.8f, u, v + h);
}
//bottom
if(GetBlock(x,y-1,z) == BTYPE_AIR){
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y - .5f, m_posz + z - .5f, 0.8f, 0.8f, 0.8f, u, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y - .5f, m_posz + z - .5f, 0.8f, 0.8f, 0.8f, u + w, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y - .5f, m_posz + z + .5f, 0.8f, 0.8f, 0.8f, u + w, v + h);
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y - .5f, m_posz + z + .5f, 0.8f, 0.8f, 0.8f, u, v + h);
}
//left
if(GetBlock(x-1,y,z) == BTYPE_AIR){
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y - .5f, m_posz + z + .5f, 0.9f, 0.9f, 0.9f, u, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y + .5f, m_posz + z + .5f, 0.9f, 0.9f, 0.9f, u + w, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y + .5f, m_posz + z - .5f, 0.9f, 0.9f, 0.9f, u + w, v + h);
vd[count++] = VertexBuffer::VertexData(m_posx + x - .5f, y - .5f, m_posz + z - .5f, 0.9f, 0.9f, 0.9f, u, v + h);
}
//Right
if(GetBlock(x+1,y,z) == BTYPE_AIR){
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y + .5f, m_posz + z - .5f, 0.9f, 0.9f, 0.9f, u, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y + .5f, m_posz + z + .5f, 0.9f, 0.9f, 0.9f, u + w, v);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y - .5f, m_posz + z + .5f, 0.9f, 0.9f, 0.9f, u + w, v + h);
vd[count++] = VertexBuffer::VertexData(m_posx + x + .5f, y - .5f, m_posz + z - .5f, 0.9f, 0.9f, 0.9f, u, v + h);
}
}
void Chunk::Render() const{
m_vertexBuffer.Render();
}
bool Chunk::IsDirty() const{
return m_isDirty;
}

732
CPP/engine.cpp Executable file
View File

@ -0,0 +1,732 @@
#include "../H/engine.h"
#include "../H/transformation.h"
#include <algorithm>
#include <cmath>
#include <iostream>
#include <fstream>
Engine::Engine() : m_p1(Vector3f(VIEW_DISTANCE,20,VIEW_DISTANCE)), m_textureAtlas(BTYPE_LAST), m_chunks(Array2d<Chunk*>(VIEW_DISTANCE * 2 / CHUNK_SIZE_X, VIEW_DISTANCE * 2 / CHUNK_SIZE_Z)), m_currentBlock(Vector4f(0,0,0,0)), m_currentMob(Vector3f(0,0,0),0,0)
{
}
Engine::~Engine()
{
SaveGame();
}
void Engine::LoadGame(std::ifstream SaveFile){
std::cout << "LOADING THE GAME" << std::endl;
if (SaveFile.is_open())
{
std::string Block;
while (std::getline(SaveFile, Block))
{
int notdigit = 0;
std::string x,y,z,t;
for (int i = 0; i < Block.length(); i++)
{
if (isdigit(Block[i]))
{
if (notdigit < 2)
x += Block[i];
else if (notdigit < 3)
y += Block[i];
else if (notdigit < 4)
z += Block[i];
else if (notdigit < 5)
t += Block[i];
}
else
notdigit++;
}
Vector4f Bloc(stoi(x), stoi(y), stoi(z), stoi(t));
m_ModifiedBlocks.push_front(Bloc);
SetBlockAt(stoi(x), stoi(y), stoi(z), stoi(t));
}
std::cout << "GAME LOADED" << std::endl;
SaveFile.close();
}
else
std::cout << "Problem opening the save file :(" << std::endl;
}
void Engine::SaveGame(){
std::cout << "SAVING THE GAME" << std::endl;
std::ofstream SaveFile("SaveFile");
if(SaveFile.is_open()){
for (size_t i = 0; i < m_ModifiedBlocks.size() + 1; i++)
{
if (m_ModifiedBlocks.front().x >= 0 && m_ModifiedBlocks.front().y >= 0 && m_ModifiedBlocks.front().z >= 0){
SaveFile << "{" << m_ModifiedBlocks.front().x << ";" << m_ModifiedBlocks.front().y << ";" << m_ModifiedBlocks.front().z << ";" << m_ModifiedBlocks.front().t << "}" << std::endl;
}
m_ModifiedBlocks.pop_front();
}
SaveFile.close();
std::cout << "GAME SAVED" << std::endl;
}
else
std::cout << "Problem writing to the save file :(" << std::endl;
}
void Engine::Init()
{
//glEnable(GL_CULL_FACE);
// Initialize GLEW
GLenum glewErr = glewInit();
if ( glewErr != GLEW_OK )
{
std :: cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std :: endl ;
abort();
}
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.0001f, 1000.0f);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LINE_SMOOTH);
// Light
GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f };
GLfloat light0Amb[4] = { 0.9f, 0.9f, 0.9f, 1.0f };
GLfloat light0Diff[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat light0Spec[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
glLightfv(GL_LIGHT0, GL_AMBIENT, light0Amb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0Diff);
glLightfv(GL_LIGHT0, GL_SPECULAR, light0Spec);
CenterMouse();
HideCursor();
}
void Engine::DeInit()
{
}
void Engine::LoadResource()
{
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp");
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp");
LoadTexture(m_textureMob, TEXTURE_PATH "mob.png");
TextureAtlas::TextureIndex texDarkIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dark.png");
TextureAtlas::TextureIndex texDarkerIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "darker.png");
TextureAtlas::TextureIndex texLightIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "light.png");
TextureAtlas::TextureIndex texLighterIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "lighter.png");
float u,v,w,h;
m_textureAtlas.TextureIndexToCoord(texDarkerIndex, u,v,w,h);
m_bi[BTYPE_DARKER].SetUVWH(u, v, w, h);
m_textureAtlas.TextureIndexToCoord(texDarkIndex, u,v,w,h);
m_bi[BTYPE_DARK].SetUVWH(u, v, w, h);
m_textureAtlas.TextureIndexToCoord(texLighterIndex, u,v,w,h);
m_bi[BTYPE_LIGHTER].SetUVWH(u, v, w, h);
m_textureAtlas.TextureIndexToCoord(texLightIndex, u,v,w,h);
m_bi[BTYPE_LIGHT].SetUVWH(u, v, w, h);
if(!m_textureAtlas.Generate(1024, false))
{
std::cout << "Unable to generate texture atlas ..." << std::endl;
abort();
}
std::cout << "Loading and compiling shaders ..." << std::endl;
if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true))
{
std::cout << " Failed to load shader " << std::endl;
exit(1);
}
for (int x = 0; x < (VIEW_DISTANCE * 2 / CHUNK_SIZE_X); x++)
{
for (int z = 0; z < (VIEW_DISTANCE * 2 / CHUNK_SIZE_Z); z++)
{
m_chunks.Set(x, z, new Chunk(x * CHUNK_SIZE_X, z * CHUNK_SIZE_Z));
}
}
m_chunks.Set(15, 15, new Chunk(15 * CHUNK_SIZE_X, 15 * CHUNK_SIZE_Z));
LoadGame(std::ifstream("SaveFile"));
}
void Engine::UnloadResource()
{
}
void Engine::Render(float elapsedTime)
{
static float gameTime = elapsedTime;
gameTime += elapsedTime;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Transformations initiales
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Transformation player_move;
bool OnGround = false;
Vector3f pos = m_p1.Position();
Vector3f delta = m_p1.SimulateMove(m_keyW, m_keyS, m_keyA, m_keyD, m_shift, elapsedTime);
delta.y = -0.1;
float jumpvalue = 0;
BlockType bt1, bt2, bt3;
bt1 = BlockAt(pos.x, pos.y - 1.7f, pos.z, BTYPE_DARK);
if (bt1 != BTYPE_AIR)
OnGround = true;
bt2 = BlockAt(pos.x, pos.y + delta.y, pos.z, BTYPE_DARK);
if (bt2 != BTYPE_AIR)
m_jumpsize = 1.6;
m_jumpsize += m_p1.SimulateJump(m_space, m_InJump, jumpvalue, OnGround, m_jumpsize);
//Collisions for x:
bt1 = BlockAt(pos.x + delta.x, pos.y, pos.z, BTYPE_AIR);
bt2 = BlockAt(pos.x + delta.x, pos.y - 0.9f, pos.z, BTYPE_AIR);
bt3 = BlockAt(pos.x + delta.x, pos.y - 1.6f, pos.z, BTYPE_AIR);
if(bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR)
delta.x = 0;
// Collisions for y
bt1 = BlockAt(pos.x, pos.y - 1.7f, pos.z, BTYPE_DARK);
if(bt1 != BTYPE_AIR){
delta.y = 0;
}
//Colisions for z
bt1 = BlockAt(pos.x, pos.y, pos.z + delta.z, BTYPE_AIR);
bt2 = BlockAt(pos.x, pos.y - 0.9f, pos.z + delta.z, BTYPE_AIR);
bt3 = BlockAt(pos.x, pos.y - 1.6f, pos.z + delta.z, BTYPE_AIR);
if(bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR)
delta.z = 0;
pos.y += jumpvalue;
pos += delta;
m_p1.SetPosition(pos);
m_p1.ApplyTransformation(player_move);
player_move.Use();
m_textureAtlas.Bind();
//translation
player_move.ApplyTranslation(0.5f,0.5f,0.5f);
//use the above
player_move.Use();
m_shader01.Use();
for (int x = 0; x < (VIEW_DISTANCE * 2 / CHUNK_SIZE_X); x++)
{
for (int z = 0; z < (VIEW_DISTANCE * 2 / CHUNK_SIZE_Z); z++)
{
if (m_chunks.Get(x,z)->IsDirty())
m_chunks.Get(x,z)->Update(m_bi);
m_chunks.Get(x,z)->Render();
}
}
Shader::Disable();
m_textureMob.Bind();
for (int i = 0; i < m_mobs.size(); i++)
{
if (m_mobs[i].Health() <= 0)
m_mobs.erase(m_mobs.begin() + i);
Vector3f posMob = m_mobs[i].Position();
if ((posMob.x <= pos.x + 0.1 && posMob.x >= pos.x - 0.1) && (posMob.y <= pos.y + 0.1 && posMob.y >= pos.y - 0.1) && (posMob.z <= pos.z + 0.1 && posMob.z >= pos.z - 0.1))
{
m_mobs[i].Damage(m_p1);
m_mobs[i].SetPosition(Vector3f(posMob.x - 5, posMob.y + 5, posMob.z - 5));
}
m_mobs[i].Move(m_p1);
m_mobs[i].RenderMob();
}
m_points = m_mobs.size() * 100;
if(m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
DrawHud(elapsedTime);
if(m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if (m_p1.Health() <= 0)
{
SaveGame();
Stop();
}
}
void Engine::KeyPressEvent(unsigned char key)
{
switch(key)
{
case 36: // ESC
SaveGame();
Stop();
break;
case 94: // F10
SetFullscreen(!IsFullscreen());
break;
case 38: // Shift
m_shift = true;
m_run = true;
break;
case 22: // W
m_keyW = true;
m_walk = true;
break;
case 0: // A
m_keyA = true;
m_walk = true;
break;
case 18: // S
m_keyS = true;
m_walk = true;
break;
case 3: // D
m_keyD = true;
m_walk = true;
break;
case 57: // spacebar
m_space = true;
break;
case 60: //tab
if (m_selectedbloc <= BTYPE_LIGHTER)
m_selectedbloc++;
else
m_selectedbloc = BTYPE_DARK;
break;
default:
std::cout << "Unhandled key: " << (int)key << std::endl;
}
}
void Engine::KeyReleaseEvent(unsigned char key)
{
switch(key)
{
case 38: // Shift
m_shift = false;
m_run = false;
break;
case 22: // W
m_keyW = false;
if (!m_keyW && !m_keyS && !m_keyD && !m_keyA)
m_walk = false;
break;
case 0: // A
m_keyA = false;
if (!m_keyW && !m_keyS && !m_keyD && !m_keyA)
m_walk = false;
break;
case 18: // S
m_keyS = false;
if (!m_keyW && !m_keyS && !m_keyD && !m_keyA)
m_walk = false;
break;
case 3: // D
m_keyD = false;
if (!m_keyW && !m_keyS && !m_keyD && !m_keyA)
m_walk = false;
break;
case 57: // spacebar
m_space = false;
break;
case 24: // Y
m_wireframe = !m_wireframe;
if(m_wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
break;
}
}
void Engine::MouseMoveEvent(int x, int y)
{
// Centrer la souris seulement si elle n'est pas d<>j<EFBFBD> centr<74>e
// Il est n<>cessaire de faire la v<>rification pour <20>viter de tomber
// dans une boucle infinie o<> l'appel <20> CenterMouse g<>n<EFBFBD>re un
// MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre
// MouseMoveEvent, etc
if(x == (Width() / 2) && y == (Height() / 2))
return;
MakeRelativeToCenter(x, y);
//m_p1.TurnLeftRight(y);
//m_p1.TurnTopBottom(x);
m_p1.TurnCamera(x, y);
CenterMouse();
}
void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y)
{
switch (button)
{
case 1:
if(!m_currentMob.isNull())
HitMob();
else
DestroyBlocGenerateMob();
break;
case 4:
CreateBloc();
break;
default:
std::cout << "Unhandled mouse action" << std::endl;
break;
}
}
void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y)
{
}
bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool stopOnError)
{
texture.Load(filename);
if(!texture.IsValid())
{
std::cerr << "Unable to load texture (" << filename << ")" << std::endl;
if(stopOnError)
Stop();
return false;
}
return true;
}
int Engine::GetFps(float elapsedTime){
return 1 / elapsedTime;
}
void Engine::DrawHud(float elapsedTime)
{
// Set the blend func, all that is black will be transparent
glDisable(GL_LIGHTING);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBlendFunc(GL_SRC_ALPHA , GL_ONE);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, Width (), 0, Height (), -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Font
m_textureFont.Bind();
std::ostringstream ss;
for (int i = 0; i < m_mobs.size(); i++)
{
ss << "Mob#" << i << " health: " << m_mobs[i].Health();
PrintText(10, Height () - 40 - (i * 10), ss.str());
ss.str("");
}
ss << "Score:" << m_points;
PrintText(Width() / 2, Height () - 25, ss.str());
ss.str("");
ss << "Health:" << m_p1.Health();
PrintText(Width() / 2, Height () - 35, ss.str());
ss.str("");
ss << "Fps: " << GetFps(elapsedTime);
PrintText(10, Height () - 25, ss.str());
ss.str("");
ss << "Selected bloc type: " << m_selectedbloc;
PrintText(10, 20, ss.str());
ss.str("");
ss << "Position: " << m_p1.Position();
PrintText (10, 10, ss.str());
// Crosshair
m_textureCrosshair.Bind();
static const int crossSize = 32;
glLoadIdentity();
glTranslated(Width () / 2 - crossSize / 2, Height () / 2 - crossSize / 2, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 0);
glTexCoord2f(1, 0);
glVertex2i(crossSize, 0);
glTexCoord2f(1, 1);
glVertex2i(crossSize, crossSize);
glTexCoord2f(0, 1);
glVertex2i(0, crossSize);
glEnd();
glEnable(GL_LIGHTING);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
void Engine::PrintText(unsigned int x, unsigned int y, const std::string& t)
{
glLoadIdentity();
glTranslated(x, y, 0);
for(unsigned int i = 0; i<t.length(); ++i)
{
float left = (float)((t[i] - 32) % 16) / 16.0f;
float top = (float)((t[i] - 32) / 16) / 16.0f;
top += 0.5f;
glBegin(GL_QUADS);
glTexCoord2f(left, 1.0f - top - 0.0625f);
glVertex2f(0, 0);
glTexCoord2f(left + 0.0625f, 1.0f - top - 0.0625f);
glVertex2f(12, 0);
glTexCoord2f(left + 0.0625f, 1.0f - top);
glVertex2f(12, 12);
glTexCoord2f(left, 1.0f - top);
glVertex2f(0, 12);
glEnd();
glTranslated(8, 0, 0);
}
}
Chunk* Engine::ChunkAt(float x, float y, float z) const
{
int cx = (int)x / CHUNK_SIZE_X;
int cz = (int)z / CHUNK_SIZE_Z;
if (cx > VIEW_DISTANCE * 2 / CHUNK_SIZE_X || cz > VIEW_DISTANCE * 2 / CHUNK_SIZE_Z || cx < 0 || cz < 0)
{
std::cout << "WRONG CHUNK POSITION" << std::endl;
return nullptr;
}
return m_chunks.Get(cx, cz);
}
Chunk* Engine::ChunkAt(const Vector3<float>& pos) const
{
return ChunkAt(pos.x, pos.y, pos.z);
}
BlockType Engine::BlockAt(float x, float y, float z, BlockType defaultBlockType) const
{
Chunk* c = ChunkAt(x, y, z);
if(!c)
return defaultBlockType;
int bx = (int)x % CHUNK_SIZE_X;
int by = (int)y % CHUNK_SIZE_Y;
int bz = (int)z % CHUNK_SIZE_Z;
return c->GetBlock(bx, by, bz);
}
void Engine::SetBlockAt(float x, float y, float z, BlockType BlockToSet) const{
Chunk* c = ChunkAt(x, y, z);
int bx = (int)x % CHUNK_SIZE_X;
int by = (int)y % CHUNK_SIZE_Y;
int bz = (int)z % CHUNK_SIZE_Z;
c->SetBlock(bx, by, bz, BlockToSet);
}
bool Engine::IsWalking(){
if (m_keyA || m_keyD || m_keyS || m_keyW)
return true;
else
return false;
}
static bool EqualWithEpsilon(const float& v1, const float& v2, float epsilon = float(0.0001))
{
return (fabs(v2 - v1) < epsilon);
}
static bool InRangeWithEpsilon(const float& v, const float& vinf, const float& vsup, float epsilon = float(0.0001))
{
return (v >= vinf - epsilon && v <= vsup + epsilon);
}
void Engine::GetBlocAtCursor()
{
int x = Width() / 2;
int y = Height() / 2;
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glGetIntegerv(GL_VIEWPORT, viewport);
winX = (float)x;
winY = (float)viewport[3] - (float)y;
glReadPixels(x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
posX += .5f;
posY += .5f;
posZ += .5f;
// Le cast vers int marche juste pour les valeurs entiere, utiliser une fonction de la libc si besoin
// de valeurs negatives
int px = (int)(posX);
int py = (int)(posY);
int pz = (int)(posZ);
bool found = false;
if((m_p1.Position() - Vector3f((float)posX, (float)posY, (float)posZ)).Length() < MAX_SELECTION_DISTANCE)
{
// Apres avoir determine la position du bloc en utilisant la partie entiere du hit
// point retourne par opengl, on doit verifier de chaque cote du bloc trouve pour trouver
// le vrai bloc. Le vrai bloc peut etre different a cause d'erreurs de precision de nos
// nombres flottants (si z = 14.999 par exemple, et qu'il n'y a pas de blocs a la position
// 14 (apres arrondi vers l'entier) on doit trouver et retourner le bloc en position 15 s'il existe
// A cause des erreurs de precisions, ils arrive que le cote d'un bloc qui doit pourtant etre a la
// position 15 par exemple nous retourne plutot la position 15.0001
for(int x = px - 1; !found && x <= px + 1; ++x)
{
for(int y = py - 1; !found && x >= 0 && y <= py + 1; ++y)
{
for(int z = pz - 1; !found && y >= 0 && z <= pz + 1; ++z)
{
if(z >= 0)
{
Mob mob = MobAt((float)x,(float)y, (float)z);
if (!mob.isNull())
m_currentMob = mob;
BlockType bt = BlockAt((float)x,(float)y, (float)z, BTYPE_AIR);
if(bt == BTYPE_AIR)
continue;
// Skip water blocs
//if(bloc->Type == BT_WATER)
// continue;
m_currentBlock.x = x;
m_currentBlock.y = y;
m_currentBlock.z = z;
m_currentBlock.t = bt;
if(InRangeWithEpsilon((float)posX, (float)x, (float)x + 1.f, 0.05f) && InRangeWithEpsilon((float)posY, (float)y, (float)y + 1.f, 0.05f) && InRangeWithEpsilon((float)posZ, (float)z, (float)z + 1.f, 0.05f))
{
found = true;
}
}
}
}
}
}
if(!found)
{
m_currentBlock.x = -1;
}
else
{
// Find on which face of the bloc we got an hit
m_currentFaceNormal.Zero();
const float epsilon = 0.09f;
// Front et back:
if(EqualWithEpsilon((float)posZ, (float)m_currentBlock.z, epsilon))
m_currentFaceNormal.z = -1;
else if(EqualWithEpsilon((float)posZ, (float)m_currentBlock.z + 1.f, epsilon))
m_currentFaceNormal.z = 1;
else if(EqualWithEpsilon((float)posX, (float)m_currentBlock.x, epsilon))
m_currentFaceNormal.x = -1;
else if(EqualWithEpsilon((float)posX, (float)m_currentBlock.x + 1.f, epsilon))
m_currentFaceNormal.x = 1;
else if(EqualWithEpsilon((float)posY, (float)m_currentBlock.y, epsilon))
m_currentFaceNormal.y = -1;
else if(EqualWithEpsilon((float)posY, (float)m_currentBlock.y + 1.f, epsilon))
m_currentFaceNormal.y = 1;
}
}
void Engine::CreateBloc(){
GetBlocAtCursor();
Vector4f Bloc(m_currentBlock.x + m_currentFaceNormal.x, m_currentBlock.y + m_currentFaceNormal.y, m_currentBlock.z + m_currentFaceNormal.z, m_selectedbloc);
m_ModifiedBlocks.push_front(Bloc);
SetBlockAt(m_currentBlock.x + m_currentFaceNormal.x, m_currentBlock.y + m_currentFaceNormal.y, m_currentBlock.z + m_currentFaceNormal.z, m_selectedbloc);
}
void Engine::DestroyBloc(){
GetBlocAtCursor();
Vector4f Bloc(m_currentBlock.x, m_currentBlock.y, m_currentBlock.z, BTYPE_AIR);
m_ModifiedBlocks.push_front(Bloc);
SetBlockAt(m_currentBlock.x, m_currentBlock.y, m_currentBlock.z, BTYPE_AIR);
}
void Engine::DestroyBlocGenerateMob(){
GetBlocAtCursor();
Vector4f Bloc(m_currentBlock.x, m_currentBlock.y, m_currentBlock.z, BTYPE_AIR);
m_ModifiedBlocks.push_front(Bloc);
SetBlockAt(m_currentBlock.x, m_currentBlock.y, m_currentBlock.z, BTYPE_AIR);
Vector3f v(m_currentBlock.x, m_currentBlock.y, m_currentBlock.z);
int dmg;
if(m_currentBlock.t == BTYPE_AIR)
dmg = 1000;
else
dmg = m_currentBlock.t;
Mob NewMob(v, dmg, dmg);
m_mobs.push_back(NewMob);
}
void Engine::HitMob(){
GetBlocAtCursor();
for (int i = 0; i < m_mobs.size(); i++)
{
if(m_mobs[i].isEqual(m_currentMob))
{
m_p1.Damage(m_mobs[i]);
}
}
}
Mob Engine::MobAt(int x, int y, int z){
for (int i = 0; i < m_mobs.size(); i++)
{
Vector3f posMob = m_mobs[i].Position();
if((posMob.x <= x + 0.5f && posMob.x >= x - 0.5f) && (posMob.y <= y + 0.5f && posMob.y >= y - 0.5f) && (posMob.z <= z + 0.5f && posMob.z >= z - 0.5f))
{
return m_mobs[i];
}
}
return Mob(Vector3f(0,0,0), 0, 0);
}

17
CPP/main.cpp Executable file
View File

@ -0,0 +1,17 @@
#include <iostream>
#include "../H/engine.h"
#include "../H/sounds.h"
void ManageSounds(Engine engine){
std::cout << "walking" << std::endl;
}
int main()
{
Engine engine;
Sounds sounds;
std::thread t(&Sounds::ManageSounds, &sounds, &engine);
engine.SetMaxFps(60);
engine.Start("TheLandofWildBlocs", 800, 600, true);
return 0;
}

133
CPP/mob.cpp Executable file
View File

@ -0,0 +1,133 @@
#include "../H/player.h"
Mob::Mob(){}
Mob::Mob(const Vector3f & position, float Damage, int Armour) : m_pos(position), m_damage(Damage), m_armour(Armour)
{
m_health = 100.f * Armour;
}
void Mob::SetPosition (Vector3f delta){
m_pos.x = delta.x;
m_pos.y = delta.y;
m_pos.z = delta.z;
}
void Mob::Move(Player p1){
double speed = 0.1;
Vector3f p1pos = p1.Position();
if (p1pos.x >= m_pos.x){
m_pos.x += speed;
}
if (p1pos.x < m_pos.x){
m_pos.x -= speed;
}
if (p1pos.y >= m_pos.y){
m_pos.y += speed;
}
if (p1pos.y < m_pos.y){
m_pos.y -= speed;
}
if (p1pos.z >= m_pos.z){
m_pos.z += speed;
}
if (p1pos.z < m_pos.z){
m_pos.z -= speed;
}
}
Vector3f Mob::Position(){
return m_pos;
}
void Mob::Damage(Player& p1){
p1.setHealth(p1.Health() - m_damage);
}
float Mob::GetDamage(){
return m_damage;
}
float Mob::Health(){
return m_health;
}
void Mob::setHealth(float health){
m_health = health;
}
void Mob::RenderMob()
{
//around1
glBegin(GL_TRIANGLES);
glNormal3f(0, 1, 0);
glTexCoord2f(0, 0);
glVertex3f(m_pos.x, m_pos.y + .5f, m_pos.z);
glTexCoord2f(1, 0);
glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z - .5f);
glTexCoord2f(1, 1);
glVertex3f(m_pos.x - .5f, m_pos.y - .5f, m_pos.z + .5f);
glEnd();
//around2
glBegin(GL_TRIANGLES);
glNormal3f(0, 1, 0);
glTexCoord2f(0, 0);
glVertex3f(m_pos.x, m_pos.y + .5f, m_pos.z);
glTexCoord2f(1, 0);
glVertex3f(m_pos.x - .5f, m_pos.y - .5f, m_pos.z + .5f);
glTexCoord2f(1, 1);
glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z + .5f);
glEnd();
//around3
glBegin(GL_TRIANGLES);
glNormal3f(0, 1, 0);
glTexCoord2f(0, 0);
glVertex3f(m_pos.x, m_pos.y + .5f, m_pos.z);
glTexCoord2f(1, 0);
glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z + .5f);
glTexCoord2f(1, 1);
glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z - .5f);
glEnd();
//bottom
glBegin(GL_TRIANGLES);
glNormal3f(0, -1, 0);
glTexCoord2f(0, 0);
glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z - .5f);
glTexCoord2f(1, 0);
glVertex3f(m_pos.x - .5f, m_pos.y - .5f, m_pos.z + .5f);
glTexCoord2f(1, 1);
glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z + .5f);
glEnd();
}
bool Mob::isNull(){
if (m_pos.x == 0 && m_pos.y == 0 && m_pos.z == 0 && m_damage == 0 && m_armour == 0)
return true;
return false;
}
int Mob::GetArmour(){
return m_armour;
}
bool Mob::isEqual(Mob mob){
Vector3f v = mob.Position();
if (m_pos.x == v.x && m_pos.y == v.y && m_pos.z == v.z && m_damage == mob.GetDamage() && m_armour == mob.GetArmour())
return true;
return false;
}

172
CPP/openglcontext.cpp Executable file
View File

@ -0,0 +1,172 @@
#include "../H/openglcontext.h"
#include "../H/define.h"
OpenglContext::OpenglContext() : m_maxFps(999999), m_fullscreen(false), m_title(""), m_lastFrameTime(0)
{
}
OpenglContext::~OpenglContext()
{
}
bool OpenglContext::Start(const std::string& title, int width, int height, bool fullscreen)
{
m_title = title;
m_fullscreen = fullscreen;
InitWindow(width, height);
Init();
LoadResource();
sf::Clock clock;
while (m_app.isOpen())
{
clock.restart();
sf::Event Event;
while (m_app.pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed:
m_app.close();
break;
case sf::Event::Resized:
glViewport(0, 0, Event.size.width, Event.size.height);
break;
case sf::Event::KeyPressed:
KeyPressEvent(Event.key.code);
break;
case sf::Event::KeyReleased:
KeyReleaseEvent(Event.key.code);
break;
case sf::Event::MouseMoved:
MouseMoveEvent(Event.mouseMove.x, Event.mouseMove.y);
break;
case sf::Event::MouseButtonPressed:
MousePressEvent(ConvertMouseButton(Event.mouseButton.button), Event.mouseButton.x, Event.mouseButton.y);
break;
case sf::Event::MouseButtonReleased:
MouseReleaseEvent(ConvertMouseButton(Event.mouseButton.button), Event.mouseButton.x, Event.mouseButton.y);
break;
case sf::Event::MouseWheelMoved:
if(Event.mouseWheel.delta > 0)
MousePressEvent(MOUSE_BUTTON_WHEEL_UP, Event.mouseButton.x, Event.mouseButton.y);
else
MousePressEvent(MOUSE_BUTTON_WHEEL_DOWN, Event.mouseButton.x, Event.mouseButton.y);
break;
}
}
m_app.setActive();
Render(m_lastFrameTime);
m_app.display();
m_lastFrameTime = clock.getElapsedTime().asSeconds();
// Handle ourself frame rate limit, sf::Window::setFramerateLimit doesn't seems to work
float waitTime = (1.f / m_maxFps) - m_lastFrameTime;
if(waitTime > 0)
{
sf::sleep(sf::seconds(waitTime));
m_lastFrameTime = clock.getElapsedTime().asSeconds();
}
}
UnloadResource();
DeInit();
return true;
}
bool OpenglContext::Stop()
{
m_app.close();
return true;
}
void OpenglContext::CenterMouse()
{
sf::Mouse::setPosition(sf::Vector2i(Width() / 2, Height() / 2), m_app);
}
int OpenglContext::Width() const
{
return m_app.getSize().x;
}
int OpenglContext::Height() const
{
return m_app.getSize().y;
}
void OpenglContext::SetMaxFps(int maxFps)
{
m_maxFps = maxFps;
m_app.setFramerateLimit(maxFps);
}
int OpenglContext::GetMaxFps() const
{
return m_maxFps;
}
void OpenglContext::SetFullscreen(bool fullscreen)
{
if(m_fullscreen == fullscreen)
return;
m_fullscreen = !m_fullscreen;
DeInit();
InitWindow(Width(), Height());
Init();
}
bool OpenglContext::IsFullscreen() const
{
return m_fullscreen;
}
void OpenglContext::MakeRelativeToCenter(int& x, int& y) const
{
x = x - (Width() / 2);
y = y - (Height() / 2);
}
void OpenglContext::ShowCursor()
{
m_app.setMouseCursorVisible(true);
}
void OpenglContext::HideCursor()
{
m_app.setMouseCursorVisible(false);
}
void OpenglContext::ShowCrossCursor() const
{
}
void OpenglContext::InitWindow(int width, int height)
{
m_app.create((m_fullscreen ? sf::VideoMode::getFullscreenModes()[0] : sf::VideoMode(width, height, 32)), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize|sf::Style::Close), sf::ContextSettings(32, 8, 0));
}
OpenglContext::MOUSE_BUTTON OpenglContext::ConvertMouseButton(sf::Mouse::Button button) const
{
switch(button)
{
case sf::Mouse::Left:
return MOUSE_BUTTON_LEFT;
case sf::Mouse::Middle:
return MOUSE_BUTTON_MIDDLE;
case sf::Mouse::Right:
return MOUSE_BUTTON_RIGHT;
default:
return MOUSE_BUTTON_NONE;
}
}

262
CPP/perlin.cpp Executable file
View File

@ -0,0 +1,262 @@
/* coherent noise function over 1, 2 or 3 dimensions */
/* (copyright Ken Perlin) */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "../H/perlin.h"
#define B SAMPLE_SIZE
#define BM (SAMPLE_SIZE-1)
#define N 0x1000
#define NP 12 /* 2^N */
#define NM 0xfff
#define s_curve(t) ( t * t * (3.0f - 2.0f * t) )
#define lerp(t, a, b) ( a + t * (b - a) )
#define setup(i,b0,b1,r0,r1)\
t = vec[i] + N;\
b0 = ((int)t) & BM;\
b1 = (b0+1) & BM;\
r0 = t - (int)t;\
r1 = r0 - 1.0f;
float Perlin::noise1(float arg)
{
int bx0, bx1;
float rx0, rx1, sx, t, u, v, vec[1];
vec[0] = arg;
if (mStart)
{
srand(mSeed);
mStart = false;
init();
}
setup(0, bx0,bx1, rx0,rx1);
sx = s_curve(rx0);
u = rx0 * g1[ p[ bx0 ] ];
v = rx1 * g1[ p[ bx1 ] ];
return lerp(sx, u, v);
}
float Perlin::noise2(float vec[2])
{
int bx0, bx1, by0, by1, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
int i, j;
if (mStart)
{
srand(mSeed);
mStart = false;
init();
}
setup(0,bx0,bx1,rx0,rx1);
setup(1,by0,by1,ry0,ry1);
i = p[bx0];
j = p[bx1];
b00 = p[i + by0];
b10 = p[j + by0];
b01 = p[i + by1];
b11 = p[j + by1];
sx = s_curve(rx0);
sy = s_curve(ry0);
#define at2(rx,ry) ( rx * q[0] + ry * q[1] )
q = g2[b00];
u = at2(rx0,ry0);
q = g2[b10];
v = at2(rx1,ry0);
a = lerp(sx, u, v);
q = g2[b01];
u = at2(rx0,ry1);
q = g2[b11];
v = at2(rx1,ry1);
b = lerp(sx, u, v);
return lerp(sy, a, b);
}
float Perlin::noise3(float vec[3])
{
int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
int i, j;
if (mStart)
{
srand(mSeed);
mStart = false;
init();
}
setup(0, bx0,bx1, rx0,rx1);
setup(1, by0,by1, ry0,ry1);
setup(2, bz0,bz1, rz0,rz1);
i = p[ bx0 ];
j = p[ bx1 ];
b00 = p[ i + by0 ];
b10 = p[ j + by0 ];
b01 = p[ i + by1 ];
b11 = p[ j + by1 ];
t = s_curve(rx0);
sy = s_curve(ry0);
sz = s_curve(rz0);
#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0);
q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0);
a = lerp(t, u, v);
q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0);
q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0);
b = lerp(t, u, v);
c = lerp(sy, a, b);
q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1);
q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1);
a = lerp(t, u, v);
q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1);
q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1);
b = lerp(t, u, v);
d = lerp(sy, a, b);
return lerp(sz, c, d);
}
void Perlin::normalize2(float v[2])
{
float s;
s = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
s = 1.0f/s;
v[0] = v[0] * s;
v[1] = v[1] * s;
}
void Perlin::normalize3(float v[3])
{
float s;
s = (float)sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
s = 1.0f/s;
v[0] = v[0] * s;
v[1] = v[1] * s;
v[2] = v[2] * s;
}
void Perlin::init(void)
{
int i, j, k;
for (i = 0 ; i < B ; i++)
{
p[i] = i;
g1[i] = (float)((rand() % (B + B)) - B) / B;
for (j = 0 ; j < 2 ; j++)
g2[i][j] = (float)((rand() % (B + B)) - B) / B;
normalize2(g2[i]);
for (j = 0 ; j < 3 ; j++)
g3[i][j] = (float)((rand() % (B + B)) - B) / B;
normalize3(g3[i]);
}
while (--i)
{
k = p[i];
p[i] = p[j = rand() % B];
p[j] = k;
}
for (i = 0 ; i < B + 2 ; i++)
{
p[B + i] = p[i];
g1[B + i] = g1[i];
for (j = 0 ; j < 2 ; j++)
g2[B + i][j] = g2[i][j];
for (j = 0 ; j < 3 ; j++)
g3[B + i][j] = g3[i][j];
}
}
float Perlin::perlin_noise_2D(float vec[2])
{
int terms = mOctaves;
//float freq = mFrequency;
float result = 0.0f;
float amp = mAmplitude;
vec[0]*=mFrequency;
vec[1]*=mFrequency;
for( int i=0; i<terms; i++ )
{
result += noise2(vec)*amp;
vec[0] *= 2.0f;
vec[1] *= 2.0f;
amp*=0.5f;
}
return result;
}
float Perlin::perlin_noise_3D(float vec[3])
{
int terms = mOctaves;
//float freq = mFrequency;
float result = 0.0f;
float amp = mAmplitude;
vec[0]*=mFrequency;
vec[1]*=mFrequency;
vec[2]*=mFrequency;
for( int i=0; i<terms; i++ )
{
result += noise3(vec)*amp;
vec[0] *= 2.0f;
vec[1] *= 2.0f;
vec[2] *= 2.0f;
amp*=0.5f;
}
return result;
}
Perlin::Perlin(int octaves,float freq,float amp,int seed)
{
mOctaves = octaves;
mFrequency = freq;
mAmplitude = amp;
mSeed = seed;
mStart = true;
}

90
CPP/player.cpp Executable file
View File

@ -0,0 +1,90 @@
#include "../H/player.h"
Player::Player(const Vector3f & position, float rotx, float roty) : m_rotx(rotx), m_roty(roty), m_pos(position){
m_health = 100.f;
std::cout << "Constructor" << std::endl;
}
Vector3f Player::Position(){
return m_pos;
}
void Player::TurnCamera(float x, float y){
x *= 0.01;
y *= 0.01;
if(m_rotx + y >= -70 && m_rotx + y <= 70)
m_rotx += y;
m_roty += x;
}
void Player::SetPosition (Vector3f delta){
m_pos.x = delta.x;
m_pos.y = delta.y;
m_pos.z = delta.z;
}
Vector3f Player::SimulateMove ( bool front , bool back , bool left , bool right , bool run, float elapsedTime ){
Vector3f delta(0, 0, 0);
double speed = 0.1;
if(run)
speed = 0.2;
if (front){
float yrotrad = (m_roty / 180 * 3.141592654f);
delta.x += float(sin(yrotrad)) * speed;
delta.z -= float(cos(yrotrad)) * speed;
}
if (back){
float yrotrad = (m_roty / 180 * 3.141592654f);
delta.x -= float(sin(yrotrad)) * speed;
delta.z += float(cos(yrotrad)) * speed;
}
if (left){
float yrotrad = (m_roty / 180 * 3.141592654f);
delta.x -= float(cos(yrotrad)) * speed;
delta.z -= float(sin(yrotrad)) * speed;
}
if(right){
float yrotrad = (m_roty / 180 * 3.141592654f);
delta.x += float(cos(yrotrad)) * speed;
delta.z += float(sin(yrotrad)) * speed;
}
return delta;
}
float Player::SimulateJump(bool jump, bool& InJump, float& deltay, bool OnGround, float& jumpsize){
if(jump){
if (OnGround)
{
InJump = true;
}
}
if(InJump){
deltay += 0.2;
if (jumpsize > 1.5)
{
InJump = false;
return -1.5;
}
return 0.1;
}
return 0;
}
void Player::ApplyTransformation ( Transformation & transformation ) const{
transformation.ApplyRotation(-m_rotx, 1.f, 0, 0);
transformation.ApplyRotation(-m_roty, 0, 1.f, 0);
transformation.ApplyTranslation(-m_pos);
}
void Player::Damage(Mob& mob){
mob.setHealth(mob.Health() - m_damage);
}
float Player::Health(){
return m_health;
}
void Player::setHealth(float health){
m_health = health;
}

155
CPP/shader.cpp Executable file
View File

@ -0,0 +1,155 @@
#include "../H/shader.h"
#include "../H/define.h"
#include "../H/tool.h"
#include <iostream>
#include <cassert>
#ifndef WINDOWS
bool Shader::Load(const std::string& vertFile, const std::string& fragFile, bool verbose)
{
std::string fragmentShader;
std::string vertexShader;
if(!Tool::LoadTextFile(vertFile, vertexShader))
{
if(verbose)
std::cout << "Failed to load " << vertFile << std::endl;
return false;
}
if(!Tool::LoadTextFile(fragFile, fragmentShader))
{
if(verbose)
std::cout << "Failed to load " << fragFile << std::endl;
return false;
}
const char * my_fragment_shader_source = fragmentShader.c_str();
const char * my_vertex_shader_source = vertexShader.c_str();
//std::cout << fragmentShader << std::endl;
//std::cout << vertexShader << std::endl;
m_program = glCreateProgram();
CHECK_GL_ERROR();
assert(glIsProgram(m_program));
m_vertexShader = glCreateShader(GL_VERTEX_SHADER_ARB);
CHECK_GL_ERROR();
assert(glIsShader(m_vertexShader));
m_fragmentShader = glCreateShader(GL_FRAGMENT_SHADER_ARB);
CHECK_GL_ERROR();
assert(glIsShader(m_fragmentShader));
// Load Shader Sources
glShaderSource(m_vertexShader, 1, (const GLchar**)&my_vertex_shader_source, NULL);
CHECK_GL_ERROR();
glShaderSource(m_fragmentShader, 1, (const GLchar**)&my_fragment_shader_source, NULL);
CHECK_GL_ERROR();
// Compile The Shaders
if(verbose)
std::cout << "Compiling vertex shader (" << vertFile << ")..." << std::endl;
glCompileShader(m_vertexShader);
if(!CheckShaderError(m_vertexShader, verbose))
return false;
if(verbose)
std::cout << "Compiling fragment shader (" << fragFile << ")..." << std::endl;
glCompileShader(m_fragmentShader);
if(!CheckShaderError(m_fragmentShader, verbose))
return false;
// Attach The Shader Objects To The Program Object
glAttachShader(m_program, m_vertexShader);
CHECK_GL_ERROR();
glAttachShader(m_program, m_fragmentShader);
CHECK_GL_ERROR();
// Link The Program Object
glLinkProgram(m_program);
//if(!CheckProgramError(m_program, verbose))
// return false;
CheckProgramError(m_program, true, verbose);
CHECK_GL_ERROR();
return true;
}
void Shader::Use() const
{
glUseProgram(m_program);
}
GLint Shader::BindIntUniform(const std::string& name) const
{
return glGetUniformLocation(m_program, name.c_str());
}
void Shader::UpdateIntUniform(GLint name, GLint value) const
{
glUniform1i(name, value);
}
void Shader::UpdateFloatUniform(GLint name, GLfloat value) const
{
glUniform1f(name, value);
}
void Shader::Disable()
{
glUseProgram(0);
}
bool Shader::CheckShaderError(GLenum shader, bool verbose)
{
GLint compileOk;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compileOk);
if(verbose && !compileOk)
{
int maxLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
char* infoLog = new char[maxLength];
glGetShaderInfoLog(shader, maxLength, &maxLength, infoLog);
std::cout << infoLog << std::endl;
delete [] infoLog;
return false;
}
return compileOk;
}
bool Shader::CheckProgramError(GLenum program, bool showWarning, bool verbose)
{
GLint compileOk;
glGetProgramiv(program, GL_LINK_STATUS, &compileOk);
CHECK_GL_ERROR();
if(verbose && (showWarning || !compileOk))
{
int maxLength;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
CHECK_GL_ERROR();
char* infoLog = new char[maxLength + 1];
glGetProgramInfoLog(program, maxLength, &maxLength, infoLog);
CHECK_GL_ERROR();
infoLog[maxLength] = 0;
std::cout << infoLog << std::endl;
delete [] infoLog;
}
return compileOk;
}
#endif

51
CPP/sounds.cpp Executable file
View File

@ -0,0 +1,51 @@
#include "../H/sounds.h"
Sounds::Sounds(){
m_BackgroundMusic.openFromFile("media/music/TheRiseoftheMechbeings.ogg");
m_BackgroundMusic.setLoop(true);
m_BackgroundMusic.play();
}
Sounds::~Sounds(){
m_BackgroundMusic.stop();
}
void Sounds::ManageSounds(Engine* en){
std::cout << "Sounds" << std::endl;
while(en->IsWalking()){
std::cout << "Is walking" << std::endl;
Move(en);
usleep(100);
}
}
sf::SoundBuffer Sounds::SelectSound(sf::SoundBuffer buffer, char& sound){
switch (sound)
{
case 0:
std::cout << "LEFT" << std::endl;
buffer.loadFromFile("media/sounds/Footstep_Tile_Left.wav");
sleep(1);
nextFootStep = 1;
break;
case 1:
std::cout << "RIGHT" << std::endl;
buffer.loadFromFile("media/sounds/Footstep_Tile_Right_2.wav");
sleep(1);
nextFootStep = 0;
break;
default:
break;
}
return buffer;
}
void Sounds::Move(Engine* en){
if (m_sound1.getStatus() != m_sound1.Playing){
m_sound1.setBuffer(SelectSound(m_buffer, nextFootStep));
if(en->m_walk){
if (en->m_run)
m_sound1.setPitch(1.2f);
m_sound1.play();
}
}
}

64
CPP/texture.cpp Executable file
View File

@ -0,0 +1,64 @@
#include "../H/texture.h"
#include <cassert>
Texture::Texture(const std::string& filename) : m_isValid(false)
{
if(filename != "")
Load(filename);
}
Texture::~Texture()
{
if(IsValid())
glDeleteTextures(1, &m_textureId);
}
bool Texture::Load(const std::string& filename)
{
// Initialize Devil only once:
static bool alreadyInitialized = false;
if(!alreadyInitialized)
{
ilInit();
alreadyInitialized = true;
}
// Use Devil library to load image data in memory
ILuint texid;
ilGenImages(1, &texid);
ilBindImage(texid);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
ilEnable(IL_ORIGIN_SET);
if (!ilLoadImage((const ILstring)filename.c_str()))
return false;
if (!ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE))
return false;
// Create mipmapped opengl texture from image data
glGenTextures(1, &m_textureId);
glBindTexture(GL_TEXTURE_2D, m_textureId);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
ilDeleteImages(1, &texid);
m_isValid = true;
return true;
}
bool Texture::IsValid() const
{
return m_isValid;
}
void Texture::Bind() const
{
assert(IsValid());
glBindTexture(GL_TEXTURE_2D, m_textureId);
}

198
CPP/textureatlas.cpp Executable file
View File

@ -0,0 +1,198 @@
#include "../H/textureatlas.h"
#include <cmath>
// TODO
#include <iostream>
#include <sstream>
#include <cassert>
#include "../H/tool.h"
TextureAtlas::TextureAtlas(unsigned int nbTexture) : m_isValid(false), m_currentTextureIndex(0)
{
if(nbTexture < 4)
nbTexture = 4;
// Arrondir sur la puissance de 2 superieure
m_nbTexturePerSide = (int)sqrt((float)nbTexture);
if(m_nbTexturePerSide * m_nbTexturePerSide < nbTexture)
m_nbTexturePerSide++;
while(!IsPowerOfTwo(m_nbTexturePerSide))
m_nbTexturePerSide++;
}
TextureAtlas::~TextureAtlas()
{
if(IsValid())
glDeleteTextures(1, &m_textureId);
}
TextureAtlas::TextureIndex TextureAtlas::AddTexture(const std::string& fname)
{
TextureList::iterator it = m_textureList.find(fname);
if(it != m_textureList.end())
return it->second.texIdx;
TextureIndex id = m_currentTextureIndex++;
m_textureList.insert(std::make_pair(fname, TextureInfo((ILuint)-1, id)));
return id;
}
bool TextureAtlas::Generate(int textureSize, bool mipmap)
{
// TODO mipmap pas encore 100% parfait...
assert(!mipmap);
if(!IsPowerOfTwo(textureSize))
return false;
// Initialize Devil only once:
static bool alreadyInitialized = false;
if(!alreadyInitialized)
{
ilInit();
iluInit();
alreadyInitialized = true;
}
for(TextureList::iterator it = m_textureList.begin(); it != m_textureList.end(); ++it)
{
ILuint texid = it->second.texId;
if(texid == (ILuint)-1)
{
std::cout << "Loading " << it->first << " (id=" << it->second.texIdx << ")..." << std::endl;
ilGenImages(1, &texid);
ilBindImage(texid);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
ilEnable(IL_ORIGIN_SET);
if (!ilLoadImage((const ILstring)it->first.c_str()))
return false;
if (!ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE))
return false;
iluScale(textureSize, textureSize, 1);
it->second.texId = texid;
}
}
//std::cout << ilGetInteger(IL_IMAGE_BPP) << std::endl;
//std::cout << ilGetInteger(IL_IMAGE_FORMAT) << std::endl;
//std::cout << ilGetInteger(IL_IMAGE_DEPTH) << std::endl;
//std::cout << ilGetInteger(IL_IMAGE_TYPE) << std::endl;
//std::cout << ilGetInteger(IL_IMAGE_WIDTH) << std::endl;
//std::cout << ilGetInteger(IL_IMAGE_HEIGHT) << std::endl;
glGenTextures(1, &m_textureId);
glBindTexture(GL_TEXTURE_2D, m_textureId);
if(mipmap)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
int level = textureSize;
int oglLevel = 0;
int mipmapSize = textureSize * m_nbTexturePerSide;
while(mipmapSize != 0)
{
ILuint atlasTex;
ilGenImages(1, &atlasTex);
ilBindImage(atlasTex);
ilTexImage(mipmapSize, mipmapSize, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, 0);
ilClearColour(1, 0, 0, 1);
ilClearImage();
for(TextureList::iterator it = m_textureList.begin(); it != m_textureList.end(); ++it)
{
ILuint tmpImg;
ilGenImages(1, &tmpImg);
ilBindImage(tmpImg);
ilCopyImage(it->second.texId);
iluImageParameter(ILU_FILTER, ILU_NEAREST);
//iluImageParameter(ILU_FILTER, ILU_BILINEAR);
if(level != textureSize)
iluScale(level, level, 1);
char* data = new char[level * level * 4];
ilCopyPixels(0, 0, 0, level, level, 1, IL_RGBA, IL_UNSIGNED_BYTE, data);
int imgIdx = it->second.texIdx;
int x = imgIdx % m_nbTexturePerSide;
int y = m_nbTexturePerSide - 1 - imgIdx / m_nbTexturePerSide;
ilBindImage(atlasTex);
ilSetPixels(x * level, y * level, 0, level, level, 1, IL_RGBA, IL_UNSIGNED_BYTE, data);
//ilOverlayImage(tmpImg, x * level, y * level, 0);
delete [] data;
ilDeleteImages(1, &tmpImg);
}
// TODO
//if(level == textureSize)
//{
//ilEnable(IL_FILE_OVERWRITE);
//ilSaveImage("textureatlas.png");
//}
//std::cout << oglLevel << ":" << level << ":" << mipmapSize << std::endl;
glTexImage2D(GL_TEXTURE_2D, oglLevel++, GL_RGBA, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, GL_RGBA, GL_UNSIGNED_BYTE, ilGetData());
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
CHECK_GL_ERROR();
ilDeleteImages(1, &atlasTex);
if(!mipmap)
break;
level /= 2;
mipmapSize /= 2;
}
m_isValid = true;
return true;
}
bool TextureAtlas::IsValid() const
{
return m_isValid;
}
void TextureAtlas::Bind() const
{
assert(IsValid());
glBindTexture(GL_TEXTURE_2D, m_textureId);
}
void TextureAtlas::TextureIndexToCoord(TextureIndex idx, float& u, float& v, float& w, float& h) const
{
w = 1.f / (float)m_nbTexturePerSide;
h = 1.f / (float)m_nbTexturePerSide;
u = (float)((unsigned int)idx % m_nbTexturePerSide) * w;
v = (float)(m_nbTexturePerSide - 1 - (unsigned int)idx / m_nbTexturePerSide) * h;
}

67
CPP/tool.cpp Executable file
View File

@ -0,0 +1,67 @@
#include "../H/tool.h"
#include "../H/define.h"
#include <cassert>
#include <iostream>
#include <fstream>
bool Tool::LoadTextFile(const std::string& filename, std::string& buffer)
{
std::ifstream f(filename.c_str(), std::ios::binary);
if(!f.is_open())
return false;
f.seekg(0, std::ios::end);
unsigned int len = f.tellg();
f.seekg(0, std::ios::beg);
char* tmp = new char[len + 1];
f.read(tmp, len);
f.close();
tmp[len] = 0;
buffer = tmp;
delete [] tmp;
return true;
}
void Tool::CheckGLError(const char* file, int line)
{
GLuint err = glGetError();
if (err != GL_NO_ERROR)
{
std::cerr << "Opengl error before " << file << "[" << line << "]:" << std::hex << err << "(";
switch(err)
{
case GL_INVALID_ENUM:
std::cerr << "GL_INVALID_ENUM";
break;
case GL_INVALID_VALUE:
std::cerr << "GL_INVALID_VALUE";
break;
case GL_INVALID_OPERATION:
std::cerr << "GL_INVALID_OPERATION";
break;
case GL_STACK_OVERFLOW:
std::cerr << "GL_STACK_OVERFLOW";
break;
case GL_STACK_UNDERFLOW:
std::cerr << "GL_STACK_UNDERFLOW";
break;
case GL_OUT_OF_MEMORY:
std::cerr << "GL_OUT_OF_MEMORY";
break;
case GL_TABLE_TOO_LARGE:
std::cerr << "GL_TABLE_TOO_LARGE";
break;
default:
std::cerr << "unknown";
}
std::cerr << ")" << std::endl;
std::cerr << "ATTENTION: this error might come from anywhere in the code since the previous call to CHECK_GL_ERROR" << std::endl;
exit(1);
}
}

63
CPP/transformation.cpp Executable file
View File

@ -0,0 +1,63 @@
#include "../H/transformation.h"
Transformation::Transformation()
{
m_stack.push(Matrix4f::IDENTITY);
}
void Transformation::SetIdentity()
{
m_stack.top().SetIdentity();
}
void Transformation::Push()
{
m_stack.push(m_stack.top());
}
void Transformation::Pop()
{
m_stack.pop();
}
void Transformation::ApplyTranslation(float x, float y, float z)
{
m_stack.top().ApplyTranslation(x, y, z);
}
void Transformation::ApplyTranslation(const Vector3f& v)
{
ApplyTranslation(v.x, v.y, v.z);
}
void Transformation::ApplyRotation(float angle, float x, float y, float z)
{
m_stack.top().ApplyRotation(angle, x, y, z);
}
void Transformation::ApplyRotation(float angle, const Vector3f& v)
{
ApplyRotation(angle, v.x, v.y, v.z);
}
void Transformation::ApplyScale(float x, float y, float z)
{
m_stack.top().ApplyScale(x, y, z);
}
void Transformation::ApplyScale(const Vector3f& v)
{
ApplyScale(v.x, v.y, v.z);
}
void Transformation::Use() const
{
glLoadMatrixf(m_stack.top().GetInternalValues());
}
const Matrix4f& Transformation::GetMatrix() const
{
return m_stack.top();
}

84
CPP/vertexbuffer.cpp Executable file
View File

@ -0,0 +1,84 @@
#include "../H/vertexbuffer.h"
#include <cassert>
#include <climits>
VertexBuffer::VertexBuffer() : m_isValid(false)
{
}
VertexBuffer::~VertexBuffer()
{
if(m_isValid)
{
glDeleteBuffers(1, &m_vertexVboId);
glDeleteBuffers(1, &m_indexVboId);
}
}
bool VertexBuffer::IsValid() const
{
return m_isValid;
}
void VertexBuffer::SetMeshData(VertexData* vd, int vertexCount)
{
assert(vertexCount <= USHRT_MAX);
if(vertexCount == 0)
return;
if(!m_isValid)
{
glGenBuffers(1, &m_vertexVboId);
glGenBuffers(1, &m_indexVboId);
}
m_vertexCount = vertexCount;
glBindBuffer(GL_ARRAY_BUFFER, m_vertexVboId);
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData) * vertexCount, vd, GL_STATIC_DRAW);
// Pour le moment, generer le index array pour inclure tout les vertex, sans
// optimisation pour reduire le nombre de vertex envoyes a la carte
// Idealement cet array devrait etre utiliser pour reutiliser les vertex et ainsi
// sauver du temps en envoyant moins de donnees a la carte (il devrait etre construit
// en meme temps que le buffer vd est rempli..)
uint16_t* idx = new uint16_t[vertexCount];
for(int i = 0; i < vertexCount; ++i)
idx[i] = i;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexVboId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint16_t) * vertexCount, idx, GL_STATIC_DRAW);
delete [] idx;
m_isValid = true;
}
void VertexBuffer::Render() const
{
if(IsValid())
{
glClientActiveTexture(GL_TEXTURE0);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexVboId);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(VertexData), (char*)0);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(3, GL_FLOAT, sizeof(VertexData), (char*)12);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexData), (char*)24);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexVboId);
glDrawElements(GL_QUADS, m_vertexCount, GL_UNSIGNED_SHORT, (char*)0);
// TODO
//glDrawRangeElements(GL_TRIANGLES, 0, 3, 3, GL_UNSIGNED_SHORT, (char*)0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
int VertexBuffer::Count() const
{
return m_vertexCount;
}

72
H/array2d.h Executable file
View File

@ -0,0 +1,72 @@
#ifndef ARRAY2D_H__
#define ARRAY2D_H__
#include "define.h"
template <class T>
class Array2d
{
public:
Array2d(int x, int y);
~Array2d();
Array2d(const Array2d& array);
void Set(int x, int y, T type);
T Get(int x, int y) const;
void Reset(T type);
private:
int To1dIndex(int x, int y) const;
private:
int m_x, m_y;
T* m_array;
};
template <class T>
Array2d<T>::Array2d(int x, int y) : m_x(x), m_y(y)
{
m_array = new T[m_x * m_y];
}
template <class T>
Array2d<T>::~Array2d()
{
delete [] m_array;
}
template <class T>
Array2d<T>::Array2d(const Array2d& array) : m_x(array.m_x), m_y(array.m_y)
{
m_array = new T[m_x * m_y];
for(int i = 0; i < m_x * m_y; ++i)
m_array[i] = array.m_array[i];
}
template <class T>
void Array2d<T>::Set(int x, int y, T type)
{
m_array[To1dIndex(x, y)] = type;
}
template <class T>
T Array2d<T>::Get(int x, int y) const
{
return m_array[To1dIndex(x, y)];
}
template <class T>
void Array2d<T>::Reset(T type)
{
for(int i = 0; i < m_x * m_y; ++i)
m_array[i] = type;
}
template <class T>
int Array2d<T>::To1dIndex(int x, int y) const
{
return x + (y * m_x);
}
#endif // ARRAY2D_H__

74
H/array3d.h Executable file
View File

@ -0,0 +1,74 @@
#ifndef ARRAY3D_H__
#define ARRAY3D_H__
#include "define.h"
template <class T>
class Array3d
{
public:
Array3d(int x, int y, int z);
~Array3d();
Array3d(const Array3d& array);
void Set(int x, int y, int z, T type) const;
T Get(int x, int y, int z) const;
void Reset(T type);
private:
int To1dIndex(int x, int y, int z) const;
private:
int m_x, m_y, m_z;
T* m_array;
};
template <class T>
Array3d<T>::Array3d(int x, int y, int z) : m_x(x), m_y(y), m_z(z)
{
m_array = new T[m_x * m_y * m_z];
Reset(BTYPE_AIR);
}
template <class T>
Array3d<T>::~Array3d()
{
delete [] m_array;
}
template <class T>
Array3d<T>::Array3d(const Array3d& array) : m_x(array.m_x), m_y(array.m_y), m_z(array.m_z)
{
m_array = new T[m_x * m_y * m_z];
for(int i = 0; i < m_x * m_y * m_z; ++i)
m_array[i] = array.m_array[i];
}
template <class T>
void Array3d<T>::Set(int x, int y, int z, T type) const
{
m_array[To1dIndex(x, y, z)] = type;
}
template <class T>
T Array3d<T>::Get(int x, int y, int z) const
{
return m_array[To1dIndex(x, y, z)];
}
template <class T>
void Array3d<T>::Reset(T type)
{
for(int i = 0; i < m_x * m_y * m_z; ++i)
m_array[i] = type;
}
template <class T>
int Array3d<T>::To1dIndex(int x, int y, int z) const
{
return x + (z * m_x) + (y * m_z * m_x);
}
#endif // ARRAY3D_H__

35
H/blockinfo.h Executable file
View File

@ -0,0 +1,35 @@
#ifndef BLOCKINFO_H__
#define BLOCKINFO_H__
#include <string>
#include "define.h"
class BlockInfo
{
public:
BlockInfo(BlockType type, const std::string& name);
BlockInfo();
~BlockInfo();
BlockType GetType() const;
void SetDurability(int durability);
int GetDurability() const;
void SetUVWH(float u, float v, float w, float h);
float GetU();
float GetV();
float GetW();
float GetH();
void Show() const;
private:
BlockType m_type;
std::string m_name;
int m_durability;
float m_u, m_v, m_w, m_h;
};
#endif // BLOCKINFO_H__

33
H/chunk.h Executable file
View File

@ -0,0 +1,33 @@
#ifndef CHUNK_H__
#define CHUNK_H__
#include "array3d.h"
#include "vertexbuffer.h"
#include "blockinfo.h"
#include "perlin.h"
#include <iostream>
class Chunk
{
public:
Chunk();
Chunk(float x, float z);
~Chunk();
void RemoveBlock(int x, int y, int z);
void SetBlock(int x, int y, int z, BlockType type);
BlockType GetBlock(int x, int y, int z);
void Update(BlockInfo bi[BTYPE_LAST]);
void AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, BlockInfo bi[BTYPE_LAST]);
void Render() const;
bool IsDirty() const;
private:
Array3d<BlockType> m_blocks;
VertexBuffer m_vertexBuffer;
bool m_isDirty;
float m_posx;
float m_posz;
float m_posy = -10;
};
#endif // CHUNK_H__

33
H/define.h Executable file
View File

@ -0,0 +1,33 @@
#ifndef DEFINE_H__
#define DEFINE_H__
#include <GL/glew.h>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <thread>
#include <list>
#ifdef _WIN32
#include <windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#else
#include <GL/glew.h>
#include <unistd.h>
#endif
#define CHUNK_SIZE_X 16
#define CHUNK_SIZE_Y 128
#define CHUNK_SIZE_Z 16
typedef uint8_t BlockType;
enum BLOCK_TYPE { BTYPE_AIR , BTYPE_DARK , BTYPE_DARKER , BTYPE_LIGHT , BTYPE_LIGHTER, BTYPE_LAST, BTYPE_MOB};
#define TEXTURE_PATH "../The_Land_of_Wild_Blocs/media/textures/"
#define SHADER_PATH "../The_Land_of_Wild_Blocs/media/shaders/"
#define VIEW_DISTANCE 128
#endif // DEFINE_H__

84
H/engine.h Executable file
View File

@ -0,0 +1,84 @@
#ifndef ENGINE_H__
#define ENGINE_H__
#include "define.h"
#include "openglcontext.h"
#include "texture.h"
#include "player.h"
#include "shader.h"
#include "chunk.h"
#include "textureatlas.h"
#include "blockinfo.h"
#include "array2d.h"
#define MAX_SELECTION_DISTANCE (VIEW_DISTANCE * 2 / CHUNK_SIZE_X)
class Engine : public OpenglContext
{
public:
Engine();
virtual ~Engine();
virtual void Init();
virtual void DeInit();
virtual void LoadResource();
virtual void UnloadResource();
virtual void Render(float elapsedTime);
virtual void KeyPressEvent(unsigned char key);
virtual void KeyReleaseEvent(unsigned char key);
virtual void MouseMoveEvent(int x, int y);
virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y);
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
virtual void PrintText(unsigned int x, unsigned int y, const std::string& t);
virtual void DrawHud(float elapsedTime);
virtual int GetFps(float elapsedTime);
Chunk* ChunkAt(float x, float y, float z) const;
BlockType BlockAt(float x, float y, float z, BlockType defaultBlockType) const;
void SetBlockAt(float x, float y, float z, BlockType BlockToSet) const;
Chunk* ChunkAt(const Vector3<float>& pos) const;
bool IsWalking();
void GetBlocAtCursor();
void SaveGame();
void LoadGame(std::ifstream SaveFile);
public:
bool m_run = false;
bool m_walk = false;
private:
bool LoadTexture(Texture& texture, const std::string& filename, bool stopOnError = true);
void CreateBloc();
void DestroyBloc();
void DestroyBlocGenerateMob();
void HitMob();
Mob MobAt(int x, int y, int z);
private:
bool m_wireframe = false;
float m_jumpsize = 0.f;
long m_points = 1;
TextureAtlas m_textureAtlas;
Texture m_textureFont;
Texture m_textureCrosshair;
Texture m_textureMob;
Shader m_shader01;
Chunk m_testChunk;
Array2d<Chunk*> m_chunks;
Player m_p1;
Vector4f m_currentBlock;
Vector3f m_currentFaceNormal;
std::list<Vector4f> m_ModifiedBlocks;
BlockInfo m_bi[BTYPE_LAST];
Mob m_currentMob;
Mob m_lastMob;
std::vector<Mob> m_mobs;
BlockType m_selectedbloc = BTYPE_DARK;
bool m_shift = false;
bool m_keyW = false;
bool m_keyA = false;
bool m_keyS = false;
bool m_keyD = false;
bool m_space = false;
bool m_InJump = false;
};
#endif // ENGINE_H__

571
H/matrix4.h Executable file
View File

@ -0,0 +1,571 @@
#ifndef MATRIX4_H__
#define MATRIX4_H__
#include <ostream>
#include <sstream>
#include <string>
#include "define.h"
#include "vector3.h"
#ifndef M_PI
#define M_PI 3.14159265f
#endif
#define DEGTORAD(x) ((x * M_PI) / 180.f)
#define RADTODEG(x) ((180.f * x) / M_PI)
template <class T>
class Matrix4
{
public:
typedef T Type;
public:
static const Matrix4<T> ZERO;
static const Matrix4<T> IDENTITY;
public:
Matrix4();
Matrix4(const T& v);
Matrix4(const Matrix4<T>& m);
Matrix4(const T& m_11, const T& m_12, const T& m_13, const T& m_14,
const T& m_21, const T& m_22, const T& m_23, const T& m_24,
const T& m_31, const T& m_32, const T& m_33, const T& m_34,
const T& m_41, const T& m_42, const T& m_43, const T& m_44);
const T& Get11() const;
const T& Get12() const;
const T& Get13() const;
const T& Get14() const;
const T& Get21() const;
const T& Get22() const;
const T& Get23() const;
const T& Get24() const;
const T& Get31() const;
const T& Get32() const;
const T& Get33() const;
const T& Get34() const;
const T& Get41() const;
const T& Get42() const;
const T& Get43() const;
const T& Get44() const;
Matrix4<T>& operator=(const Matrix4<T>& m);
Matrix4<T> operator+(const Matrix4<T>& m) const;
const Matrix4<T>& operator+=(const Matrix4<T>& m);
Matrix4<T> operator-(const Matrix4<T>& m) const;
Matrix4<T> operator-() const;
const Matrix4<T>& operator-=(const Matrix4<T>& m);
Matrix4<T> operator*(const Matrix4<T>& m) const;
Matrix4<T> operator*(const T& v) const;
const Matrix4<T>& operator*=(const Matrix4<T>& m);
const Matrix4<T>& operator*=(const T& v);
Matrix4<T> operator/(const T& v) const;
const Matrix4<T>& operator/=(const T& v);
bool operator==(const Matrix4<T>& m) const;
bool operator!=(const Matrix4<T>& m) const;
void SetZero();
void SetIdentity();
void SetPerspectiveProjection(const T& fov, const T& aspect, const T& nearPlane, const T& farPlane);
void SetOrthographicProjection(const T& left, const T& right, const T& bottom, const T& top, const T& nearPlane, const T& farPlane);
void SetLookAt(const Vector3<T>& eyePosition, const Vector3<T>& lookAtPosition, Vector3<T> upVector = Vector3<T>(T(0), T(1), T(0)));
bool IsZero() const;
bool IsIdentity() const;
void ApplyTranslation(const T& x, const T& y, const T& z);
void ApplyRotation(const T& angle, const T& x, const T& y, const T& z);
void ApplyScale(const T& x, const T& y, const T& z);
Vector3<T> GetTranslation() const;
const T* GetInternalValues() const;
T* GetInternalValues();
std::string ToString(const std::string& lineBegin = "|", const std::string& lineEnd = "|\n") const;
private:
union {
// column-major matrix
struct
{
T m_11, m_21, m_31, m_41, m_12, m_22, m_32, m_42, m_13, m_23, m_33, m_43, m_14, m_24, m_34, m_44;
};
T m_values[16];
};
};
typedef Matrix4<int> Matrix4i;
typedef Matrix4<float> Matrix4f;
typedef Matrix4<double> Matrix4d;
template <class T>
const Matrix4<T> Matrix4<T>::ZERO = Matrix4<T>(0);
template <class T>
const Matrix4<T> Matrix4<T>::IDENTITY = Matrix4<T>(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
template <class T>
std::ostream& operator<<(std::ostream& out, const Matrix4<T>& m)
{
out << m.ToString();
return out;
}
template <class T>
Matrix4<T>::Matrix4()
{
// Leave matrix uninitialized
}
template <class T>
Matrix4<T>::Matrix4(const T& v)
{
for(int i = 0; i < 16; ++i)
m_values[i] = v;
}
template <class T>
Matrix4<T>::Matrix4(const Matrix4<T>& m)
{
for(int i = 0; i < 16; ++i)
m_values[i] = m.m_values[i];
}
template <class T>
Matrix4<T>::Matrix4(const T& m_11, const T& m_12, const T& m_13, const T& m_14,
const T& m_21, const T& m_22, const T& m_23, const T& m_24,
const T& m_31, const T& m_32, const T& m_33, const T& m_34,
const T& m_41, const T& m_42, const T& m_43, const T& m_44)
{
this->m_11 = m_11;
this->m_12 = m_12;
this->m_13 = m_13;
this->m_14 = m_14;
this->m_21 = m_21;
this->m_22 = m_22;
this->m_23 = m_23;
this->m_24 = m_24;
this->m_31 = m_31;
this->m_32 = m_32;
this->m_33 = m_33;
this->m_34 = m_34;
this->m_41 = m_41;
this->m_42 = m_42;
this->m_43 = m_43;
this->m_44 = m_44;
}
template <class T>
const T& Matrix4<T>::Get11() const
{
return m_11;
}
template <class T>
const T& Matrix4<T>::Get12() const
{
return m_12;
}
template <class T>
const T& Matrix4<T>::Get13() const
{
return m_13;
}
template <class T>
const T& Matrix4<T>::Get14() const
{
return m_14;
}
template <class T>
const T& Matrix4<T>::Get21() const
{
return m_21;
}
template <class T>
const T& Matrix4<T>::Get22() const
{
return m_22;
}
template <class T>
const T& Matrix4<T>::Get23() const
{
return m_23;
}
template <class T>
const T& Matrix4<T>::Get24() const
{
return m_24;
}
template <class T>
const T& Matrix4<T>::Get31() const
{
return m_31;
}
template <class T>
const T& Matrix4<T>::Get32() const
{
return m_32;
}
template <class T>
const T& Matrix4<T>::Get33() const
{
return m_33;
}
template <class T>
const T& Matrix4<T>::Get34() const
{
return m_34;
}
template <class T>
const T& Matrix4<T>::Get41() const
{
return m_41;
}
template <class T>
const T& Matrix4<T>::Get42() const
{
return m_42;
}
template <class T>
const T& Matrix4<T>::Get43() const
{
return m_43;
}
template <class T>
const T& Matrix4<T>::Get44() const
{
return m_44;
}
template <class T>
Matrix4<T>& Matrix4<T>::operator=(const Matrix4<T>& m)
{
if(this != &m)
{
for(int i = 0; i < 16; ++i)
m_values[i] = m.m_values[i];
}
return *this;
}
template <class T>
Matrix4<T> Matrix4<T>::operator+(const Matrix4<T>& m) const
{
return Matrix4<T>(
m_11 + m.m_11, m_12 + m.m_12, m_13 + m.m_13, m_14 + m.m_14,
m_21 + m.m_21, m_22 + m.m_22, m_23 + m.m_23, m_24 + m.m_24,
m_31 + m.m_31, m_32 + m.m_32, m_33 + m.m_33, m_34 + m.m_34,
m_41 + m.m_41, m_42 + m.m_42, m_43 + m.m_43, m_44 + m.m_44);
}
template <class T>
const Matrix4<T>& Matrix4<T>::operator+=(const Matrix4<T>& m)
{
*this = *this + m;
return *this;
}
template <class T>
Matrix4<T> Matrix4<T>::operator-(const Matrix4<T>& m) const
{
return Matrix4<T>(
m_11 - m.m_11, m_12 - m.m_12, m_13 - m.m_13, m_14 - m.m_14,
m_21 - m.m_21, m_22 - m.m_22, m_23 - m.m_23, m_24 - m.m_24,
m_31 - m.m_31, m_32 - m.m_32, m_33 - m.m_33, m_34 - m.m_34,
m_41 - m.m_41, m_42 - m.m_42, m_43 - m.m_43, m_44 - m.m_44);
}
template <class T>
Matrix4<T> Matrix4<T>::operator-() const
{
return Matrix4<T>(
-m_11, -m_12, -m_13, -m_14,
-m_21, -m_22, -m_23, -m_24,
-m_31, -m_32, -m_33, -m_34,
-m_41, -m_42, -m_43, -m_44);
}
template <class T>
const Matrix4<T>& Matrix4<T>::operator-=(const Matrix4<T>& m)
{
*this = *this - m;
return *this;
}
template <class T>
Matrix4<T> Matrix4<T>::operator*(const Matrix4<T>& m) const
{
return Matrix4<T>(
m_11 * m.m_11 + m_12 * m.m_21 + m_13 * m.m_31 + m_14 * m.m_41,
m_11 * m.m_12 + m_12 * m.m_22 + m_13 * m.m_32 + m_14 * m.m_42,
m_11 * m.m_13 + m_12 * m.m_23 + m_13 * m.m_33 + m_14 * m.m_43,
m_11 * m.m_14 + m_12 * m.m_24 + m_13 * m.m_34 + m_14 * m.m_44,
m_21 * m.m_11 + m_22 * m.m_21 + m_23 * m.m_31 + m_24 * m.m_41,
m_21 * m.m_12 + m_22 * m.m_22 + m_23 * m.m_32 + m_24 * m.m_42,
m_21 * m.m_13 + m_22 * m.m_23 + m_23 * m.m_33 + m_24 * m.m_43,
m_21 * m.m_14 + m_22 * m.m_24 + m_23 * m.m_34 + m_24 * m.m_44,
m_31 * m.m_11 + m_32 * m.m_21 + m_33 * m.m_31 + m_34 * m.m_41,
m_31 * m.m_12 + m_32 * m.m_22 + m_33 * m.m_32 + m_34 * m.m_42,
m_31 * m.m_13 + m_32 * m.m_23 + m_33 * m.m_33 + m_34 * m.m_43,
m_31 * m.m_14 + m_32 * m.m_24 + m_33 * m.m_34 + m_34 * m.m_44,
m_41 * m.m_11 + m_42 * m.m_21 + m_43 * m.m_31 + m_44 * m.m_41,
m_41 * m.m_12 + m_42 * m.m_22 + m_43 * m.m_32 + m_44 * m.m_42,
m_41 * m.m_13 + m_42 * m.m_23 + m_43 * m.m_33 + m_44 * m.m_43,
m_41 * m.m_14 + m_42 * m.m_24 + m_43 * m.m_34 + m_44 * m.m_44);
}
template <class T>
Matrix4<T> Matrix4<T>::operator*(const T& v) const
{
return Matrix4<T>(
m_11 * v, m_12 * v, m_13 * v, m_14 * v,
m_21 * v, m_22 * v, m_23 * v, m_24 * v,
m_31 * v, m_32 * v, m_33 * v, m_34 * v,
m_41 * v, m_42 * v, m_43 * v, m_44 * v);
}
template <class T>
const Matrix4<T>& Matrix4<T>::operator*=(const Matrix4<T>& m)
{
*this = *this * m;
return *this;
}
template <class T>
const Matrix4<T>& Matrix4<T>::operator*=(const T& v)
{
*this = *this * v;
return *this;
}
template <class T>
Matrix4<T> Matrix4<T>::operator/(const T& v) const
{
return Matrix4<T>(
m_11 / v, m_12 / v, m_13 / v, m_14 / v,
m_21 / v, m_22 / v, m_23 / v, m_24 / v,
m_31 / v, m_32 / v, m_33 / v, m_34 / v,
m_41 / v, m_42 / v, m_43 / v, m_44 / v);
}
template <class T>
const Matrix4<T>& Matrix4<T>::operator/=(const T& v)
{
*this = *this / v;
return *this;
}
template <class T>
bool Matrix4<T>::operator==(const Matrix4<T>& m) const
{
for(int i = 0; i < 16; ++i)
if(m_values[i] != m.m_values[i])
return false;
return true;
}
template <class T>
bool Matrix4<T>::operator!=(const Matrix4<T>& m) const
{
return !(*this == m);
}
template <class T>
void Matrix4<T>::SetZero()
{
*this = ZERO;
}
template <class T>
void Matrix4<T>::SetIdentity()
{
*this = IDENTITY;
}
template <class T>
void Matrix4<T>::SetPerspectiveProjection(const T& fov, const T& aspect, const T& nearPlane, const T& farPlane)
{
const float h = T(1) / tan(fov * T(M_PI / 360.f));
T negDepth = nearPlane - farPlane;
SetZero();
m_11 = h / aspect;
m_22 = h;
m_33 = (farPlane + nearPlane) / negDepth;
m_34 = T(2) * (nearPlane * farPlane) / negDepth;
m_43 = -T(1);
}
template <class T>
void Matrix4<T>::SetOrthographicProjection(const T& left, const T& right, const T& bottom, const T& top, const T& nearPlane, const T& farPlane)
{
m_11 = T(2) / (right - left);
m_12 = T(0);
m_13 = T(0);
m_14 = -(right + left) / (right - left);
m_21 = T(0);
m_22 = T(2) / (top - bottom);
m_23 = T(0);
m_24 = -(top + bottom) / (top - bottom);
m_31 = T(0);
m_32 = T(0);
m_33 = -T(2) / (farPlane - nearPlane);
m_34 = -(farPlane + nearPlane) / (farPlane - nearPlane);
m_41 = T(0);
m_42 = T(0);
m_43 = T(0);
m_44 = T(1);
}
template <class T>
void Matrix4<T>::SetLookAt(const Vector3<T>& eyePosition, const Vector3<T>& lookAtPosition, Vector3<T> upVector)
{
Vector3f L = lookAtPosition - eyePosition;
L.Normalize();
upVector.Normalize();
Vector3f S = L.Cross(upVector);
S.Normalize();
Vector3f U = S.Cross(L);
Matrix4<T> M;
M.m_11 = S.x;
M.m_12 = S.y;
M.m_13 = S.z;
M.m_14 = 0;
M.m_21 = U.x;
M.m_22 = U.y;
M.m_23 = U.z;
M.m_24 = 0;
M.m_31 = -L.x;
M.m_32 = -L.y;
M.m_33 = -L.z;
M.m_34 = 0;
M.m_41 = 0;
M.m_42 = 0;
M.m_43 = 0;
M.m_44 = 1.f;
SetIdentity();
*this *= M;
ApplyTranslation(-eyePosition.x, -eyePosition.y, -eyePosition.z);
}
template <class T>
void Matrix4<T>::ApplyTranslation(const T& x, const T& y, const T& z)
{
Matrix4<T> tmp(
1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1);
*this *= tmp;
}
template <class T>
void Matrix4<T>::ApplyRotation(const T& angle, const T& x, const T& y, const T& z)
{
// TODO axis (x, y, z) must be normalized...
T s = sin(DEGTORAD(angle));
T c = cos(DEGTORAD(angle));
T ic = T(1) - c;
Matrix4<T> tmp(
x * x * ic + c, y * x * ic + (z * s), z * x * ic - (y * s), 0,
x * y * ic - (z * s), y * y * ic + c, z * y * ic + (x * s), 0,
x * z * ic + (y * s), y * z * ic - (x * s), z * z * ic + c, 0,
0, 0, 0, 1);
*this *= tmp;
}
template <class T>
void Matrix4<T>::ApplyScale(const T& x, const T& y, const T& z)
{
Matrix4<T> tmp(
x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1);
*this *= tmp;
}
template <class T>
Vector3<T> Matrix4<T>::GetTranslation() const
{
// NOTE: Works only if the matrix doesn't contains scale information (only rotation and translation)
// Reference: http://www.gamedev.net/topic/397751-how-to-get-camera-position/
T x = -(m_11 * m_14 + m_21 * m_24 + m_31 * m_34);
T y = -(m_12 * m_14 + m_22 * m_24 + m_32 * m_34);
T z = -(m_13 * m_14 + m_23 * m_24 + m_33 * m_34);
return Vector3<T>(x, y, z);
}
template <class T>
T* Matrix4<T>::GetInternalValues()
{
return m_values;
}
template <class T>
const T* Matrix4<T>::GetInternalValues() const
{
return m_values;
}
template <class T>
std::string Matrix4<T>::ToString(const std::string& lineBegin, const std::string& lineEnd) const
{
std::ostringstream ss;
ss << lineBegin << m_11 << " " << m_12 << " " << m_13 << " " << m_14 << lineEnd;
ss << lineBegin << m_21 << " " << m_22 << " " << m_23 << " " << m_24 << lineEnd;
ss << lineBegin << m_31 << " " << m_32 << " " << m_33 << " " << m_34 << lineEnd;
ss << lineBegin << m_41 << " " << m_42 << " " << m_43 << " " << m_44 << lineEnd;
return ss.str();
}
#endif // MATRIX4_H__

68
H/openglcontext.h Executable file
View File

@ -0,0 +1,68 @@
#ifndef OPENGLCONTEXT_H__
#define OPENGLCONTEXT_H__
#include "define.h"
#include <string>
#include <SFML/Window.hpp>
// Documentation de SFML: http://www.sfml-dev.org/documentation/index-fr.php
class OpenglContext
{
public:
enum MOUSE_BUTTON {
MOUSE_BUTTON_NONE = 0x00,
MOUSE_BUTTON_LEFT = 0x01,
MOUSE_BUTTON_MIDDLE = 0x02,
MOUSE_BUTTON_RIGHT = 0x04,
MOUSE_BUTTON_WHEEL_UP = 0x08,
MOUSE_BUTTON_WHEEL_DOWN = 0x10
};
OpenglContext();
virtual ~OpenglContext();
virtual void Init() = 0;
virtual void DeInit() = 0;
virtual void LoadResource() = 0;
virtual void UnloadResource() = 0;
virtual void Render(float elapsedTime) = 0;
virtual void KeyPressEvent(unsigned char key) = 0;
virtual void KeyReleaseEvent(unsigned char key) = 0;
virtual void MouseMoveEvent(int x, int y) = 0;
virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y) = 0;
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y) = 0;
bool Start(const std::string& title, int width, int height, bool fullscreen);
bool Stop();
int Width() const;
int Height() const;
void SetMaxFps(int maxFps);
int GetMaxFps() const;
void SetFullscreen(bool fullscreen);
bool IsFullscreen() const;
protected:
void CenterMouse();
void MakeRelativeToCenter(int& x, int& y) const;
void ShowCursor();
void HideCursor();
void ShowCrossCursor() const;
private:
void InitWindow(int width, int height);
MOUSE_BUTTON ConvertMouseButton(sf::Mouse::Button button) const;
private:
sf::Window m_app;
int m_maxFps;
bool m_fullscreen;
std::string m_title;
float m_lastFrameTime;
};
#endif // OPENGLCONTEXT_H__

60
H/perlin.h Executable file
View File

@ -0,0 +1,60 @@
//http://www.flipcode.com/archives/Perlin_Noise_Class.shtml
#ifndef PERLIN_H_
#define PERLIN_H_
#include <stdlib.h>
#define SAMPLE_SIZE 1024
class Perlin
{
public:
Perlin(int octaves,float freq,float amp,int seed);
float Get(float x,float y)
{
float vec[2];
vec[0] = x;
vec[1] = y;
return perlin_noise_2D(vec);
};
float Get(float x,float y, float z)
{
float vec[3];
vec[0] = x;
vec[1] = y;
vec[2] = z;
return perlin_noise_3D(vec);
};
private:
void init_perlin(int n,float p);
float perlin_noise_2D(float vec[2]);
float perlin_noise_3D(float vec[3]);
float noise1(float arg);
float noise2(float vec[2]);
float noise3(float vec[3]);
void normalize2(float v[2]);
void normalize3(float v[3]);
void init(void);
int mOctaves;
float mFrequency;
float mAmplitude;
int mSeed;
int p[SAMPLE_SIZE + SAMPLE_SIZE + 2];
float g3[SAMPLE_SIZE + SAMPLE_SIZE + 2][3];
float g2[SAMPLE_SIZE + SAMPLE_SIZE + 2][2];
float g1[SAMPLE_SIZE + SAMPLE_SIZE + 2];
bool mStart;
};
#endif

50
H/player.h Executable file
View File

@ -0,0 +1,50 @@
#ifndef PLAYER_H__
#define PLAYER_H__
#include "define.h"
#include "transformation.h"
#include "vertexbuffer.h"
#include "blockinfo.h"
struct Mob;
class Player{
public:
Player ( const Vector3f & position , float rotX = 0 , float rotY = 0);
void TurnCamera(float x, float y);
void SetPosition(Vector3f delta);
Vector3f SimulateMove ( bool front , bool back , bool left , bool right , bool run , float elapsedTime );
float SimulateJump( bool jump, bool& InJump, float& deltay, bool OnGround, float& jumpsize);
void ApplyTransformation ( Transformation & transformation ) const;
Vector3f Position();
void Damage(Mob& mob);
float Health();
void setHealth(float health);
private:
float m_rotx = 0;
float m_roty = 0;
float m_health;
float m_damage = 50.f;
Vector3f m_pos;
};
class Mob{
public:
Mob();
Mob(const Vector3f & position, float Damage, int Armour);
void SetPosition(Vector3f delta);
void Move(Player p1);
Vector3f Position();
void Damage(Player& p1);
void RenderMob();
float GetDamage();
float Health();
void setHealth(float health);
int GetArmour();
bool isNull();
bool isEqual(Mob mob);
private:
float m_health;
int m_armour;
float m_damage;
Vector3f m_pos;
};
#endif

30
H/shader.h Executable file
View File

@ -0,0 +1,30 @@
#ifndef SHADER_H__
#define SHADER_H__
#include <string>
#include "define.h"
class Shader
{
public:
bool Load(const std::string& vertFile, const std::string& fragFile, bool verbose = false);
void Use() const;
GLint BindIntUniform(const std::string& name) const;
void UpdateIntUniform(GLint name, GLint value) const;
void UpdateFloatUniform(GLint name, GLfloat value) const;
static void Disable();
private:
GLenum m_program;
GLenum m_vertexShader;
GLenum m_fragmentShader;
private:
bool CheckShaderError(GLenum shader, bool verbose);
bool CheckProgramError(GLenum program, bool showWarning, bool verbose);
};
#endif // SHADER_H__

23
H/sounds.h Executable file
View File

@ -0,0 +1,23 @@
#ifndef SOUNDS_H__
#define SOUNDS_H__
#include "define.h"
#include "engine.h"
class Sounds
{
public:
Sounds();
~Sounds();
void ManageSounds(Engine* en);
private:
void Move(Engine* en);
sf::SoundBuffer SelectSound(sf::SoundBuffer buffer, char& sound);
sf::Music m_BackgroundMusic;
sf::SoundBuffer m_buffer;
sf::Sound m_sound1;
char nextFootStep = 0;
};
#endif // SOUNDS_H__

23
H/texture.h Executable file
View File

@ -0,0 +1,23 @@
#ifndef TEXTURE_H__
#define TEXTURE_H__
#include "define.h"
#include <IL/il.h>
#include <string>
class Texture
{
public:
Texture(const std::string& filename = "");
~Texture();
bool Load(const std::string& filename);
bool IsValid() const;
void Bind() const;
private:
GLuint m_textureId;
bool m_isValid;
};
#endif // TEXTURE_H__

49
H/textureatlas.h Executable file
View File

@ -0,0 +1,49 @@
#ifndef TEXTUREATLAS_H__
#define TEXTUREATLAS_H__
#include "define.h"
#include <string>
#include <map>
#include <IL/ilu.h>
class TextureAtlas
{
public:
typedef unsigned int TextureIndex;
public:
TextureAtlas(unsigned int nbTexture);
~TextureAtlas();
TextureIndex AddTexture(const std::string& fname);
bool Generate(int textureSize, bool mipmap);
bool IsValid() const;
void Bind() const;
void TextureIndexToCoord(TextureIndex idx, float& u, float& v, float& w, float& h) const;
private:
bool IsPowerOfTwo(unsigned int x)
{
return ((x != 0) && ((x & (~x + 1)) == x));
}
private:
struct TextureInfo
{
ILuint texId;
TextureIndex texIdx;
TextureInfo(ILuint _texId, unsigned int _texIdx) : texId(_texId), texIdx(_texIdx) {}
};
// On utilise un std::map pour avoir des valeurs uniques
typedef std::map<std::string, TextureInfo> TextureList;
TextureList m_textureList;
TextureIndex m_currentTextureIndex;
GLuint m_textureId;
bool m_isValid;
unsigned int m_nbTexturePerSide;
};
#endif // TEXTUREATLAS_H__

25
H/tool.h Executable file
View File

@ -0,0 +1,25 @@
#ifndef TOOL_H__
#define TOOL_H__
#include <string>
// TODO ne pas oublier de ne pas definir DEBUGMODE en release
#ifndef DEBUGMODE
#define DEBUGMODE
#endif
#ifdef DEBUGMODE
# define CHECK_GL_ERROR() Tool::CheckGLError(__FILE__, __LINE__);
#else
# define CHECK_GL_ERROR()
#endif
class Tool
{
public:
static bool LoadTextFile(const std::string& filename, std::string& buffer);
static void CheckGLError(const char* file, int line);
};
#endif // TOOL_H__

35
H/transformation.h Executable file
View File

@ -0,0 +1,35 @@
#ifndef TRANSFORMATION_H__
#define TRANSFORMATION_H__
#include "matrix4.h"
#include "vector3.h"
#include <stack>
class Transformation
{
public:
Transformation();
void SetIdentity();
void Push();
void Pop();
void ApplyTranslation(float x, float y, float z);
void ApplyTranslation(const Vector3f& v);
void ApplyRotation(float angle, float x, float y, float z);
void ApplyRotation(float angle, const Vector3f& v);
void ApplyScale(float x, float y, float z);
void ApplyScale(const Vector3f& v);
void Use() const;
const Matrix4f& GetMatrix() const;
private:
std::stack<Matrix4f> m_stack;
};
#endif // TRANSFORMATION_H__

227
H/vector3.h Executable file
View File

@ -0,0 +1,227 @@
#ifndef VECTOR3_H__
#define VECTOR3_H__
#include <iostream>
#include <cmath>
struct Vector4f
{
float x, y, z;
int t;
Vector4f();
Vector4f(float x, float y, float z, int t) : x(x), y(y), z(z), t(t) {}
};
template <class T>
class Vector3
{
public:
Vector3();
Vector3(const T& x, const T& y, const T& z);
~Vector3();
T Length() const;
void Normalize();
void Zero();
T Dot(const Vector3<T>& v) const;
Vector3<T> Cross(const Vector3<T>& v) const;
Vector3<T> operator+(const Vector3<T>& v) const;
Vector3<T> operator-(const Vector3<T>& v) const;
Vector3<T> operator-() const;
Vector3<T> operator+(const T& v) const;
Vector3<T> operator-(const T& v) const;
Vector3<T> operator/(const T& v) const;
Vector3<T> operator*(const T& v) const;
Vector3<T>& operator=(const Vector3<T>& v);
Vector3<T>& operator+=(const Vector3<T>& v);
Vector3<T>& operator-=(const Vector3<T>& v);
Vector3<T>& operator+=(const T& v);
Vector3<T>& operator-=(const T& v);
Vector3<T>& operator/=(const T& v);
Vector3<T>& operator*=(const T& v);
bool operator==(const Vector3<T>& v) const;
bool operator!=(const Vector3<T>& v) const;
void Afficher() const;
public:
T x, y, z;
};
typedef Vector3<int> Vector3i;
typedef Vector3<float> Vector3f;
template <class T>
inline std::ostream& operator<<(std::ostream& out, const Vector3<T>& v)
{
out << "[" << v.x << ", " << v.y << ", " << v.z << "]";
return out;
}
template <class T>
Vector3<T>::Vector3()
{
}
template <class T>
Vector3<T>::Vector3(const T& x, const T& y, const T& z) : x(x), y(y), z(z)
{
}
template <class T>
Vector3<T>::~Vector3()
{
}
template <class T>
T Vector3<T>::Length() const
{
return sqrt(x*x + y*y + z*z);
}
template <class T>
void Vector3<T>::Normalize()
{
T len = Length();
if (len != 0)
{
x /= len;
y /= len;
z /= len;
}
}
template <class T>
void Vector3<T>::Zero()
{
x = y = z = 0;
}
template <class T>
T Vector3<T>::Dot(const Vector3<T>& v) const
{
return (x * v.x) + (y * v.y) + (z * v.z);
}
template <class T>
Vector3<T> Vector3<T>::Cross(const Vector3<T>& v) const
{
return Vector3<T>(
y * v.z - v.y * z,
z * v.x - v.z * x,
x * v.y - v.x * y);
}
template <class T>
Vector3<T> Vector3<T>::operator+(const Vector3<T>& v) const
{
return Vector3<T>(x + v.x, y + v.y, z + v.z);
}
template <class T>
Vector3<T> Vector3<T>::operator-(const Vector3<T>& v) const
{
return Vector3<T>(x - v.x, y - v.y, z - v.z);
}
template <class T>
Vector3<T> Vector3<T>::operator-() const
{
return Vector3<T>(-x, -y, -z);
}
template <class T>
Vector3<T> Vector3<T>::operator+(const T& v) const
{
return Vector3<T>(x + v, y + v, z + v);
}
template <class T>
Vector3<T> Vector3<T>::operator-(const T& v) const
{
return Vector3<T>(x - v, y - v, z - v);
}
template <class T>
Vector3<T> Vector3<T>::operator/(const T& v) const
{
return Vector3<T>(x / v, y / v, z / v);
}
template <class T>
Vector3<T> Vector3<T>::operator*(const T& v) const
{
return Vector3<T>(x * v, y * v, z * v);
}
template <class T>
Vector3<T>& Vector3<T>::operator=(const Vector3<T>& v)
{
x = v.x;
y = v.y;
z = v.z;
return *this;
}
template <class T>
Vector3<T>& Vector3<T>::operator+=(const Vector3<T>& v)
{
return (*this = *this + v);
}
template <class T>
Vector3<T>& Vector3<T>::operator-=(const Vector3<T>& v)
{
return (*this = *this - v);
}
template <class T>
Vector3<T>& Vector3<T>::operator+=(const T& v)
{
return (*this = *this + v);
}
template <class T>
Vector3<T>& Vector3<T>::operator-=(const T& v)
{
return (*this = *this - v);
}
template <class T>
Vector3<T>& Vector3<T>::operator/=(const T& v)
{
return (*this = *this / v);
}
template <class T>
Vector3<T>& Vector3<T>::operator*=(const T& v)
{
return (*this = *this * v);
}
template <class T>
bool Vector3<T>::operator==(const Vector3<T>& v) const
{
return (x == v.x && y == v.y && z == v.z);
}
template <class T>
bool Vector3<T>::operator!=(const Vector3<T>& v) const
{
return !(*this == v);
}
template <class T>
void Vector3<T>::Afficher() const
{
std::cout << "[" << x << ", " << y << ", " << z << "]" << std::endl;
}
#endif // VECTOR3_H__

42
H/vertexbuffer.h Executable file
View File

@ -0,0 +1,42 @@
#ifndef VERTEXBUFFER_H__
#define VERTEXBUFFER_H__
#include "define.h"
class VertexBuffer
{
public:
// Structure représentant toutes les informations de chacuns des vertex
// S'assurer que le size de cette struct reste un multiple de 32
// octet pour un maximum de performance
// Au besoin, ajouter du padding
struct VertexData
{
float x, y, z;
float r, g, b;
float u, v;
VertexData() {}
VertexData(float x, float y, float z, float r, float g, float b, float u, float v) : x(x), y(y), z(z), r(r), g(g), b(b), u(u), v(v) {}
};
public:
VertexBuffer();
~VertexBuffer();
bool IsValid() const;
void SetMeshData(VertexData* vd, int vertexCount);
void Render() const;
int Count() const;
private:
bool m_isValid;
int m_vertexCount;
GLuint m_vertexVboId;
GLuint m_indexVboId;
};
#endif // VERTEXBUFFER_H__

64
Makefile Executable file
View File

@ -0,0 +1,64 @@
SRCS = $(wildcard CPP/*.cpp)
OBJS = $(SRCS:.cpp=.o)
BINFILE = ./TheLandOfWildBlocs
CC = g++
COMPILER_FLAGS = -I/usr/X11R6/include -I/usr/local/include -I./external/noise/include -I./external/enet-1.3.1/include -finline-functions -std=c++11
LINKER_FLAGS = -lm -L/usr/X11R6/lib -L/usr/local/lib -lGL -lGLU -lpthread -lsfml-graphics -lsfml-window -lsfml-system -lsndfile -lopenal -lsfml-audio -lXrandr -lIL -lILU -lX11 -ldl -lGLEW
# Release:
#CFLAGS = -O3 -fomit-frame-pointer -ffast-math -w $(COMPILER_FLAGS)
#LFLAGS = $(LINKER_FLAGS)
# Debug:
CFLAGS = -g -W -Wall $(COMPILER_FLAGS) -Wno-write-strings -Wno-unused-parameter -Wno-switch -Wno-reorder -DDEBUGMODE -DDEBUG
LFLAGS = $(LINKER_FLAGS)
# Profiling:
#CFLAGS = -pg -W -Wall $(COMPILER_FLAGS) -Wno-write-strings
#LFLAGS = -pg $(LINKER_FLAGS)
all : $(BINFILE)
$(BINFILE) : $(OBJS)
@echo Linking to $(BINFILE)...
@$(CC) $(OBJS) -o $(BINFILE) $(LFLAGS)
%.o : %.cpp
@echo CC $@
@$(CC) $(CFLAGS) -c $< -o $@
%.o : %.cc
@echo CC $@
@$(CC) $(CFLAGS) -c $< -o $@
%.o : %.C
@echo CC $@
@$(CC) $(CFLAGS) -c $< -o $@
%.o : %.cxx
@echo CC $@
@$(CC) $(CFLAGS) -c $< -o $@
strip:
@strip $(BINFILE)
clean:
@rm -f Makefile.bak
@rm -f $(OBJS)
@rm -f gmon.out
@rm -f profiler_output.txt
@rm -f $(BINFILE)
depend:
@$(CC) -MM $(CFLAGS) $(SRCS) > Makefile.dep
@make -s clean
info:
@echo SRCS: $(SRCS)
@echo OBJS: $(OBJS)
@echo $(BINFILE)
include Makefile.dep

101
README.md Normal file → Executable file
View File

@ -1,92 +1,21 @@
# TheLandOfWildBlocs
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.com/thatscringebro/thelandofwildblocs.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.com/thatscringebro/thelandofwildblocs/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
# The Land of Wild Blocs
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
This is a small minecraft clone with a small engine designed to be small and simple. The project is made primarly in c++
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## How to compile and run the game
* Install dependencies sfml and devil
* Open a terminal in the main folder
* Run the 'Build_Run.sh' script using the following command
```bash
sh Build_Run.sh
```
The game should now compile and run as wanted. Build files are automatically deleted when the game is closed
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Developper
|Name|Github|
|--|--|
|Merlin Gelinas|thatscringebro|
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
<sub>All music and sounds used in the game was found on this website: https://soundimage.org/</sub>

140
external/devil178/include/IL/config.h vendored Executable file
View File

@ -0,0 +1,140 @@
/* include/IL/config.h. Generated by configure. */
/* include/IL/config.h.in. Generated from configure.in by autoheader. */
#ifndef __CONFIG_H__
#define __CONFIG_H__
#define IL_USE_PRAGMA_LIBS
// Supported image formats (IL)
// #define IL_NO_BLP
// #define IL_NO_BMP
// #define IL_NO_CUT
// #define IL_NO_CHEAD
// #define IL_NO_DCX
// #define IL_NO_DDS
// #define IL_NO_DICOM
// #define IL_NO_DOOM
// #define IL_NO_EXR
// #define IL_NO_FITS
// #define IL_NO_FTX
// #define IL_NO_GIF
// #define IL_NO_HDR
// #define IL_NO_ICO
// #define IL_NO_ICNS
// #define IL_NO_IWI
// #define IL_NO_JP2
// #define IL_NO_JPG
// #define IL_NO_LCMS
// #define IL_NO_LIF
// #define IL_NO_MDL
// #define IL_NO_MNG
// #define IL_NO_PCD
// #define IL_NO_PCX
// #define IL_NO_PIC
// #define IL_NO_PIX
// #define IL_NO_PNG
// #define IL_NO_PNM
// #define IL_NO_PSD
// #define IL_NO_PSP
// #define IL_NO_PXR
// #define IL_NO_RAW
// #define IL_NO_ROT
// #define IL_NO_SGI
// #define IL_NO_SUN
// #define IL_NO_TGA
// #define IL_NO_TIF
// #define IL_NO_TPL
// #define IL_NO_WAL
// #define IL_NO_WDP
// #define IL_NO_XPM
#define IL_USE_JPEGLIB_UNMODIFIED 1
//#define IL_USE_DXTC_NVIDIA
#define IL_USE_DXTC_SQUISH
/* Supported api (ilut) */
//
// sorry just
// cant get this one to work under windows
// have disabled for the now
//
// will look at it some more later
//
// Kriss
//
#undef ILUT_USE_ALLEGRO
#undef ILUT_USE_DIRECTX8
//#define ILUT_USE_DIRECTX9
//#define ILUT_USE_DIRECTX10
//#define ILUT_USE_OPENGL
//#define ILUT_USE_SDL
//#define ILUT_USE_WIN32
/* Define to 1 if you have the <dlfcn.h> header file. */
//#define HAVE_DLFCN_H 1
/* Define to 1 if you have the <inttypes.h> header file. */
//#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <memory.h> header file. */
//#define HAVE_MEMORY_H 1
/* Define to 1 if you have the <stdint.h> header file. */
//#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
//#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
//#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
//#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
//#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
//#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
//#define HAVE_UNISTD_H 1
/* Name of package */
#define IL_PACKAGE "DevIL"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define IL_PACKAGE_NAME ""
/* Define to the full name and version of this package. */
#define IL_PACKAGE_STRING ""
/* Define to the one symbol short name of this package. */
#define IL_PACKAGE_TARNAME ""
/* Define to the version of this package. */
#define IL_PACKAGE_VERSION ""
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Version number of package */
//#define IL_VERSION "1.7.3"
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
/* #undef WORDS_BIGENDIAN */
/* If using Mac OS X uncomment this line */
/* #include "macconfig.h" */
/* Define to 1 if the X Window System is missing or not being used. */
/* #undef X_DISPLAY_MISSING */
#endif /* __CONFIG_H__ */

79
external/devil178/include/IL/config.h.win vendored Executable file
View File

@ -0,0 +1,79 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__
#define IL_USE_PRAGMA_LIBS // Links to only the libraries that are requested.
#define IL_INLINE_ASM 1 // Define if you can support at least some ASM
// Supported images formats (IL)
// #define IL_NO_BLP
// #define IL_NO_BMP
// #define IL_NO_CUT
// #define IL_NO_CHEAD
// #define IL_NO_DCX
// #define IL_NO_DDS
// #define IL_NO_DICOM
// #define IL_NO_DOOM
// #define IL_NO_EXR
// #define IL_NO_FITS
// #define IL_NO_FTX
// #define IL_NO_GIF
// #define IL_NO_HDR
// #define IL_NO_ICO
// #define IL_NO_ICNS
// #define IL_NO_IWI
// #define IL_NO_JP2
// #define IL_NO_JPG
// #define IL_NO_LCMS
// #define IL_NO_LIF
// #define IL_NO_MDL
// #define IL_NO_MNG
// #define IL_NO_PCD
// #define IL_NO_PCX
// #define IL_NO_PIC
// #define IL_NO_PIX
// #define IL_NO_PNG
// #define IL_NO_PNM
// #define IL_NO_PSD
// #define IL_NO_PSP
// #define IL_NO_PXR
// #define IL_NO_RAW
// #define IL_NO_ROT
// #define IL_NO_SGI
// #define IL_NO_SUN
// #define IL_NO_TGA
// #define IL_NO_TIF
// #define IL_NO_TPL
// #define IL_NO_WAL
// #define IL_NO_WDP
// #define IL_NO_XPM
#define IL_USE_JPEGLIB_UNMODIFIED 1
#define IL_USE_DXTC_NVIDIA
#define IL_USE_DXTC_SQUISH
//#define IL_NO_GAMES
/* Supported api (ilut) */
//
// sorry just
// cant get this one to work under windows
// have disabled for the now
//
// will look at it some more later
//
// Kriss
//
#undef ILUT_USE_ALLEGRO
#undef ILUT_USE_DIRECTX8
#define ILUT_USE_DIRECTX9
#define ILUT_USE_DIRECTX10
#define ILUT_USE_OPENGL
#define ILUT_USE_SDL
#define ILUT_USE_WIN32
#endif /* __CONFIG_H__ */

View File

@ -0,0 +1,161 @@
//-----------------------------------------------------------------------------
//
// ImageLib Sources
// Copyright (C) 2000-2009 by Denton Woods
// Last modified: 01/06/2009
//
// Filename: IL/devil_internal_exports.h
//
// Description: Internal stuff for DevIL (IL, ILU and ILUT)
//
//-----------------------------------------------------------------------------
#ifndef IL_EXPORTS_H
#define IL_EXPORTS_H
#include "IL/il.h"
#ifdef DEBUG
#include <assert.h>
#else
#define assert(x)
#endif
//#ifndef NOINLINE
#ifndef INLINE
#if defined(__GNUC__)
#define INLINE extern inline
#elif defined(_MSC_VER) //@TODO: Get this working in MSVC++.
// http://www.greenend.org.uk/rjk/2003/03/inline.html
#define NOINLINE
//#define INLINE
/*#ifndef _WIN64 // Cannot use inline assembly in x64 target platform.
#define USE_WIN32_ASM
#endif//_WIN64*/
#define INLINE __inline
#else
#define INLINE inline
#endif
#endif
//#else
//#define INLINE
//#endif //NOINLINE
#ifdef __cplusplus
extern "C" {
#endif
#define IL_MAX(a,b) (((a) > (b)) ? (a) : (b))
#define IL_MIN(a,b) (((a) < (b)) ? (a) : (b))
//! Basic Palette struct
typedef struct ILpal
{
ILubyte* Palette; //!< the image palette (if any)
ILuint PalSize; //!< size of the palette (in bytes)
ILenum PalType; //!< the palette types in il.h (0x0500 range)
} ILpal;
//! The Fundamental Image structure
/*! Every bit of information about an image is stored in this internal structure.*/
typedef struct ILimage
{
ILuint Width; //!< the image's width
ILuint Height; //!< the image's height
ILuint Depth; //!< the image's depth
ILubyte Bpp; //!< bytes per pixel (now number of channels)
ILubyte Bpc; //!< bytes per channel
ILuint Bps; //!< bytes per scanline (components for IL)
ILubyte* Data; //!< the image data
ILuint SizeOfData; //!< the total size of the data (in bytes)
ILuint SizeOfPlane; //!< SizeOfData in a 2d image, size of each plane slice in a 3d image (in bytes)
ILenum Format; //!< image format (in IL enum style)
ILenum Type; //!< image type (in IL enum style)
ILenum Origin; //!< origin of the image
ILpal Pal; //!< palette details
ILuint Duration; //!< length of the time to display this "frame"
ILenum CubeFlags; //!< cube map flags for sides present in chain
struct ILimage* Mipmaps; //!< mipmapped versions of this image terminated by a NULL - usu. NULL
struct ILimage* Next; //!< next image in the chain - usu. NULL
struct ILimage* Faces; //!< next cubemap face in the chain - usu. NULL
struct ILimage* Layers; //!< subsequent layers in the chain - usu. NULL
ILuint* AnimList; //!< animation list
ILuint AnimSize; //!< animation list size
void* Profile; //!< colour profile
ILuint ProfileSize; //!< colour profile size
ILuint OffX; //!< x-offset of the image
ILuint OffY; //!< y-offset of the image
ILubyte* DxtcData; //!< compressed data
ILenum DxtcFormat; //!< compressed data format
ILuint DxtcSize; //!< compressed data size
} ILimage;
// Memory functions
ILAPI void* ILAPIENTRY ialloc(const ILsizei Size);
ILAPI void ILAPIENTRY ifree(const void *Ptr);
ILAPI void* ILAPIENTRY icalloc(const ILsizei Size, const ILsizei Num);
#ifdef ALTIVEC_GCC
ILAPI void* ILAPIENTRY ivec_align_buffer(void *buffer, const ILuint size);
#endif
// Internal library functions in IL
ILAPI ILimage* ILAPIENTRY ilGetCurImage(void);
ILAPI void ILAPIENTRY ilSetCurImage(ILimage *Image);
ILAPI void ILAPIENTRY ilSetError(ILenum Error);
ILAPI void ILAPIENTRY ilSetPal(ILpal *Pal);
//
// Utility functions
//
ILAPI ILubyte ILAPIENTRY ilGetBppFormat(ILenum Format);
ILAPI ILenum ILAPIENTRY ilGetFormatBpp(ILubyte Bpp);
ILAPI ILubyte ILAPIENTRY ilGetBpcType(ILenum Type);
ILAPI ILenum ILAPIENTRY ilGetTypeBpc(ILubyte Bpc);
ILAPI ILubyte ILAPIENTRY ilGetBppPal(ILenum PalType);
ILAPI ILenum ILAPIENTRY ilGetPalBaseType(ILenum PalType);
ILAPI ILuint ILAPIENTRY ilNextPower2(ILuint Num);
ILAPI ILenum ILAPIENTRY ilTypeFromExt(ILconst_string FileName);
ILAPI void ILAPIENTRY ilReplaceCurImage(ILimage *Image);
ILAPI void ILAPIENTRY iMemSwap(ILubyte *, ILubyte *, const ILuint);
//
// Image functions
//
ILAPI void ILAPIENTRY iBindImageTemp (void);
ILAPI ILboolean ILAPIENTRY ilClearImage_ (ILimage *Image);
ILAPI void ILAPIENTRY ilCloseImage (ILimage *Image);
ILAPI void ILAPIENTRY ilClosePal (ILpal *Palette);
ILAPI ILpal* ILAPIENTRY iCopyPal (void);
ILAPI ILboolean ILAPIENTRY ilCopyImageAttr (ILimage *Dest, ILimage *Src);
ILAPI ILimage* ILAPIENTRY ilCopyImage_ (ILimage *Src);
ILAPI void ILAPIENTRY ilGetClear (void *Colours, ILenum Format, ILenum Type);
ILAPI ILuint ILAPIENTRY ilGetCurName (void);
ILAPI ILboolean ILAPIENTRY ilIsValidPal (ILpal *Palette);
ILAPI ILimage* ILAPIENTRY ilNewImage (ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc);
ILAPI ILimage* ILAPIENTRY ilNewImageFull (ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data);
ILAPI ILboolean ILAPIENTRY ilInitImage (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data);
ILAPI ILboolean ILAPIENTRY ilResizeImage (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILubyte Bpc);
ILAPI ILboolean ILAPIENTRY ilTexImage_ (ILimage *Image, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp, ILenum Format, ILenum Type, void *Data);
ILAPI ILboolean ILAPIENTRY ilTexSubImage_ (ILimage *Image, void *Data);
ILAPI void* ILAPIENTRY ilConvertBuffer (ILuint SizeOfData, ILenum SrcFormat, ILenum DestFormat, ILenum SrcType, ILenum DestType, ILpal *SrcPal, void *Buffer);
ILAPI ILimage* ILAPIENTRY iConvertImage (ILimage *Image, ILenum DestFormat, ILenum DestType);
ILAPI ILpal* ILAPIENTRY iConvertPal (ILpal *Pal, ILenum DestFormat);
ILAPI ILubyte* ILAPIENTRY iGetFlipped (ILimage *Image);
ILAPI ILboolean ILAPIENTRY iMirror();
ILAPI void ILAPIENTRY iFlipBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num);
ILubyte* iFlipNewBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num);
ILAPI void ILAPIENTRY iGetIntegervImage(ILimage *Image, ILenum Mode, ILint *Param);
// Internal library functions in ILU
ILAPI ILimage* ILAPIENTRY iluRotate_(ILimage *Image, ILfloat Angle);
ILAPI ILimage* ILAPIENTRY iluRotate3D_(ILimage *Image, ILfloat x, ILfloat y, ILfloat z, ILfloat Angle);
ILAPI ILimage* ILAPIENTRY iluScale_(ILimage *Image, ILuint Width, ILuint Height, ILuint Depth);
#ifdef __cplusplus
}
#endif
#endif//IL_EXPORTS_H

644
external/devil178/include/IL/il.h vendored Executable file
View File

@ -0,0 +1,644 @@
//-----------------------------------------------------------------------------
//
// ImageLib Sources
// Copyright (C) 2000-2009 by Denton Woods
// Last modified: 03/07/2009
//
// Filename: IL/il.h
//
// Description: The main include file for DevIL
//
//-----------------------------------------------------------------------------
// Doxygen comment
/*! \file il.h
The main include file for DevIL
*/
#ifndef __il_h_
#ifndef __IL_H__
#define __il_h_
#define __IL_H__
#ifdef __cplusplus
extern "C" {
#endif
//this define controls if floats and doubles are clampled to [0..1]
//during conversion. It takes a little more time, but it is the correct
//way of doing this. If you are sure your floats are always valid,
//you can undefine this value...
#define CLAMP_HALF 1
#define CLAMP_FLOATS 1
#define CLAMP_DOUBLES 1
/*#ifdef _WIN32_WCE
#define IL_NO_EXR
#define IL_NO_GIF
#define IL_NO_JP2
#define IL_NO_JPG
#define IL_NO_MNG
#define IL_NO_PNG
#define IL_NO_TIF
#define IL_NO_LCMS
#endif //_WIN32_WCE
#ifdef DJGPP
#define IL_NO_EXR
#define IL_NO_GIF
#define IL_NO_JP2
#define IL_NO_JPG
#define IL_NO_MNG
#define IL_NO_PNG
#define IL_NO_TIF
#define IL_NO_LCMS
#endif //DJGPP*/
#ifdef _WIN32
#if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY))
#if defined(_MSC_VER) || defined(__BORLANDC__)
#pragma comment(lib, "DevIL.lib")
#endif
#endif
#endif
#ifdef RESTRICT_KEYWORD
#define RESTRICT restrict
#define CONST_RESTRICT const restrict
#else
#define RESTRICT
#define CONST_RESTRICT const
#endif
#include <stdio.h>
typedef unsigned int ILenum;
typedef unsigned char ILboolean;
typedef unsigned int ILbitfield;
typedef signed char ILbyte;
typedef signed short ILshort;
typedef int ILint;
typedef size_t ILsizei;
typedef unsigned char ILubyte;
typedef unsigned short ILushort;
typedef unsigned int ILuint;
typedef float ILfloat;
typedef float ILclampf;
typedef double ILdouble;
typedef double ILclampd;
#ifdef _MSC_VER
typedef __int64 ILint64;
typedef unsigned __int64 ILuint64;
#else
typedef long long int ILint64;
typedef long long unsigned int ILuint64;
#endif
#include <limits.h>
#ifdef _UNICODE
#ifndef _WIN32_WCE
#include <wchar.h>
#endif
//if we use a define instead of a typedef,
//ILconst_string works as intended
#define ILchar wchar_t
#define ILstring wchar_t*
#define ILconst_string wchar_t const *
#else
//if we use a define instead of a typedef,
//ILconst_string works as intended
#define ILchar char
#define ILstring char*
#define ILconst_string char const *
#endif //_UNICODE
#define IL_FALSE 0
#define IL_TRUE 1
// Matches OpenGL's right now.
//! Data formats \link Formats Formats\endlink
#define IL_COLOUR_INDEX 0x1900
#define IL_COLOR_INDEX 0x1900
#define IL_ALPHA 0x1906
#define IL_RGB 0x1907
#define IL_RGBA 0x1908
#define IL_BGR 0x80E0
#define IL_BGRA 0x80E1
#define IL_LUMINANCE 0x1909
#define IL_LUMINANCE_ALPHA 0x190A
//! Data types \link Types Types\endlink
#define IL_BYTE 0x1400
#define IL_UNSIGNED_BYTE 0x1401
#define IL_SHORT 0x1402
#define IL_UNSIGNED_SHORT 0x1403
#define IL_INT 0x1404
#define IL_UNSIGNED_INT 0x1405
#define IL_FLOAT 0x1406
#define IL_DOUBLE 0x140A
#define IL_HALF 0x140B
#define IL_MAX_BYTE SCHAR_MAX
#define IL_MAX_UNSIGNED_BYTE UCHAR_MAX
#define IL_MAX_SHORT SHRT_MAX
#define IL_MAX_UNSIGNED_SHORT USHRT_MAX
#define IL_MAX_INT INT_MAX
#define IL_MAX_UNSIGNED_INT UINT_MAX
#define IL_LIMIT(x,m,M) (x<m?m:(x>M?M:x))
#define IL_CLAMP(x) IL_LIMIT(x,0,1)
#define IL_VENDOR 0x1F00
#define IL_LOAD_EXT 0x1F01
#define IL_SAVE_EXT 0x1F02
//
// IL-specific #define's
//
#define IL_VERSION_1_7_8 1
#define IL_VERSION 178
// Attribute Bits
#define IL_ORIGIN_BIT 0x00000001
#define IL_FILE_BIT 0x00000002
#define IL_PAL_BIT 0x00000004
#define IL_FORMAT_BIT 0x00000008
#define IL_TYPE_BIT 0x00000010
#define IL_COMPRESS_BIT 0x00000020
#define IL_LOADFAIL_BIT 0x00000040
#define IL_FORMAT_SPECIFIC_BIT 0x00000080
#define IL_ALL_ATTRIB_BITS 0x000FFFFF
// Palette types
#define IL_PAL_NONE 0x0400
#define IL_PAL_RGB24 0x0401
#define IL_PAL_RGB32 0x0402
#define IL_PAL_RGBA32 0x0403
#define IL_PAL_BGR24 0x0404
#define IL_PAL_BGR32 0x0405
#define IL_PAL_BGRA32 0x0406
// Image types
#define IL_TYPE_UNKNOWN 0x0000
#define IL_BMP 0x0420 //!< Microsoft Windows Bitmap - .bmp extension
#define IL_CUT 0x0421 //!< Dr. Halo - .cut extension
#define IL_DOOM 0x0422 //!< DooM walls - no specific extension
#define IL_DOOM_FLAT 0x0423 //!< DooM flats - no specific extension
#define IL_ICO 0x0424 //!< Microsoft Windows Icons and Cursors - .ico and .cur extensions
#define IL_JPG 0x0425 //!< JPEG - .jpg, .jpe and .jpeg extensions
#define IL_JFIF 0x0425 //!<
#define IL_ILBM 0x0426 //!< Amiga IFF (FORM ILBM) - .iff, .ilbm, .lbm extensions
#define IL_PCD 0x0427 //!< Kodak PhotoCD - .pcd extension
#define IL_PCX 0x0428 //!< ZSoft PCX - .pcx extension
#define IL_PIC 0x0429 //!< PIC - .pic extension
#define IL_PNG 0x042A //!< Portable Network Graphics - .png extension
#define IL_PNM 0x042B //!< Portable Any Map - .pbm, .pgm, .ppm and .pnm extensions
#define IL_SGI 0x042C //!< Silicon Graphics - .sgi, .bw, .rgb and .rgba extensions
#define IL_TGA 0x042D //!< TrueVision Targa File - .tga, .vda, .icb and .vst extensions
#define IL_TIF 0x042E //!< Tagged Image File Format - .tif and .tiff extensions
#define IL_CHEAD 0x042F //!< C-Style Header - .h extension
#define IL_RAW 0x0430 //!< Raw Image Data - any extension
#define IL_MDL 0x0431 //!< Half-Life Model Texture - .mdl extension
#define IL_WAL 0x0432 //!< Quake 2 Texture - .wal extension
#define IL_LIF 0x0434 //!< Homeworld Texture - .lif extension
#define IL_MNG 0x0435 //!< Multiple-image Network Graphics - .mng extension
#define IL_JNG 0x0435 //!<
#define IL_GIF 0x0436 //!< Graphics Interchange Format - .gif extension
#define IL_DDS 0x0437 //!< DirectDraw Surface - .dds extension
#define IL_DCX 0x0438 //!< ZSoft Multi-PCX - .dcx extension
#define IL_PSD 0x0439 //!< Adobe PhotoShop - .psd extension
#define IL_EXIF 0x043A //!<
#define IL_PSP 0x043B //!< PaintShop Pro - .psp extension
#define IL_PIX 0x043C //!< PIX - .pix extension
#define IL_PXR 0x043D //!< Pixar - .pxr extension
#define IL_XPM 0x043E //!< X Pixel Map - .xpm extension
#define IL_HDR 0x043F //!< Radiance High Dynamic Range - .hdr extension
#define IL_ICNS 0x0440 //!< Macintosh Icon - .icns extension
#define IL_JP2 0x0441 //!< Jpeg 2000 - .jp2 extension
#define IL_EXR 0x0442 //!< OpenEXR - .exr extension
#define IL_WDP 0x0443 //!< Microsoft HD Photo - .wdp and .hdp extension
#define IL_VTF 0x0444 //!< Valve Texture Format - .vtf extension
#define IL_WBMP 0x0445 //!< Wireless Bitmap - .wbmp extension
#define IL_SUN 0x0446 //!< Sun Raster - .sun, .ras, .rs, .im1, .im8, .im24 and .im32 extensions
#define IL_IFF 0x0447 //!< Interchange File Format - .iff extension
#define IL_TPL 0x0448 //!< Gamecube Texture - .tpl extension
#define IL_FITS 0x0449 //!< Flexible Image Transport System - .fit and .fits extensions
#define IL_DICOM 0x044A //!< Digital Imaging and Communications in Medicine (DICOM) - .dcm and .dicom extensions
#define IL_IWI 0x044B //!< Call of Duty Infinity Ward Image - .iwi extension
#define IL_BLP 0x044C //!< Blizzard Texture Format - .blp extension
#define IL_FTX 0x044D //!< Heavy Metal: FAKK2 Texture - .ftx extension
#define IL_ROT 0x044E //!< Homeworld 2 - Relic Texture - .rot extension
#define IL_TEXTURE 0x044F //!< Medieval II: Total War Texture - .texture extension
#define IL_DPX 0x0450 //!< Digital Picture Exchange - .dpx extension
#define IL_UTX 0x0451 //!< Unreal (and Unreal Tournament) Texture - .utx extension
#define IL_MP3 0x0452 //!< MPEG-1 Audio Layer 3 - .mp3 extension
#define IL_JASC_PAL 0x0475 //!< PaintShop Pro Palette
// Error Types
#define IL_NO_ERROR 0x0000
#define IL_INVALID_ENUM 0x0501
#define IL_OUT_OF_MEMORY 0x0502
#define IL_FORMAT_NOT_SUPPORTED 0x0503
#define IL_INTERNAL_ERROR 0x0504
#define IL_INVALID_VALUE 0x0505
#define IL_ILLEGAL_OPERATION 0x0506
#define IL_ILLEGAL_FILE_VALUE 0x0507
#define IL_INVALID_FILE_HEADER 0x0508
#define IL_INVALID_PARAM 0x0509
#define IL_COULD_NOT_OPEN_FILE 0x050A
#define IL_INVALID_EXTENSION 0x050B
#define IL_FILE_ALREADY_EXISTS 0x050C
#define IL_OUT_FORMAT_SAME 0x050D
#define IL_STACK_OVERFLOW 0x050E
#define IL_STACK_UNDERFLOW 0x050F
#define IL_INVALID_CONVERSION 0x0510
#define IL_BAD_DIMENSIONS 0x0511
#define IL_FILE_READ_ERROR 0x0512 // 05/12/2002: Addition by Sam.
#define IL_FILE_WRITE_ERROR 0x0512
#define IL_LIB_GIF_ERROR 0x05E1
#define IL_LIB_JPEG_ERROR 0x05E2
#define IL_LIB_PNG_ERROR 0x05E3
#define IL_LIB_TIFF_ERROR 0x05E4
#define IL_LIB_MNG_ERROR 0x05E5
#define IL_LIB_JP2_ERROR 0x05E6
#define IL_LIB_EXR_ERROR 0x05E7
#define IL_UNKNOWN_ERROR 0x05FF
// Origin Definitions
#define IL_ORIGIN_SET 0x0600
#define IL_ORIGIN_LOWER_LEFT 0x0601
#define IL_ORIGIN_UPPER_LEFT 0x0602
#define IL_ORIGIN_MODE 0x0603
// Format and Type Mode Definitions
#define IL_FORMAT_SET 0x0610
#define IL_FORMAT_MODE 0x0611
#define IL_TYPE_SET 0x0612
#define IL_TYPE_MODE 0x0613
// File definitions
#define IL_FILE_OVERWRITE 0x0620
#define IL_FILE_MODE 0x0621
// Palette definitions
#define IL_CONV_PAL 0x0630
// Load fail definitions
#define IL_DEFAULT_ON_FAIL 0x0632
// Key colour and alpha definitions
#define IL_USE_KEY_COLOUR 0x0635
#define IL_USE_KEY_COLOR 0x0635
#define IL_BLIT_BLEND 0x0636
// Interlace definitions
#define IL_SAVE_INTERLACED 0x0639
#define IL_INTERLACE_MODE 0x063A
// Quantization definitions
#define IL_QUANTIZATION_MODE 0x0640
#define IL_WU_QUANT 0x0641
#define IL_NEU_QUANT 0x0642
#define IL_NEU_QUANT_SAMPLE 0x0643
#define IL_MAX_QUANT_INDEXS 0x0644 //XIX : ILint : Maximum number of colors to reduce to, default of 256. and has a range of 2-256
#define IL_MAX_QUANT_INDICES 0x0644 // Redefined, since the above #define is misspelled
// Hints
#define IL_FASTEST 0x0660
#define IL_LESS_MEM 0x0661
#define IL_DONT_CARE 0x0662
#define IL_MEM_SPEED_HINT 0x0665
#define IL_USE_COMPRESSION 0x0666
#define IL_NO_COMPRESSION 0x0667
#define IL_COMPRESSION_HINT 0x0668
// Compression
#define IL_NVIDIA_COMPRESS 0x0670
#define IL_SQUISH_COMPRESS 0x0671
// Subimage types
#define IL_SUB_NEXT 0x0680
#define IL_SUB_MIPMAP 0x0681
#define IL_SUB_LAYER 0x0682
// Compression definitions
#define IL_COMPRESS_MODE 0x0700
#define IL_COMPRESS_NONE 0x0701
#define IL_COMPRESS_RLE 0x0702
#define IL_COMPRESS_LZO 0x0703
#define IL_COMPRESS_ZLIB 0x0704
// File format-specific values
#define IL_TGA_CREATE_STAMP 0x0710
#define IL_JPG_QUALITY 0x0711
#define IL_PNG_INTERLACE 0x0712
#define IL_TGA_RLE 0x0713
#define IL_BMP_RLE 0x0714
#define IL_SGI_RLE 0x0715
#define IL_TGA_ID_STRING 0x0717
#define IL_TGA_AUTHNAME_STRING 0x0718
#define IL_TGA_AUTHCOMMENT_STRING 0x0719
#define IL_PNG_AUTHNAME_STRING 0x071A
#define IL_PNG_TITLE_STRING 0x071B
#define IL_PNG_DESCRIPTION_STRING 0x071C
#define IL_TIF_DESCRIPTION_STRING 0x071D
#define IL_TIF_HOSTCOMPUTER_STRING 0x071E
#define IL_TIF_DOCUMENTNAME_STRING 0x071F
#define IL_TIF_AUTHNAME_STRING 0x0720
#define IL_JPG_SAVE_FORMAT 0x0721
#define IL_CHEAD_HEADER_STRING 0x0722
#define IL_PCD_PICNUM 0x0723
#define IL_PNG_ALPHA_INDEX 0x0724 //XIX : ILint : the color in the palette at this index value (0-255) is considered transparent, -1 for no trasparent color
#define IL_JPG_PROGRESSIVE 0x0725
#define IL_VTF_COMP 0x0726
// DXTC definitions
#define IL_DXTC_FORMAT 0x0705
#define IL_DXT1 0x0706
#define IL_DXT2 0x0707
#define IL_DXT3 0x0708
#define IL_DXT4 0x0709
#define IL_DXT5 0x070A
#define IL_DXT_NO_COMP 0x070B
#define IL_KEEP_DXTC_DATA 0x070C
#define IL_DXTC_DATA_FORMAT 0x070D
#define IL_3DC 0x070E
#define IL_RXGB 0x070F
#define IL_ATI1N 0x0710
#define IL_DXT1A 0x0711 // Normally the same as IL_DXT1, except for nVidia Texture Tools.
// Environment map definitions
#define IL_CUBEMAP_POSITIVEX 0x00000400
#define IL_CUBEMAP_NEGATIVEX 0x00000800
#define IL_CUBEMAP_POSITIVEY 0x00001000
#define IL_CUBEMAP_NEGATIVEY 0x00002000
#define IL_CUBEMAP_POSITIVEZ 0x00004000
#define IL_CUBEMAP_NEGATIVEZ 0x00008000
#define IL_SPHEREMAP 0x00010000
// Values
#define IL_VERSION_NUM 0x0DE2
#define IL_IMAGE_WIDTH 0x0DE4
#define IL_IMAGE_HEIGHT 0x0DE5
#define IL_IMAGE_DEPTH 0x0DE6
#define IL_IMAGE_SIZE_OF_DATA 0x0DE7
#define IL_IMAGE_BPP 0x0DE8
#define IL_IMAGE_BYTES_PER_PIXEL 0x0DE8
#define IL_IMAGE_BPP 0x0DE8
#define IL_IMAGE_BITS_PER_PIXEL 0x0DE9
#define IL_IMAGE_FORMAT 0x0DEA
#define IL_IMAGE_TYPE 0x0DEB
#define IL_PALETTE_TYPE 0x0DEC
#define IL_PALETTE_SIZE 0x0DED
#define IL_PALETTE_BPP 0x0DEE
#define IL_PALETTE_NUM_COLS 0x0DEF
#define IL_PALETTE_BASE_TYPE 0x0DF0
#define IL_NUM_FACES 0x0DE1
#define IL_NUM_IMAGES 0x0DF1
#define IL_NUM_MIPMAPS 0x0DF2
#define IL_NUM_LAYERS 0x0DF3
#define IL_ACTIVE_IMAGE 0x0DF4
#define IL_ACTIVE_MIPMAP 0x0DF5
#define IL_ACTIVE_LAYER 0x0DF6
#define IL_ACTIVE_FACE 0x0E00
#define IL_CUR_IMAGE 0x0DF7
#define IL_IMAGE_DURATION 0x0DF8
#define IL_IMAGE_PLANESIZE 0x0DF9
#define IL_IMAGE_BPC 0x0DFA
#define IL_IMAGE_OFFX 0x0DFB
#define IL_IMAGE_OFFY 0x0DFC
#define IL_IMAGE_CUBEFLAGS 0x0DFD
#define IL_IMAGE_ORIGIN 0x0DFE
#define IL_IMAGE_CHANNELS 0x0DFF
# if defined __GNUC__ && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0))
// __attribute__((deprecated)) is supported by GCC 3.1 and later.
# define DEPRECATED(D) D __attribute__((deprecated))
# elif defined _MSC_VER && _MSC_VER >= 1300
// __declspec(deprecated) is supported by MSVC 7.0 and later.
# define DEPRECATED(D) __declspec(deprecated) D
# else
# define DEPRECATED (D) D
# endif
//
// Section shamelessly modified from the glut header.
//
// This is from Win32's <windef.h>
#if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__)
#define ILAPIENTRY __stdcall
#define IL_PACKSTRUCT
//#elif defined(linux) || defined(MACOSX) || defined(__CYGWIN__) //fix bug 840364
#elif defined( __GNUC__ )
// this should work for any of the above commented platforms
// plus any platform using GCC
#ifdef __MINGW32__
#define ILAPIENTRY __stdcall
#else
#define ILAPIENTRY
#endif
#define IL_PACKSTRUCT __attribute__ ((packed))
#else
#define ILAPIENTRY
#define IL_PACKSTRUCT
#endif
// This is from Win32's <wingdi.h> and <winnt.h>
#if defined(__LCC__)
#define ILAPI __stdcall
#elif defined(_WIN32) //changed 20031221 to fix bug 840421
#ifdef IL_STATIC_LIB
#define ILAPI
#else
#ifdef _IL_BUILD_LIBRARY
#define ILAPI __declspec(dllexport)
#else
#define ILAPI __declspec(dllimport)
#endif
#endif
#elif __APPLE__
#define ILAPI extern
#else
#define ILAPI
#endif
#define IL_SEEK_SET 0
#define IL_SEEK_CUR 1
#define IL_SEEK_END 2
#define IL_EOF -1
// Callback functions for file reading
typedef void* ILHANDLE;
typedef void (ILAPIENTRY *fCloseRProc)(ILHANDLE);
typedef ILboolean (ILAPIENTRY *fEofProc) (ILHANDLE);
typedef ILint (ILAPIENTRY *fGetcProc) (ILHANDLE);
typedef ILHANDLE (ILAPIENTRY *fOpenRProc) (ILconst_string);
typedef ILint (ILAPIENTRY *fReadProc) (void*, ILuint, ILuint, ILHANDLE);
typedef ILint (ILAPIENTRY *fSeekRProc) (ILHANDLE, ILint, ILint);
typedef ILint (ILAPIENTRY *fTellRProc) (ILHANDLE);
// Callback functions for file writing
typedef void (ILAPIENTRY *fCloseWProc)(ILHANDLE);
typedef ILHANDLE (ILAPIENTRY *fOpenWProc) (ILconst_string);
typedef ILint (ILAPIENTRY *fPutcProc) (ILubyte, ILHANDLE);
typedef ILint (ILAPIENTRY *fSeekWProc) (ILHANDLE, ILint, ILint);
typedef ILint (ILAPIENTRY *fTellWProc) (ILHANDLE);
typedef ILint (ILAPIENTRY *fWriteProc) (const void*, ILuint, ILuint, ILHANDLE);
// Callback functions for allocation and deallocation
typedef void* (ILAPIENTRY *mAlloc)(const ILsizei);
typedef void (ILAPIENTRY *mFree) (const void* CONST_RESTRICT);
// Registered format procedures
typedef ILenum (ILAPIENTRY *IL_LOADPROC)(ILconst_string);
typedef ILenum (ILAPIENTRY *IL_SAVEPROC)(ILconst_string);
// ImageLib Functions
ILAPI ILboolean ILAPIENTRY ilActiveFace(ILuint Number);
ILAPI ILboolean ILAPIENTRY ilActiveImage(ILuint Number);
ILAPI ILboolean ILAPIENTRY ilActiveLayer(ILuint Number);
ILAPI ILboolean ILAPIENTRY ilActiveMipmap(ILuint Number);
ILAPI ILboolean ILAPIENTRY ilApplyPal(ILconst_string FileName);
ILAPI ILboolean ILAPIENTRY ilApplyProfile(ILstring InProfile, ILstring OutProfile);
ILAPI void ILAPIENTRY ilBindImage(ILuint Image);
ILAPI ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ, ILuint SrcX, ILuint SrcY, ILuint SrcZ, ILuint Width, ILuint Height, ILuint Depth);
ILAPI ILboolean ILAPIENTRY ilClampNTSC(void);
ILAPI void ILAPIENTRY ilClearColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha);
ILAPI ILboolean ILAPIENTRY ilClearImage(void);
ILAPI ILuint ILAPIENTRY ilCloneCurImage(void);
ILAPI ILubyte* ILAPIENTRY ilCompressDXT(ILubyte *Data, ILuint Width, ILuint Height, ILuint Depth, ILenum DXTCFormat, ILuint *DXTCSize);
ILAPI ILboolean ILAPIENTRY ilCompressFunc(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilConvertImage(ILenum DestFormat, ILenum DestType);
ILAPI ILboolean ILAPIENTRY ilConvertPal(ILenum DestFormat);
ILAPI ILboolean ILAPIENTRY ilCopyImage(ILuint Src);
ILAPI ILuint ILAPIENTRY ilCopyPixels(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type, void *Data);
ILAPI ILuint ILAPIENTRY ilCreateSubImage(ILenum Type, ILuint Num);
ILAPI ILboolean ILAPIENTRY ilDefaultImage(void);
ILAPI void ILAPIENTRY ilDeleteImage(const ILuint Num);
ILAPI void ILAPIENTRY ilDeleteImages(ILsizei Num, const ILuint *Images);
ILAPI ILenum ILAPIENTRY ilDetermineType(ILconst_string FileName);
ILAPI ILenum ILAPIENTRY ilDetermineTypeF(ILHANDLE File);
ILAPI ILenum ILAPIENTRY ilDetermineTypeL(const void *Lump, ILuint Size);
ILAPI ILboolean ILAPIENTRY ilDisable(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilDxtcDataToImage(void);
ILAPI ILboolean ILAPIENTRY ilDxtcDataToSurface(void);
ILAPI ILboolean ILAPIENTRY ilEnable(ILenum Mode);
ILAPI void ILAPIENTRY ilFlipSurfaceDxtcData(void);
ILAPI ILboolean ILAPIENTRY ilFormatFunc(ILenum Mode);
ILAPI void ILAPIENTRY ilGenImages(ILsizei Num, ILuint *Images);
ILAPI ILuint ILAPIENTRY ilGenImage(void);
ILAPI ILubyte* ILAPIENTRY ilGetAlpha(ILenum Type);
ILAPI ILboolean ILAPIENTRY ilGetBoolean(ILenum Mode);
ILAPI void ILAPIENTRY ilGetBooleanv(ILenum Mode, ILboolean *Param);
ILAPI ILubyte* ILAPIENTRY ilGetData(void);
ILAPI ILuint ILAPIENTRY ilGetDXTCData(void *Buffer, ILuint BufferSize, ILenum DXTCFormat);
ILAPI ILenum ILAPIENTRY ilGetError(void);
ILAPI ILint ILAPIENTRY ilGetInteger(ILenum Mode);
ILAPI void ILAPIENTRY ilGetIntegerv(ILenum Mode, ILint *Param);
ILAPI ILuint ILAPIENTRY ilGetLumpPos(void);
ILAPI ILubyte* ILAPIENTRY ilGetPalette(void);
ILAPI ILconst_string ILAPIENTRY ilGetString(ILenum StringName);
ILAPI void ILAPIENTRY ilHint(ILenum Target, ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilInvertSurfaceDxtcDataAlpha(void);
ILAPI void ILAPIENTRY ilInit(void);
ILAPI ILboolean ILAPIENTRY ilImageToDxtcData(ILenum Format);
ILAPI ILboolean ILAPIENTRY ilIsDisabled(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilIsEnabled(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilIsImage(ILuint Image);
ILAPI ILboolean ILAPIENTRY ilIsValid(ILenum Type, ILconst_string FileName);
ILAPI ILboolean ILAPIENTRY ilIsValidF(ILenum Type, ILHANDLE File);
ILAPI ILboolean ILAPIENTRY ilIsValidL(ILenum Type, void *Lump, ILuint Size);
ILAPI void ILAPIENTRY ilKeyColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha);
ILAPI ILboolean ILAPIENTRY ilLoad(ILenum Type, ILconst_string FileName);
ILAPI ILboolean ILAPIENTRY ilLoadF(ILenum Type, ILHANDLE File);
ILAPI ILboolean ILAPIENTRY ilLoadImage(ILconst_string FileName);
ILAPI ILboolean ILAPIENTRY ilLoadL(ILenum Type, const void *Lump, ILuint Size);
ILAPI ILboolean ILAPIENTRY ilLoadPal(ILconst_string FileName);
ILAPI void ILAPIENTRY ilModAlpha(ILdouble AlphaValue);
ILAPI ILboolean ILAPIENTRY ilOriginFunc(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, ILint ZCoord);
ILAPI void ILAPIENTRY ilPopAttrib(void);
ILAPI void ILAPIENTRY ilPushAttrib(ILuint Bits);
ILAPI void ILAPIENTRY ilRegisterFormat(ILenum Format);
ILAPI ILboolean ILAPIENTRY ilRegisterLoad(ILconst_string Ext, IL_LOADPROC Load);
ILAPI ILboolean ILAPIENTRY ilRegisterMipNum(ILuint Num);
ILAPI ILboolean ILAPIENTRY ilRegisterNumFaces(ILuint Num);
ILAPI ILboolean ILAPIENTRY ilRegisterNumImages(ILuint Num);
ILAPI void ILAPIENTRY ilRegisterOrigin(ILenum Origin);
ILAPI void ILAPIENTRY ilRegisterPal(void *Pal, ILuint Size, ILenum Type);
ILAPI ILboolean ILAPIENTRY ilRegisterSave(ILconst_string Ext, IL_SAVEPROC Save);
ILAPI void ILAPIENTRY ilRegisterType(ILenum Type);
ILAPI ILboolean ILAPIENTRY ilRemoveLoad(ILconst_string Ext);
ILAPI ILboolean ILAPIENTRY ilRemoveSave(ILconst_string Ext);
ILAPI void ILAPIENTRY ilResetMemory(void); // Deprecated
ILAPI void ILAPIENTRY ilResetRead(void);
ILAPI void ILAPIENTRY ilResetWrite(void);
ILAPI ILboolean ILAPIENTRY ilSave(ILenum Type, ILconst_string FileName);
ILAPI ILuint ILAPIENTRY ilSaveF(ILenum Type, ILHANDLE File);
ILAPI ILboolean ILAPIENTRY ilSaveImage(ILconst_string FileName);
ILAPI ILuint ILAPIENTRY ilSaveL(ILenum Type, void *Lump, ILuint Size);
ILAPI ILboolean ILAPIENTRY ilSavePal(ILconst_string FileName);
ILAPI ILboolean ILAPIENTRY ilSetAlpha(ILdouble AlphaValue);
ILAPI ILboolean ILAPIENTRY ilSetData(void *Data);
ILAPI ILboolean ILAPIENTRY ilSetDuration(ILuint Duration);
ILAPI void ILAPIENTRY ilSetInteger(ILenum Mode, ILint Param);
ILAPI void ILAPIENTRY ilSetMemory(mAlloc, mFree);
ILAPI void ILAPIENTRY ilSetPixels(ILint XOff, ILint YOff, ILint ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type, void *Data);
ILAPI void ILAPIENTRY ilSetRead(fOpenRProc, fCloseRProc, fEofProc, fGetcProc, fReadProc, fSeekRProc, fTellRProc);
ILAPI void ILAPIENTRY ilSetString(ILenum Mode, const char *String);
ILAPI void ILAPIENTRY ilSetWrite(fOpenWProc, fCloseWProc, fPutcProc, fSeekWProc, fTellWProc, fWriteProc);
ILAPI void ILAPIENTRY ilShutDown(void);
ILAPI ILboolean ILAPIENTRY ilSurfaceToDxtcData(ILenum Format);
ILAPI ILboolean ILAPIENTRY ilTexImage(ILuint Width, ILuint Height, ILuint Depth, ILubyte NumChannels, ILenum Format, ILenum Type, void *Data);
ILAPI ILboolean ILAPIENTRY ilTexImageDxtc(ILint w, ILint h, ILint d, ILenum DxtFormat, const ILubyte* data);
ILAPI ILenum ILAPIENTRY ilTypeFromExt(ILconst_string FileName);
ILAPI ILboolean ILAPIENTRY ilTypeFunc(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilLoadData(ILconst_string FileName, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
ILAPI ILboolean ILAPIENTRY ilLoadDataF(ILHANDLE File, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
ILAPI ILboolean ILAPIENTRY ilLoadDataL(void *Lump, ILuint Size, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp);
ILAPI ILboolean ILAPIENTRY ilSaveData(ILconst_string FileName);
// For all those weirdos that spell "colour" without the 'u'.
#define ilClearColor ilClearColour
#define ilKeyColor ilKeyColour
#define imemclear(x,y) memset(x,0,y);
#ifdef __cplusplus
}
#endif
#endif // __IL_H__
#endif // __il_h__

205
external/devil178/include/IL/il_wrap.h vendored Executable file
View File

@ -0,0 +1,205 @@
#ifndef WRAPPER_H
#define WRAPPER_H
/*#include <il/il.h>
#include <il/ilu.h>*/
#include <IL/ilut.h> // Probably only have to #include this one
#ifdef _MSC_VER
#ifndef _IL_WRAP_BUILD_LIB
#pragma comment(lib, "il_wrap.lib")
#endif
#endif
class ilImage
{
public:
ilImage();
ilImage(char *);
ilImage(const ilImage &);
virtual ~ilImage();
ILboolean Load(char *);
ILboolean Load(char *, ILenum);
ILboolean Save(char *);
ILboolean Save(char *, ILenum);
// ImageLib functions
ILboolean ActiveImage(ILuint);
ILboolean ActiveLayer(ILuint);
ILboolean ActiveMipmap(ILuint);
ILboolean Clear(void);
ILvoid ClearColour(ILclampf, ILclampf, ILclampf, ILclampf);
ILboolean Convert(ILenum);
ILboolean Copy(ILuint);
ILboolean Default(void);
ILboolean Flip(void);
ILboolean SwapColours(void);
ILboolean Resize(ILuint, ILuint, ILuint);
ILboolean TexImage(ILuint, ILuint, ILuint, ILubyte, ILenum, ILenum, ILvoid*);
// Image handling
ILvoid Bind(void) const;
ILvoid Bind(ILuint);
ILvoid Close(void) { this->Delete(); }
ILvoid Delete(void);
ILvoid iGenBind();
ILenum PaletteAlphaIndex();
// Image characteristics
ILuint Width(void);
ILuint Height(void);
ILuint Depth(void);
ILubyte Bpp(void);
ILubyte Bitpp(void);
ILenum PaletteType(void);
ILenum Format(void);
ILenum Type(void);
ILuint NumImages(void);
ILuint NumMipmaps(void);
ILuint GetId(void) const;
ILenum GetOrigin(void);
ILubyte *GetData(void);
ILubyte *GetPalette(void);
// Rendering
ILuint BindImage(void);
ILuint BindImage(ILenum);
// Operators
ilImage& operator = (ILuint);
ilImage& operator = (const ilImage &);
protected:
ILuint Id;
private:
ILvoid iStartUp();
};
class ilFilters
{
public:
static ILboolean Alienify(ilImage &);
static ILboolean BlurAvg(ilImage &, ILuint Iter);
static ILboolean BlurGaussian(ilImage &, ILuint Iter);
static ILboolean Contrast(ilImage &, ILfloat Contrast);
static ILboolean EdgeDetectE(ilImage &);
static ILboolean EdgeDetectP(ilImage &);
static ILboolean EdgeDetectS(ilImage &);
static ILboolean Emboss(ilImage &);
static ILboolean Gamma(ilImage &, ILfloat Gamma);
static ILboolean Negative(ilImage &);
static ILboolean Noisify(ilImage &, ILubyte Factor);
static ILboolean Pixelize(ilImage &, ILuint PixSize);
static ILboolean Saturate(ilImage &, ILfloat Saturation);
static ILboolean Saturate(ilImage &, ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation);
static ILboolean ScaleColours(ilImage &, ILfloat r, ILfloat g, ILfloat b);
static ILboolean Sharpen(ilImage &, ILfloat Factor, ILuint Iter);
};
#ifdef ILUT_USE_OPENGL
class ilOgl
{
public:
static ILvoid Init(void);
static GLuint BindTex(ilImage &);
static ILboolean Upload(ilImage &, ILuint);
static GLuint Mipmap(ilImage &);
static ILboolean Screen(void);
static ILboolean Screenie(void);
};
#endif//ILUT_USE_OPENGL
#ifdef ILUT_USE_ALLEGRO
class ilAlleg
{
public:
static ILvoid Init(void);
static BITMAP *Convert(ilImage &);
};
#endif//ILUT_USE_ALLEGRO
#ifdef ILUT_USE_WIN32
class ilWin32
{
public:
static ILvoid Init(void);
static HBITMAP Convert(ilImage &);
static ILboolean GetClipboard(ilImage &);
static ILvoid GetInfo(ilImage &, BITMAPINFO *Info);
static ILubyte *GetPadData(ilImage &);
static HPALETTE GetPal(ilImage &);
static ILboolean GetResource(ilImage &, HINSTANCE hInst, ILint ID, char *ResourceType);
static ILboolean GetResource(ilImage &, HINSTANCE hInst, ILint ID, char *ResourceType, ILenum Type);
static ILboolean SetClipboard(ilImage &);
};
#endif//ILUT_USE_WIN32
class ilValidate
{
public:
static ILboolean Valid(ILenum, char *);
static ILboolean Valid(ILenum, FILE *);
static ILboolean Valid(ILenum, ILvoid *, ILuint);
protected:
private:
};
class ilState
{
public:
static ILboolean Disable(ILenum);
static ILboolean Enable(ILenum);
static ILvoid Get(ILenum, ILboolean &);
static ILvoid Get(ILenum, ILint &);
static ILboolean GetBool(ILenum);
static ILint GetInt(ILenum);
static const char *GetString(ILenum);
static ILboolean IsDisabled(ILenum);
static ILboolean IsEnabled(ILenum);
static ILboolean Origin(ILenum);
static ILvoid Pop(void);
static ILvoid Push(ILuint);
protected:
private:
};
class ilError
{
public:
static ILvoid Check(ILvoid (*Callback)(const char*));
static ILvoid Check(ILvoid (*Callback)(ILenum));
static ILenum Get(void);
static const char *String(void);
static const char *String(ILenum);
protected:
private:
};
#endif//WRAPPER_H

195
external/devil178/include/IL/ilu.h vendored Executable file
View File

@ -0,0 +1,195 @@
//-----------------------------------------------------------------------------
//
// ImageLib Utility Sources
// Copyright (C) 2000-2009 by Denton Woods
// Last modified: 03/07/2009
//
// Filename: IL/ilu.h
//
// Description: The main include file for ILU
//
//-----------------------------------------------------------------------------
// Doxygen comment
/*! \file ilu.h
The main include file for ILU
*/
#ifndef __ilu_h_
#ifndef __ILU_H__
#define __ilu_h_
#define __ILU_H__
#include <IL/il.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY))
#if defined(_MSC_VER) || defined(__BORLANDC__)
#pragma comment(lib, "ILU.lib")
#endif
#endif
#endif
#define ILU_VERSION_1_7_8 1
#define ILU_VERSION 178
#define ILU_FILTER 0x2600
#define ILU_NEAREST 0x2601
#define ILU_LINEAR 0x2602
#define ILU_BILINEAR 0x2603
#define ILU_SCALE_BOX 0x2604
#define ILU_SCALE_TRIANGLE 0x2605
#define ILU_SCALE_BELL 0x2606
#define ILU_SCALE_BSPLINE 0x2607
#define ILU_SCALE_LANCZOS3 0x2608
#define ILU_SCALE_MITCHELL 0x2609
// Error types
#define ILU_INVALID_ENUM 0x0501
#define ILU_OUT_OF_MEMORY 0x0502
#define ILU_INTERNAL_ERROR 0x0504
#define ILU_INVALID_VALUE 0x0505
#define ILU_ILLEGAL_OPERATION 0x0506
#define ILU_INVALID_PARAM 0x0509
// Values
#define ILU_PLACEMENT 0x0700
#define ILU_LOWER_LEFT 0x0701
#define ILU_LOWER_RIGHT 0x0702
#define ILU_UPPER_LEFT 0x0703
#define ILU_UPPER_RIGHT 0x0704
#define ILU_CENTER 0x0705
#define ILU_CONVOLUTION_MATRIX 0x0710
#define ILU_VERSION_NUM IL_VERSION_NUM
#define ILU_VENDOR IL_VENDOR
// Languages
#define ILU_ENGLISH 0x0800
#define ILU_ARABIC 0x0801
#define ILU_DUTCH 0x0802
#define ILU_JAPANESE 0x0803
#define ILU_SPANISH 0x0804
#define ILU_GERMAN 0x0805
#define ILU_FRENCH 0x0806
// Filters
/*
#define ILU_FILTER_BLUR 0x0803
#define ILU_FILTER_GAUSSIAN_3x3 0x0804
#define ILU_FILTER_GAUSSIAN_5X5 0x0805
#define ILU_FILTER_EMBOSS1 0x0807
#define ILU_FILTER_EMBOSS2 0x0808
#define ILU_FILTER_LAPLACIAN1 0x080A
#define ILU_FILTER_LAPLACIAN2 0x080B
#define ILU_FILTER_LAPLACIAN3 0x080C
#define ILU_FILTER_LAPLACIAN4 0x080D
#define ILU_FILTER_SHARPEN1 0x080E
#define ILU_FILTER_SHARPEN2 0x080F
#define ILU_FILTER_SHARPEN3 0x0810
*/
typedef struct ILinfo
{
ILuint Id; // the image's id
ILubyte *Data; // the image's data
ILuint Width; // the image's width
ILuint Height; // the image's height
ILuint Depth; // the image's depth
ILubyte Bpp; // bytes per pixel (not bits) of the image
ILuint SizeOfData; // the total size of the data (in bytes)
ILenum Format; // image format (in IL enum style)
ILenum Type; // image type (in IL enum style)
ILenum Origin; // origin of the image
ILubyte *Palette; // the image's palette
ILenum PalType; // palette type
ILuint PalSize; // palette size
ILenum CubeFlags; // flags for what cube map sides are present
ILuint NumNext; // number of images following
ILuint NumMips; // number of mipmaps
ILuint NumLayers; // number of layers
} ILinfo;
typedef struct ILpointf {
ILfloat x;
ILfloat y;
} ILpointf;
typedef struct ILpointi {
ILint x;
ILint y;
} ILpointi;
ILAPI ILboolean ILAPIENTRY iluAlienify(void);
ILAPI ILboolean ILAPIENTRY iluBlurAvg(ILuint Iter);
ILAPI ILboolean ILAPIENTRY iluBlurGaussian(ILuint Iter);
ILAPI ILboolean ILAPIENTRY iluBuildMipmaps(void);
ILAPI ILuint ILAPIENTRY iluColoursUsed(void);
ILAPI ILboolean ILAPIENTRY iluCompareImage(ILuint Comp);
ILAPI ILboolean ILAPIENTRY iluContrast(ILfloat Contrast);
ILAPI ILboolean ILAPIENTRY iluCrop(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, ILuint Height, ILuint Depth);
ILAPI void ILAPIENTRY iluDeleteImage(ILuint Id); // Deprecated
ILAPI ILboolean ILAPIENTRY iluEdgeDetectE(void);
ILAPI ILboolean ILAPIENTRY iluEdgeDetectP(void);
ILAPI ILboolean ILAPIENTRY iluEdgeDetectS(void);
ILAPI ILboolean ILAPIENTRY iluEmboss(void);
ILAPI ILboolean ILAPIENTRY iluEnlargeCanvas(ILuint Width, ILuint Height, ILuint Depth);
ILAPI ILboolean ILAPIENTRY iluEnlargeImage(ILfloat XDim, ILfloat YDim, ILfloat ZDim);
ILAPI ILboolean ILAPIENTRY iluEqualize(void);
ILAPI ILconst_string ILAPIENTRY iluErrorString(ILenum Error);
ILAPI ILboolean ILAPIENTRY iluConvolution(ILint *matrix, ILint scale, ILint bias);
ILAPI ILboolean ILAPIENTRY iluFlipImage(void);
ILAPI ILboolean ILAPIENTRY iluGammaCorrect(ILfloat Gamma);
ILAPI ILuint ILAPIENTRY iluGenImage(void); // Deprecated
ILAPI void ILAPIENTRY iluGetImageInfo(ILinfo *Info);
ILAPI ILint ILAPIENTRY iluGetInteger(ILenum Mode);
ILAPI void ILAPIENTRY iluGetIntegerv(ILenum Mode, ILint *Param);
ILAPI ILstring ILAPIENTRY iluGetString(ILenum StringName);
ILAPI void ILAPIENTRY iluImageParameter(ILenum PName, ILenum Param);
ILAPI void ILAPIENTRY iluInit(void);
ILAPI ILboolean ILAPIENTRY iluInvertAlpha(void);
ILAPI ILuint ILAPIENTRY iluLoadImage(ILconst_string FileName);
ILAPI ILboolean ILAPIENTRY iluMirror(void);
ILAPI ILboolean ILAPIENTRY iluNegative(void);
ILAPI ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance);
ILAPI ILboolean ILAPIENTRY iluPixelize(ILuint PixSize);
ILAPI void ILAPIENTRY iluRegionfv(ILpointf *Points, ILuint n);
ILAPI void ILAPIENTRY iluRegioniv(ILpointi *Points, ILuint n);
ILAPI ILboolean ILAPIENTRY iluReplaceColour(ILubyte Red, ILubyte Green, ILubyte Blue, ILfloat Tolerance);
ILAPI ILboolean ILAPIENTRY iluRotate(ILfloat Angle);
ILAPI ILboolean ILAPIENTRY iluRotate3D(ILfloat x, ILfloat y, ILfloat z, ILfloat Angle);
ILAPI ILboolean ILAPIENTRY iluSaturate1f(ILfloat Saturation);
ILAPI ILboolean ILAPIENTRY iluSaturate4f(ILfloat r, ILfloat g, ILfloat b, ILfloat Saturation);
ILAPI ILboolean ILAPIENTRY iluScale(ILuint Width, ILuint Height, ILuint Depth);
ILAPI ILboolean ILAPIENTRY iluScaleAlpha(ILfloat scale);
ILAPI ILboolean ILAPIENTRY iluScaleColours(ILfloat r, ILfloat g, ILfloat b);
ILAPI ILboolean ILAPIENTRY iluSetLanguage(ILenum Language);
ILAPI ILboolean ILAPIENTRY iluSharpen(ILfloat Factor, ILuint Iter);
ILAPI ILboolean ILAPIENTRY iluSwapColours(void);
ILAPI ILboolean ILAPIENTRY iluWave(ILfloat Angle);
#define iluColorsUsed iluColoursUsed
#define iluSwapColors iluSwapColours
#define iluReplaceColor iluReplaceColour
#define iluScaleColor iluScaleColour
#ifdef __cplusplus
}
#endif
#endif // __ILU_H__
#endif // __ilu_h_

25
external/devil178/include/IL/ilu_region.h vendored Executable file
View File

@ -0,0 +1,25 @@
//-----------------------------------------------------------------------------
//
// ImageLib Utility Sources
// Copyright (C) 2000-2002 by Denton Woods
// Last modified: 07/09/2002 <--Y2K Compliant! =]
//
// Filename: src-ILU/src/ilu_region.h
//
// Description: Creates an image region.
//
//-----------------------------------------------------------------------------
#ifndef ILU_REGION_H
#define ILU_REGION_H
typedef struct Edge
{
ILint yUpper;
ILfloat xIntersect, dxPerScan;
struct Edge *next;
} Edge;
#endif//ILU_REGION_H

390
external/devil178/include/IL/ilut.h vendored Executable file
View File

@ -0,0 +1,390 @@
//-----------------------------------------------------------------------------
//
// ImageLib Utility Toolkit Sources
// Copyright (C) 2000-2009 by Denton Woods
// Last modified: 03/07/2009
//
// Filename: IL/ilut.h
//
// Description: The main include file for ILUT
//
//-----------------------------------------------------------------------------
// Doxygen comment
/*! \file ilut.h
The main include file for ILUT
*/
#ifndef __ilut_h_
#ifndef __ILUT_H__
#define __ilut_h_
#define __ILUT_H__
#include <IL/il.h>
#include <IL/ilu.h>
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#define ILUT_VERSION_1_7_8 1
#define ILUT_VERSION 178
// Attribute Bits
#define ILUT_OPENGL_BIT 0x00000001
#define ILUT_D3D_BIT 0x00000002
#define ILUT_ALL_ATTRIB_BITS 0x000FFFFF
// Error Types
#define ILUT_INVALID_ENUM 0x0501
#define ILUT_OUT_OF_MEMORY 0x0502
#define ILUT_INVALID_VALUE 0x0505
#define ILUT_ILLEGAL_OPERATION 0x0506
#define ILUT_INVALID_PARAM 0x0509
#define ILUT_COULD_NOT_OPEN_FILE 0x050A
#define ILUT_STACK_OVERFLOW 0x050E
#define ILUT_STACK_UNDERFLOW 0x050F
#define ILUT_BAD_DIMENSIONS 0x0511
#define ILUT_NOT_SUPPORTED 0x0550
// State Definitions
#define ILUT_PALETTE_MODE 0x0600
#define ILUT_OPENGL_CONV 0x0610
#define ILUT_D3D_MIPLEVELS 0x0620
#define ILUT_MAXTEX_WIDTH 0x0630
#define ILUT_MAXTEX_HEIGHT 0x0631
#define ILUT_MAXTEX_DEPTH 0x0632
#define ILUT_GL_USE_S3TC 0x0634
#define ILUT_D3D_USE_DXTC 0x0634
#define ILUT_GL_GEN_S3TC 0x0635
#define ILUT_D3D_GEN_DXTC 0x0635
#define ILUT_S3TC_FORMAT 0x0705
#define ILUT_DXTC_FORMAT 0x0705
#define ILUT_D3D_POOL 0x0706
#define ILUT_D3D_ALPHA_KEY_COLOR 0x0707
#define ILUT_D3D_ALPHA_KEY_COLOUR 0x0707
#define ILUT_FORCE_INTEGER_FORMAT 0x0636
//This new state does automatic texture target detection
//if enabled. Currently, only cubemap detection is supported.
//if the current image is no cubemap, the 2d texture is chosen.
#define ILUT_GL_AUTODETECT_TEXTURE_TARGET 0x0807
// Values
#define ILUT_VERSION_NUM IL_VERSION_NUM
#define ILUT_VENDOR IL_VENDOR
// The different rendering api's...more to be added later?
#define ILUT_OPENGL 0
#define ILUT_ALLEGRO 1
#define ILUT_WIN32 2
#define ILUT_DIRECT3D8 3
#define ILUT_DIRECT3D9 4
#define ILUT_X11 5
#define ILUT_DIRECT3D10 6
/*
// Includes specific config
#ifdef DJGPP
#define ILUT_USE_ALLEGRO
#elif _WIN32_WCE
#define ILUT_USE_WIN32
#elif _WIN32
//#ifdef __GNUC__ //__CYGWIN32__ (Cygwin seems to not define this with DevIL builds)
#define ILUT_USE_WIN32
#include "IL/config.h"
// Temporary fix for the SDL main() linker bug.
//#ifdef ILUT_USE_SDL
//#undef ILUT_USE_SDL
//#endif//ILUT_USE_SDL
//#else
// #define ILUT_USE_WIN32
// #define ILUT_USE_OPENGL
// #define ILUT_USE_SDL
// #define ILUT_USE_DIRECTX8
//#endif
#elif BEOS // Don't know the #define
#define ILUT_USE_BEOS
#define ILUT_USE_OPENGL
#elif MACOSX
#define ILUT_USE_OPENGL
#else
// We are surely using a *nix so the configure script
// may have written the configured config.h header
#include "IL/config.h"
#endif
*/
#if (defined(_WIN32) || defined(_WIN64))
#if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY))
#if defined(_MSC_VER) || defined(__BORLANDC__)
#pragma comment(lib, "ILUT.lib")
#endif
#endif
#include <IL/ilut_config.h>
#endif
//this should remain private and hidden
//#include "IL/config.h"
//////////////
// OpenGL
//////////////
#ifdef ILUT_USE_OPENGL
#if defined(_MSC_VER) || defined(_WIN32)
//#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif//_MSC_VER
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif//__APPLE__
#endif
#ifdef ILUT_USE_WIN32
//#define WIN32_LEAN_AND_MEAN
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#ifndef _WIN32_WCE
#include <crtdbg.h>
#endif
#endif
#include <windows.h>
#endif
//
// If we can avoid including these in all cases thing tend to break less
// and we can keep all of them defined as available
//
// Kriss
//
// ImageLib Utility Toolkit's Allegro Functions
#ifdef ILUT_USE_ALLEGRO
// #include <allegro.h>
#endif//ILUT_USE_ALLEGRO
#ifdef ILUT_USE_SDL
// #include <SDL.h>
#endif
#ifdef ILUT_USE_DIRECTX8
#include <d3d8.h>
#endif//ILUT_USE_DIRECTX9
#ifdef ILUT_USE_DIRECTX9
#include <d3d9.h>
#endif//ILUT_USE_DIRECTX9
#ifdef ILUT_USE_DIRECTX10
#pragma warning(push)
#pragma warning(disable : 4201) // Disables 'nonstandard extension used : nameless struct/union' warning
#include <rpcsal.h>
#include <sal.h>
#include <d3d10.h>
#pragma warning(pop)
#endif//ILUT_USE_DIRECTX10
#ifdef ILUT_USE_X11
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef ILUT_USE_XSHM
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/XShm.h>
#endif//ILUT_USE_XSHM
#endif//ILUT_USE_X11
//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
// ImageLib Utility Toolkit Functions
ILAPI ILboolean ILAPIENTRY ilutDisable(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilutEnable(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilutGetBoolean(ILenum Mode);
ILAPI void ILAPIENTRY ilutGetBooleanv(ILenum Mode, ILboolean *Param);
ILAPI ILint ILAPIENTRY ilutGetInteger(ILenum Mode);
ILAPI void ILAPIENTRY ilutGetIntegerv(ILenum Mode, ILint *Param);
ILAPI ILstring ILAPIENTRY ilutGetString(ILenum StringName);
ILAPI void ILAPIENTRY ilutInit(void);
ILAPI ILboolean ILAPIENTRY ilutIsDisabled(ILenum Mode);
ILAPI ILboolean ILAPIENTRY ilutIsEnabled(ILenum Mode);
ILAPI void ILAPIENTRY ilutPopAttrib(void);
ILAPI void ILAPIENTRY ilutPushAttrib(ILuint Bits);
ILAPI void ILAPIENTRY ilutSetInteger(ILenum Mode, ILint Param);
ILAPI ILboolean ILAPIENTRY ilutRenderer(ILenum Renderer);
// ImageLib Utility Toolkit's OpenGL Functions
#ifdef ILUT_USE_OPENGL
ILAPI GLuint ILAPIENTRY ilutGLBindTexImage();
ILAPI GLuint ILAPIENTRY ilutGLBindMipmaps(void);
ILAPI ILboolean ILAPIENTRY ilutGLBuildMipmaps(void);
ILAPI GLuint ILAPIENTRY ilutGLLoadImage(ILstring FileName);
ILAPI ILboolean ILAPIENTRY ilutGLScreen(void);
ILAPI ILboolean ILAPIENTRY ilutGLScreenie(void);
ILAPI ILboolean ILAPIENTRY ilutGLSaveImage(ILstring FileName, GLuint TexID);
ILAPI ILboolean ILAPIENTRY ilutGLSubTex2D(GLuint TexID, ILuint XOff, ILuint YOff);
ILAPI ILboolean ILAPIENTRY ilutGLSubTex3D(GLuint TexID, ILuint XOff, ILuint YOff, ILuint ZOff);
ILAPI ILboolean ILAPIENTRY ilutGLSetTex2D(GLuint TexID);
ILAPI ILboolean ILAPIENTRY ilutGLSetTex3D(GLuint TexID);
ILAPI ILboolean ILAPIENTRY ilutGLTexImage(GLuint Level);
ILAPI ILboolean ILAPIENTRY ilutGLSubTex(GLuint TexID, ILuint XOff, ILuint YOff);
ILAPI ILboolean ILAPIENTRY ilutGLSetTex(GLuint TexID); // Deprecated - use ilutGLSetTex2D.
ILAPI ILboolean ILAPIENTRY ilutGLSubTex(GLuint TexID, ILuint XOff, ILuint YOff); // Use ilutGLSubTex2D.
#endif//ILUT_USE_OPENGL
// ImageLib Utility Toolkit's Allegro Functions
#ifdef ILUT_USE_ALLEGRO
#ifdef __cplusplus
extern "C" {
#endif
#include <allegro.h>
#ifdef __cplusplus
}
#endif
ILAPI BITMAP* ILAPIENTRY ilutAllegLoadImage(ILstring FileName);
ILAPI BITMAP* ILAPIENTRY ilutConvertToAlleg(PALETTE Pal);
#endif//ILUT_USE_ALLEGRO
// ImageLib Utility Toolkit's SDL Functions
#ifdef ILUT_USE_SDL
ILAPI struct SDL_Surface* ILAPIENTRY ilutConvertToSDLSurface(unsigned int flags);
ILAPI struct SDL_Surface* ILAPIENTRY ilutSDLSurfaceLoadImage(ILstring FileName);
ILAPI ILboolean ILAPIENTRY ilutSDLSurfaceFromBitmap(struct SDL_Surface *Bitmap);
#endif//ILUT_USE_SDL
// ImageLib Utility Toolkit's BeOS Functions
#ifdef ILUT_USE_BEOS
ILAPI BBitmap ILAPIENTRY ilutConvertToBBitmap(void);
#endif//ILUT_USE_BEOS
// ImageLib Utility Toolkit's Win32 GDI Functions
#ifdef ILUT_USE_WIN32
ILAPI HBITMAP ILAPIENTRY ilutConvertToHBitmap(HDC hDC);
ILAPI HBITMAP ILAPIENTRY ilutConvertSliceToHBitmap(HDC hDC, ILuint slice);
ILAPI void ILAPIENTRY ilutFreePaddedData(ILubyte *Data);
ILAPI void ILAPIENTRY ilutGetBmpInfo(BITMAPINFO *Info);
ILAPI HPALETTE ILAPIENTRY ilutGetHPal(void);
ILAPI ILubyte* ILAPIENTRY ilutGetPaddedData(void);
ILAPI ILboolean ILAPIENTRY ilutGetWinClipboard(void);
ILAPI ILboolean ILAPIENTRY ilutLoadResource(HINSTANCE hInst, ILint ID, ILstring ResourceType, ILenum Type);
ILAPI ILboolean ILAPIENTRY ilutSetHBitmap(HBITMAP Bitmap);
ILAPI ILboolean ILAPIENTRY ilutSetHPal(HPALETTE Pal);
ILAPI ILboolean ILAPIENTRY ilutSetWinClipboard(void);
ILAPI HBITMAP ILAPIENTRY ilutWinLoadImage(ILstring FileName, HDC hDC);
ILAPI ILboolean ILAPIENTRY ilutWinLoadUrl(ILstring Url);
ILAPI ILboolean ILAPIENTRY ilutWinPrint(ILuint XPos, ILuint YPos, ILuint Width, ILuint Height, HDC hDC);
ILAPI ILboolean ILAPIENTRY ilutWinSaveImage(ILstring FileName, HBITMAP Bitmap);
#endif//ILUT_USE_WIN32
// ImageLib Utility Toolkit's DirectX 8 Functions
#ifdef ILUT_USE_DIRECTX8
// ILAPI void ILAPIENTRY ilutD3D8MipFunc(ILuint NumLevels);
ILAPI struct IDirect3DTexture8* ILAPIENTRY ilutD3D8Texture(struct IDirect3DDevice8 *Device);
ILAPI struct IDirect3DVolumeTexture8* ILAPIENTRY ilutD3D8VolumeTexture(struct IDirect3DDevice8 *Device);
ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFile(struct IDirect3DDevice8 *Device, char *FileName, struct IDirect3DTexture8 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFile(struct IDirect3DDevice8 *Device, char *FileName, struct IDirect3DVolumeTexture8 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFileInMemory(struct IDirect3DDevice8 *Device, void *Lump, ILuint Size, struct IDirect3DTexture8 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFileInMemory(struct IDirect3DDevice8 *Device, void *Lump, ILuint Size, struct IDirect3DVolumeTexture8 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromFileHandle(struct IDirect3DDevice8 *Device, ILHANDLE File, struct IDirect3DTexture8 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromFileHandle(struct IDirect3DDevice8 *Device, ILHANDLE File, struct IDirect3DVolumeTexture8 **Texture);
// These two are not tested yet.
ILAPI ILboolean ILAPIENTRY ilutD3D8TexFromResource(struct IDirect3DDevice8 *Device, HMODULE SrcModule, char *SrcResource, struct IDirect3DTexture8 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D8VolTexFromResource(struct IDirect3DDevice8 *Device, HMODULE SrcModule, char *SrcResource, struct IDirect3DVolumeTexture8 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D8LoadSurface(struct IDirect3DDevice8 *Device, struct IDirect3DSurface8 *Surface);
#endif//ILUT_USE_DIRECTX8
#ifdef ILUT_USE_DIRECTX9
#pragma warning(push)
#pragma warning(disable : 4115) // Disables 'named type definition in parentheses' warning
// ILAPI void ILAPIENTRY ilutD3D9MipFunc(ILuint NumLevels);
ILAPI struct IDirect3DTexture9* ILAPIENTRY ilutD3D9Texture (struct IDirect3DDevice9* Device);
ILAPI struct IDirect3DVolumeTexture9* ILAPIENTRY ilutD3D9VolumeTexture (struct IDirect3DDevice9* Device);
ILAPI struct IDirect3DCubeTexture9* ILAPIENTRY ilutD3D9CubeTexture (struct IDirect3DDevice9* Device);
ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DCubeTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DCubeTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DCubeTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9CubeTexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DCubeTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFile(struct IDirect3DDevice9 *Device, ILconst_string FileName, struct IDirect3DVolumeTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFileInMemory(struct IDirect3DDevice9 *Device, void *Lump, ILuint Size, struct IDirect3DVolumeTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromFileHandle(struct IDirect3DDevice9 *Device, ILHANDLE File, struct IDirect3DVolumeTexture9 **Texture);
// These three are not tested yet.
ILAPI ILboolean ILAPIENTRY ilutD3D9TexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9VolTexFromResource(struct IDirect3DDevice9 *Device, HMODULE SrcModule, ILconst_string SrcResource, struct IDirect3DVolumeTexture9 **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D9LoadSurface(struct IDirect3DDevice9 *Device, struct IDirect3DSurface9 *Surface);
#pragma warning(pop)
#endif//ILUT_USE_DIRECTX9
#ifdef ILUT_USE_DIRECTX10
ILAPI ID3D10Texture2D* ILAPIENTRY ilutD3D10Texture(ID3D10Device *Device);
ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFile(ID3D10Device *Device, ILconst_string FileName, ID3D10Texture2D **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFileInMemory(ID3D10Device *Device, void *Lump, ILuint Size, ID3D10Texture2D **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromResource(ID3D10Device *Device, HMODULE SrcModule, ILconst_string SrcResource, ID3D10Texture2D **Texture);
ILAPI ILboolean ILAPIENTRY ilutD3D10TexFromFileHandle(ID3D10Device *Device, ILHANDLE File, ID3D10Texture2D **Texture);
#endif//ILUT_USE_DIRECTX10
#ifdef ILUT_USE_X11
ILAPI XImage * ILAPIENTRY ilutXCreateImage( Display* );
ILAPI Pixmap ILAPIENTRY ilutXCreatePixmap( Display*,Drawable );
ILAPI XImage * ILAPIENTRY ilutXLoadImage( Display*,char* );
ILAPI Pixmap ILAPIENTRY ilutXLoadPixmap( Display*,Drawable,char* );
#ifdef ILUT_USE_XSHM
ILAPI XImage * ILAPIENTRY ilutXShmCreateImage( Display*,XShmSegmentInfo* );
ILAPI void ILAPIENTRY ilutXShmDestroyImage( Display*,XImage*,XShmSegmentInfo* );
ILAPI Pixmap ILAPIENTRY ilutXShmCreatePixmap( Display*,Drawable,XShmSegmentInfo* );
ILAPI void ILAPIENTRY ilutXShmFreePixmap( Display*,Pixmap,XShmSegmentInfo* );
ILAPI XImage * ILAPIENTRY ilutXShmLoadImage( Display*,char*,XShmSegmentInfo* );
ILAPI Pixmap ILAPIENTRY ilutXShmLoadPixmap( Display*,Drawable,char*,XShmSegmentInfo* );
#endif//ILUT_USE_XSHM
#endif//ILUT_USE_X11
#ifdef __cplusplus
}
#endif
#endif // __ILUT_H__
#endif // __ilut_h_

26
external/devil178/include/IL/ilut_config.h vendored Executable file
View File

@ -0,0 +1,26 @@
#ifndef __ILUT_CONFIG_H__
#define __ILUT_CONFIG_H__
#define IL_USE_PRAGMA_LIBS
// Supported APIs (ILUT)
//
// sorry just
// cant get this one to work under windows
// have disabled for the now
//
// will look at it some more later
//
// Kriss
//
#undef ILUT_USE_ALLEGRO
#undef ILUT_USE_DIRECTX8
//#define ILUT_USE_DIRECTX9
//#define ILUT_USE_DIRECTX10
#define ILUT_USE_OPENGL
//#define ILUT_USE_SDL
#define ILUT_USE_WIN32
#endif//__ILUT_CONFIG_H__

BIN
external/devil178/lib/DevIL.dll vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/DevIL.lib vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/ILU.dll vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/ILU.lib vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/ILUT.dll vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/ILUT.lib vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/unicode/DevIL.dll vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/unicode/DevIL.lib vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/unicode/ILU.dll vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/unicode/ILU.lib vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/unicode/ILUT.dll vendored Executable file

Binary file not shown.

BIN
external/devil178/lib/unicode/ILUT.lib vendored Executable file

Binary file not shown.

56
external/sfml23/include/SFML/Audio.hpp vendored Executable file
View File

@ -0,0 +1,56 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_AUDIO_HPP
#define SFML_AUDIO_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System.hpp>
#include <SFML/Audio/InputSoundFile.hpp>
#include <SFML/Audio/Listener.hpp>
#include <SFML/Audio/Music.hpp>
#include <SFML/Audio/OutputSoundFile.hpp>
#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Audio/SoundBufferRecorder.hpp>
#include <SFML/Audio/SoundFileFactory.hpp>
#include <SFML/Audio/SoundFileReader.hpp>
#include <SFML/Audio/SoundFileWriter.hpp>
#include <SFML/Audio/SoundRecorder.hpp>
#include <SFML/Audio/SoundSource.hpp>
#include <SFML/Audio/SoundStream.hpp>
#endif // SFML_AUDIO_HPP
////////////////////////////////////////////////////////////
/// \defgroup audio Audio module
///
/// Sounds, streaming (musics or custom sources), recording,
/// spatialization.
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,70 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_ALRESOURCE_HPP
#define SFML_ALRESOURCE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Base class for classes that require an OpenAL context
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API AlResource
{
protected:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
AlResource();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~AlResource();
};
} // namespace sf
#endif // SFML_ALRESOURCE_HPP
////////////////////////////////////////////////////////////
/// \class sf::AlResource
/// \ingroup audio
///
/// This class is for internal use only, it must be the base
/// of every class that requires a valid OpenAL context in
/// order to work.
///
////////////////////////////////////////////////////////////

48
external/sfml23/include/SFML/Audio/Export.hpp vendored Executable file
View File

@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_AUDIO_EXPORT_HPP
#define SFML_AUDIO_EXPORT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
////////////////////////////////////////////////////////////
// Define portable import / export macros
////////////////////////////////////////////////////////////
#if defined(SFML_AUDIO_EXPORTS)
#define SFML_AUDIO_API SFML_API_EXPORT
#else
#define SFML_AUDIO_API SFML_API_IMPORT
#endif
#endif // SFML_AUDIO_EXPORT_HPP

View File

@ -0,0 +1,250 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_INPUTSOUNDFILE_HPP
#define SFML_INPUTSOUNDFILE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/System/NonCopyable.hpp>
#include <SFML/System/Time.hpp>
#include <string>
namespace sf
{
class InputStream;
class SoundFileReader;
////////////////////////////////////////////////////////////
/// \brief Provide read access to sound files
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API InputSoundFile : NonCopyable
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
InputSoundFile();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~InputSoundFile();
////////////////////////////////////////////////////////////
/// \brief Open a sound file from the disk for reading
///
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
///
/// \param filename Path of the sound file to load
///
/// \return True if the file was successfully opened
///
////////////////////////////////////////////////////////////
bool openFromFile(const std::string& filename);
////////////////////////////////////////////////////////////
/// \brief Open a sound file in memory for reading
///
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
///
/// \param data Pointer to the file data in memory
/// \param sizeInBytes Size of the data to load, in bytes
///
/// \return True if the file was successfully opened
///
////////////////////////////////////////////////////////////
bool openFromMemory(const void* data, std::size_t sizeInBytes);
////////////////////////////////////////////////////////////
/// \brief Open a sound file from a custom stream for reading
///
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
///
/// \param stream Source stream to read from
///
/// \return True if the file was successfully opened
///
////////////////////////////////////////////////////////////
bool openFromStream(InputStream& stream);
////////////////////////////////////////////////////////////
/// \brief Open the sound file from the disk for writing
///
/// \param filename Path of the sound file to write
/// \param channelCount Number of channels in the sound
/// \param sampleRate Sample rate of the sound
///
/// \return True if the file was successfully opened
///
////////////////////////////////////////////////////////////
bool openForWriting(const std::string& filename, unsigned int channelCount, unsigned int sampleRate);
////////////////////////////////////////////////////////////
/// \brief Get the total number of audio samples in the file
///
/// \return Number of samples
///
////////////////////////////////////////////////////////////
Uint64 getSampleCount() const;
////////////////////////////////////////////////////////////
/// \brief Get the number of channels used by the sound
///
/// \return Number of channels (1 = mono, 2 = stereo)
///
////////////////////////////////////////////////////////////
unsigned int getChannelCount() const;
////////////////////////////////////////////////////////////
/// \brief Get the sample rate of the sound
///
/// \return Sample rate, in samples per second
///
////////////////////////////////////////////////////////////
unsigned int getSampleRate() const;
////////////////////////////////////////////////////////////
/// \brief Get the total duration of the sound file
///
/// This function is provided for convenience, the duration is
/// deduced from the other sound file attributes.
///
/// \return Duration of the sound file
///
////////////////////////////////////////////////////////////
Time getDuration() const;
////////////////////////////////////////////////////////////
/// \brief Change the current read position to the given sample offset
///
/// This function takes a sample offset to provide maximum
/// precision. If you need to jump to a given time, use the
/// other overload.
///
/// If the given offset exceeds to total number of samples,
/// this function jumps to the end of the sound file.
///
/// \param sampleOffset Index of the sample to jump to, relative to the beginning
///
////////////////////////////////////////////////////////////
void seek(Uint64 sampleOffset);
////////////////////////////////////////////////////////////
/// \brief Change the current read position to the given time offset
///
/// Using a time offset is handy but imprecise. If you need an accurate
/// result, consider using the overload which takes a sample offset.
///
/// If the given time exceeds to total duration, this function jumps
/// to the end of the sound file.
///
/// \param timeOffset Time to jump to, relative to the beginning
///
////////////////////////////////////////////////////////////
void seek(Time timeOffset);
////////////////////////////////////////////////////////////
/// \brief Read audio samples from the open file
///
/// \param samples Pointer to the sample array to fill
/// \param maxCount Maximum number of samples to read
///
/// \return Number of samples actually read (may be less than \a maxCount)
///
////////////////////////////////////////////////////////////
Uint64 read(Int16* samples, Uint64 maxCount);
private:
////////////////////////////////////////////////////////////
/// \brief Close the current file
///
////////////////////////////////////////////////////////////
void close();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
SoundFileReader* m_reader; ///< Reader that handles I/O on the file's format
InputStream* m_stream; ///< Input stream used to access the file's data
bool m_streamOwned; ///< Is the stream internal or external?
Uint64 m_sampleCount; ///< Total number of samples in the file
unsigned int m_channelCount; ///< Number of channels of the sound
unsigned int m_sampleRate; ///< Number of samples per second
};
} // namespace sf
#endif // SFML_INPUTSOUNDFILE_HPP
////////////////////////////////////////////////////////////
/// \class sf::InputSoundFile
/// \ingroup audio
///
/// This class decodes audio samples from a sound file. It is
/// used internally by higher-level classes such as sf::SoundBuffer
/// and sf::Music, but can also be useful if you want to process
/// or analyze audio files without playing them, or if you want to
/// implement your own version of sf::Music with more specific
/// features.
///
/// Usage example:
/// \code
/// // Open a sound file
/// sf::InputSoundFile file;
/// if (!file.openFromFile("music.ogg"))
/// /* error */;
///
/// // Print the sound attributes
/// std::cout << "duration: " << file.getDuration().asSeconds() << std::endl;
/// std::cout << "channels: " << file.getChannelCount() << std::endl;
/// std::cout << "sample rate: " << file.getSampleRate() << std::endl;
/// std::cout << "sample count: " << file.getSampleCount() << std::endl;
///
/// // Read and process batches of samples until the end of file is reached
/// sf::Int16 samples[1024];
/// sf::Uint64 count;
/// do
/// {
/// count = file.read(samples, 1024);
///
/// // process, analyze, play, convert, or whatever
/// // you want to do with the samples...
/// }
/// while (count > 0);
/// \endcode
///
/// \see sf::SoundFileReader, sf::OutputSoundFile
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,234 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_LISTENER_HPP
#define SFML_LISTENER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/System/Vector3.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief The audio listener is the point in the scene
/// from where all the sounds are heard
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API Listener
{
public:
////////////////////////////////////////////////////////////
/// \brief Change the global volume of all the sounds and musics
///
/// The volume is a number between 0 and 100; it is combined with
/// the individual volume of each sound / music.
/// The default value for the volume is 100 (maximum).
///
/// \param volume New global volume, in the range [0, 100]
///
/// \see getGlobalVolume
///
////////////////////////////////////////////////////////////
static void setGlobalVolume(float volume);
////////////////////////////////////////////////////////////
/// \brief Get the current value of the global volume
///
/// \return Current global volume, in the range [0, 100]
///
/// \see setGlobalVolume
///
////////////////////////////////////////////////////////////
static float getGlobalVolume();
////////////////////////////////////////////////////////////
/// \brief Set the position of the listener in the scene
///
/// The default listener's position is (0, 0, 0).
///
/// \param x X coordinate of the listener's position
/// \param y Y coordinate of the listener's position
/// \param z Z coordinate of the listener's position
///
/// \see getPosition, setDirection
///
////////////////////////////////////////////////////////////
static void setPosition(float x, float y, float z);
////////////////////////////////////////////////////////////
/// \brief Set the position of the listener in the scene
///
/// The default listener's position is (0, 0, 0).
///
/// \param position New listener's position
///
/// \see getPosition, setDirection
///
////////////////////////////////////////////////////////////
static void setPosition(const Vector3f& position);
////////////////////////////////////////////////////////////
/// \brief Get the current position of the listener in the scene
///
/// \return Listener's position
///
/// \see setPosition
///
////////////////////////////////////////////////////////////
static Vector3f getPosition();
////////////////////////////////////////////////////////////
/// \brief Set the forward vector of the listener in the scene
///
/// The direction (also called "at vector") is the vector
/// pointing forward from the listener's perspective. Together
/// with the up vector, it defines the 3D orientation of the
/// listener in the scene. The direction vector doesn't
/// have to be normalized.
/// The default listener's direction is (0, 0, -1).
///
/// \param x X coordinate of the listener's direction
/// \param y Y coordinate of the listener's direction
/// \param z Z coordinate of the listener's direction
///
/// \see getDirection, setUpVector, setPosition
///
////////////////////////////////////////////////////////////
static void setDirection(float x, float y, float z);
////////////////////////////////////////////////////////////
/// \brief Set the forward vector of the listener in the scene
///
/// The direction (also called "at vector") is the vector
/// pointing forward from the listener's perspective. Together
/// with the up vector, it defines the 3D orientation of the
/// listener in the scene. The direction vector doesn't
/// have to be normalized.
/// The default listener's direction is (0, 0, -1).
///
/// \param direction New listener's direction
///
/// \see getDirection, setUpVector, setPosition
///
////////////////////////////////////////////////////////////
static void setDirection(const Vector3f& direction);
////////////////////////////////////////////////////////////
/// \brief Get the current forward vector of the listener in the scene
///
/// \return Listener's forward vector (not normalized)
///
/// \see setDirection
///
////////////////////////////////////////////////////////////
static Vector3f getDirection();
////////////////////////////////////////////////////////////
/// \brief Set the upward vector of the listener in the scene
///
/// The up vector is the vector that points upward from the
/// listener's perspective. Together with the direction, it
/// defines the 3D orientation of the listener in the scene.
/// The up vector doesn't have to be normalized.
/// The default listener's up vector is (0, 1, 0). It is usually
/// not necessary to change it, especially in 2D scenarios.
///
/// \param x X coordinate of the listener's up vector
/// \param y Y coordinate of the listener's up vector
/// \param z Z coordinate of the listener's up vector
///
/// \see getUpVector, setDirection, setPosition
///
////////////////////////////////////////////////////////////
static void setUpVector(float x, float y, float z);
////////////////////////////////////////////////////////////
/// \brief Set the upward vector of the listener in the scene
///
/// The up vector is the vector that points upward from the
/// listener's perspective. Together with the direction, it
/// defines the 3D orientation of the listener in the scene.
/// The up vector doesn't have to be normalized.
/// The default listener's up vector is (0, 1, 0). It is usually
/// not necessary to change it, especially in 2D scenarios.
///
/// \param upVector New listener's up vector
///
/// \see getUpVector, setDirection, setPosition
///
////////////////////////////////////////////////////////////
static void setUpVector(const Vector3f& upVector);
////////////////////////////////////////////////////////////
/// \brief Get the current upward vector of the listener in the scene
///
/// \return Listener's upward vector (not normalized)
///
/// \see setUpVector
///
////////////////////////////////////////////////////////////
static Vector3f getUpVector();
};
} // namespace sf
#endif // SFML_LISTENER_HPP
////////////////////////////////////////////////////////////
/// \class sf::Listener
/// \ingroup audio
///
/// The audio listener defines the global properties of the
/// audio environment, it defines where and how sounds and musics
/// are heard. If sf::View is the eyes of the user, then sf::Listener
/// is his ears (by the way, they are often linked together --
/// same position, orientation, etc.).
///
/// sf::Listener is a simple interface, which allows to setup the
/// listener in the 3D audio environment (position, direction and
/// up vector), and to adjust the global volume.
///
/// Because the listener is unique in the scene, sf::Listener only
/// contains static functions and doesn't have to be instantiated.
///
/// Usage example:
/// \code
/// // Move the listener to the position (1, 0, -5)
/// sf::Listener::setPosition(1, 0, -5);
///
/// // Make it face the right axis (1, 0, 0)
/// sf::Listener::setDirection(1, 0, 0);
///
/// // Reduce the global volume
/// sf::Listener::setGlobalVolume(50);
/// \endcode
///
////////////////////////////////////////////////////////////

229
external/sfml23/include/SFML/Audio/Music.hpp vendored Executable file
View File

@ -0,0 +1,229 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_MUSIC_HPP
#define SFML_MUSIC_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/Audio/SoundStream.hpp>
#include <SFML/Audio/InputSoundFile.hpp>
#include <SFML/System/Mutex.hpp>
#include <SFML/System/Time.hpp>
#include <string>
#include <vector>
namespace sf
{
class InputStream;
////////////////////////////////////////////////////////////
/// \brief Streamed music played from an audio file
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API Music : public SoundStream
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
Music();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~Music();
////////////////////////////////////////////////////////////
/// \brief Open a music from an audio file
///
/// This function doesn't start playing the music (call play()
/// to do so).
/// See the documentation of sf::InputSoundFile for the list
/// of supported formats.
///
/// \warning Since the music is not loaded at once but rather
/// streamed continuously, the file must remain accessible until
/// the sf::Music object loads a new music or is destroyed.
///
/// \param filename Path of the music file to open
///
/// \return True if loading succeeded, false if it failed
///
/// \see openFromMemory, openFromStream
///
////////////////////////////////////////////////////////////
bool openFromFile(const std::string& filename);
////////////////////////////////////////////////////////////
/// \brief Open a music from an audio file in memory
///
/// This function doesn't start playing the music (call play()
/// to do so).
/// See the documentation of sf::InputSoundFile for the list
/// of supported formats.
///
/// \warning Since the music is not loaded at once but rather streamed
/// continuously, the \a data buffer must remain accessible until
/// the sf::Music object loads a new music or is destroyed. That is,
/// you can't deallocate the buffer right after calling this function.
///
/// \param data Pointer to the file data in memory
/// \param sizeInBytes Size of the data to load, in bytes
///
/// \return True if loading succeeded, false if it failed
///
/// \see openFromFile, openFromStream
///
////////////////////////////////////////////////////////////
bool openFromMemory(const void* data, std::size_t sizeInBytes);
////////////////////////////////////////////////////////////
/// \brief Open a music from an audio file in a custom stream
///
/// This function doesn't start playing the music (call play()
/// to do so).
/// See the documentation of sf::InputSoundFile for the list
/// of supported formats.
///
/// \warning Since the music is not loaded at once but rather
/// streamed continuously, the \a stream must remain accessible
/// until the sf::Music object loads a new music or is destroyed.
///
/// \param stream Source stream to read from
///
/// \return True if loading succeeded, false if it failed
///
/// \see openFromFile, openFromMemory
///
////////////////////////////////////////////////////////////
bool openFromStream(InputStream& stream);
////////////////////////////////////////////////////////////
/// \brief Get the total duration of the music
///
/// \return Music duration
///
////////////////////////////////////////////////////////////
Time getDuration() const;
protected:
////////////////////////////////////////////////////////////
/// \brief Request a new chunk of audio samples from the stream source
///
/// This function fills the chunk from the next samples
/// to read from the audio file.
///
/// \param data Chunk of data to fill
///
/// \return True to continue playback, false to stop
///
////////////////////////////////////////////////////////////
virtual bool onGetData(Chunk& data);
////////////////////////////////////////////////////////////
/// \brief Change the current playing position in the stream source
///
/// \param timeOffset New playing position, from the beginning of the music
///
////////////////////////////////////////////////////////////
virtual void onSeek(Time timeOffset);
private:
////////////////////////////////////////////////////////////
/// \brief Initialize the internal state after loading a new music
///
////////////////////////////////////////////////////////////
void initialize();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
InputSoundFile m_file; ///< The streamed music file
Time m_duration; ///< Music duration
std::vector<Int16> m_samples; ///< Temporary buffer of samples
Mutex m_mutex; ///< Mutex protecting the data
};
} // namespace sf
#endif // SFML_MUSIC_HPP
////////////////////////////////////////////////////////////
/// \class sf::Music
/// \ingroup audio
///
/// Musics are sounds that are streamed rather than completely
/// loaded in memory. This is especially useful for compressed
/// musics that usually take hundreds of MB when they are
/// uncompressed: by streaming it instead of loading it entirely,
/// you avoid saturating the memory and have almost no loading delay.
/// This implies that the underlying resource (file, stream or
/// memory buffer) must remain valid for the lifetime of the
/// sf::Music object.
///
/// Apart from that, a sf::Music has almost the same features as
/// the sf::SoundBuffer / sf::Sound pair: you can play/pause/stop
/// it, request its parameters (channels, sample rate), change
/// the way it is played (pitch, volume, 3D position, ...), etc.
///
/// As a sound stream, a music is played in its own thread in order
/// not to block the rest of the program. This means that you can
/// leave the music alone after calling play(), it will manage itself
/// very well.
///
/// Usage example:
/// \code
/// // Declare a new music
/// sf::Music music;
///
/// // Open it from an audio file
/// if (!music.openFromFile("music.ogg"))
/// {
/// // error...
/// }
///
/// // Change some parameters
/// music.setPosition(0, 1, 10); // change its 3D position
/// music.setPitch(2); // increase the pitch
/// music.setVolume(50); // reduce the volume
/// music.setLoop(true); // make it loop
///
/// // Play it
/// music.play();
/// \endcode
///
/// \see sf::Sound, sf::SoundStream
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,133 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_OUTPUTSOUNDFILE_HPP
#define SFML_OUTPUTSOUNDFILE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/System/NonCopyable.hpp>
#include <string>
namespace sf
{
class SoundFileWriter;
////////////////////////////////////////////////////////////
/// \brief Provide write access to sound files
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API OutputSoundFile : NonCopyable
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
OutputSoundFile();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
/// Closes the file if it was still open.
///
////////////////////////////////////////////////////////////
~OutputSoundFile();
////////////////////////////////////////////////////////////
/// \brief Open the sound file from the disk for writing
///
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
///
/// \param filename Path of the sound file to write
/// \param sampleRate Sample rate of the sound
/// \param channelCount Number of channels in the sound
///
/// \return True if the file was successfully opened
///
////////////////////////////////////////////////////////////
bool openFromFile(const std::string& filename, unsigned int sampleRate, unsigned int channelCount);
////////////////////////////////////////////////////////////
/// \brief Write audio samples to the file
///
/// \param samples Pointer to the sample array to write
/// \param count Number of samples to write
///
////////////////////////////////////////////////////////////
void write(const Int16* samples, Uint64 count);
private:
////////////////////////////////////////////////////////////
/// \brief Close the current file
///
////////////////////////////////////////////////////////////
void close();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
SoundFileWriter* m_writer; ///< Writer that handles I/O on the file's format
};
} // namespace sf
#endif // SFML_OUTPUTSOUNDFILE_HPP
////////////////////////////////////////////////////////////
/// \class sf::OutputSoundFile
/// \ingroup audio
///
/// This class encodes audio samples to a sound file. It is
/// used internally by higher-level classes such as sf::SoundBuffer,
/// but can also be useful if you want to create audio files from
/// custom data sources, like generated audio samples.
///
/// Usage example:
/// \code
/// // Create a sound file, ogg/vorbis format, 44100 Hz, stereo
/// sf::OutputSoundFile file;
/// if (!file.openFromFile("music.ogg", 44100, 2))
/// /* error */;
///
/// while (...)
/// {
/// // Read or generate audio samples from your custom source
/// std::vector<sf::Int16> samples = ...;
///
/// // Write them to the file
/// file.write(samples.data(), samples.size());
/// }
/// \endcode
///
/// \see sf::SoundFileWriter, sf::InputSoundFile
///
////////////////////////////////////////////////////////////

264
external/sfml23/include/SFML/Audio/Sound.hpp vendored Executable file
View File

@ -0,0 +1,264 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUND_HPP
#define SFML_SOUND_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/Audio/SoundSource.hpp>
#include <SFML/System/Time.hpp>
#include <cstdlib>
namespace sf
{
class SoundBuffer;
////////////////////////////////////////////////////////////
/// \brief Regular sound that can be played in the audio environment
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API Sound : public SoundSource
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
Sound();
////////////////////////////////////////////////////////////
/// \brief Construct the sound with a buffer
///
/// \param buffer Sound buffer containing the audio data to play with the sound
///
////////////////////////////////////////////////////////////
explicit Sound(const SoundBuffer& buffer);
////////////////////////////////////////////////////////////
/// \brief Copy constructor
///
/// \param copy Instance to copy
///
////////////////////////////////////////////////////////////
Sound(const Sound& copy);
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~Sound();
////////////////////////////////////////////////////////////
/// \brief Start or resume playing the sound
///
/// This function starts the stream if it was stopped, resumes
/// it if it was paused, and restarts it from beginning if it
/// was it already playing.
/// This function uses its own thread so that it doesn't block
/// the rest of the program while the sound is played.
///
/// \see pause, stop
///
////////////////////////////////////////////////////////////
void play();
////////////////////////////////////////////////////////////
/// \brief Pause the sound
///
/// This function pauses the sound if it was playing,
/// otherwise (sound already paused or stopped) it has no effect.
///
/// \see play, stop
///
////////////////////////////////////////////////////////////
void pause();
////////////////////////////////////////////////////////////
/// \brief stop playing the sound
///
/// This function stops the sound if it was playing or paused,
/// and does nothing if it was already stopped.
/// It also resets the playing position (unlike pause()).
///
/// \see play, pause
///
////////////////////////////////////////////////////////////
void stop();
////////////////////////////////////////////////////////////
/// \brief Set the source buffer containing the audio data to play
///
/// It is important to note that the sound buffer is not copied,
/// thus the sf::SoundBuffer instance must remain alive as long
/// as it is attached to the sound.
///
/// \param buffer Sound buffer to attach to the sound
///
/// \see getBuffer
///
////////////////////////////////////////////////////////////
void setBuffer(const SoundBuffer& buffer);
////////////////////////////////////////////////////////////
/// \brief Set whether or not the sound should loop after reaching the end
///
/// If set, the sound will restart from beginning after
/// reaching the end and so on, until it is stopped or
/// setLoop(false) is called.
/// The default looping state for sound is false.
///
/// \param loop True to play in loop, false to play once
///
/// \see getLoop
///
////////////////////////////////////////////////////////////
void setLoop(bool loop);
////////////////////////////////////////////////////////////
/// \brief Change the current playing position of the sound
///
/// The playing position can be changed when the sound is
/// either paused or playing. Changing the playing position
/// when the sound is stopped has no effect, since playing
/// the sound will reset its position.
///
/// \param timeOffset New playing position, from the beginning of the sound
///
/// \see getPlayingOffset
///
////////////////////////////////////////////////////////////
void setPlayingOffset(Time timeOffset);
////////////////////////////////////////////////////////////
/// \brief Get the audio buffer attached to the sound
///
/// \return Sound buffer attached to the sound (can be NULL)
///
////////////////////////////////////////////////////////////
const SoundBuffer* getBuffer() const;
////////////////////////////////////////////////////////////
/// \brief Tell whether or not the sound is in loop mode
///
/// \return True if the sound is looping, false otherwise
///
/// \see setLoop
///
////////////////////////////////////////////////////////////
bool getLoop() const;
////////////////////////////////////////////////////////////
/// \brief Get the current playing position of the sound
///
/// \return Current playing position, from the beginning of the sound
///
/// \see setPlayingOffset
///
////////////////////////////////////////////////////////////
Time getPlayingOffset() const;
////////////////////////////////////////////////////////////
/// \brief Get the current status of the sound (stopped, paused, playing)
///
/// \return Current status of the sound
///
////////////////////////////////////////////////////////////
Status getStatus() const;
////////////////////////////////////////////////////////////
/// \brief Overload of assignment operator
///
/// \param right Instance to assign
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
Sound& operator =(const Sound& right);
////////////////////////////////////////////////////////////
/// \brief Reset the internal buffer of the sound
///
/// This function is for internal use only, you don't have
/// to use it. It is called by the sf::SoundBuffer that
/// this sound uses, when it is destroyed in order to prevent
/// the sound from using a dead buffer.
///
////////////////////////////////////////////////////////////
void resetBuffer();
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
const SoundBuffer* m_buffer; ///< Sound buffer bound to the source
};
} // namespace sf
#endif // SFML_SOUND_HPP
////////////////////////////////////////////////////////////
/// \class sf::Sound
/// \ingroup audio
///
/// sf::Sound is the class to use to play sounds.
/// It provides:
/// \li Control (play, pause, stop)
/// \li Ability to modify output parameters in real-time (pitch, volume, ...)
/// \li 3D spatial features (position, attenuation, ...).
///
/// sf::Sound is perfect for playing short sounds that can
/// fit in memory and require no latency, like foot steps or
/// gun shots. For longer sounds, like background musics
/// or long speeches, rather see sf::Music (which is based
/// on streaming).
///
/// In order to work, a sound must be given a buffer of audio
/// data to play. Audio data (samples) is stored in sf::SoundBuffer,
/// and attached to a sound with the setBuffer() function.
/// The buffer object attached to a sound must remain alive
/// as long as the sound uses it. Note that multiple sounds
/// can use the same sound buffer at the same time.
///
/// Usage example:
/// \code
/// sf::SoundBuffer buffer;
/// buffer.loadFromFile("sound.wav");
///
/// sf::Sound sound;
/// sound.setBuffer(buffer);
/// sound.play();
/// \endcode
///
/// \see sf::SoundBuffer, sf::Music
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,352 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDBUFFER_HPP
#define SFML_SOUNDBUFFER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/Audio/AlResource.hpp>
#include <SFML/System/Time.hpp>
#include <string>
#include <vector>
#include <set>
namespace sf
{
class Sound;
class InputSoundFile;
class InputStream;
////////////////////////////////////////////////////////////
/// \brief Storage for audio samples defining a sound
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API SoundBuffer : AlResource
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
SoundBuffer();
////////////////////////////////////////////////////////////
/// \brief Copy constructor
///
/// \param copy Instance to copy
///
////////////////////////////////////////////////////////////
SoundBuffer(const SoundBuffer& copy);
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~SoundBuffer();
////////////////////////////////////////////////////////////
/// \brief Load the sound buffer from a file
///
/// See the documentation of sf::InputSoundFile for the list
/// of supported formats.
///
/// \param filename Path of the sound file to load
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromMemory, loadFromStream, loadFromSamples, saveToFile
///
////////////////////////////////////////////////////////////
bool loadFromFile(const std::string& filename);
////////////////////////////////////////////////////////////
/// \brief Load the sound buffer from a file in memory
///
/// See the documentation of sf::InputSoundFile for the list
/// of supported formats.
///
/// \param data Pointer to the file data in memory
/// \param sizeInBytes Size of the data to load, in bytes
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromStream, loadFromSamples
///
////////////////////////////////////////////////////////////
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
////////////////////////////////////////////////////////////
/// \brief Load the sound buffer from a custom stream
///
/// See the documentation of sf::InputSoundFile for the list
/// of supported formats.
///
/// \param stream Source stream to read from
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromMemory, loadFromSamples
///
////////////////////////////////////////////////////////////
bool loadFromStream(InputStream& stream);
////////////////////////////////////////////////////////////
/// \brief Load the sound buffer from an array of audio samples
///
/// The assumed format of the audio samples is 16 bits signed integer
/// (sf::Int16).
///
/// \param samples Pointer to the array of samples in memory
/// \param sampleCount Number of samples in the array
/// \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
/// \param sampleRate Sample rate (number of samples to play per second)
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromMemory, saveToFile
///
////////////////////////////////////////////////////////////
bool loadFromSamples(const Int16* samples, Uint64 sampleCount, unsigned int channelCount, unsigned int sampleRate);
////////////////////////////////////////////////////////////
/// \brief Save the sound buffer to an audio file
///
/// See the documentation of sf::OutputSoundFile for the list
/// of supported formats.
///
/// \param filename Path of the sound file to write
///
/// \return True if saving succeeded, false if it failed
///
/// \see loadFromFile, loadFromMemory, loadFromSamples
///
////////////////////////////////////////////////////////////
bool saveToFile(const std::string& filename) const;
////////////////////////////////////////////////////////////
/// \brief Get the array of audio samples stored in the buffer
///
/// The format of the returned samples is 16 bits signed integer
/// (sf::Int16). The total number of samples in this array
/// is given by the getSampleCount() function.
///
/// \return Read-only pointer to the array of sound samples
///
/// \see getSampleCount
///
////////////////////////////////////////////////////////////
const Int16* getSamples() const;
////////////////////////////////////////////////////////////
/// \brief Get the number of samples stored in the buffer
///
/// The array of samples can be accessed with the getSamples()
/// function.
///
/// \return Number of samples
///
/// \see getSamples
///
////////////////////////////////////////////////////////////
Uint64 getSampleCount() const;
////////////////////////////////////////////////////////////
/// \brief Get the sample rate of the sound
///
/// The sample rate is the number of samples played per second.
/// The higher, the better the quality (for example, 44100
/// samples/s is CD quality).
///
/// \return Sample rate (number of samples per second)
///
/// \see getChannelCount, getDuration
///
////////////////////////////////////////////////////////////
unsigned int getSampleRate() const;
////////////////////////////////////////////////////////////
/// \brief Get the number of channels used by the sound
///
/// If the sound is mono then the number of channels will
/// be 1, 2 for stereo, etc.
///
/// \return Number of channels
///
/// \see getSampleRate, getDuration
///
////////////////////////////////////////////////////////////
unsigned int getChannelCount() const;
////////////////////////////////////////////////////////////
/// \brief Get the total duration of the sound
///
/// \return Sound duration
///
/// \see getSampleRate, getChannelCount
///
////////////////////////////////////////////////////////////
Time getDuration() const;
////////////////////////////////////////////////////////////
/// \brief Overload of assignment operator
///
/// \param right Instance to assign
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
SoundBuffer& operator =(const SoundBuffer& right);
private:
friend class Sound;
////////////////////////////////////////////////////////////
/// \brief Initialize the internal state after loading a new sound
///
/// \param file Sound file providing access to the new loaded sound
///
/// \return True on successful initialization, false on failure
///
////////////////////////////////////////////////////////////
bool initialize(InputSoundFile& file);
////////////////////////////////////////////////////////////
/// \brief Update the internal buffer with the cached audio samples
///
/// \param channelCount Number of channels
/// \param sampleRate Sample rate (number of samples per second)
///
/// \return True on success, false if any error happened
///
////////////////////////////////////////////////////////////
bool update(unsigned int channelCount, unsigned int sampleRate);
////////////////////////////////////////////////////////////
/// \brief Add a sound to the list of sounds that use this buffer
///
/// \param sound Sound instance to attach
///
////////////////////////////////////////////////////////////
void attachSound(Sound* sound) const;
////////////////////////////////////////////////////////////
/// \brief Remove a sound from the list of sounds that use this buffer
///
/// \param sound Sound instance to detach
///
////////////////////////////////////////////////////////////
void detachSound(Sound* sound) const;
////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////
typedef std::set<Sound*> SoundList; ///< Set of unique sound instances
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int m_buffer; ///< OpenAL buffer identifier
std::vector<Int16> m_samples; ///< Samples buffer
Time m_duration; ///< Sound duration
mutable SoundList m_sounds; ///< List of sounds that are using this buffer
};
} // namespace sf
#endif // SFML_SOUNDBUFFER_HPP
////////////////////////////////////////////////////////////
/// \class sf::SoundBuffer
/// \ingroup audio
///
/// A sound buffer holds the data of a sound, which is
/// an array of audio samples. A sample is a 16 bits signed integer
/// that defines the amplitude of the sound at a given time.
/// The sound is then reconstituted by playing these samples at
/// a high rate (for example, 44100 samples per second is the
/// standard rate used for playing CDs). In short, audio samples
/// are like texture pixels, and a sf::SoundBuffer is similar to
/// a sf::Texture.
///
/// A sound buffer can be loaded from a file (see loadFromFile()
/// for the complete list of supported formats), from memory, from
/// a custom stream (see sf::InputStream) or directly from an array
/// of samples. It can also be saved back to a file.
///
/// Sound buffers alone are not very useful: they hold the audio data
/// but cannot be played. To do so, you need to use the sf::Sound class,
/// which provides functions to play/pause/stop the sound as well as
/// changing the way it is outputted (volume, pitch, 3D position, ...).
/// This separation allows more flexibility and better performances:
/// indeed a sf::SoundBuffer is a heavy resource, and any operation on it
/// is slow (often too slow for real-time applications). On the other
/// side, a sf::Sound is a lightweight object, which can use the audio data
/// of a sound buffer and change the way it is played without actually
/// modifying that data. Note that it is also possible to bind
/// several sf::Sound instances to the same sf::SoundBuffer.
///
/// It is important to note that the sf::Sound instance doesn't
/// copy the buffer that it uses, it only keeps a reference to it.
/// Thus, a sf::SoundBuffer must not be destructed while it is
/// used by a sf::Sound (i.e. never write a function that
/// uses a local sf::SoundBuffer instance for loading a sound).
///
/// Usage example:
/// \code
/// // Declare a new sound buffer
/// sf::SoundBuffer buffer;
///
/// // Load it from a file
/// if (!buffer.loadFromFile("sound.wav"))
/// {
/// // error...
/// }
///
/// // Create a sound source and bind it to the buffer
/// sf::Sound sound1;
/// sound1.setBuffer(buffer);
///
/// // Play the sound
/// sound1.play();
///
/// // Create another sound source bound to the same buffer
/// sf::Sound sound2;
/// sound2.setBuffer(buffer);
///
/// // Play it with a higher pitch -- the first sound remains unchanged
/// sound2.setPitch(2);
/// sound2.play();
/// \endcode
///
/// \see sf::Sound, sf::SoundBufferRecorder
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,138 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDBUFFERRECORDER_HPP
#define SFML_SOUNDBUFFERRECORDER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Audio/SoundRecorder.hpp>
#include <vector>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Specialized SoundRecorder which stores the captured
/// audio data into a sound buffer
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
{
public:
////////////////////////////////////////////////////////////
/// \brief Get the sound buffer containing the captured audio data
///
/// The sound buffer is valid only after the capture has ended.
/// This function provides a read-only access to the internal
/// sound buffer, but it can be copied if you need to
/// make any modification to it.
///
/// \return Read-only access to the sound buffer
///
////////////////////////////////////////////////////////////
const SoundBuffer& getBuffer() const;
protected:
////////////////////////////////////////////////////////////
/// \brief Start capturing audio data
///
/// \return True to start the capture, or false to abort it
///
////////////////////////////////////////////////////////////
virtual bool onStart();
////////////////////////////////////////////////////////////
/// \brief Process a new chunk of recorded samples
///
/// \param samples Pointer to the new chunk of recorded samples
/// \param sampleCount Number of samples pointed by \a samples
///
/// \return True to continue the capture, or false to stop it
///
////////////////////////////////////////////////////////////
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount);
////////////////////////////////////////////////////////////
/// \brief Stop capturing audio data
///
////////////////////////////////////////////////////////////
virtual void onStop();
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::vector<Int16> m_samples; ///< Temporary sample buffer to hold the recorded data
SoundBuffer m_buffer; ///< Sound buffer that will contain the recorded data
};
} // namespace sf
#endif // SFML_SOUNDBUFFERRECORDER_HPP
////////////////////////////////////////////////////////////
/// \class sf::SoundBufferRecorder
/// \ingroup audio
///
/// sf::SoundBufferRecorder allows to access a recorded sound
/// through a sf::SoundBuffer, so that it can be played, saved
/// to a file, etc.
///
/// It has the same simple interface as its base class (start(), stop())
/// and adds a function to retrieve the recorded sound buffer
/// (getBuffer()).
///
/// As usual, don't forget to call the isAvailable() function
/// before using this class (see sf::SoundRecorder for more details
/// about this).
///
/// Usage example:
/// \code
/// if (sf::SoundBufferRecorder::isAvailable())
/// {
/// // Record some audio data
/// sf::SoundBufferRecorder recorder;
/// recorder.start();
/// ...
/// recorder.stop();
///
/// // Get the buffer containing the captured audio data
/// const sf::SoundBuffer& buffer = recorder.getBuffer();
///
/// // Save it to a file (for example...)
/// buffer.saveToFile("my_record.ogg");
/// }
/// \endcode
///
/// \see sf::SoundRecorder
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,197 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDFILEFACTORY_HPP
#define SFML_SOUNDFILEFACTORY_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <string>
#include <vector>
namespace sf
{
class InputStream;
class SoundFileReader;
class SoundFileWriter;
////////////////////////////////////////////////////////////
/// \brief Manages and instantiates sound file readers and writers
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API SoundFileFactory
{
public:
////////////////////////////////////////////////////////////
/// \brief Register a new reader
///
/// \see unregisterReader
///
////////////////////////////////////////////////////////////
template <typename T>
static void registerReader();
////////////////////////////////////////////////////////////
/// \brief Unregister a reader
///
/// \see registerReader
///
////////////////////////////////////////////////////////////
template <typename T>
static void unregisterReader();
////////////////////////////////////////////////////////////
/// \brief Register a new writer
///
/// \see unregisterWriter
///
////////////////////////////////////////////////////////////
template <typename T>
static void registerWriter();
////////////////////////////////////////////////////////////
/// \brief Unregister a writer
///
/// \see registerWriter
///
////////////////////////////////////////////////////////////
template <typename T>
static void unregisterWriter();
////////////////////////////////////////////////////////////
/// \brief Instantiate the right reader for the given file on disk
///
/// It's up to the caller to release the returned reader
///
/// \param filename Path of the sound file
///
/// \return A new sound file reader that can read the given file, or null if no reader can handle it
///
/// \see createReaderFromMemory, createReaderFromStream
///
////////////////////////////////////////////////////////////
static SoundFileReader* createReaderFromFilename(const std::string& filename);
////////////////////////////////////////////////////////////
/// \brief Instantiate the right codec for the given file in memory
///
/// It's up to the caller to release the returned reader
///
/// \param data Pointer to the file data in memory
/// \param sizeInBytes Total size of the file data, in bytes
///
/// \return A new sound file codec that can read the given file, or null if no codec can handle it
///
/// \see createReaderFromFilename, createReaderFromStream
///
////////////////////////////////////////////////////////////
static SoundFileReader* createReaderFromMemory(const void* data, std::size_t sizeInBytes);
////////////////////////////////////////////////////////////
/// \brief Instantiate the right codec for the given file in stream
///
/// It's up to the caller to release the returned reader
///
/// \param stream Source stream to read from
///
/// \return A new sound file codec that can read the given file, or null if no codec can handle it
///
/// \see createReaderFromFilename, createReaderFromMemory
///
////////////////////////////////////////////////////////////
static SoundFileReader* createReaderFromStream(InputStream& stream);
////////////////////////////////////////////////////////////
/// \brief Instantiate the right writer for the given file on disk
///
/// It's up to the caller to release the returned writer
///
/// \param filename Path of the sound file
///
/// \return A new sound file writer that can write given file, or null if no writer can handle it
///
////////////////////////////////////////////////////////////
static SoundFileWriter* createWriterFromFilename(const std::string& filename);
private:
////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////
struct ReaderFactory
{
bool (*check)(InputStream&);
SoundFileReader* (*create)();
};
typedef std::vector<ReaderFactory> ReaderFactoryArray;
struct WriterFactory
{
bool (*check)(const std::string&);
SoundFileWriter* (*create)();
};
typedef std::vector<WriterFactory> WriterFactoryArray;
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static ReaderFactoryArray s_readers; ///< List of all registered readers
static WriterFactoryArray s_writers; ///< List of all registered writers
};
} // namespace sf
#include <SFML/Audio/SoundFileFactory.inl>
#endif // SFML_SOUNDFILEFACTORY_HPP
////////////////////////////////////////////////////////////
/// \class sf::SoundFileFactory
/// \ingroup audio
///
/// This class is where all the sound file readers and writers are
/// registered. You should normally only need to use its registration
/// and unregistration functions; readers/writers creation and manipulation
/// are wrapped into the higher-level classes sf::InputSoundFile and
/// sf::OutputSoundFile.
///
/// To register a new reader (writer) use the sf::SoundFileFactory::registerReader
/// (registerWriter) static function. You don't have to call the unregisterReader
/// (unregisterWriter) function, unless you want to unregister a format before your
/// application ends (typically, when a plugin is unloaded).
///
/// Usage example:
/// \code
/// sf::SoundFileFactory::registerReader<MySoundFileReader>();
/// sf::SoundFileFactory::registerWriter<MySoundFileWriter>();
/// \endcode
///
/// \see sf::InputSoundFile, sf::OutputSoundFile, sf::SoundFileReader, sf::SoundFileWriter
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,100 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
namespace sf
{
namespace priv
{
template <typename T> SoundFileReader* createReader() {return new T;}
template <typename T> SoundFileWriter* createWriter() {return new T;}
}
////////////////////////////////////////////////////////////
template <typename T>
void SoundFileFactory::registerReader()
{
// Make sure the same class won't be registered twice
unregisterReader<T>();
// Create a new factory with the functions provided by the class
ReaderFactory factory;
factory.check = &T::check;
factory.create = &priv::createReader<T>;
// Add it
s_readers.push_back(factory);
}
////////////////////////////////////////////////////////////
template <typename T>
void SoundFileFactory::unregisterReader()
{
// Remove the instance(s) of the reader from the array of factories
for (ReaderFactoryArray::iterator it = s_readers.begin(); it != s_readers.end(); )
{
if (it->create == &priv::createReader<T>)
it = s_readers.erase(it);
else
++it;
}
}
////////////////////////////////////////////////////////////
template <typename T>
void SoundFileFactory::registerWriter()
{
// Make sure the same class won't be registered twice
unregisterWriter<T>();
// Create a new factory with the functions provided by the class
WriterFactory factory;
factory.check = &T::check;
factory.create = &priv::createWriter<T>;
// Add it
s_writers.push_back(factory);
}
////////////////////////////////////////////////////////////
template <typename T>
void SoundFileFactory::unregisterWriter()
{
// Remove the instance(s) of the writer from the array of factories
for (WriterFactoryArray::iterator it = s_writers.begin(); it != s_writers.end(); )
{
if (it->create == &priv::createWriter<T>)
it = s_writers.erase(it);
else
++it;
}
}
} // namespace sf

View File

@ -0,0 +1,161 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDFILEREADER_HPP
#define SFML_SOUNDFILEREADER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <string>
namespace sf
{
class InputStream;
////////////////////////////////////////////////////////////
/// \brief Abstract base class for sound file decoding
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API SoundFileReader
{
public:
////////////////////////////////////////////////////////////
/// \brief Structure holding the audio properties of a sound file
///
////////////////////////////////////////////////////////////
struct Info
{
Uint64 sampleCount; ///< Total number of samples in the file
unsigned int channelCount; ///< Number of channels of the sound
unsigned int sampleRate; ///< Samples rate of the sound, in samples per second
};
////////////////////////////////////////////////////////////
/// \brief Virtual destructor
///
////////////////////////////////////////////////////////////
virtual ~SoundFileReader() {}
////////////////////////////////////////////////////////////
/// \brief Open a sound file for reading
///
/// The provided stream reference is valid as long as the
/// SoundFileReader is alive, so it is safe to use/store it
/// during the whole lifetime of the reader.
///
/// \param stream Source stream to read from
/// \param info Structure to fill with the properties of the loaded sound
///
/// \return True if the file was successfully opened
///
////////////////////////////////////////////////////////////
virtual bool open(InputStream& stream, Info& info) = 0;
////////////////////////////////////////////////////////////
/// \brief Change the current read position to the given sample offset
///
/// If the given offset exceeds to total number of samples,
/// this function must jump to the end of the file.
///
/// \param sampleOffset Index of the sample to jump to, relative to the beginning
///
////////////////////////////////////////////////////////////
virtual void seek(Uint64 sampleOffset) = 0;
////////////////////////////////////////////////////////////
/// \brief Read audio samples from the open file
///
/// \param samples Pointer to the sample array to fill
/// \param maxCount Maximum number of samples to read
///
/// \return Number of samples actually read (may be less than \a maxCount)
///
////////////////////////////////////////////////////////////
virtual Uint64 read(Int16* samples, Uint64 maxCount) = 0;
};
} // namespace sf
#endif // SFML_SOUNDFILEREADER_HPP
////////////////////////////////////////////////////////////
/// \class sf::SoundFileReader
/// \ingroup audio
///
/// This class allows users to read audio file formats not natively
/// supported by SFML, and thus extend the set of supported readable
/// audio formats.
///
/// A valid sound file reader must override the open, seek and write functions,
/// as well as providing a static check function; the latter is used by
/// SFML to find a suitable writer for a given input file.
///
/// To register a new reader, use the sf::SoundFileFactory::registerReader
/// template function.
///
/// Usage example:
/// \code
/// class MySoundFileReader : public sf::SoundFileReader
/// {
/// public:
///
/// static bool check(sf::InputStream& stream)
/// {
/// // typically, read the first few header bytes and check fields that identify the format
/// // return true if the reader can handle the format
/// }
///
/// virtual bool open(sf::InputStream& stream, Info& info)
/// {
/// // read the sound file header and fill the sound attributes
/// // (channel count, sample count and sample rate)
/// // return true on success
/// }
///
/// virtual void seek(sf::Uint64 sampleOffset)
/// {
/// // advance to the sampleOffset-th sample from the beginning of the sound
/// }
///
/// virtual sf::Uint64 read(sf::Int16* samples, sf::Uint64 maxCount)
/// {
/// // read up to 'maxCount' samples into the 'samples' array,
/// // convert them (for example from normalized float) if they are not stored
/// // as 16-bits signed integers in the file
/// // return the actual number of samples read
/// }
/// };
///
/// sf::SoundFileFactory::registerReader<MySoundFileReader>();
/// \endcode
///
/// \see sf::InputSoundFile, sf::SoundFileFactory, sf::SoundFileWriter
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,125 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDFILEWRITER_HPP
#define SFML_SOUNDFILEWRITER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <string>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Abstract base class for sound file encoding
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API SoundFileWriter
{
public:
////////////////////////////////////////////////////////////
/// \brief Virtual destructor
///
////////////////////////////////////////////////////////////
virtual ~SoundFileWriter() {}
////////////////////////////////////////////////////////////
/// \brief Open a sound file for writing
///
/// \param filename Path of the file to open
/// \param sampleRate Sample rate of the sound
/// \param channelCount Number of channels of the sound
///
/// \return True if the file was successfully opened
///
////////////////////////////////////////////////////////////
virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) = 0;
////////////////////////////////////////////////////////////
/// \brief Write audio samples to the open file
///
/// \param samples Pointer to the sample array to write
/// \param count Number of samples to write
///
////////////////////////////////////////////////////////////
virtual void write(const Int16* samples, Uint64 count) = 0;
};
} // namespace sf
#endif // SFML_SOUNDFILEWRITER_HPP
////////////////////////////////////////////////////////////
/// \class sf::SoundFileWriter
/// \ingroup audio
///
/// This class allows users to write audio file formats not natively
/// supported by SFML, and thus extend the set of supported writable
/// audio formats.
///
/// A valid sound file writer must override the open and write functions,
/// as well as providing a static check function; the latter is used by
/// SFML to find a suitable writer for a given filename.
///
/// To register a new writer, use the sf::SoundFileFactory::registerWriter
/// template function.
///
/// Usage example:
/// \code
/// class MySoundFileWriter : public sf::SoundFileWriter
/// {
/// public:
///
/// static bool check(const std::string& filename)
/// {
/// // typically, check the extension
/// // return true if the writer can handle the format
/// }
///
/// virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount)
/// {
/// // open the file 'filename' for writing,
/// // write the given sample rate and channel count to the file header
/// // return true on success
/// }
///
/// virtual void write(const sf::Int16* samples, sf::Uint64 count)
/// {
/// // write 'count' samples stored at address 'samples',
/// // convert them (for example to normalized float) if the format requires it
/// }
/// };
///
/// sf::SoundFileFactory::registerWriter<MySoundFileWriter>();
/// \endcode
///
/// \see sf::OutputSoundFile, sf::SoundFileFactory, sf::SoundFileReader
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,364 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDRECORDER_HPP
#define SFML_SOUNDRECORDER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/Audio/AlResource.hpp>
#include <SFML/System/Thread.hpp>
#include <SFML/System/Time.hpp>
#include <vector>
#include <string>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Abstract base class for capturing sound data
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API SoundRecorder : AlResource
{
public:
////////////////////////////////////////////////////////////
/// \brief destructor
///
////////////////////////////////////////////////////////////
virtual ~SoundRecorder();
////////////////////////////////////////////////////////////
/// \brief Start the capture
///
/// The \a sampleRate parameter defines the number of audio samples
/// captured per second. The higher, the better the quality
/// (for example, 44100 samples/sec is CD quality).
/// This function uses its own thread so that it doesn't block
/// the rest of the program while the capture runs.
/// Please note that only one capture can happen at the same time.
/// You can select which capture device will be used, by passing
/// the name to the setDevice() method. If none was selected
/// before, the default capture device will be used. You can get a
/// list of the names of all available capture devices by calling
/// getAvailableDevices().
///
/// \param sampleRate Desired capture rate, in number of samples per second
///
/// \return True, if start of capture was successful
///
/// \see stop, getAvailableDevices
///
////////////////////////////////////////////////////////////
bool start(unsigned int sampleRate = 44100);
////////////////////////////////////////////////////////////
/// \brief Stop the capture
///
/// \see start
///
////////////////////////////////////////////////////////////
void stop();
////////////////////////////////////////////////////////////
/// \brief Get the sample rate
///
/// The sample rate defines the number of audio samples
/// captured per second. The higher, the better the quality
/// (for example, 44100 samples/sec is CD quality).
///
/// \return Sample rate, in samples per second
///
////////////////////////////////////////////////////////////
unsigned int getSampleRate() const;
////////////////////////////////////////////////////////////
/// \brief Get a list of the names of all available audio capture devices
///
/// This function returns a vector of strings, containing
/// the names of all available audio capture devices.
///
/// \return A vector of strings containing the names
///
////////////////////////////////////////////////////////////
static std::vector<std::string> getAvailableDevices();
////////////////////////////////////////////////////////////
/// \brief Get the name of the default audio capture device
///
/// This function returns the name of the default audio
/// capture device. If none is available, an empty string
/// is returned.
///
/// \return The name of the default audio capture device
///
////////////////////////////////////////////////////////////
static std::string getDefaultDevice();
////////////////////////////////////////////////////////////
/// \brief Set the audio capture device
///
/// This function sets the audio capture device to the device
/// with the given \a name. It can be called on the fly (i.e:
/// while recording). If you do so while recording and
/// opening the device fails, it stops the recording.
///
/// \param name The name of the audio capture device
///
/// \return True, if it was able to set the requested device
///
/// \see getAvailableDevices, getDefaultDevice
///
////////////////////////////////////////////////////////////
bool setDevice(const std::string& name);
////////////////////////////////////////////////////////////
/// \brief Get the name of the current audio capture device
///
/// \return The name of the current audio capture device
///
////////////////////////////////////////////////////////////
const std::string& getDevice() const;
////////////////////////////////////////////////////////////
/// \brief Check if the system supports audio capture
///
/// This function should always be called before using
/// the audio capture features. If it returns false, then
/// any attempt to use sf::SoundRecorder or one of its derived
/// classes will fail.
///
/// \return True if audio capture is supported, false otherwise
///
////////////////////////////////////////////////////////////
static bool isAvailable();
protected:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor is only meant to be called by derived classes.
///
////////////////////////////////////////////////////////////
SoundRecorder();
////////////////////////////////////////////////////////////
/// \brief Set the processing interval
///
/// The processing interval controls the period
/// between calls to the onProcessSamples function. You may
/// want to use a small interval if you want to process the
/// recorded data in real time, for example.
///
/// Note: this is only a hint, the actual period may vary.
/// So don't rely on this parameter to implement precise timing.
///
/// The default processing interval is 100 ms.
///
/// \param interval Processing interval
///
////////////////////////////////////////////////////////////
void setProcessingInterval(Time interval);
////////////////////////////////////////////////////////////
/// \brief Start capturing audio data
///
/// This virtual function may be overridden by a derived class
/// if something has to be done every time a new capture
/// starts. If not, this function can be ignored; the default
/// implementation does nothing.
///
/// \return True to start the capture, or false to abort it
///
////////////////////////////////////////////////////////////
virtual bool onStart();
////////////////////////////////////////////////////////////
/// \brief Process a new chunk of recorded samples
///
/// This virtual function is called every time a new chunk of
/// recorded data is available. The derived class can then do
/// whatever it wants with it (storing it, playing it, sending
/// it over the network, etc.).
///
/// \param samples Pointer to the new chunk of recorded samples
/// \param sampleCount Number of samples pointed by \a samples
///
/// \return True to continue the capture, or false to stop it
///
////////////////////////////////////////////////////////////
virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount) = 0;
////////////////////////////////////////////////////////////
/// \brief Stop capturing audio data
///
/// This virtual function may be overridden by a derived class
/// if something has to be done every time the capture
/// ends. If not, this function can be ignored; the default
/// implementation does nothing.
///
////////////////////////////////////////////////////////////
virtual void onStop();
private:
////////////////////////////////////////////////////////////
/// \brief Function called as the entry point of the thread
///
/// This function starts the recording loop, and returns
/// only when the capture is stopped.
///
////////////////////////////////////////////////////////////
void record();
////////////////////////////////////////////////////////////
/// \brief Get the new available audio samples and process them
///
/// This function is called continuously during the
/// capture loop. It retrieves the captured samples and
/// forwards them to the derived class.
///
////////////////////////////////////////////////////////////
void processCapturedSamples();
////////////////////////////////////////////////////////////
/// \brief Clean up the recorder's internal resources
///
/// This function is called when the capture stops.
///
////////////////////////////////////////////////////////////
void cleanup();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Thread m_thread; ///< Thread running the background recording task
std::vector<Int16> m_samples; ///< Buffer to store captured samples
unsigned int m_sampleRate; ///< Sample rate
Time m_processingInterval; ///< Time period between calls to onProcessSamples
bool m_isCapturing; ///< Capturing state
std::string m_deviceName; ///< Name of the audio capture device
};
} // namespace sf
#endif // SFML_SOUNDRECORDER_HPP
////////////////////////////////////////////////////////////
/// \class sf::SoundRecorder
/// \ingroup audio
///
/// sf::SoundBuffer provides a simple interface to access
/// the audio recording capabilities of the computer
/// (the microphone). As an abstract base class, it only cares
/// about capturing sound samples, the task of making something
/// useful with them is left to the derived class. Note that
/// SFML provides a built-in specialization for saving the
/// captured data to a sound buffer (see sf::SoundBufferRecorder).
///
/// A derived class has only one virtual function to override:
/// \li onProcessSamples provides the new chunks of audio samples while the capture happens
///
/// Moreover, two additional virtual functions can be overridden
/// as well if necessary:
/// \li onStart is called before the capture happens, to perform custom initializations
/// \li onStop is called after the capture ends, to perform custom cleanup
///
/// A derived class can also control the frequency of the onProcessSamples
/// calls, with the setProcessingInterval protected function. The default
/// interval is chosen so that recording thread doesn't consume too much
/// CPU, but it can be changed to a smaller value if you need to process
/// the recorded data in real time, for example.
///
/// The audio capture feature may not be supported or activated
/// on every platform, thus it is recommended to check its
/// availability with the isAvailable() function. If it returns
/// false, then any attempt to use an audio recorder will fail.
///
/// If you have multiple sound input devices connected to your
/// computer (for example: microphone, external soundcard, webcam mic, ...)
/// you can get a list of all available devices through the
/// getAvailableDevices() function. You can then select a device
/// by calling setDevice() with the appropriate device. Otherwise
/// the default capturing device will be used.
///
/// It is important to note that the audio capture happens in a
/// separate thread, so that it doesn't block the rest of the
/// program. In particular, the onProcessSamples virtual function
/// (but not onStart and not onStop) will be called
/// from this separate thread. It is important to keep this in
/// mind, because you may have to take care of synchronization
/// issues if you share data between threads.
///
/// Usage example:
/// \code
/// class CustomRecorder : public sf::SoundRecorder
/// {
/// virtual bool onStart() // optional
/// {
/// // Initialize whatever has to be done before the capture starts
/// ...
///
/// // Return true to start playing
/// return true;
/// }
///
/// virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount)
/// {
/// // Do something with the new chunk of samples (store them, send them, ...)
/// ...
///
/// // Return true to continue playing
/// return true;
/// }
///
/// virtual void onStop() // optional
/// {
/// // Clean up whatever has to be done after the capture ends
/// ...
/// }
/// }
///
/// // Usage
/// if (CustomRecorder::isAvailable())
/// {
/// CustomRecorder recorder;
///
/// if (!recorder.start())
/// return -1;
///
/// ...
/// recorder.stop();
/// }
/// \endcode
///
/// \see sf::SoundBufferRecorder
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,287 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDSOURCE_HPP
#define SFML_SOUNDSOURCE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/Audio/AlResource.hpp>
#include <SFML/System/Vector3.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Base class defining a sound's properties
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API SoundSource : AlResource
{
public:
////////////////////////////////////////////////////////////
/// \brief Enumeration of the sound source states
///
////////////////////////////////////////////////////////////
enum Status
{
Stopped, ///< Sound is not playing
Paused, ///< Sound is paused
Playing ///< Sound is playing
};
////////////////////////////////////////////////////////////
/// \brief Copy constructor
///
/// \param copy Instance to copy
///
////////////////////////////////////////////////////////////
SoundSource(const SoundSource& copy);
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
virtual ~SoundSource();
////////////////////////////////////////////////////////////
/// \brief Set the pitch of the sound
///
/// The pitch represents the perceived fundamental frequency
/// of a sound; thus you can make a sound more acute or grave
/// by changing its pitch. A side effect of changing the pitch
/// is to modify the playing speed of the sound as well.
/// The default value for the pitch is 1.
///
/// \param pitch New pitch to apply to the sound
///
/// \see getPitch
///
////////////////////////////////////////////////////////////
void setPitch(float pitch);
////////////////////////////////////////////////////////////
/// \brief Set the volume of the sound
///
/// The volume is a value between 0 (mute) and 100 (full volume).
/// The default value for the volume is 100.
///
/// \param volume Volume of the sound
///
/// \see getVolume
///
////////////////////////////////////////////////////////////
void setVolume(float volume);
////////////////////////////////////////////////////////////
/// \brief Set the 3D position of the sound in the audio scene
///
/// Only sounds with one channel (mono sounds) can be
/// spatialized.
/// The default position of a sound is (0, 0, 0).
///
/// \param x X coordinate of the position of the sound in the scene
/// \param y Y coordinate of the position of the sound in the scene
/// \param z Z coordinate of the position of the sound in the scene
///
/// \see getPosition
///
////////////////////////////////////////////////////////////
void setPosition(float x, float y, float z);
////////////////////////////////////////////////////////////
/// \brief Set the 3D position of the sound in the audio scene
///
/// Only sounds with one channel (mono sounds) can be
/// spatialized.
/// The default position of a sound is (0, 0, 0).
///
/// \param position Position of the sound in the scene
///
/// \see getPosition
///
////////////////////////////////////////////////////////////
void setPosition(const Vector3f& position);
////////////////////////////////////////////////////////////
/// \brief Make the sound's position relative to the listener or absolute
///
/// Making a sound relative to the listener will ensure that it will always
/// be played the same way regardless of the position of the listener.
/// This can be useful for non-spatialized sounds, sounds that are
/// produced by the listener, or sounds attached to it.
/// The default value is false (position is absolute).
///
/// \param relative True to set the position relative, false to set it absolute
///
/// \see isRelativeToListener
///
////////////////////////////////////////////////////////////
void setRelativeToListener(bool relative);
////////////////////////////////////////////////////////////
/// \brief Set the minimum distance of the sound
///
/// The "minimum distance" of a sound is the maximum
/// distance at which it is heard at its maximum volume. Further
/// than the minimum distance, it will start to fade out according
/// to its attenuation factor. A value of 0 ("inside the head
/// of the listener") is an invalid value and is forbidden.
/// The default value of the minimum distance is 1.
///
/// \param distance New minimum distance of the sound
///
/// \see getMinDistance, setAttenuation
///
////////////////////////////////////////////////////////////
void setMinDistance(float distance);
////////////////////////////////////////////////////////////
/// \brief Set the attenuation factor of the sound
///
/// The attenuation is a multiplicative factor which makes
/// the sound more or less loud according to its distance
/// from the listener. An attenuation of 0 will produce a
/// non-attenuated sound, i.e. its volume will always be the same
/// whether it is heard from near or from far. On the other hand,
/// an attenuation value such as 100 will make the sound fade out
/// very quickly as it gets further from the listener.
/// The default value of the attenuation is 1.
///
/// \param attenuation New attenuation factor of the sound
///
/// \see getAttenuation, setMinDistance
///
////////////////////////////////////////////////////////////
void setAttenuation(float attenuation);
////////////////////////////////////////////////////////////
/// \brief Get the pitch of the sound
///
/// \return Pitch of the sound
///
/// \see setPitch
///
////////////////////////////////////////////////////////////
float getPitch() const;
////////////////////////////////////////////////////////////
/// \brief Get the volume of the sound
///
/// \return Volume of the sound, in the range [0, 100]
///
/// \see setVolume
///
////////////////////////////////////////////////////////////
float getVolume() const;
////////////////////////////////////////////////////////////
/// \brief Get the 3D position of the sound in the audio scene
///
/// \return Position of the sound
///
/// \see setPosition
///
////////////////////////////////////////////////////////////
Vector3f getPosition() const;
////////////////////////////////////////////////////////////
/// \brief Tell whether the sound's position is relative to the
/// listener or is absolute
///
/// \return True if the position is relative, false if it's absolute
///
/// \see setRelativeToListener
///
////////////////////////////////////////////////////////////
bool isRelativeToListener() const;
////////////////////////////////////////////////////////////
/// \brief Get the minimum distance of the sound
///
/// \return Minimum distance of the sound
///
/// \see setMinDistance, getAttenuation
///
////////////////////////////////////////////////////////////
float getMinDistance() const;
////////////////////////////////////////////////////////////
/// \brief Get the attenuation factor of the sound
///
/// \return Attenuation factor of the sound
///
/// \see setAttenuation, getMinDistance
///
////////////////////////////////////////////////////////////
float getAttenuation() const;
protected:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor is meant to be called by derived classes only.
///
////////////////////////////////////////////////////////////
SoundSource();
////////////////////////////////////////////////////////////
/// \brief Get the current status of the sound (stopped, paused, playing)
///
/// \return Current status of the sound
///
////////////////////////////////////////////////////////////
Status getStatus() const;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int m_source; ///< OpenAL source identifier
};
} // namespace sf
#endif // SFML_SOUNDSOURCE_HPP
////////////////////////////////////////////////////////////
/// \class sf::SoundSource
/// \ingroup audio
///
/// sf::SoundSource is not meant to be used directly, it
/// only serves as a common base for all audio objects
/// that can live in the audio environment.
///
/// It defines several properties for the sound: pitch,
/// volume, position, attenuation, etc. All of them can be
/// changed at any time with no impact on performances.
///
/// \see sf::Sound, sf::SoundStream
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,386 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDSTREAM_HPP
#define SFML_SOUNDSTREAM_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>
#include <SFML/Audio/SoundSource.hpp>
#include <SFML/System/Thread.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/System/Mutex.hpp>
#include <cstdlib>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Abstract base class for streamed audio sources
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API SoundStream : public SoundSource
{
public:
////////////////////////////////////////////////////////////
/// \brief Structure defining a chunk of audio data to stream
///
////////////////////////////////////////////////////////////
struct Chunk
{
const Int16* samples; ///< Pointer to the audio samples
std::size_t sampleCount; ///< Number of samples pointed by Samples
};
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
virtual ~SoundStream();
////////////////////////////////////////////////////////////
/// \brief Start or resume playing the audio stream
///
/// This function starts the stream if it was stopped, resumes
/// it if it was paused, and restarts it from the beginning if
/// it was already playing.
/// This function uses its own thread so that it doesn't block
/// the rest of the program while the stream is played.
///
/// \see pause, stop
///
////////////////////////////////////////////////////////////
void play();
////////////////////////////////////////////////////////////
/// \brief Pause the audio stream
///
/// This function pauses the stream if it was playing,
/// otherwise (stream already paused or stopped) it has no effect.
///
/// \see play, stop
///
////////////////////////////////////////////////////////////
void pause();
////////////////////////////////////////////////////////////
/// \brief Stop playing the audio stream
///
/// This function stops the stream if it was playing or paused,
/// and does nothing if it was already stopped.
/// It also resets the playing position (unlike pause()).
///
/// \see play, pause
///
////////////////////////////////////////////////////////////
void stop();
////////////////////////////////////////////////////////////
/// \brief Return the number of channels of the stream
///
/// 1 channel means a mono sound, 2 means stereo, etc.
///
/// \return Number of channels
///
////////////////////////////////////////////////////////////
unsigned int getChannelCount() const;
////////////////////////////////////////////////////////////
/// \brief Get the stream sample rate of the stream
///
/// The sample rate is the number of audio samples played per
/// second. The higher, the better the quality.
///
/// \return Sample rate, in number of samples per second
///
////////////////////////////////////////////////////////////
unsigned int getSampleRate() const;
////////////////////////////////////////////////////////////
/// \brief Get the current status of the stream (stopped, paused, playing)
///
/// \return Current status
///
////////////////////////////////////////////////////////////
Status getStatus() const;
////////////////////////////////////////////////////////////
/// \brief Change the current playing position of the stream
///
/// The playing position can be changed when the stream is
/// either paused or playing. Changing the playing position
/// when the stream is stopped has no effect, since playing
/// the stream would reset its position.
///
/// \param timeOffset New playing position, from the beginning of the stream
///
/// \see getPlayingOffset
///
////////////////////////////////////////////////////////////
void setPlayingOffset(Time timeOffset);
////////////////////////////////////////////////////////////
/// \brief Get the current playing position of the stream
///
/// \return Current playing position, from the beginning of the stream
///
/// \see setPlayingOffset
///
////////////////////////////////////////////////////////////
Time getPlayingOffset() const;
////////////////////////////////////////////////////////////
/// \brief Set whether or not the stream should loop after reaching the end
///
/// If set, the stream will restart from beginning after
/// reaching the end and so on, until it is stopped or
/// setLoop(false) is called.
/// The default looping state for streams is false.
///
/// \param loop True to play in loop, false to play once
///
/// \see getLoop
///
////////////////////////////////////////////////////////////
void setLoop(bool loop);
////////////////////////////////////////////////////////////
/// \brief Tell whether or not the stream is in loop mode
///
/// \return True if the stream is looping, false otherwise
///
/// \see setLoop
///
////////////////////////////////////////////////////////////
bool getLoop() const;
protected:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor is only meant to be called by derived classes.
///
////////////////////////////////////////////////////////////
SoundStream();
////////////////////////////////////////////////////////////
/// \brief Define the audio stream parameters
///
/// This function must be called by derived classes as soon
/// as they know the audio settings of the stream to play.
/// Any attempt to manipulate the stream (play(), ...) before
/// calling this function will fail.
/// It can be called multiple times if the settings of the
/// audio stream change, but only when the stream is stopped.
///
/// \param channelCount Number of channels of the stream
/// \param sampleRate Sample rate, in samples per second
///
////////////////////////////////////////////////////////////
void initialize(unsigned int channelCount, unsigned int sampleRate);
////////////////////////////////////////////////////////////
/// \brief Request a new chunk of audio samples from the stream source
///
/// This function must be overridden by derived classes to provide
/// the audio samples to play. It is called continuously by the
/// streaming loop, in a separate thread.
/// The source can choose to stop the streaming loop at any time, by
/// returning false to the caller.
/// If you return true (i.e. continue streaming) it is important that
/// the returned array of samples is not empty; this would stop the stream
/// due to an internal limitation.
///
/// \param data Chunk of data to fill
///
/// \return True to continue playback, false to stop
///
////////////////////////////////////////////////////////////
virtual bool onGetData(Chunk& data) = 0;
////////////////////////////////////////////////////////////
/// \brief Change the current playing position in the stream source
///
/// This function must be overridden by derived classes to
/// allow random seeking into the stream source.
///
/// \param timeOffset New playing position, relative to the beginning of the stream
///
////////////////////////////////////////////////////////////
virtual void onSeek(Time timeOffset) = 0;
private:
////////////////////////////////////////////////////////////
/// \brief Function called as the entry point of the thread
///
/// This function starts the streaming loop, and returns
/// only when the sound is stopped.
///
////////////////////////////////////////////////////////////
void streamData();
////////////////////////////////////////////////////////////
/// \brief Fill a new buffer with audio samples, and append
/// it to the playing queue
///
/// This function is called as soon as a buffer has been fully
/// consumed; it fills it again and inserts it back into the
/// playing queue.
///
/// \param bufferNum Number of the buffer to fill (in [0, BufferCount])
///
/// \return True if the stream source has requested to stop, false otherwise
///
////////////////////////////////////////////////////////////
bool fillAndPushBuffer(unsigned int bufferNum);
////////////////////////////////////////////////////////////
/// \brief Fill the audio buffers and put them all into the playing queue
///
/// This function is called when playing starts and the
/// playing queue is empty.
///
/// \return True if the derived class has requested to stop, false otherwise
///
////////////////////////////////////////////////////////////
bool fillQueue();
////////////////////////////////////////////////////////////
/// \brief Clear all the audio buffers and empty the playing queue
///
/// This function is called when the stream is stopped.
///
////////////////////////////////////////////////////////////
void clearQueue();
enum
{
BufferCount = 3 ///< Number of audio buffers used by the streaming loop
};
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Thread m_thread; ///< Thread running the background tasks
mutable Mutex m_threadMutex; ///< Thread mutex
Status m_threadStartState; ///< State the thread starts in (Playing, Paused, Stopped)
bool m_isStreaming; ///< Streaming state (true = playing, false = stopped)
unsigned int m_buffers[BufferCount]; ///< Sound buffers used to store temporary audio data
unsigned int m_channelCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
unsigned int m_sampleRate; ///< Frequency (samples / second)
Uint32 m_format; ///< Format of the internal sound buffers
bool m_loop; ///< Loop flag (true to loop, false to play once)
Uint64 m_samplesProcessed; ///< Number of buffers processed since beginning of the stream
bool m_endBuffers[BufferCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation
};
} // namespace sf
#endif // SFML_SOUNDSTREAM_HPP
////////////////////////////////////////////////////////////
/// \class sf::SoundStream
/// \ingroup audio
///
/// Unlike audio buffers (see sf::SoundBuffer), audio streams
/// are never completely loaded in memory. Instead, the audio
/// data is acquired continuously while the stream is playing.
/// This behavior allows to play a sound with no loading delay,
/// and keeps the memory consumption very low.
///
/// Sound sources that need to be streamed are usually big files
/// (compressed audio musics that would eat hundreds of MB in memory)
/// or files that would take a lot of time to be received
/// (sounds played over the network).
///
/// sf::SoundStream is a base class that doesn't care about the
/// stream source, which is left to the derived class. SFML provides
/// a built-in specialization for big files (see sf::Music).
/// No network stream source is provided, but you can write your own
/// by combining this class with the network module.
///
/// A derived class has to override two virtual functions:
/// \li onGetData fills a new chunk of audio data to be played
/// \li onSeek changes the current playing position in the source
///
/// It is important to note that each SoundStream is played in its
/// own separate thread, so that the streaming loop doesn't block the
/// rest of the program. In particular, the OnGetData and OnSeek
/// virtual functions may sometimes be called from this separate thread.
/// It is important to keep this in mind, because you may have to take
/// care of synchronization issues if you share data between threads.
///
/// Usage example:
/// \code
/// class CustomStream : public sf::SoundStream
/// {
/// public:
///
/// bool open(const std::string& location)
/// {
/// // Open the source and get audio settings
/// ...
/// unsigned int channelCount = ...;
/// unsigned int sampleRate = ...;
///
/// // Initialize the stream -- important!
/// initialize(channelCount, sampleRate);
/// }
///
/// private:
///
/// virtual bool onGetData(Chunk& data)
/// {
/// // Fill the chunk with audio data from the stream source
/// // (note: must not be empty if you want to continue playing)
/// data.samples = ...;
/// data.sampleCount = ...;
///
/// // Return true to continue playing
/// return true;
/// }
///
/// virtual void onSeek(Uint32 timeOffset)
/// {
/// // Change the current position in the stream source
/// ...
/// }
/// }
///
/// // Usage
/// CustomStream stream;
/// stream.open("path/to/stream");
/// stream.play();
/// \endcode
///
/// \see sf::Music
///
////////////////////////////////////////////////////////////

193
external/sfml23/include/SFML/Config.hpp vendored Executable file
View File

@ -0,0 +1,193 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CONFIG_HPP
#define SFML_CONFIG_HPP
////////////////////////////////////////////////////////////
// Define the SFML version
////////////////////////////////////////////////////////////
#define SFML_VERSION_MAJOR 2
#define SFML_VERSION_MINOR 3
#define SFML_VERSION_PATCH 2
////////////////////////////////////////////////////////////
// Identify the operating system
// see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
////////////////////////////////////////////////////////////
#if defined(_WIN32)
// Windows
#define SFML_SYSTEM_WINDOWS
#ifndef NOMINMAX
#define NOMINMAX
#endif
#elif defined(__APPLE__) && defined(__MACH__)
// Apple platform, see which one it is
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
// iOS
#define SFML_SYSTEM_IOS
#elif TARGET_OS_MAC
// MacOS
#define SFML_SYSTEM_MACOS
#else
// Unsupported Apple system
#error This Apple operating system is not supported by SFML library
#endif
#elif defined(__unix__)
// UNIX system, see which one it is
#if defined(__ANDROID__)
// Android
#define SFML_SYSTEM_ANDROID
#elif defined(__linux__)
// Linux
#define SFML_SYSTEM_LINUX
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
// FreeBSD
#define SFML_SYSTEM_FREEBSD
#else
// Unsupported UNIX system
#error This UNIX operating system is not supported by SFML library
#endif
#else
// Unsupported system
#error This operating system is not supported by SFML library
#endif
////////////////////////////////////////////////////////////
// Define a portable debug macro
////////////////////////////////////////////////////////////
#if !defined(NDEBUG)
#define SFML_DEBUG
#endif
////////////////////////////////////////////////////////////
// Define helpers to create portable import / export macros for each module
////////////////////////////////////////////////////////////
#if !defined(SFML_STATIC)
#if defined(SFML_SYSTEM_WINDOWS)
// Windows compilers need specific (and different) keywords for export and import
#define SFML_API_EXPORT __declspec(dllexport)
#define SFML_API_IMPORT __declspec(dllimport)
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning
#ifdef _MSC_VER
#pragma warning(disable: 4251)
#endif
#else // Linux, FreeBSD, Mac OS X
#if __GNUC__ >= 4
// GCC 4 has special keywords for showing/hidding symbols,
// the same keyword is used for both importing and exporting
#define SFML_API_EXPORT __attribute__ ((__visibility__ ("default")))
#define SFML_API_IMPORT __attribute__ ((__visibility__ ("default")))
#else
// GCC < 4 has no mechanism to explicitely hide symbols, everything's exported
#define SFML_API_EXPORT
#define SFML_API_IMPORT
#endif
#endif
#else
// Static build doesn't need import/export macros
#define SFML_API_EXPORT
#define SFML_API_IMPORT
#endif
////////////////////////////////////////////////////////////
// Define portable fixed-size types
////////////////////////////////////////////////////////////
namespace sf
{
// All "common" platforms use the same size for char, short and int
// (basically there are 3 types for 3 sizes, so no other match is possible),
// we can use them without doing any kind of check
// 8 bits integer types
typedef signed char Int8;
typedef unsigned char Uint8;
// 16 bits integer types
typedef signed short Int16;
typedef unsigned short Uint16;
// 32 bits integer types
typedef signed int Int32;
typedef unsigned int Uint32;
// 64 bits integer types
#if defined(_MSC_VER)
typedef signed __int64 Int64;
typedef unsigned __int64 Uint64;
#else
typedef signed long long Int64;
typedef unsigned long long Uint64;
#endif
} // namespace sf
#endif // SFML_CONFIG_HPP

67
external/sfml23/include/SFML/Graphics.hpp vendored Executable file
View File

@ -0,0 +1,67 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_GRAPHICS_HPP
#define SFML_GRAPHICS_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/ConvexShape.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Glyph.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/RenderStates.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Shader.hpp>
#include <SFML/Graphics/Shape.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Transform.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/VertexArray.hpp>
#include <SFML/Graphics/View.hpp>
#endif // SFML_GRAPHICS_HPP
////////////////////////////////////////////////////////////
/// \defgroup graphics Graphics module
///
/// 2D graphics module: sprites, text, shapes, ...
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,214 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_BLENDMODE_HPP
#define SFML_BLENDMODE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Blending modes for drawing
///
////////////////////////////////////////////////////////////
struct SFML_GRAPHICS_API BlendMode
{
////////////////////////////////////////////////////////
/// \brief Enumeration of the blending factors
///
/// The factors are mapped directly to their OpenGL equivalents,
/// specified by glBlendFunc() or glBlendFuncSeparate().
////////////////////////////////////////////////////////
enum Factor
{
Zero, ///< (0, 0, 0, 0)
One, ///< (1, 1, 1, 1)
SrcColor, ///< (src.r, src.g, src.b, src.a)
OneMinusSrcColor, ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
DstColor, ///< (dst.r, dst.g, dst.b, dst.a)
OneMinusDstColor, ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
SrcAlpha, ///< (src.a, src.a, src.a, src.a)
OneMinusSrcAlpha, ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
DstAlpha, ///< (dst.a, dst.a, dst.a, dst.a)
OneMinusDstAlpha ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
};
////////////////////////////////////////////////////////
/// \brief Enumeration of the blending equations
///
/// The equations are mapped directly to their OpenGL equivalents,
/// specified by glBlendEquation() or glBlendEquationSeparate().
////////////////////////////////////////////////////////
enum Equation
{
Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor
Subtract ///< Pixel = Src * SrcFactor - Dst * DstFactor
};
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Constructs a blending mode that does alpha blending.
///
////////////////////////////////////////////////////////////
BlendMode();
////////////////////////////////////////////////////////////
/// \brief Construct the blend mode given the factors and equation.
///
/// This constructor uses the same factors and equation for both
/// color and alpha components. It also defaults to the Add equation.
///
/// \param sourceFactor Specifies how to compute the source factor for the color and alpha channels.
/// \param destinationFactor Specifies how to compute the destination factor for the color and alpha channels.
/// \param blendEquation Specifies how to combine the source and destination colors and alpha.
///
////////////////////////////////////////////////////////////
BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Add);
////////////////////////////////////////////////////////////
/// \brief Construct the blend mode given the factors and equation.
///
/// \param colorSourceFactor Specifies how to compute the source factor for the color channels.
/// \param colorDestinationFactor Specifies how to compute the destination factor for the color channels.
/// \param colorBlendEquation Specifies how to combine the source and destination colors.
/// \param alphaSourceFactor Specifies how to compute the source factor.
/// \param alphaDestinationFactor Specifies how to compute the destination factor.
/// \param alphaBlendEquation Specifies how to combine the source and destination alphas.
///
////////////////////////////////////////////////////////////
BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor,
Equation colorBlendEquation, Factor alphaSourceFactor,
Factor alphaDestinationFactor, Equation alphaBlendEquation);
////////////////////////////////////////////////////////////
// Member Data
////////////////////////////////////////////////////////////
Factor colorSrcFactor; ///< Source blending factor for the color channels
Factor colorDstFactor; ///< Destination blending factor for the color channels
Equation colorEquation; ///< Blending equation for the color channels
Factor alphaSrcFactor; ///< Source blending factor for the alpha channel
Factor alphaDstFactor; ///< Destination blending factor for the alpha channel
Equation alphaEquation; ///< Blending equation for the alpha channel
};
////////////////////////////////////////////////////////////
/// \relates BlendMode
/// \brief Overload of the == operator
///
/// \param left Left operand
/// \param right Right operand
///
/// \return True if blending modes are equal, false if they are different
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right);
////////////////////////////////////////////////////////////
/// \relates BlendMode
/// \brief Overload of the != operator
///
/// \param left Left operand
/// \param right Right operand
///
/// \return True if blending modes are different, false if they are equal
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right);
////////////////////////////////////////////////////////////
// Commonly used blending modes
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API extern const BlendMode BlendAlpha; ///< Blend source and dest according to dest alpha
SFML_GRAPHICS_API extern const BlendMode BlendAdd; ///< Add source to dest
SFML_GRAPHICS_API extern const BlendMode BlendMultiply; ///< Multiply source and dest
SFML_GRAPHICS_API extern const BlendMode BlendNone; ///< Overwrite dest with source
} // namespace sf
#endif // SFML_BLENDMODE_HPP
////////////////////////////////////////////////////////////
/// \class sf::BlendMode
/// \ingroup graphics
///
/// sf::BlendMode is a class that represents a blend mode. A blend
/// mode determines how the colors of an object you draw are
/// mixed with the colors that are already in the buffer.
///
/// The class is composed of 6 components, each of which has its
/// own public member variable:
/// \li %Color Source Factor (@ref colorSrcFactor)
/// \li %Color Destination Factor (@ref colorDstFactor)
/// \li %Color Blend Equation (@ref colorEquation)
/// \li Alpha Source Factor (@ref alphaSrcFactor)
/// \li Alpha Destination Factor (@ref alphaDstFactor)
/// \li Alpha Blend Equation (@ref alphaEquation)
///
/// The source factor specifies how the pixel you are drawing contributes
/// to the final color. The destination factor specifies how the pixel
/// already drawn in the buffer contributes to the final color.
///
/// The color channels RGB (red, green, blue; simply referred to as
/// color) and A (alpha; the transparency) can be treated separately. This
/// separation can be useful for specific blend modes, but most often you
/// won't need it and will simply treat the color as a single unit.
///
/// The blend factors and equations correspond to their OpenGL equivalents.
/// In general, the color of the resulting pixel is calculated according
/// to the following formula (\a src is the color of the source pixel, \a dst
/// the color of the destination pixel, the other variables correspond to the
/// public members, with the equations being + or - operators):
/// \code
/// dst.rgb = colorSrcFactor * src.rgb (colorEquation) colorDstFactor * dst.rgb
/// dst.a = alphaSrcFactor * src.a (alphaEquation) alphaDstFactor * dst.a
/// \endcode
/// All factors and colors are represented as floating point numbers between
/// 0 and 1. Where necessary, the result is clamped to fit in that range.
///
/// The most common blending modes are defined as constants
/// in the sf namespace:
///
/// \code
/// sf::BlendMode alphaBlending = sf::BlendAlpha;
/// sf::BlendMode additiveBlending = sf::BlendAdd;
/// sf::BlendMode multiplicativeBlending = sf::BlendMultipy;
/// sf::BlendMode noBlending = sf::BlendNone;
/// \endcode
///
/// In SFML, a blend mode can be specified every time you draw a sf::Drawable
/// object to a render target. It is part of the sf::RenderStates compound
/// that is passed to the member function sf::RenderTarget::draw().
///
/// \see sf::RenderStates, sf::RenderTarget
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,154 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CIRCLESHAPE_HPP
#define SFML_CIRCLESHAPE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Shape.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Specialized shape representing a circle
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API CircleShape : public Shape
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// \param radius Radius of the circle
/// \param pointCount Number of points composing the circle
///
////////////////////////////////////////////////////////////
explicit CircleShape(float radius = 0, std::size_t pointCount = 30);
////////////////////////////////////////////////////////////
/// \brief Set the radius of the circle
///
/// \param radius New radius of the circle
///
/// \see getRadius
///
////////////////////////////////////////////////////////////
void setRadius(float radius);
////////////////////////////////////////////////////////////
/// \brief Get the radius of the circle
///
/// \return Radius of the circle
///
/// \see setRadius
///
////////////////////////////////////////////////////////////
float getRadius() const;
////////////////////////////////////////////////////////////
/// \brief Set the number of points of the circle
///
/// \param count New number of points of the circle
///
/// \see getPointCount
///
////////////////////////////////////////////////////////////
void setPointCount(std::size_t count);
////////////////////////////////////////////////////////////
/// \brief Get the number of points of the circle
///
/// \return Number of points of the circle
///
/// \see setPointCount
///
////////////////////////////////////////////////////////////
virtual std::size_t getPointCount() const;
////////////////////////////////////////////////////////////
/// \brief Get a point of the circle
///
/// The returned point is in local coordinates, that is,
/// the shape's transforms (position, rotation, scale) are
/// not taken into account.
/// The result is undefined if \a index is out of the valid range.
///
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
///
/// \return index-th point of the shape
///
////////////////////////////////////////////////////////////
virtual Vector2f getPoint(std::size_t index) const;
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
float m_radius; ///< Radius of the circle
std::size_t m_pointCount; ///< Number of points composing the circle
};
} // namespace sf
#endif // SFML_CIRCLESHAPE_HPP
////////////////////////////////////////////////////////////
/// \class sf::CircleShape
/// \ingroup graphics
///
/// This class inherits all the functions of sf::Transformable
/// (position, rotation, scale, bounds, ...) as well as the
/// functions of sf::Shape (outline, color, texture, ...).
///
/// Usage example:
/// \code
/// sf::CircleShape circle;
/// circle.setRadius(150);
/// circle.setOutlineColor(sf::Color::Red);
/// circle.setOutlineThickness(5);
/// circle.setPosition(10, 20);
/// ...
/// window.draw(circle);
/// \endcode
///
/// Since the graphics card can't draw perfect circles, we have to
/// fake them with multiple triangles connected to each other. The
/// "points count" property of sf::CircleShape defines how many of these
/// triangles to use, and therefore defines the quality of the circle.
///
/// The number of points can also be used for another purpose; with
/// small numbers you can create any regular polygon shape:
/// equilateral triangle, square, pentagon, hexagon, ...
///
/// \see sf::Shape, sf::RectangleShape, sf::ConvexShape
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,275 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_COLOR_HPP
#define SFML_COLOR_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Utility class for manipulating RGBA colors
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Color
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Constructs an opaque black color. It is equivalent to
/// sf::Color(0, 0, 0, 255).
///
////////////////////////////////////////////////////////////
Color();
////////////////////////////////////////////////////////////
/// \brief Construct the color from its 4 RGBA components
///
/// \param red Red component (in the range [0, 255])
/// \param green Green component (in the range [0, 255])
/// \param blue Blue component (in the range [0, 255])
/// \param alpha Alpha (opacity) component (in the range [0, 255])
///
////////////////////////////////////////////////////////////
Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
////////////////////////////////////////////////////////////
/// \brief Construct the color from 32-bit unsigned integer
///
/// \param color Number containing the RGBA components (in that order)
///
////////////////////////////////////////////////////////////
explicit Color(Uint32 color);
////////////////////////////////////////////////////////////
/// \brief Retrieve the color as a 32-bit unsigned integer
///
/// \return Color represented as a 32-bit unsigned integer
///
////////////////////////////////////////////////////////////
Uint32 toInteger() const;
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static const Color Black; ///< Black predefined color
static const Color White; ///< White predefined color
static const Color Red; ///< Red predefined color
static const Color Green; ///< Green predefined color
static const Color Blue; ///< Blue predefined color
static const Color Yellow; ///< Yellow predefined color
static const Color Magenta; ///< Magenta predefined color
static const Color Cyan; ///< Cyan predefined color
static const Color Transparent; ///< Transparent (black) predefined color
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Uint8 r; ///< Red component
Uint8 g; ///< Green component
Uint8 b; ///< Blue component
Uint8 a; ///< Alpha (opacity) component
};
////////////////////////////////////////////////////////////
/// \relates Color
/// \brief Overload of the == operator
///
/// This operator compares two colors and check if they are equal.
///
/// \param left Left operand
/// \param right Right operand
///
/// \return True if colors are equal, false if they are different
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API bool operator ==(const Color& left, const Color& right);
////////////////////////////////////////////////////////////
/// \relates Color
/// \brief Overload of the != operator
///
/// This operator compares two colors and check if they are different.
///
/// \param left Left operand
/// \param right Right operand
///
/// \return True if colors are different, false if they are equal
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API bool operator !=(const Color& left, const Color& right);
////////////////////////////////////////////////////////////
/// \relates Color
/// \brief Overload of the binary + operator
///
/// This operator returns the component-wise sum of two colors.
/// Components that exceed 255 are clamped to 255.
///
/// \param left Left operand
/// \param right Right operand
///
/// \return Result of \a left + \a right
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Color operator +(const Color& left, const Color& right);
////////////////////////////////////////////////////////////
/// \relates Color
/// \brief Overload of the binary - operator
///
/// This operator returns the component-wise subtraction of two colors.
/// Components below 0 are clamped to 0.
///
/// \param left Left operand
/// \param right Right operand
///
/// \return Result of \a left - \a right
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Color operator -(const Color& left, const Color& right);
////////////////////////////////////////////////////////////
/// \relates Color
/// \brief Overload of the binary * operator
///
/// This operator returns the component-wise multiplication
/// (also called "modulation") of two colors.
/// Components are then divided by 255 so that the result is
/// still in the range [0, 255].
///
/// \param left Left operand
/// \param right Right operand
///
/// \return Result of \a left * \a right
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Color operator *(const Color& left, const Color& right);
////////////////////////////////////////////////////////////
/// \relates Color
/// \brief Overload of the binary += operator
///
/// This operator computes the component-wise sum of two colors,
/// and assigns the result to the left operand.
/// Components that exceed 255 are clamped to 255.
///
/// \param left Left operand
/// \param right Right operand
///
/// \return Reference to \a left
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Color& operator +=(Color& left, const Color& right);
////////////////////////////////////////////////////////////
/// \relates Color
/// \brief Overload of the binary -= operator
///
/// This operator computes the component-wise subtraction of two colors,
/// and assigns the result to the left operand.
/// Components below 0 are clamped to 0.
///
/// \param left Left operand
/// \param right Right operand
///
/// \return Reference to \a left
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Color& operator -=(Color& left, const Color& right);
////////////////////////////////////////////////////////////
/// \relates Color
/// \brief Overload of the binary *= operator
///
/// This operator returns the component-wise multiplication
/// (also called "modulation") of two colors, and assigns
/// the result to the left operand.
/// Components are then divided by 255 so that the result is
/// still in the range [0, 255].
///
/// \param left Left operand
/// \param right Right operand
///
/// \return Reference to \a left
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Color& operator *=(Color& left, const Color& right);
} // namespace sf
#endif // SFML_COLOR_HPP
////////////////////////////////////////////////////////////
/// \class sf::Color
/// \ingroup graphics
///
/// sf::Color is a simple color class composed of 4 components:
/// \li Red
/// \li Green
/// \li Blue
/// \li Alpha (opacity)
///
/// Each component is a public member, an unsigned integer in
/// the range [0, 255]. Thus, colors can be constructed and
/// manipulated very easily:
///
/// \code
/// sf::Color color(255, 0, 0); // red
/// color.r = 0; // make it black
/// color.b = 128; // make it dark blue
/// \endcode
///
/// The fourth component of colors, named "alpha", represents
/// the opacity of the color. A color with an alpha value of
/// 255 will be fully opaque, while an alpha value of 0 will
/// make a color fully transparent, whatever the value of the
/// other components is.
///
/// The most common colors are already defined as static variables:
/// \code
/// sf::Color black = sf::Color::Black;
/// sf::Color white = sf::Color::White;
/// sf::Color red = sf::Color::Red;
/// sf::Color green = sf::Color::Green;
/// sf::Color blue = sf::Color::Blue;
/// sf::Color yellow = sf::Color::Yellow;
/// sf::Color magenta = sf::Color::Magenta;
/// sf::Color cyan = sf::Color::Cyan;
/// sf::Color transparent = sf::Color::Transparent;
/// \endcode
///
/// Colors can also be added and modulated (multiplied) using the
/// overloaded operators + and *.
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,153 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CONVEXSHAPE_HPP
#define SFML_CONVEXSHAPE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Shape.hpp>
#include <vector>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Specialized shape representing a convex polygon
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API ConvexShape : public Shape
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// \param pointCount Number of points of the polygon
///
////////////////////////////////////////////////////////////
explicit ConvexShape(std::size_t pointCount = 0);
////////////////////////////////////////////////////////////
/// \brief Set the number of points of the polygon
///
/// \a count must be greater than 2 to define a valid shape.
///
/// \param count New number of points of the polygon
///
/// \see getPointCount
///
////////////////////////////////////////////////////////////
void setPointCount(std::size_t count);
////////////////////////////////////////////////////////////
/// \brief Get the number of points of the polygon
///
/// \return Number of points of the polygon
///
/// \see setPointCount
///
////////////////////////////////////////////////////////////
virtual std::size_t getPointCount() const;
////////////////////////////////////////////////////////////
/// \brief Set the position of a point
///
/// Don't forget that the polygon must remain convex, and
/// the points need to stay ordered!
/// setPointCount must be called first in order to set the total
/// number of points. The result is undefined if \a index is out
/// of the valid range.
///
/// \param index Index of the point to change, in range [0 .. getPointCount() - 1]
/// \param point New position of the point
///
/// \see getPoint
///
////////////////////////////////////////////////////////////
void setPoint(std::size_t index, const Vector2f& point);
////////////////////////////////////////////////////////////
/// \brief Get the position of a point
///
/// The returned point is in local coordinates, that is,
/// the shape's transforms (position, rotation, scale) are
/// not taken into account.
/// The result is undefined if \a index is out of the valid range.
///
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
///
/// \return Position of the index-th point of the polygon
///
/// \see setPoint
///
////////////////////////////////////////////////////////////
virtual Vector2f getPoint(std::size_t index) const;
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::vector<Vector2f> m_points; ///< Points composing the convex polygon
};
} // namespace sf
#endif // SFML_CONVEXSHAPE_HPP
////////////////////////////////////////////////////////////
/// \class sf::ConvexShape
/// \ingroup graphics
///
/// This class inherits all the functions of sf::Transformable
/// (position, rotation, scale, bounds, ...) as well as the
/// functions of sf::Shape (outline, color, texture, ...).
///
/// It is important to keep in mind that a convex shape must
/// always be... convex, otherwise it may not be drawn correctly.
/// Moreover, the points must be defined in order; using a random
/// order would result in an incorrect shape.
///
/// Usage example:
/// \code
/// sf::ConvexShape polygon;
/// polygon.setPointCount(3);
/// polygon.setPoint(0, sf::Vector2f(0, 0));
/// polygon.setPoint(1, sf::Vector2f(0, 10));
/// polygon.setPoint(2, sf::Vector2f(25, 5));
/// polygon.setOutlineColor(sf::Color::Red);
/// polygon.setOutlineThickness(5);
/// polygon.setPosition(10, 20);
/// ...
/// window.draw(polygon);
/// \endcode
///
/// \see sf::Shape, sf::RectangleShape, sf::CircleShape
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,126 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_DRAWABLE_HPP
#define SFML_DRAWABLE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/RenderStates.hpp>
namespace sf
{
class RenderTarget;
////////////////////////////////////////////////////////////
/// \brief Abstract base class for objects that can be drawn
/// to a render target
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Drawable
{
public:
////////////////////////////////////////////////////////////
/// \brief Virtual destructor
///
////////////////////////////////////////////////////////////
virtual ~Drawable() {}
protected:
friend class RenderTarget;
////////////////////////////////////////////////////////////
/// \brief Draw the object to a render target
///
/// This is a pure virtual function that has to be implemented
/// by the derived class to define how the drawable should be
/// drawn.
///
/// \param target Render target to draw to
/// \param states Current render states
///
////////////////////////////////////////////////////////////
virtual void draw(RenderTarget& target, RenderStates states) const = 0;
};
} // namespace sf
#endif // SFML_DRAWABLE_HPP
////////////////////////////////////////////////////////////
/// \class sf::Drawable
/// \ingroup graphics
///
/// sf::Drawable is a very simple base class that allows objects
/// of derived classes to be drawn to a sf::RenderTarget.
///
/// All you have to do in your derived class is to override the
/// draw virtual function.
///
/// Note that inheriting from sf::Drawable is not mandatory,
/// but it allows this nice syntax "window.draw(object)" rather
/// than "object.draw(window)", which is more consistent with other
/// SFML classes.
///
/// Example:
/// \code
/// class MyDrawable : public sf::Drawable
/// {
/// public:
///
/// ...
///
/// private:
///
/// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
/// {
/// // You can draw other high-level objects
/// target.draw(m_sprite, states);
///
/// // ... or use the low-level API
/// states.texture = &m_texture;
/// target.draw(m_vertices, states);
///
/// // ... or draw with OpenGL directly
/// glBegin(GL_QUADS);
/// ...
/// glEnd();
/// }
///
/// sf::Sprite m_sprite;
/// sf::Texture m_texture;
/// sf::VertexArray m_vertices;
/// };
/// \endcode
///
/// \see sf::RenderTarget
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_GRAPHICS_EXPORT_HPP
#define SFML_GRAPHICS_EXPORT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
////////////////////////////////////////////////////////////
// Define portable import / export macros
////////////////////////////////////////////////////////////
#if defined(SFML_GRAPHICS_EXPORTS)
#define SFML_GRAPHICS_API SFML_API_EXPORT
#else
#define SFML_GRAPHICS_API SFML_API_IMPORT
#endif
#endif // SFML_GRAPHICS_EXPORT_HPP

433
external/sfml23/include/SFML/Graphics/Font.hpp vendored Executable file
View File

@ -0,0 +1,433 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_FONT_HPP
#define SFML_FONT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Glyph.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/String.hpp>
#include <map>
#include <string>
#include <vector>
namespace sf
{
class InputStream;
////////////////////////////////////////////////////////////
/// \brief Class for loading and manipulating character fonts
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Font
{
public:
////////////////////////////////////////////////////////////
/// \brief Holds various information about a font
///
////////////////////////////////////////////////////////////
struct Info
{
std::string family; ///< The font family
};
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor defines an empty font
///
////////////////////////////////////////////////////////////
Font();
////////////////////////////////////////////////////////////
/// \brief Copy constructor
///
/// \param copy Instance to copy
///
////////////////////////////////////////////////////////////
Font(const Font& copy);
////////////////////////////////////////////////////////////
/// \brief Destructor
///
/// Cleans up all the internal resources used by the font
///
////////////////////////////////////////////////////////////
~Font();
////////////////////////////////////////////////////////////
/// \brief Load the font from a file
///
/// The supported font formats are: TrueType, Type 1, CFF,
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
/// Note that this function know nothing about the standard
/// fonts installed on the user's system, thus you can't
/// load them directly.
///
/// \warning SFML cannot preload all the font data in this
/// function, so the file has to remain accessible until
/// the sf::Font object loads a new font or is destroyed.
///
/// \param filename Path of the font file to load
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromMemory, loadFromStream
///
////////////////////////////////////////////////////////////
bool loadFromFile(const std::string& filename);
////////////////////////////////////////////////////////////
/// \brief Load the font from a file in memory
///
/// The supported font formats are: TrueType, Type 1, CFF,
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
///
/// \warning SFML cannot preload all the font data in this
/// function, so the buffer pointed by \a data has to remain
/// valid until the sf::Font object loads a new font or
/// is destroyed.
///
/// \param data Pointer to the file data in memory
/// \param sizeInBytes Size of the data to load, in bytes
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromStream
///
////////////////////////////////////////////////////////////
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
////////////////////////////////////////////////////////////
/// \brief Load the font from a custom stream
///
/// The supported font formats are: TrueType, Type 1, CFF,
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
/// Warning: SFML cannot preload all the font data in this
/// function, so the contents of \a stream have to remain
/// valid as long as the font is used.
///
/// \warning SFML cannot preload all the font data in this
/// function, so the stream has to remain accessible until
/// the sf::Font object loads a new font or is destroyed.
///
/// \param stream Source stream to read from
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromMemory
///
////////////////////////////////////////////////////////////
bool loadFromStream(InputStream& stream);
////////////////////////////////////////////////////////////
/// \brief Get the font information
///
/// \return A structure that holds the font information
///
////////////////////////////////////////////////////////////
const Info& getInfo() const;
////////////////////////////////////////////////////////////
/// \brief Retrieve a glyph of the font
///
/// If the font is a bitmap font, not all character sizes
/// might be available. If the glyph is not available at the
/// requested size, an empty glyph is returned.
///
/// \param codePoint Unicode code point of the character to get
/// \param characterSize Reference character size
/// \param bold Retrieve the bold version or the regular one?
///
/// \return The glyph corresponding to \a codePoint and \a characterSize
///
////////////////////////////////////////////////////////////
const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
////////////////////////////////////////////////////////////
/// \brief Get the kerning offset of two glyphs
///
/// The kerning is an extra offset (negative) to apply between two
/// glyphs when rendering them, to make the pair look more "natural".
/// For example, the pair "AV" have a special kerning to make them
/// closer than other characters. Most of the glyphs pairs have a
/// kerning offset of zero, though.
///
/// \param first Unicode code point of the first character
/// \param second Unicode code point of the second character
/// \param characterSize Reference character size
///
/// \return Kerning value for \a first and \a second, in pixels
///
////////////////////////////////////////////////////////////
float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
////////////////////////////////////////////////////////////
/// \brief Get the line spacing
///
/// Line spacing is the vertical offset to apply between two
/// consecutive lines of text.
///
/// \param characterSize Reference character size
///
/// \return Line spacing, in pixels
///
////////////////////////////////////////////////////////////
float getLineSpacing(unsigned int characterSize) const;
////////////////////////////////////////////////////////////
/// \brief Get the position of the underline
///
/// Underline position is the vertical offset to apply between the
/// baseline and the underline.
///
/// \param characterSize Reference character size
///
/// \return Underline position, in pixels
///
/// \see getUnderlineThickness
///
////////////////////////////////////////////////////////////
float getUnderlinePosition(unsigned int characterSize) const;
////////////////////////////////////////////////////////////
/// \brief Get the thickness of the underline
///
/// Underline thickness is the vertical size of the underline.
///
/// \param characterSize Reference character size
///
/// \return Underline thickness, in pixels
///
/// \see getUnderlinePosition
///
////////////////////////////////////////////////////////////
float getUnderlineThickness(unsigned int characterSize) const;
////////////////////////////////////////////////////////////
/// \brief Retrieve the texture containing the loaded glyphs of a certain size
///
/// The contents of the returned texture changes as more glyphs
/// are requested, thus it is not very relevant. It is mainly
/// used internally by sf::Text.
///
/// \param characterSize Reference character size
///
/// \return Texture containing the glyphs of the requested size
///
////////////////////////////////////////////////////////////
const Texture& getTexture(unsigned int characterSize) const;
////////////////////////////////////////////////////////////
/// \brief Overload of assignment operator
///
/// \param right Instance to assign
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
Font& operator =(const Font& right);
private:
////////////////////////////////////////////////////////////
/// \brief Structure defining a row of glyphs
///
////////////////////////////////////////////////////////////
struct Row
{
Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
unsigned int width; ///< Current width of the row
unsigned int top; ///< Y position of the row into the texture
unsigned int height; ///< Height of the row
};
////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////
typedef std::map<Uint32, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
////////////////////////////////////////////////////////////
/// \brief Structure defining a page of glyphs
///
////////////////////////////////////////////////////////////
struct Page
{
Page();
GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph
Texture texture; ///< Texture containing the pixels of the glyphs
unsigned int nextRow; ///< Y position of the next new row in the texture
std::vector<Row> rows; ///< List containing the position of all the existing rows
};
////////////////////////////////////////////////////////////
/// \brief Free all the internal resources
///
////////////////////////////////////////////////////////////
void cleanup();
////////////////////////////////////////////////////////////
/// \brief Load a new glyph and store it in the cache
///
/// \param codePoint Unicode code point of the character to load
/// \param characterSize Reference character size
/// \param bold Retrieve the bold version or the regular one?
///
/// \return The glyph corresponding to \a codePoint and \a characterSize
///
////////////////////////////////////////////////////////////
Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const;
////////////////////////////////////////////////////////////
/// \brief Find a suitable rectangle within the texture for a glyph
///
/// \param page Page of glyphs to search in
/// \param width Width of the rectangle
/// \param height Height of the rectangle
///
/// \return Found rectangle within the texture
///
////////////////////////////////////////////////////////////
IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const;
////////////////////////////////////////////////////////////
/// \brief Make sure that the given size is the current one
///
/// \param characterSize Reference character size
///
/// \return True on success, false if any error happened
///
////////////////////////////////////////////////////////////
bool setCurrentSize(unsigned int characterSize) const;
////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////
typedef std::map<unsigned int, Page> PageTable; ///< Table mapping a character size to its page (texture)
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
void* m_library; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details)
void* m_face; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details)
void* m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details)
int* m_refCount; ///< Reference counter used by implicit sharing
Info m_info; ///< Information about the font
mutable PageTable m_pages; ///< Table containing the glyphs pages by character size
mutable std::vector<Uint8> m_pixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture
#ifdef SFML_SYSTEM_ANDROID
void* m_stream; ///< Asset file streamer (if loaded from file)
#endif
};
} // namespace sf
#endif // SFML_FONT_HPP
////////////////////////////////////////////////////////////
/// \class sf::Font
/// \ingroup graphics
///
/// Fonts can be loaded from a file, from memory or from a custom
/// stream, and supports the most common types of fonts. See
/// the loadFromFile function for the complete list of supported formats.
///
/// Once it is loaded, a sf::Font instance provides three
/// types of information about the font:
/// \li Global metrics, such as the line spacing
/// \li Per-glyph metrics, such as bounding box or kerning
/// \li Pixel representation of glyphs
///
/// Fonts alone are not very useful: they hold the font data
/// but cannot make anything useful of it. To do so you need to
/// use the sf::Text class, which is able to properly output text
/// with several options such as character size, style, color,
/// position, rotation, etc.
/// This separation allows more flexibility and better performances:
/// indeed a sf::Font is a heavy resource, and any operation on it
/// is slow (often too slow for real-time applications). On the other
/// side, a sf::Text is a lightweight object which can combine the
/// glyphs data and metrics of a sf::Font to display any text on a
/// render target.
/// Note that it is also possible to bind several sf::Text instances
/// to the same sf::Font.
///
/// It is important to note that the sf::Text instance doesn't
/// copy the font that it uses, it only keeps a reference to it.
/// Thus, a sf::Font must not be destructed while it is
/// used by a sf::Text (i.e. never write a function that
/// uses a local sf::Font instance for creating a text).
///
/// Usage example:
/// \code
/// // Declare a new font
/// sf::Font font;
///
/// // Load it from a file
/// if (!font.loadFromFile("arial.ttf"))
/// {
/// // error...
/// }
///
/// // Create a text which uses our font
/// sf::Text text1;
/// text1.setFont(font);
/// text1.setCharacterSize(30);
/// text1.setStyle(sf::Text::Regular);
///
/// // Create another text using the same font, but with different parameters
/// sf::Text text2;
/// text2.setFont(font);
/// text2.setCharacterSize(50);
/// text2.setStyle(sf::Text::Italic);
/// \endcode
///
/// Apart from loading font files, and passing them to instances
/// of sf::Text, you should normally not have to deal directly
/// with this class. However, it may be useful to access the
/// font metrics or rasterized glyphs for advanced usage.
///
/// Note that if the font is a bitmap font, it is not scalable,
/// thus not all requested sizes will be available to use. This
/// needs to be taken into consideration when using sf::Text.
/// If you need to display text of a certain size, make sure the
/// corresponding bitmap font that supports that size is used.
///
/// \see sf::Text
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,79 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_GLYPH_HPP
#define SFML_GLYPH_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Rect.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Structure describing a glyph
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Glyph
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
Glyph() : advance(0) {}
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
float advance; ///< Offset to move horizontally to the next character
FloatRect bounds; ///< Bounding rectangle of the glyph, in coordinates relative to the baseline
IntRect textureRect; ///< Texture coordinates of the glyph inside the font's texture
};
} // namespace sf
#endif // SFML_GLYPH_HPP
////////////////////////////////////////////////////////////
/// \class sf::Glyph
/// \ingroup graphics
///
/// A glyph is the visual representation of a character.
///
/// The sf::Glyph structure provides the information needed
/// to handle the glyph:
/// \li its coordinates in the font's texture
/// \li its bounding rectangle
/// \li the offset to apply to get the starting position of the next glyph
///
/// \see sf::Font
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,327 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_IMAGE_HPP
#define SFML_IMAGE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <string>
#include <vector>
namespace sf
{
class InputStream;
////////////////////////////////////////////////////////////
/// \brief Class for loading, manipulating and saving images
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Image
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates an empty image.
///
////////////////////////////////////////////////////////////
Image();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~Image();
////////////////////////////////////////////////////////////
/// \brief Create the image and fill it with a unique color
///
/// \param width Width of the image
/// \param height Height of the image
/// \param color Fill color
///
////////////////////////////////////////////////////////////
void create(unsigned int width, unsigned int height, const Color& color = Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// \brief Create the image from an array of pixels
///
/// The \a pixel array is assumed to contain 32-bits RGBA pixels,
/// and have the given \a width and \a height. If not, this is
/// an undefined behavior.
/// If \a pixels is null, an empty image is created.
///
/// \param width Width of the image
/// \param height Height of the image
/// \param pixels Array of pixels to copy to the image
///
////////////////////////////////////////////////////////////
void create(unsigned int width, unsigned int height, const Uint8* pixels);
////////////////////////////////////////////////////////////
/// \brief Load the image from a file on disk
///
/// The supported image formats are bmp, png, tga, jpg, gif,
/// psd, hdr and pic. Some format options are not supported,
/// like progressive jpeg.
/// If this function fails, the image is left unchanged.
///
/// \param filename Path of the image file to load
///
/// \return True if loading was successful
///
/// \see loadFromMemory, loadFromStream, saveToFile
///
////////////////////////////////////////////////////////////
bool loadFromFile(const std::string& filename);
////////////////////////////////////////////////////////////
/// \brief Load the image from a file in memory
///
/// The supported image formats are bmp, png, tga, jpg, gif,
/// psd, hdr and pic. Some format options are not supported,
/// like progressive jpeg.
/// If this function fails, the image is left unchanged.
///
/// \param data Pointer to the file data in memory
/// \param size Size of the data to load, in bytes
///
/// \return True if loading was successful
///
/// \see loadFromFile, loadFromStream
///
////////////////////////////////////////////////////////////
bool loadFromMemory(const void* data, std::size_t size);
////////////////////////////////////////////////////////////
/// \brief Load the image from a custom stream
///
/// The supported image formats are bmp, png, tga, jpg, gif,
/// psd, hdr and pic. Some format options are not supported,
/// like progressive jpeg.
/// If this function fails, the image is left unchanged.
///
/// \param stream Source stream to read from
///
/// \return True if loading was successful
///
/// \see loadFromFile, loadFromMemory
///
////////////////////////////////////////////////////////////
bool loadFromStream(InputStream& stream);
////////////////////////////////////////////////////////////
/// \brief Save the image to a file on disk
///
/// The format of the image is automatically deduced from
/// the extension. The supported image formats are bmp, png,
/// tga and jpg. The destination file is overwritten
/// if it already exists. This function fails if the image is empty.
///
/// \param filename Path of the file to save
///
/// \return True if saving was successful
///
/// \see create, loadFromFile, loadFromMemory
///
////////////////////////////////////////////////////////////
bool saveToFile(const std::string& filename) const;
////////////////////////////////////////////////////////////
/// \brief Return the size (width and height) of the image
///
/// \return Size of the image, in pixels
///
////////////////////////////////////////////////////////////
Vector2u getSize() const;
////////////////////////////////////////////////////////////
/// \brief Create a transparency mask from a specified color-key
///
/// This function sets the alpha value of every pixel matching
/// the given color to \a alpha (0 by default), so that they
/// become transparent.
///
/// \param color Color to make transparent
/// \param alpha Alpha value to assign to transparent pixels
///
////////////////////////////////////////////////////////////
void createMaskFromColor(const Color& color, Uint8 alpha = 0);
////////////////////////////////////////////////////////////
/// \brief Copy pixels from another image onto this one
///
/// This function does a slow pixel copy and should not be
/// used intensively. It can be used to prepare a complex
/// static image from several others, but if you need this
/// kind of feature in real-time you'd better use sf::RenderTexture.
///
/// If \a sourceRect is empty, the whole image is copied.
/// If \a applyAlpha is set to true, the transparency of
/// source pixels is applied. If it is false, the pixels are
/// copied unchanged with their alpha value.
///
/// \param source Source image to copy
/// \param destX X coordinate of the destination position
/// \param destY Y coordinate of the destination position
/// \param sourceRect Sub-rectangle of the source image to copy
/// \param applyAlpha Should the copy take into account the source transparency?
///
////////////////////////////////////////////////////////////
void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false);
////////////////////////////////////////////////////////////
/// \brief Change the color of a pixel
///
/// This function doesn't check the validity of the pixel
/// coordinates, using out-of-range values will result in
/// an undefined behavior.
///
/// \param x X coordinate of pixel to change
/// \param y Y coordinate of pixel to change
/// \param color New color of the pixel
///
/// \see getPixel
///
////////////////////////////////////////////////////////////
void setPixel(unsigned int x, unsigned int y, const Color& color);
////////////////////////////////////////////////////////////
/// \brief Get the color of a pixel
///
/// This function doesn't check the validity of the pixel
/// coordinates, using out-of-range values will result in
/// an undefined behavior.
///
/// \param x X coordinate of pixel to get
/// \param y Y coordinate of pixel to get
///
/// \return Color of the pixel at coordinates (x, y)
///
/// \see setPixel
///
////////////////////////////////////////////////////////////
Color getPixel(unsigned int x, unsigned int y) const;
////////////////////////////////////////////////////////////
/// \brief Get a read-only pointer to the array of pixels
///
/// The returned value points to an array of RGBA pixels made of
/// 8 bits integers components. The size of the array is
/// width * height * 4 (getSize().x * getSize().y * 4).
/// Warning: the returned pointer may become invalid if you
/// modify the image, so you should never store it for too long.
/// If the image is empty, a null pointer is returned.
///
/// \return Read-only pointer to the array of pixels
///
////////////////////////////////////////////////////////////
const Uint8* getPixelsPtr() const;
////////////////////////////////////////////////////////////
/// \brief Flip the image horizontally (left <-> right)
///
////////////////////////////////////////////////////////////
void flipHorizontally();
////////////////////////////////////////////////////////////
/// \brief Flip the image vertically (top <-> bottom)
///
////////////////////////////////////////////////////////////
void flipVertically();
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Vector2u m_size; ///< Image size
std::vector<Uint8> m_pixels; ///< Pixels of the image
#ifdef SFML_SYSTEM_ANDROID
void* m_stream; ///< Asset file streamer (if loaded from file)
#endif
};
} // namespace sf
#endif // SFML_IMAGE_HPP
////////////////////////////////////////////////////////////
/// \class sf::Image
/// \ingroup graphics
///
/// sf::Image is an abstraction to manipulate images
/// as bidimensional arrays of pixels. The class provides
/// functions to load, read, write and save pixels, as well
/// as many other useful functions.
///
/// sf::Image can handle a unique internal representation of
/// pixels, which is RGBA 32 bits. This means that a pixel
/// must be composed of 8 bits red, green, blue and alpha
/// channels -- just like a sf::Color.
/// All the functions that return an array of pixels follow
/// this rule, and all parameters that you pass to sf::Image
/// functions (such as loadFromMemory) must use this
/// representation as well.
///
/// A sf::Image can be copied, but it is a heavy resource and
/// if possible you should always use [const] references to
/// pass or return them to avoid useless copies.
///
/// Usage example:
/// \code
/// // Load an image file from a file
/// sf::Image background;
/// if (!background.loadFromFile("background.jpg"))
/// return -1;
///
/// // Create a 20x20 image filled with black color
/// sf::Image image;
/// image.create(20, 20, sf::Color::Black);
///
/// // Copy image1 on image2 at position (10, 10)
/// image.copy(background, 10, 10);
///
/// // Make the top-left pixel transparent
/// sf::Color color = image.getPixel(0, 0);
/// color.a = 0;
/// image.setPixel(0, 0, color);
///
/// // Save the image to a file
/// if (!image.saveToFile("result.png"))
/// return -1;
/// \endcode
///
/// \see sf::Texture
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,53 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_PRIMITIVETYPE_HPP
#define SFML_PRIMITIVETYPE_HPP
namespace sf
{
////////////////////////////////////////////////////////////
/// \ingroup graphics
/// \brief Types of primitives that a sf::VertexArray can render
///
/// Points and lines have no area, therefore their thickness
/// will always be 1 pixel, regardless the current transform
/// and view.
///
////////////////////////////////////////////////////////////
enum PrimitiveType
{
Points, ///< List of individual points
Lines, ///< List of individual lines
LinesStrip, ///< List of connected lines, a point uses the previous point to form a line
Triangles, ///< List of individual triangles
TrianglesStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle
TrianglesFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle
Quads ///< List of individual quads (deprecated, don't work with OpenGL ES)
};
} // namespace sf
#endif // SFML_PRIMITIVETYPE_HPP

248
external/sfml23/include/SFML/Graphics/Rect.hpp vendored Executable file
View File

@ -0,0 +1,248 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RECT_HPP
#define SFML_RECT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Vector2.hpp>
#include <algorithm>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Utility class for manipulating 2D axis aligned rectangles
///
////////////////////////////////////////////////////////////
template <typename T>
class Rect
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates an empty rectangle (it is equivalent to calling
/// Rect(0, 0, 0, 0)).
///
////////////////////////////////////////////////////////////
Rect();
////////////////////////////////////////////////////////////
/// \brief Construct the rectangle from its coordinates
///
/// Be careful, the last two parameters are the width
/// and height, not the right and bottom coordinates!
///
/// \param rectLeft Left coordinate of the rectangle
/// \param rectTop Top coordinate of the rectangle
/// \param rectWidth Width of the rectangle
/// \param rectHeight Height of the rectangle
///
////////////////////////////////////////////////////////////
Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight);
////////////////////////////////////////////////////////////
/// \brief Construct the rectangle from position and size
///
/// Be careful, the last parameter is the size,
/// not the bottom-right corner!
///
/// \param position Position of the top-left corner of the rectangle
/// \param size Size of the rectangle
///
////////////////////////////////////////////////////////////
Rect(const Vector2<T>& position, const Vector2<T>& size);
////////////////////////////////////////////////////////////
/// \brief Construct the rectangle from another type of rectangle
///
/// This constructor doesn't replace the copy constructor,
/// it's called only when U != T.
/// A call to this constructor will fail to compile if U
/// is not convertible to T.
///
/// \param rectangle Rectangle to convert
///
////////////////////////////////////////////////////////////
template <typename U>
explicit Rect(const Rect<U>& rectangle);
////////////////////////////////////////////////////////////
/// \brief Check if a point is inside the rectangle's area
///
/// \param x X coordinate of the point to test
/// \param y Y coordinate of the point to test
///
/// \return True if the point is inside, false otherwise
///
/// \see intersects
///
////////////////////////////////////////////////////////////
bool contains(T x, T y) const;
////////////////////////////////////////////////////////////
/// \brief Check if a point is inside the rectangle's area
///
/// \param point Point to test
///
/// \return True if the point is inside, false otherwise
///
/// \see intersects
///
////////////////////////////////////////////////////////////
bool contains(const Vector2<T>& point) const;
////////////////////////////////////////////////////////////
/// \brief Check the intersection between two rectangles
///
/// \param rectangle Rectangle to test
///
/// \return True if rectangles overlap, false otherwise
///
/// \see contains
///
////////////////////////////////////////////////////////////
bool intersects(const Rect<T>& rectangle) const;
////////////////////////////////////////////////////////////
/// \brief Check the intersection between two rectangles
///
/// This overload returns the overlapped rectangle in the
/// \a intersection parameter.
///
/// \param rectangle Rectangle to test
/// \param intersection Rectangle to be filled with the intersection
///
/// \return True if rectangles overlap, false otherwise
///
/// \see contains
///
////////////////////////////////////////////////////////////
bool intersects(const Rect<T>& rectangle, Rect<T>& intersection) const;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
T left; ///< Left coordinate of the rectangle
T top; ///< Top coordinate of the rectangle
T width; ///< Width of the rectangle
T height; ///< Height of the rectangle
};
////////////////////////////////////////////////////////////
/// \relates Rect
/// \brief Overload of binary operator ==
///
/// This operator compares strict equality between two rectangles.
///
/// \param left Left operand (a rectangle)
/// \param right Right operand (a rectangle)
///
/// \return True if \a left is equal to \a right
///
////////////////////////////////////////////////////////////
template <typename T>
bool operator ==(const Rect<T>& left, const Rect<T>& right);
////////////////////////////////////////////////////////////
/// \relates Rect
/// \brief Overload of binary operator !=
///
/// This operator compares strict difference between two rectangles.
///
/// \param left Left operand (a rectangle)
/// \param right Right operand (a rectangle)
///
/// \return True if \a left is not equal to \a right
///
////////////////////////////////////////////////////////////
template <typename T>
bool operator !=(const Rect<T>& left, const Rect<T>& right);
#include <SFML/Graphics/Rect.inl>
// Create typedefs for the most common types
typedef Rect<int> IntRect;
typedef Rect<float> FloatRect;
} // namespace sf
#endif // SFML_RECT_HPP
////////////////////////////////////////////////////////////
/// \class sf::Rect
/// \ingroup graphics
///
/// A rectangle is defined by its top-left corner and its size.
/// It is a very simple class defined for convenience, so
/// its member variables (left, top, width and height) are public
/// and can be accessed directly, just like the vector classes
/// (Vector2 and Vector3).
///
/// To keep things simple, sf::Rect doesn't define
/// functions to emulate the properties that are not directly
/// members (such as right, bottom, center, etc.), it rather
/// only provides intersection functions.
///
/// sf::Rect uses the usual rules for its boundaries:
/// \li The left and top edges are included in the rectangle's area
/// \li The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area
///
/// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1)
/// don't intersect.
///
/// sf::Rect is a template and may be used with any numeric type, but
/// for simplicity the instantiations used by SFML are typedef'd:
/// \li sf::Rect<int> is sf::IntRect
/// \li sf::Rect<float> is sf::FloatRect
///
/// So that you don't have to care about the template syntax.
///
/// Usage example:
/// \code
/// // Define a rectangle, located at (0, 0) with a size of 20x5
/// sf::IntRect r1(0, 0, 20, 5);
///
/// // Define another rectangle, located at (4, 2) with a size of 18x10
/// sf::Vector2i position(4, 2);
/// sf::Vector2i size(18, 10);
/// sf::IntRect r2(position, size);
///
/// // Test intersections with the point (3, 1)
/// bool b1 = r1.contains(3, 1); // true
/// bool b2 = r2.contains(3, 1); // false
///
/// // Test the intersection between r1 and r2
/// sf::IntRect result;
/// bool b3 = r1.intersects(r2, result); // true
/// // result == (4, 2, 16, 3)
/// \endcode
///
////////////////////////////////////////////////////////////

159
external/sfml23/include/SFML/Graphics/Rect.inl vendored Executable file
View File

@ -0,0 +1,159 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
template <typename T>
Rect<T>::Rect() :
left (0),
top (0),
width (0),
height(0)
{
}
////////////////////////////////////////////////////////////
template <typename T>
Rect<T>::Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) :
left (rectLeft),
top (rectTop),
width (rectWidth),
height(rectHeight)
{
}
////////////////////////////////////////////////////////////
template <typename T>
Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) :
left (position.x),
top (position.y),
width (size.x),
height(size.y)
{
}
////////////////////////////////////////////////////////////
template <typename T>
template <typename U>
Rect<T>::Rect(const Rect<U>& rectangle) :
left (static_cast<T>(rectangle.left)),
top (static_cast<T>(rectangle.top)),
width (static_cast<T>(rectangle.width)),
height(static_cast<T>(rectangle.height))
{
}
////////////////////////////////////////////////////////////
template <typename T>
bool Rect<T>::contains(T x, T y) const
{
// Rectangles with negative dimensions are allowed, so we must handle them correctly
// Compute the real min and max of the rectangle on both axes
T minX = std::min(left, static_cast<T>(left + width));
T maxX = std::max(left, static_cast<T>(left + width));
T minY = std::min(top, static_cast<T>(top + height));
T maxY = std::max(top, static_cast<T>(top + height));
return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY);
}
////////////////////////////////////////////////////////////
template <typename T>
bool Rect<T>::contains(const Vector2<T>& point) const
{
return contains(point.x, point.y);
}
////////////////////////////////////////////////////////////
template <typename T>
bool Rect<T>::intersects(const Rect<T>& rectangle) const
{
Rect<T> intersection;
return intersects(rectangle, intersection);
}
////////////////////////////////////////////////////////////
template <typename T>
bool Rect<T>::intersects(const Rect<T>& rectangle, Rect<T>& intersection) const
{
// Rectangles with negative dimensions are allowed, so we must handle them correctly
// Compute the min and max of the first rectangle on both axes
T r1MinX = std::min(left, static_cast<T>(left + width));
T r1MaxX = std::max(left, static_cast<T>(left + width));
T r1MinY = std::min(top, static_cast<T>(top + height));
T r1MaxY = std::max(top, static_cast<T>(top + height));
// Compute the min and max of the second rectangle on both axes
T r2MinX = std::min(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
T r2MaxX = std::max(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
T r2MinY = std::min(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
T r2MaxY = std::max(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
// Compute the intersection boundaries
T interLeft = std::max(r1MinX, r2MinX);
T interTop = std::max(r1MinY, r2MinY);
T interRight = std::min(r1MaxX, r2MaxX);
T interBottom = std::min(r1MaxY, r2MaxY);
// If the intersection is valid (positive non zero area), then there is an intersection
if ((interLeft < interRight) && (interTop < interBottom))
{
intersection = Rect<T>(interLeft, interTop, interRight - interLeft, interBottom - interTop);
return true;
}
else
{
intersection = Rect<T>(0, 0, 0, 0);
return false;
}
}
////////////////////////////////////////////////////////////
template <typename T>
inline bool operator ==(const Rect<T>& left, const Rect<T>& right)
{
return (left.left == right.left) && (left.width == right.width) &&
(left.top == right.top) && (left.height == right.height);
}
////////////////////////////////////////////////////////////
template <typename T>
inline bool operator !=(const Rect<T>& left, const Rect<T>& right)
{
return !(left == right);
}

View File

@ -0,0 +1,132 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RECTANGLESHAPE_HPP
#define SFML_RECTANGLESHAPE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Shape.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Specialized shape representing a rectangle
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API RectangleShape : public Shape
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// \param size Size of the rectangle
///
////////////////////////////////////////////////////////////
explicit RectangleShape(const Vector2f& size = Vector2f(0, 0));
////////////////////////////////////////////////////////////
/// \brief Set the size of the rectangle
///
/// \param size New size of the rectangle
///
/// \see getSize
///
////////////////////////////////////////////////////////////
void setSize(const Vector2f& size);
////////////////////////////////////////////////////////////
/// \brief Get the size of the rectangle
///
/// \return Size of the rectangle
///
/// \see setSize
///
////////////////////////////////////////////////////////////
const Vector2f& getSize() const;
////////////////////////////////////////////////////////////
/// \brief Get the number of points defining the shape
///
/// \return Number of points of the shape. For rectangle
/// shapes, this number is always 4.
///
////////////////////////////////////////////////////////////
virtual std::size_t getPointCount() const;
////////////////////////////////////////////////////////////
/// \brief Get a point of the rectangle
///
/// The returned point is in local coordinates, that is,
/// the shape's transforms (position, rotation, scale) are
/// not taken into account.
/// The result is undefined if \a index is out of the valid range.
///
/// \param index Index of the point to get, in range [0 .. 3]
///
/// \return index-th point of the shape
///
////////////////////////////////////////////////////////////
virtual Vector2f getPoint(std::size_t index) const;
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Vector2f m_size; ///< Size of the rectangle
};
} // namespace sf
#endif // SFML_RECTANGLESHAPE_HPP
////////////////////////////////////////////////////////////
/// \class sf::RectangleShape
/// \ingroup graphics
///
/// This class inherits all the functions of sf::Transformable
/// (position, rotation, scale, bounds, ...) as well as the
/// functions of sf::Shape (outline, color, texture, ...).
///
/// Usage example:
/// \code
/// sf::RectangleShape rectangle;
/// rectangle.setSize(sf::Vector2f(100, 50));
/// rectangle.setOutlineColor(sf::Color::Red);
/// rectangle.setOutlineThickness(5);
/// rectangle.setPosition(10, 20);
/// ...
/// window.draw(rectangle);
/// \endcode
///
/// \see sf::Shape, sf::CircleShape, sf::ConvexShape
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,174 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERSTATES_HPP
#define SFML_RENDERSTATES_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/Transform.hpp>
namespace sf
{
class Shader;
class Texture;
////////////////////////////////////////////////////////////
/// \brief Define the states used for drawing to a RenderTarget
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API RenderStates
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Constructing a default set of render states is equivalent
/// to using sf::RenderStates::Default.
/// The default set defines:
/// \li the BlendAlpha blend mode
/// \li the identity transform
/// \li a null texture
/// \li a null shader
///
////////////////////////////////////////////////////////////
RenderStates();
////////////////////////////////////////////////////////////
/// \brief Construct a default set of render states with a custom blend mode
///
/// \param theBlendMode Blend mode to use
///
////////////////////////////////////////////////////////////
RenderStates(const BlendMode& theBlendMode);
////////////////////////////////////////////////////////////
/// \brief Construct a default set of render states with a custom transform
///
/// \param theTransform Transform to use
///
////////////////////////////////////////////////////////////
RenderStates(const Transform& theTransform);
////////////////////////////////////////////////////////////
/// \brief Construct a default set of render states with a custom texture
///
/// \param theTexture Texture to use
///
////////////////////////////////////////////////////////////
RenderStates(const Texture* theTexture);
////////////////////////////////////////////////////////////
/// \brief Construct a default set of render states with a custom shader
///
/// \param theShader Shader to use
///
////////////////////////////////////////////////////////////
RenderStates(const Shader* theShader);
////////////////////////////////////////////////////////////
/// \brief Construct a set of render states with all its attributes
///
/// \param theBlendMode Blend mode to use
/// \param theTransform Transform to use
/// \param theTexture Texture to use
/// \param theShader Shader to use
///
////////////////////////////////////////////////////////////
RenderStates(const BlendMode& theBlendMode, const Transform& theTransform,
const Texture* theTexture, const Shader* theShader);
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static const RenderStates Default; ///< Special instance holding the default render states
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
BlendMode blendMode; ///< Blending mode
Transform transform; ///< Transform
const Texture* texture; ///< Texture
const Shader* shader; ///< Shader
};
} // namespace sf
#endif // SFML_RENDERSTATES_HPP
////////////////////////////////////////////////////////////
/// \class sf::RenderStates
/// \ingroup graphics
///
/// There are four global states that can be applied to
/// the drawn objects:
/// \li the blend mode: how pixels of the object are blended with the background
/// \li the transform: how the object is positioned/rotated/scaled
/// \li the texture: what image is mapped to the object
/// \li the shader: what custom effect is applied to the object
///
/// High-level objects such as sprites or text force some of
/// these states when they are drawn. For example, a sprite
/// will set its own texture, so that you don't have to care
/// about it when drawing the sprite.
///
/// The transform is a special case: sprites, texts and shapes
/// (and it's a good idea to do it with your own drawable classes
/// too) combine their transform with the one that is passed in the
/// RenderStates structure. So that you can use a "global" transform
/// on top of each object's transform.
///
/// Most objects, especially high-level drawables, can be drawn
/// directly without defining render states explicitly -- the
/// default set of states is ok in most cases.
/// \code
/// window.draw(sprite);
/// \endcode
///
/// If you want to use a single specific render state,
/// for example a shader, you can pass it directly to the Draw
/// function: sf::RenderStates has an implicit one-argument
/// constructor for each state.
/// \code
/// window.draw(sprite, shader);
/// \endcode
///
/// When you're inside the Draw function of a drawable
/// object (inherited from sf::Drawable), you can
/// either pass the render states unmodified, or change
/// some of them.
/// For example, a transformable object will combine the
/// current transform with its own transform. A sprite will
/// set its texture. Etc.
///
/// \see sf::RenderTarget, sf::Drawable
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,451 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERTARGET_HPP
#define SFML_RENDERTARGET_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/View.hpp>
#include <SFML/Graphics/Transform.hpp>
#include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/RenderStates.hpp>
#include <SFML/Graphics/PrimitiveType.hpp>
#include <SFML/Graphics/Vertex.hpp>
#include <SFML/System/NonCopyable.hpp>
namespace sf
{
class Drawable;
////////////////////////////////////////////////////////////
/// \brief Base class for all render targets (window, texture, ...)
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API RenderTarget : NonCopyable
{
public:
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
virtual ~RenderTarget();
////////////////////////////////////////////////////////////
/// \brief Clear the entire target with a single color
///
/// This function is usually called once every frame,
/// to clear the previous contents of the target.
///
/// \param color Fill color to use to clear the render target
///
////////////////////////////////////////////////////////////
void clear(const Color& color = Color(0, 0, 0, 255));
////////////////////////////////////////////////////////////
/// \brief Change the current active view
///
/// The view is like a 2D camera, it controls which part of
/// the 2D scene is visible, and how it is viewed in the
/// render target.
/// The new view will affect everything that is drawn, until
/// another view is set.
/// The render target keeps its own copy of the view object,
/// so it is not necessary to keep the original one alive
/// after calling this function.
/// To restore the original view of the target, you can pass
/// the result of getDefaultView() to this function.
///
/// \param view New view to use
///
/// \see getView, getDefaultView
///
////////////////////////////////////////////////////////////
void setView(const View& view);
////////////////////////////////////////////////////////////
/// \brief Get the view currently in use in the render target
///
/// \return The view object that is currently used
///
/// \see setView, getDefaultView
///
////////////////////////////////////////////////////////////
const View& getView() const;
////////////////////////////////////////////////////////////
/// \brief Get the default view of the render target
///
/// The default view has the initial size of the render target,
/// and never changes after the target has been created.
///
/// \return The default view of the render target
///
/// \see setView, getView
///
////////////////////////////////////////////////////////////
const View& getDefaultView() const;
////////////////////////////////////////////////////////////
/// \brief Get the viewport of a view, applied to this render target
///
/// The viewport is defined in the view as a ratio, this function
/// simply applies this ratio to the current dimensions of the
/// render target to calculate the pixels rectangle that the viewport
/// actually covers in the target.
///
/// \param view The view for which we want to compute the viewport
///
/// \return Viewport rectangle, expressed in pixels
///
////////////////////////////////////////////////////////////
IntRect getViewport(const View& view) const;
////////////////////////////////////////////////////////////
/// \brief Convert a point from target coordinates to world
/// coordinates, using the current view
///
/// This function is an overload of the mapPixelToCoords
/// function that implicitly uses the current view.
/// It is equivalent to:
/// \code
/// target.mapPixelToCoords(point, target.getView());
/// \endcode
///
/// \param point Pixel to convert
///
/// \return The converted point, in "world" coordinates
///
/// \see mapCoordsToPixel
///
////////////////////////////////////////////////////////////
Vector2f mapPixelToCoords(const Vector2i& point) const;
////////////////////////////////////////////////////////////
/// \brief Convert a point from target coordinates to world coordinates
///
/// This function finds the 2D position that matches the
/// given pixel of the render target. In other words, it does
/// the inverse of what the graphics card does, to find the
/// initial position of a rendered pixel.
///
/// Initially, both coordinate systems (world units and target pixels)
/// match perfectly. But if you define a custom view or resize your
/// render target, this assertion is not true anymore, i.e. a point
/// located at (10, 50) in your render target may map to the point
/// (150, 75) in your 2D world -- if the view is translated by (140, 25).
///
/// For render-windows, this function is typically used to find
/// which point (or object) is located below the mouse cursor.
///
/// This version uses a custom view for calculations, see the other
/// overload of the function if you want to use the current view of the
/// render target.
///
/// \param point Pixel to convert
/// \param view The view to use for converting the point
///
/// \return The converted point, in "world" units
///
/// \see mapCoordsToPixel
///
////////////////////////////////////////////////////////////
Vector2f mapPixelToCoords(const Vector2i& point, const View& view) const;
////////////////////////////////////////////////////////////
/// \brief Convert a point from world coordinates to target
/// coordinates, using the current view
///
/// This function is an overload of the mapCoordsToPixel
/// function that implicitly uses the current view.
/// It is equivalent to:
/// \code
/// target.mapCoordsToPixel(point, target.getView());
/// \endcode
///
/// \param point Point to convert
///
/// \return The converted point, in target coordinates (pixels)
///
/// \see mapPixelToCoords
///
////////////////////////////////////////////////////////////
Vector2i mapCoordsToPixel(const Vector2f& point) const;
////////////////////////////////////////////////////////////
/// \brief Convert a point from world coordinates to target coordinates
///
/// This function finds the pixel of the render target that matches
/// the given 2D point. In other words, it goes through the same process
/// as the graphics card, to compute the final position of a rendered point.
///
/// Initially, both coordinate systems (world units and target pixels)
/// match perfectly. But if you define a custom view or resize your
/// render target, this assertion is not true anymore, i.e. a point
/// located at (150, 75) in your 2D world may map to the pixel
/// (10, 50) of your render target -- if the view is translated by (140, 25).
///
/// This version uses a custom view for calculations, see the other
/// overload of the function if you want to use the current view of the
/// render target.
///
/// \param point Point to convert
/// \param view The view to use for converting the point
///
/// \return The converted point, in target coordinates (pixels)
///
/// \see mapPixelToCoords
///
////////////////////////////////////////////////////////////
Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) const;
////////////////////////////////////////////////////////////
/// \brief Draw a drawable object to the render target
///
/// \param drawable Object to draw
/// \param states Render states to use for drawing
///
////////////////////////////////////////////////////////////
void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
////////////////////////////////////////////////////////////
/// \brief Draw primitives defined by an array of vertices
///
/// \param vertices Pointer to the vertices
/// \param vertexCount Number of vertices in the array
/// \param type Type of primitives to draw
/// \param states Render states to use for drawing
///
////////////////////////////////////////////////////////////
void draw(const Vertex* vertices, std::size_t vertexCount,
PrimitiveType type, const RenderStates& states = RenderStates::Default);
////////////////////////////////////////////////////////////
/// \brief Return the size of the rendering region of the target
///
/// \return Size in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2u getSize() const = 0;
////////////////////////////////////////////////////////////
/// \brief Save the current OpenGL render states and matrices
///
/// This function can be used when you mix SFML drawing
/// and direct OpenGL rendering. Combined with popGLStates,
/// it ensures that:
/// \li SFML's internal states are not messed up by your OpenGL code
/// \li your OpenGL states are not modified by a call to a SFML function
///
/// More specifically, it must be used around code that
/// calls Draw functions. Example:
/// \code
/// // OpenGL code here...
/// window.pushGLStates();
/// window.draw(...);
/// window.draw(...);
/// window.popGLStates();
/// // OpenGL code here...
/// \endcode
///
/// Note that this function is quite expensive: it saves all the
/// possible OpenGL states and matrices, even the ones you
/// don't care about. Therefore it should be used wisely.
/// It is provided for convenience, but the best results will
/// be achieved if you handle OpenGL states yourself (because
/// you know which states have really changed, and need to be
/// saved and restored). Take a look at the resetGLStates
/// function if you do so.
///
/// \see popGLStates
///
////////////////////////////////////////////////////////////
void pushGLStates();
////////////////////////////////////////////////////////////
/// \brief Restore the previously saved OpenGL render states and matrices
///
/// See the description of pushGLStates to get a detailed
/// description of these functions.
///
/// \see pushGLStates
///
////////////////////////////////////////////////////////////
void popGLStates();
////////////////////////////////////////////////////////////
/// \brief Reset the internal OpenGL states so that the target is ready for drawing
///
/// This function can be used when you mix SFML drawing
/// and direct OpenGL rendering, if you choose not to use
/// pushGLStates/popGLStates. It makes sure that all OpenGL
/// states needed by SFML are set, so that subsequent draw()
/// calls will work as expected.
///
/// Example:
/// \code
/// // OpenGL code here...
/// glPushAttrib(...);
/// window.resetGLStates();
/// window.draw(...);
/// window.draw(...);
/// glPopAttrib(...);
/// // OpenGL code here...
/// \endcode
///
////////////////////////////////////////////////////////////
void resetGLStates();
protected:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
RenderTarget();
////////////////////////////////////////////////////////////
/// \brief Performs the common initialization step after creation
///
/// The derived classes must call this function after the
/// target is created and ready for drawing.
///
////////////////////////////////////////////////////////////
void initialize();
private:
////////////////////////////////////////////////////////////
/// \brief Apply the current view
///
////////////////////////////////////////////////////////////
void applyCurrentView();
////////////////////////////////////////////////////////////
/// \brief Apply a new blending mode
///
/// \param mode Blending mode to apply
///
////////////////////////////////////////////////////////////
void applyBlendMode(const BlendMode& mode);
////////////////////////////////////////////////////////////
/// \brief Apply a new transform
///
/// \param transform Transform to apply
///
////////////////////////////////////////////////////////////
void applyTransform(const Transform& transform);
////////////////////////////////////////////////////////////
/// \brief Apply a new texture
///
/// \param texture Texture to apply
///
////////////////////////////////////////////////////////////
void applyTexture(const Texture* texture);
////////////////////////////////////////////////////////////
/// \brief Apply a new shader
///
/// \param shader Shader to apply
///
////////////////////////////////////////////////////////////
void applyShader(const Shader* shader);
////////////////////////////////////////////////////////////
/// \brief Activate the target for rendering
///
/// This function must be implemented by derived classes to make
/// their OpenGL context current; it is called by the base class
/// everytime it's going to use OpenGL calls.
///
/// \param active True to make the target active, false to deactivate it
///
/// \return True if the function succeeded
///
////////////////////////////////////////////////////////////
virtual bool activate(bool active) = 0;
////////////////////////////////////////////////////////////
/// \brief Render states cache
///
////////////////////////////////////////////////////////////
struct StatesCache
{
enum {VertexCacheSize = 4};
bool glStatesSet; ///< Are our internal GL states set yet?
bool viewChanged; ///< Has the current view changed since last draw?
BlendMode lastBlendMode; ///< Cached blending mode
Uint64 lastTextureId; ///< Cached texture
bool useVertexCache; ///< Did we previously use the vertex cache?
Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertices cache
};
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
View m_defaultView; ///< Default view
View m_view; ///< Current view
StatesCache m_cache; ///< Render states cache
};
} // namespace sf
#endif // SFML_RENDERTARGET_HPP
////////////////////////////////////////////////////////////
/// \class sf::RenderTarget
/// \ingroup graphics
///
/// sf::RenderTarget defines the common behavior of all the
/// 2D render targets usable in the graphics module. It makes
/// it possible to draw 2D entities like sprites, shapes, text
/// without using any OpenGL command directly.
///
/// A sf::RenderTarget is also able to use views (sf::View),
/// which are a kind of 2D cameras. With views you can globally
/// scroll, rotate or zoom everything that is drawn,
/// without having to transform every single entity. See the
/// documentation of sf::View for more details and sample pieces of
/// code about this class.
///
/// On top of that, render targets are still able to render direct
/// OpenGL stuff. It is even possible to mix together OpenGL calls
/// and regular SFML drawing commands. When doing so, make sure that
/// OpenGL states are not messed up by calling the
/// pushGLStates/popGLStates functions.
///
/// \see sf::RenderWindow, sf::RenderTexture, sf::View
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,280 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERTEXTURE_HPP
#define SFML_RENDERTEXTURE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
namespace sf
{
namespace priv
{
class RenderTextureImpl;
}
////////////////////////////////////////////////////////////
/// \brief Target for off-screen 2D rendering into a texture
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API RenderTexture : public RenderTarget
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Constructs an empty, invalid render-texture. You must
/// call create to have a valid render-texture.
///
/// \see create
///
////////////////////////////////////////////////////////////
RenderTexture();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
virtual ~RenderTexture();
////////////////////////////////////////////////////////////
/// \brief Create the render-texture
///
/// Before calling this function, the render-texture is in
/// an invalid state, thus it is mandatory to call it before
/// doing anything with the render-texture.
/// The last parameter, \a depthBuffer, is useful if you want
/// to use the render-texture for 3D OpenGL rendering that requires
/// a depth buffer. Otherwise it is unnecessary, and you should
/// leave this parameter to false (which is its default value).
///
/// \param width Width of the render-texture
/// \param height Height of the render-texture
/// \param depthBuffer Do you want this render-texture to have a depth buffer?
///
/// \return True if creation has been successful
///
////////////////////////////////////////////////////////////
bool create(unsigned int width, unsigned int height, bool depthBuffer = false);
////////////////////////////////////////////////////////////
/// \brief Enable or disable texture smoothing
///
/// This function is similar to Texture::setSmooth.
/// This parameter is disabled by default.
///
/// \param smooth True to enable smoothing, false to disable it
///
/// \see isSmooth
///
////////////////////////////////////////////////////////////
void setSmooth(bool smooth);
////////////////////////////////////////////////////////////
/// \brief Tell whether the smooth filtering is enabled or not
///
/// \return True if texture smoothing is enabled
///
/// \see setSmooth
///
////////////////////////////////////////////////////////////
bool isSmooth() const;
////////////////////////////////////////////////////////////
/// \brief Enable or disable texture repeating
///
/// This function is similar to Texture::setRepeated.
/// This parameter is disabled by default.
///
/// \param repeated True to enable repeating, false to disable it
///
/// \see isRepeated
///
////////////////////////////////////////////////////////////
void setRepeated(bool repeated);
////////////////////////////////////////////////////////////
/// \brief Tell whether the texture is repeated or not
///
/// \return True if texture is repeated
///
/// \see setRepeated
///
////////////////////////////////////////////////////////////
bool isRepeated() const;
////////////////////////////////////////////////////////////
/// \brief Activate of deactivate the render-texture for rendering
///
/// This function makes the render-texture's context current for
/// future OpenGL rendering operations (so you shouldn't care
/// about it if you're not doing direct OpenGL stuff).
/// Only one context can be current in a thread, so if you
/// want to draw OpenGL geometry to another render target
/// (like a RenderWindow) don't forget to activate it again.
///
/// \param active True to activate, false to deactivate
///
/// \return True if operation was successful, false otherwise
///
////////////////////////////////////////////////////////////
bool setActive(bool active = true);
////////////////////////////////////////////////////////////
/// \brief Update the contents of the target texture
///
/// This function updates the target texture with what
/// has been drawn so far. Like for windows, calling this
/// function is mandatory at the end of rendering. Not calling
/// it may leave the texture in an undefined state.
///
////////////////////////////////////////////////////////////
void display();
////////////////////////////////////////////////////////////
/// \brief Return the size of the rendering region of the texture
///
/// The returned value is the size that you passed to
/// the create function.
///
/// \return Size in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2u getSize() const;
////////////////////////////////////////////////////////////
/// \brief Get a read-only reference to the target texture
///
/// After drawing to the render-texture and calling Display,
/// you can retrieve the updated texture using this function,
/// and draw it using a sprite (for example).
/// The internal sf::Texture of a render-texture is always the
/// same instance, so that it is possible to call this function
/// once and keep a reference to the texture even after it is
/// modified.
///
/// \return Const reference to the texture
///
////////////////////////////////////////////////////////////
const Texture& getTexture() const;
private:
////////////////////////////////////////////////////////////
/// \brief Activate the target for rendering
///
/// This function is called by the base class
/// everytime it's going to use OpenGL calls.
///
/// \param active True to make the target active, false to deactivate it
///
/// \return True if the function succeeded
///
////////////////////////////////////////////////////////////
virtual bool activate(bool active);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
priv::RenderTextureImpl* m_impl; ///< Platform/hardware specific implementation
Texture m_texture; ///< Target texture to draw on
};
} // namespace sf
#endif // SFML_RENDERTEXTURE_HPP
////////////////////////////////////////////////////////////
/// \class sf::RenderTexture
/// \ingroup graphics
///
/// sf::RenderTexture is the little brother of sf::RenderWindow.
/// It implements the same 2D drawing and OpenGL-related functions
/// (see their base class sf::RenderTarget for more details),
/// the difference is that the result is stored in an off-screen
/// texture rather than being show in a window.
///
/// Rendering to a texture can be useful in a variety of situations:
/// \li precomputing a complex static texture (like a level's background from multiple tiles)
/// \li applying post-effects to the whole scene with shaders
/// \li creating a sprite from a 3D object rendered with OpenGL
/// \li etc.
///
/// Usage example:
///
/// \code
/// // Create a new render-window
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
///
/// // Create a new render-texture
/// sf::RenderTexture texture;
/// if (!texture.create(500, 500))
/// return -1;
///
/// // The main loop
/// while (window.isOpen())
/// {
/// // Event processing
/// // ...
///
/// // Clear the whole texture with red color
/// texture.clear(sf::Color::Red);
///
/// // Draw stuff to the texture
/// texture.draw(sprite); // sprite is a sf::Sprite
/// texture.draw(shape); // shape is a sf::Shape
/// texture.draw(text); // text is a sf::Text
///
/// // We're done drawing to the texture
/// texture.display();
///
/// // Now we start rendering to the window, clear it first
/// window.clear();
///
/// // Draw the texture
/// sf::Sprite sprite(texture.getTexture());
/// window.draw(sprite);
///
/// // End the current frame and display its contents on screen
/// window.display();
/// }
/// \endcode
///
/// Like sf::RenderWindow, sf::RenderTexture is still able to render direct
/// OpenGL stuff. It is even possible to mix together OpenGL calls
/// and regular SFML drawing commands. If you need a depth buffer for
/// 3D rendering, don't forget to request it when calling RenderTexture::create.
///
/// \see sf::RenderTarget, sf::RenderWindow, sf::View, sf::Texture
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,267 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERWINDOW_HPP
#define SFML_RENDERWINDOW_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Window/Window.hpp>
#include <string>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Window that can serve as a target for 2D drawing
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor doesn't actually create the window,
/// use the other constructors or call create() to do so.
///
////////////////////////////////////////////////////////////
RenderWindow();
////////////////////////////////////////////////////////////
/// \brief Construct a new window
///
/// This constructor creates the window with the size and pixel
/// depth defined in \a mode. An optional style can be passed to
/// customize the look and behavior of the window (borders,
/// title bar, resizable, closable, ...).
///
/// The fourth parameter is an optional structure specifying
/// advanced OpenGL context settings such as antialiasing,
/// depth-buffer bits, etc. You shouldn't care about these
/// parameters for a regular usage of the graphics module.
///
/// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
/// \param title Title of the window
/// \param style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
////////////////////////////////////////////////////////////
/// \brief Construct the window from an existing control
///
/// Use this constructor if you want to create an SFML
/// rendering area into an already existing control.
///
/// The second parameter is an optional structure specifying
/// advanced OpenGL context settings such as antialiasing,
/// depth-buffer bits, etc. You shouldn't care about these
/// parameters for a regular usage of the graphics module.
///
/// \param handle Platform-specific handle of the control (\a HWND on
/// Windows, \a %Window on Linux/FreeBSD, \a NSWindow on OS X)
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
explicit RenderWindow(WindowHandle handle, const ContextSettings& settings = ContextSettings());
////////////////////////////////////////////////////////////
/// \brief Destructor
///
/// Closes the window and frees all the resources attached to it.
///
////////////////////////////////////////////////////////////
virtual ~RenderWindow();
////////////////////////////////////////////////////////////
/// \brief Get the size of the rendering region of the window
///
/// The size doesn't include the titlebar and borders
/// of the window.
///
/// \return Size in pixels
///
////////////////////////////////////////////////////////////
virtual Vector2u getSize() const;
////////////////////////////////////////////////////////////
/// \brief Copy the current contents of the window to an image
///
/// This is a slow operation, whose main purpose is to make
/// screenshots of the application. If you want to update an
/// image with the contents of the window and then use it for
/// drawing, you should rather use a sf::Texture and its
/// update(Window&) function.
/// You can also draw things directly to a texture with the
/// sf::RenderTexture class.
///
/// \return Image containing the captured contents
///
////////////////////////////////////////////////////////////
Image capture() const;
protected:
////////////////////////////////////////////////////////////
/// \brief Function called after the window has been created
///
/// This function is called so that derived classes can
/// perform their own specific initialization as soon as
/// the window is created.
///
////////////////////////////////////////////////////////////
virtual void onCreate();
////////////////////////////////////////////////////////////
/// \brief Function called after the window has been resized
///
/// This function is called so that derived classes can
/// perform custom actions when the size of the window changes.
///
////////////////////////////////////////////////////////////
virtual void onResize();
private:
////////////////////////////////////////////////////////////
/// \brief Activate the target for rendering
///
/// \param active True to make the target active, false to deactivate it
///
/// \return True if the function succeeded
///
////////////////////////////////////////////////////////////
virtual bool activate(bool active);
};
} // namespace sf
#endif // SFML_RENDERWINDOW_HPP
////////////////////////////////////////////////////////////
/// \class sf::RenderWindow
/// \ingroup graphics
///
/// sf::RenderWindow is the main class of the Graphics module.
/// It defines an OS window that can be painted using the other
/// classes of the graphics module.
///
/// sf::RenderWindow is derived from sf::Window, thus it inherits
/// all its features: events, window management, OpenGL rendering,
/// etc. See the documentation of sf::Window for a more complete
/// description of all these features, as well as code examples.
///
/// On top of that, sf::RenderWindow adds more features related to
/// 2D drawing with the graphics module (see its base class
/// sf::RenderTarget for more details).
/// Here is a typical rendering and event loop with a sf::RenderWindow:
///
/// \code
/// // Declare and create a new render-window
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
///
/// // Limit the framerate to 60 frames per second (this step is optional)
/// window.setFramerateLimit(60);
///
/// // The main loop - ends as soon as the window is closed
/// while (window.isOpen())
/// {
/// // Event processing
/// sf::Event event;
/// while (window.pollEvent(event))
/// {
/// // Request for closing the window
/// if (event.type == sf::Event::Closed)
/// window.close();
/// }
///
/// // Clear the whole window before rendering a new frame
/// window.clear();
///
/// // Draw some graphical entities
/// window.draw(sprite);
/// window.draw(circle);
/// window.draw(text);
///
/// // End the current frame and display its contents on screen
/// window.display();
/// }
/// \endcode
///
/// Like sf::Window, sf::RenderWindow is still able to render direct
/// OpenGL stuff. It is even possible to mix together OpenGL calls
/// and regular SFML drawing commands.
///
/// \code
/// // Create the render window
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL");
///
/// // Create a sprite and a text to display
/// sf::Sprite sprite;
/// sf::Text text;
/// ...
///
/// // Perform OpenGL initializations
/// glMatrixMode(GL_PROJECTION);
/// ...
///
/// // Start the rendering loop
/// while (window.isOpen())
/// {
/// // Process events
/// ...
///
/// // Draw a background sprite
/// window.pushGLStates();
/// window.draw(sprite);
/// window.popGLStates();
///
/// // Draw a 3D object using OpenGL
/// glBegin(GL_QUADS);
/// glVertex3f(...);
/// ...
/// glEnd();
///
/// // Draw text on top of the 3D object
/// window.pushGLStates();
/// window.draw(text);
/// window.popGLStates();
///
/// // Finally, display the rendered frame on screen
/// window.display();
/// }
/// \endcode
///
/// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,659 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SHADER_HPP
#define SFML_SHADER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Transform.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Window/GlResource.hpp>
#include <SFML/System/NonCopyable.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp>
#include <map>
#include <string>
namespace sf
{
class InputStream;
class Texture;
////////////////////////////////////////////////////////////
/// \brief Shader class (vertex and fragment)
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Shader : GlResource, NonCopyable
{
public:
////////////////////////////////////////////////////////////
/// \brief Types of shaders
///
////////////////////////////////////////////////////////////
enum Type
{
Vertex, ///< Vertex shader
Fragment ///< Fragment (pixel) shader
};
////////////////////////////////////////////////////////////
/// \brief Special type that can be passed to setParameter,
/// and that represents the texture of the object being drawn
///
/// \see setParameter(const std::string&, CurrentTextureType)
///
////////////////////////////////////////////////////////////
struct CurrentTextureType {};
////////////////////////////////////////////////////////////
/// \brief Represents the texture of the object being drawn
///
/// \see setParameter(const std::string&, CurrentTextureType)
///
////////////////////////////////////////////////////////////
static CurrentTextureType CurrentTexture;
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor creates an invalid shader.
///
////////////////////////////////////////////////////////////
Shader();
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~Shader();
////////////////////////////////////////////////////////////
/// \brief Load either the vertex or fragment shader from a file
///
/// This function loads a single shader, either vertex or
/// fragment, identified by the second argument.
/// The source must be a text file containing a valid
/// shader in GLSL language. GLSL is a C-like language
/// dedicated to OpenGL shaders; you'll probably need to
/// read a good documentation for it before writing your
/// own shaders.
///
/// \param filename Path of the vertex or fragment shader file to load
/// \param type Type of shader (vertex or fragment)
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromMemory, loadFromStream
///
////////////////////////////////////////////////////////////
bool loadFromFile(const std::string& filename, Type type);
////////////////////////////////////////////////////////////
/// \brief Load both the vertex and fragment shaders from files
///
/// This function loads both the vertex and the fragment
/// shaders. If one of them fails to load, the shader is left
/// empty (the valid shader is unloaded).
/// The sources must be text files containing valid shaders
/// in GLSL language. GLSL is a C-like language dedicated to
/// OpenGL shaders; you'll probably need to read a good documentation
/// for it before writing your own shaders.
///
/// \param vertexShaderFilename Path of the vertex shader file to load
/// \param fragmentShaderFilename Path of the fragment shader file to load
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromMemory, loadFromStream
///
////////////////////////////////////////////////////////////
bool loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename);
////////////////////////////////////////////////////////////
/// \brief Load either the vertex or fragment shader from a source code in memory
///
/// This function loads a single shader, either vertex or
/// fragment, identified by the second argument.
/// The source code must be a valid shader in GLSL language.
/// GLSL is a C-like language dedicated to OpenGL shaders;
/// you'll probably need to read a good documentation for
/// it before writing your own shaders.
///
/// \param shader String containing the source code of the shader
/// \param type Type of shader (vertex or fragment)
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromStream
///
////////////////////////////////////////////////////////////
bool loadFromMemory(const std::string& shader, Type type);
////////////////////////////////////////////////////////////
/// \brief Load both the vertex and fragment shaders from source codes in memory
///
/// This function loads both the vertex and the fragment
/// shaders. If one of them fails to load, the shader is left
/// empty (the valid shader is unloaded).
/// The sources must be valid shaders in GLSL language. GLSL is
/// a C-like language dedicated to OpenGL shaders; you'll
/// probably need to read a good documentation for it before
/// writing your own shaders.
///
/// \param vertexShader String containing the source code of the vertex shader
/// \param fragmentShader String containing the source code of the fragment shader
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromStream
///
////////////////////////////////////////////////////////////
bool loadFromMemory(const std::string& vertexShader, const std::string& fragmentShader);
////////////////////////////////////////////////////////////
/// \brief Load either the vertex or fragment shader from a custom stream
///
/// This function loads a single shader, either vertex or
/// fragment, identified by the second argument.
/// The source code must be a valid shader in GLSL language.
/// GLSL is a C-like language dedicated to OpenGL shaders;
/// you'll probably need to read a good documentation for it
/// before writing your own shaders.
///
/// \param stream Source stream to read from
/// \param type Type of shader (vertex or fragment)
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromMemory
///
////////////////////////////////////////////////////////////
bool loadFromStream(InputStream& stream, Type type);
////////////////////////////////////////////////////////////
/// \brief Load both the vertex and fragment shaders from custom streams
///
/// This function loads both the vertex and the fragment
/// shaders. If one of them fails to load, the shader is left
/// empty (the valid shader is unloaded).
/// The source codes must be valid shaders in GLSL language.
/// GLSL is a C-like language dedicated to OpenGL shaders;
/// you'll probably need to read a good documentation for
/// it before writing your own shaders.
///
/// \param vertexShaderStream Source stream to read the vertex shader from
/// \param fragmentShaderStream Source stream to read the fragment shader from
///
/// \return True if loading succeeded, false if it failed
///
/// \see loadFromFile, loadFromMemory
///
////////////////////////////////////////////////////////////
bool loadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream);
////////////////////////////////////////////////////////////
/// \brief Change a float parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a float
/// (float GLSL type).
///
/// Example:
/// \code
/// uniform float myparam; // this is the variable in the shader
/// \endcode
/// \code
/// shader.setParameter("myparam", 5.2f);
/// \endcode
///
/// \param name Name of the parameter in the shader
/// \param x Value to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, float x);
////////////////////////////////////////////////////////////
/// \brief Change a 2-components vector parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a 2x1 vector
/// (vec2 GLSL type).
///
/// Example:
/// \code
/// uniform vec2 myparam; // this is the variable in the shader
/// \endcode
/// \code
/// shader.setParameter("myparam", 5.2f, 6.0f);
/// \endcode
///
/// \param name Name of the parameter in the shader
/// \param x First component of the value to assign
/// \param y Second component of the value to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, float x, float y);
////////////////////////////////////////////////////////////
/// \brief Change a 3-components vector parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a 3x1 vector
/// (vec3 GLSL type).
///
/// Example:
/// \code
/// uniform vec3 myparam; // this is the variable in the shader
/// \endcode
/// \code
/// shader.setParameter("myparam", 5.2f, 6.0f, -8.1f);
/// \endcode
///
/// \param name Name of the parameter in the shader
/// \param x First component of the value to assign
/// \param y Second component of the value to assign
/// \param z Third component of the value to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, float x, float y, float z);
////////////////////////////////////////////////////////////
/// \brief Change a 4-components vector parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a 4x1 vector
/// (vec4 GLSL type).
///
/// Example:
/// \code
/// uniform vec4 myparam; // this is the variable in the shader
/// \endcode
/// \code
/// shader.setParameter("myparam", 5.2f, 6.0f, -8.1f, 0.4f);
/// \endcode
///
/// \param name Name of the parameter in the shader
/// \param x First component of the value to assign
/// \param y Second component of the value to assign
/// \param z Third component of the value to assign
/// \param w Fourth component of the value to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, float x, float y, float z, float w);
////////////////////////////////////////////////////////////
/// \brief Change a 2-components vector parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a 2x1 vector
/// (vec2 GLSL type).
///
/// Example:
/// \code
/// uniform vec2 myparam; // this is the variable in the shader
/// \endcode
/// \code
/// shader.setParameter("myparam", sf::Vector2f(5.2f, 6.0f));
/// \endcode
///
/// \param name Name of the parameter in the shader
/// \param vector Vector to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, const Vector2f& vector);
////////////////////////////////////////////////////////////
/// \brief Change a 3-components vector parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a 3x1 vector
/// (vec3 GLSL type).
///
/// Example:
/// \code
/// uniform vec3 myparam; // this is the variable in the shader
/// \endcode
/// \code
/// shader.setParameter("myparam", sf::Vector3f(5.2f, 6.0f, -8.1f));
/// \endcode
///
/// \param name Name of the parameter in the shader
/// \param vector Vector to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, const Vector3f& vector);
////////////////////////////////////////////////////////////
/// \brief Change a color parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a 4x1 vector
/// (vec4 GLSL type).
///
/// It is important to note that the components of the color are
/// normalized before being passed to the shader. Therefore,
/// they are converted from range [0 .. 255] to range [0 .. 1].
/// For example, a sf::Color(255, 125, 0, 255) will be transformed
/// to a vec4(1.0, 0.5, 0.0, 1.0) in the shader.
///
/// Example:
/// \code
/// uniform vec4 color; // this is the variable in the shader
/// \endcode
/// \code
/// shader.setParameter("color", sf::Color(255, 128, 0, 255));
/// \endcode
///
/// \param name Name of the parameter in the shader
/// \param color Color to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, const Color& color);
////////////////////////////////////////////////////////////
/// \brief Change a matrix parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a 4x4 matrix
/// (mat4 GLSL type).
///
/// Example:
/// \code
/// uniform mat4 matrix; // this is the variable in the shader
/// \endcode
/// \code
/// sf::Transform transform;
/// transform.translate(5, 10);
/// shader.setParameter("matrix", transform);
/// \endcode
///
/// \param name Name of the parameter in the shader
/// \param transform Transform to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, const Transform& transform);
////////////////////////////////////////////////////////////
/// \brief Change a texture parameter of the shader
///
/// \a name is the name of the variable to change in the shader.
/// The corresponding parameter in the shader must be a 2D texture
/// (sampler2D GLSL type).
///
/// Example:
/// \code
/// uniform sampler2D the_texture; // this is the variable in the shader
/// \endcode
/// \code
/// sf::Texture texture;
/// ...
/// shader.setParameter("the_texture", texture);
/// \endcode
/// It is important to note that \a texture must remain alive as long
/// as the shader uses it, no copy is made internally.
///
/// To use the texture of the object being draw, which cannot be
/// known in advance, you can pass the special value
/// sf::Shader::CurrentTexture:
/// \code
/// shader.setParameter("the_texture", sf::Shader::CurrentTexture).
/// \endcode
///
/// \param name Name of the texture in the shader
/// \param texture Texture to assign
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, const Texture& texture);
////////////////////////////////////////////////////////////
/// \brief Change a texture parameter of the shader
///
/// This overload maps a shader texture variable to the
/// texture of the object being drawn, which cannot be
/// known in advance. The second argument must be
/// sf::Shader::CurrentTexture.
/// The corresponding parameter in the shader must be a 2D texture
/// (sampler2D GLSL type).
///
/// Example:
/// \code
/// uniform sampler2D current; // this is the variable in the shader
/// \endcode
/// \code
/// shader.setParameter("current", sf::Shader::CurrentTexture);
/// \endcode
///
/// \param name Name of the texture in the shader
///
////////////////////////////////////////////////////////////
void setParameter(const std::string& name, CurrentTextureType);
////////////////////////////////////////////////////////////
/// \brief Get the underlying OpenGL handle of the shader.
///
/// You shouldn't need to use this function, unless you have
/// very specific stuff to implement that SFML doesn't support,
/// or implement a temporary workaround until a bug is fixed.
///
/// \return OpenGL handle of the shader or 0 if not yet loaded
///
////////////////////////////////////////////////////////////
unsigned int getNativeHandle() const;
////////////////////////////////////////////////////////////
/// \brief Bind a shader for rendering
///
/// This function is not part of the graphics API, it mustn't be
/// used when drawing SFML entities. It must be used only if you
/// mix sf::Shader with OpenGL code.
///
/// \code
/// sf::Shader s1, s2;
/// ...
/// sf::Shader::bind(&s1);
/// // draw OpenGL stuff that use s1...
/// sf::Shader::bind(&s2);
/// // draw OpenGL stuff that use s2...
/// sf::Shader::bind(NULL);
/// // draw OpenGL stuff that use no shader...
/// \endcode
///
/// \param shader Shader to bind, can be null to use no shader
///
////////////////////////////////////////////////////////////
static void bind(const Shader* shader);
////////////////////////////////////////////////////////////
/// \brief Tell whether or not the system supports shaders
///
/// This function should always be called before using
/// the shader features. If it returns false, then
/// any attempt to use sf::Shader will fail.
///
/// Note: The first call to this function, whether by your
/// code or SFML will result in a context switch.
///
/// \return True if shaders are supported, false otherwise
///
////////////////////////////////////////////////////////////
static bool isAvailable();
private:
////////////////////////////////////////////////////////////
/// \brief Compile the shader(s) and create the program
///
/// If one of the arguments is NULL, the corresponding shader
/// is not created.
///
/// \param vertexShaderCode Source code of the vertex shader
/// \param fragmentShaderCode Source code of the fragment shader
///
/// \return True on success, false if any error happened
///
////////////////////////////////////////////////////////////
bool compile(const char* vertexShaderCode, const char* fragmentShaderCode);
////////////////////////////////////////////////////////////
/// \brief Bind all the textures used by the shader
///
/// This function each texture to a different unit, and
/// updates the corresponding variables in the shader accordingly.
///
////////////////////////////////////////////////////////////
void bindTextures() const;
////////////////////////////////////////////////////////////
/// \brief Get the location ID of a shader parameter
///
/// \param name Name of the parameter to search
///
/// \return Location ID of the parameter, or -1 if not found
///
////////////////////////////////////////////////////////////
int getParamLocation(const std::string& name);
////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////
typedef std::map<int, const Texture*> TextureTable;
typedef std::map<std::string, int> ParamTable;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int m_shaderProgram; ///< OpenGL identifier for the program
int m_currentTexture; ///< Location of the current texture in the shader
TextureTable m_textures; ///< Texture variables in the shader, mapped to their location
ParamTable m_params; ///< Parameters location cache
};
} // namespace sf
#endif // SFML_SHADER_HPP
////////////////////////////////////////////////////////////
/// \class sf::Shader
/// \ingroup graphics
///
/// Shaders are programs written using a specific language,
/// executed directly by the graphics card and allowing
/// to apply real-time operations to the rendered entities.
///
/// There are two kinds of shaders:
/// \li Vertex shaders, that process vertices
/// \li Fragment (pixel) shaders, that process pixels
///
/// A sf::Shader can be composed of either a vertex shader
/// alone, a fragment shader alone, or both combined
/// (see the variants of the load functions).
///
/// Shaders are written in GLSL, which is a C-like
/// language dedicated to OpenGL shaders. You'll probably
/// need to learn its basics before writing your own shaders
/// for SFML.
///
/// Like any C/C++ program, a shader has its own variables
/// that you can set from your C++ application. sf::Shader
/// handles 5 different types of variables:
/// \li floats
/// \li vectors (2, 3 or 4 components)
/// \li colors
/// \li textures
/// \li transforms (matrices)
///
/// The value of the variables can be changed at any time
/// with the various overloads of the setParameter function:
/// \code
/// shader.setParameter("offset", 2.f);
/// shader.setParameter("point", 0.5f, 0.8f, 0.3f);
/// shader.setParameter("color", sf::Color(128, 50, 255));
/// shader.setParameter("matrix", transform); // transform is a sf::Transform
/// shader.setParameter("overlay", texture); // texture is a sf::Texture
/// shader.setParameter("texture", sf::Shader::CurrentTexture);
/// \endcode
///
/// The special Shader::CurrentTexture argument maps the
/// given texture variable to the current texture of the
/// object being drawn (which cannot be known in advance).
///
/// To apply a shader to a drawable, you must pass it as an
/// additional parameter to the Draw function:
/// \code
/// window.draw(sprite, &shader);
/// \endcode
///
/// ... which is in fact just a shortcut for this:
/// \code
/// sf::RenderStates states;
/// states.shader = &shader;
/// window.draw(sprite, states);
/// \endcode
///
/// In the code above we pass a pointer to the shader, because it may
/// be null (which means "no shader").
///
/// Shaders can be used on any drawable, but some combinations are
/// not interesting. For example, using a vertex shader on a sf::Sprite
/// is limited because there are only 4 vertices, the sprite would
/// have to be subdivided in order to apply wave effects.
/// Another bad example is a fragment shader with sf::Text: the texture
/// of the text is not the actual text that you see on screen, it is
/// a big texture containing all the characters of the font in an
/// arbitrary order; thus, texture lookups on pixels other than the
/// current one may not give you the expected result.
///
/// Shaders can also be used to apply global post-effects to the
/// current contents of the target (like the old sf::PostFx class
/// in SFML 1). This can be done in two different ways:
/// \li draw everything to a sf::RenderTexture, then draw it to
/// the main target using the shader
/// \li draw everything directly to the main target, then use
/// sf::Texture::update(Window&) to copy its contents to a texture
/// and draw it to the main target using the shader
///
/// The first technique is more optimized because it doesn't involve
/// retrieving the target's pixels to system memory, but the
/// second one doesn't impact the rendering process and can be
/// easily inserted anywhere without impacting all the code.
///
/// Like sf::Texture that can be used as a raw OpenGL texture,
/// sf::Shader can also be used directly as a raw shader for
/// custom OpenGL geometry.
/// \code
/// sf::Shader::bind(&shader);
/// ... render OpenGL geometry ...
/// sf::Shader::bind(NULL);
/// \endcode
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,355 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SHAPE_HPP
#define SFML_SHAPE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/VertexArray.hpp>
#include <SFML/System/Vector2.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Base class for textured shapes with outline
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
{
public:
////////////////////////////////////////////////////////////
/// \brief Virtual destructor
///
////////////////////////////////////////////////////////////
virtual ~Shape();
////////////////////////////////////////////////////////////
/// \brief Change the source texture of the shape
///
/// The \a texture argument refers to a texture that must
/// exist as long as the shape uses it. Indeed, the shape
/// doesn't store its own copy of the texture, but rather keeps
/// a pointer to the one that you passed to this function.
/// If the source texture is destroyed and the shape tries to
/// use it, the behavior is undefined.
/// \a texture can be NULL to disable texturing.
/// If \a resetRect is true, the TextureRect property of
/// the shape is automatically adjusted to the size of the new
/// texture. If it is false, the texture rect is left unchanged.
///
/// \param texture New texture
/// \param resetRect Should the texture rect be reset to the size of the new texture?
///
/// \see getTexture, setTextureRect
///
////////////////////////////////////////////////////////////
void setTexture(const Texture* texture, bool resetRect = false);
////////////////////////////////////////////////////////////
/// \brief Set the sub-rectangle of the texture that the shape will display
///
/// The texture rect is useful when you don't want to display
/// the whole texture, but rather a part of it.
/// By default, the texture rect covers the entire texture.
///
/// \param rect Rectangle defining the region of the texture to display
///
/// \see getTextureRect, setTexture
///
////////////////////////////////////////////////////////////
void setTextureRect(const IntRect& rect);
////////////////////////////////////////////////////////////
/// \brief Set the fill color of the shape
///
/// This color is modulated (multiplied) with the shape's
/// texture if any. It can be used to colorize the shape,
/// or change its global opacity.
/// You can use sf::Color::Transparent to make the inside of
/// the shape transparent, and have the outline alone.
/// By default, the shape's fill color is opaque white.
///
/// \param color New color of the shape
///
/// \see getFillColor, setOutlineColor
///
////////////////////////////////////////////////////////////
void setFillColor(const Color& color);
////////////////////////////////////////////////////////////
/// \brief Set the outline color of the shape
///
/// By default, the shape's outline color is opaque white.
///
/// \param color New outline color of the shape
///
/// \see getOutlineColor, setFillColor
///
////////////////////////////////////////////////////////////
void setOutlineColor(const Color& color);
////////////////////////////////////////////////////////////
/// \brief Set the thickness of the shape's outline
///
/// Note that negative values are allowed (so that the outline
/// expands towards the center of the shape), and using zero
/// disables the outline.
/// By default, the outline thickness is 0.
///
/// \param thickness New outline thickness
///
/// \see getOutlineThickness
///
////////////////////////////////////////////////////////////
void setOutlineThickness(float thickness);
////////////////////////////////////////////////////////////
/// \brief Get the source texture of the shape
///
/// If the shape has no source texture, a NULL pointer is returned.
/// The returned pointer is const, which means that you can't
/// modify the texture when you retrieve it with this function.
///
/// \return Pointer to the shape's texture
///
/// \see setTexture
///
////////////////////////////////////////////////////////////
const Texture* getTexture() const;
////////////////////////////////////////////////////////////
/// \brief Get the sub-rectangle of the texture displayed by the shape
///
/// \return Texture rectangle of the shape
///
/// \see setTextureRect
///
////////////////////////////////////////////////////////////
const IntRect& getTextureRect() const;
////////////////////////////////////////////////////////////
/// \brief Get the fill color of the shape
///
/// \return Fill color of the shape
///
/// \see setFillColor
///
////////////////////////////////////////////////////////////
const Color& getFillColor() const;
////////////////////////////////////////////////////////////
/// \brief Get the outline color of the shape
///
/// \return Outline color of the shape
///
/// \see setOutlineColor
///
////////////////////////////////////////////////////////////
const Color& getOutlineColor() const;
////////////////////////////////////////////////////////////
/// \brief Get the outline thickness of the shape
///
/// \return Outline thickness of the shape
///
/// \see setOutlineThickness
///
////////////////////////////////////////////////////////////
float getOutlineThickness() const;
////////////////////////////////////////////////////////////
/// \brief Get the total number of points of the shape
///
/// \return Number of points of the shape
///
/// \see getPoint
///
////////////////////////////////////////////////////////////
virtual std::size_t getPointCount() const = 0;
////////////////////////////////////////////////////////////
/// \brief Get a point of the shape
///
/// The returned point is in local coordinates, that is,
/// the shape's transforms (position, rotation, scale) are
/// not taken into account.
/// The result is undefined if \a index is out of the valid range.
///
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
///
/// \return index-th point of the shape
///
/// \see getPointCount
///
////////////////////////////////////////////////////////////
virtual Vector2f getPoint(std::size_t index) const = 0;
////////////////////////////////////////////////////////////
/// \brief Get the local bounding rectangle of the entity
///
/// The returned rectangle is in local coordinates, which means
/// that it ignores the transformations (translation, rotation,
/// scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// entity in the entity's coordinate system.
///
/// \return Local bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
FloatRect getLocalBounds() const;
////////////////////////////////////////////////////////////
/// \brief Get the global (non-minimal) bounding rectangle of the entity
///
/// The returned rectangle is in global coordinates, which means
/// that it takes into account the transformations (translation,
/// rotation, scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// shape in the global 2D world's coordinate system.
///
/// This function does not necessarily return the \a minimal
/// bounding rectangle. It merely ensures that the returned
/// rectangle covers all the vertices (but possibly more).
/// This allows for a fast approximation of the bounds as a
/// first check; you may want to use more precise checks
/// on top of that.
///
/// \return Global bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
FloatRect getGlobalBounds() const;
protected:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
Shape();
////////////////////////////////////////////////////////////
/// \brief Recompute the internal geometry of the shape
///
/// This function must be called by the derived class everytime
/// the shape's points change (i.e. the result of either
/// getPointCount or getPoint is different).
///
////////////////////////////////////////////////////////////
void update();
private:
////////////////////////////////////////////////////////////
/// \brief Draw the shape to a render target
///
/// \param target Render target to draw to
/// \param states Current render states
///
////////////////////////////////////////////////////////////
virtual void draw(RenderTarget& target, RenderStates states) const;
////////////////////////////////////////////////////////////
/// \brief Update the fill vertices' color
///
////////////////////////////////////////////////////////////
void updateFillColors();
////////////////////////////////////////////////////////////
/// \brief Update the fill vertices' texture coordinates
///
////////////////////////////////////////////////////////////
void updateTexCoords();
////////////////////////////////////////////////////////////
/// \brief Update the outline vertices' position
///
////////////////////////////////////////////////////////////
void updateOutline();
////////////////////////////////////////////////////////////
/// \brief Update the outline vertices' color
///
////////////////////////////////////////////////////////////
void updateOutlineColors();
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
const Texture* m_texture; ///< Texture of the shape
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
Color m_fillColor; ///< Fill color
Color m_outlineColor; ///< Outline color
float m_outlineThickness; ///< Thickness of the shape's outline
VertexArray m_vertices; ///< Vertex array containing the fill geometry
VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
FloatRect m_insideBounds; ///< Bounding rectangle of the inside (fill)
FloatRect m_bounds; ///< Bounding rectangle of the whole shape (outline + fill)
};
} // namespace sf
#endif // SFML_SHAPE_HPP
////////////////////////////////////////////////////////////
/// \class sf::Shape
/// \ingroup graphics
///
/// sf::Shape is a drawable class that allows to define and
/// display a custom convex shape on a render target.
/// It's only an abstract base, it needs to be specialized for
/// concrete types of shapes (circle, rectangle, convex polygon,
/// star, ...).
///
/// In addition to the attributes provided by the specialized
/// shape classes, a shape always has the following attributes:
/// \li a texture
/// \li a texture rectangle
/// \li a fill color
/// \li an outline color
/// \li an outline thickness
///
/// Each feature is optional, and can be disabled easily:
/// \li the texture can be null
/// \li the fill/outline colors can be sf::Color::Transparent
/// \li the outline thickness can be zero
///
/// You can write your own derived shape class, there are only
/// two virtual functions to override:
/// \li getPointCount must return the number of points of the shape
/// \li getPoint must return the points of the shape
///
/// \see sf::RectangleShape, sf::CircleShape, sf::ConvexShape, sf::Transformable
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,279 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SPRITE_HPP
#define SFML_SPRITE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Vertex.hpp>
#include <SFML/Graphics/Rect.hpp>
namespace sf
{
class Texture;
////////////////////////////////////////////////////////////
/// \brief Drawable representation of a texture, with its
/// own transformations, color, etc.
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates an empty sprite with no source texture.
///
////////////////////////////////////////////////////////////
Sprite();
////////////////////////////////////////////////////////////
/// \brief Construct the sprite from a source texture
///
/// \param texture Source texture
///
/// \see setTexture
///
////////////////////////////////////////////////////////////
explicit Sprite(const Texture& texture);
////////////////////////////////////////////////////////////
/// \brief Construct the sprite from a sub-rectangle of a source texture
///
/// \param texture Source texture
/// \param rectangle Sub-rectangle of the texture to assign to the sprite
///
/// \see setTexture, setTextureRect
///
////////////////////////////////////////////////////////////
Sprite(const Texture& texture, const IntRect& rectangle);
////////////////////////////////////////////////////////////
/// \brief Change the source texture of the sprite
///
/// The \a texture argument refers to a texture that must
/// exist as long as the sprite uses it. Indeed, the sprite
/// doesn't store its own copy of the texture, but rather keeps
/// a pointer to the one that you passed to this function.
/// If the source texture is destroyed and the sprite tries to
/// use it, the behavior is undefined.
/// If \a resetRect is true, the TextureRect property of
/// the sprite is automatically adjusted to the size of the new
/// texture. If it is false, the texture rect is left unchanged.
///
/// \param texture New texture
/// \param resetRect Should the texture rect be reset to the size of the new texture?
///
/// \see getTexture, setTextureRect
///
////////////////////////////////////////////////////////////
void setTexture(const Texture& texture, bool resetRect = false);
////////////////////////////////////////////////////////////
/// \brief Set the sub-rectangle of the texture that the sprite will display
///
/// The texture rect is useful when you don't want to display
/// the whole texture, but rather a part of it.
/// By default, the texture rect covers the entire texture.
///
/// \param rectangle Rectangle defining the region of the texture to display
///
/// \see getTextureRect, setTexture
///
////////////////////////////////////////////////////////////
void setTextureRect(const IntRect& rectangle);
////////////////////////////////////////////////////////////
/// \brief Set the global color of the sprite
///
/// This color is modulated (multiplied) with the sprite's
/// texture. It can be used to colorize the sprite, or change
/// its global opacity.
/// By default, the sprite's color is opaque white.
///
/// \param color New color of the sprite
///
/// \see getColor
///
////////////////////////////////////////////////////////////
void setColor(const Color& color);
////////////////////////////////////////////////////////////
/// \brief Get the source texture of the sprite
///
/// If the sprite has no source texture, a NULL pointer is returned.
/// The returned pointer is const, which means that you can't
/// modify the texture when you retrieve it with this function.
///
/// \return Pointer to the sprite's texture
///
/// \see setTexture
///
////////////////////////////////////////////////////////////
const Texture* getTexture() const;
////////////////////////////////////////////////////////////
/// \brief Get the sub-rectangle of the texture displayed by the sprite
///
/// \return Texture rectangle of the sprite
///
/// \see setTextureRect
///
////////////////////////////////////////////////////////////
const IntRect& getTextureRect() const;
////////////////////////////////////////////////////////////
/// \brief Get the global color of the sprite
///
/// \return Global color of the sprite
///
/// \see setColor
///
////////////////////////////////////////////////////////////
const Color& getColor() const;
////////////////////////////////////////////////////////////
/// \brief Get the local bounding rectangle of the entity
///
/// The returned rectangle is in local coordinates, which means
/// that it ignores the transformations (translation, rotation,
/// scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// entity in the entity's coordinate system.
///
/// \return Local bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
FloatRect getLocalBounds() const;
////////////////////////////////////////////////////////////
/// \brief Get the global bounding rectangle of the entity
///
/// The returned rectangle is in global coordinates, which means
/// that it takes into account the transformations (translation,
/// rotation, scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// sprite in the global 2D world's coordinate system.
///
/// \return Global bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
FloatRect getGlobalBounds() const;
private:
////////////////////////////////////////////////////////////
/// \brief Draw the sprite to a render target
///
/// \param target Render target to draw to
/// \param states Current render states
///
////////////////////////////////////////////////////////////
virtual void draw(RenderTarget& target, RenderStates states) const;
////////////////////////////////////////////////////////////
/// \brief Update the vertices' positions
///
////////////////////////////////////////////////////////////
void updatePositions();
////////////////////////////////////////////////////////////
/// \brief Update the vertices' texture coordinates
///
////////////////////////////////////////////////////////////
void updateTexCoords();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Vertex m_vertices[4]; ///< Vertices defining the sprite's geometry
const Texture* m_texture; ///< Texture of the sprite
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
};
} // namespace sf
#endif // SFML_SPRITE_HPP
////////////////////////////////////////////////////////////
/// \class sf::Sprite
/// \ingroup graphics
///
/// sf::Sprite is a drawable class that allows to easily display
/// a texture (or a part of it) on a render target.
///
/// It inherits all the functions from sf::Transformable:
/// position, rotation, scale, origin. It also adds sprite-specific
/// properties such as the texture to use, the part of it to display,
/// and some convenience functions to change the overall color of the
/// sprite, or to get its bounding rectangle.
///
/// sf::Sprite works in combination with the sf::Texture class, which
/// loads and provides the pixel data of a given texture.
///
/// The separation of sf::Sprite and sf::Texture allows more flexibility
/// and better performances: indeed a sf::Texture is a heavy resource,
/// and any operation on it is slow (often too slow for real-time
/// applications). On the other side, a sf::Sprite is a lightweight
/// object which can use the pixel data of a sf::Texture and draw
/// it with its own transformation/color/blending attributes.
///
/// It is important to note that the sf::Sprite instance doesn't
/// copy the texture that it uses, it only keeps a reference to it.
/// Thus, a sf::Texture must not be destroyed while it is
/// used by a sf::Sprite (i.e. never write a function that
/// uses a local sf::Texture instance for creating a sprite).
///
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
///
/// Usage example:
/// \code
/// // Declare and load a texture
/// sf::Texture texture;
/// texture.loadFromFile("texture.png");
///
/// // Create a sprite
/// sf::Sprite sprite;
/// sprite.setTexture(texture);
/// sprite.setTextureRect(sf::IntRect(10, 10, 50, 30));
/// sprite.setColor(sf::Color(255, 255, 255, 200));
/// sprite.setPosition(100, 25);
///
/// // Draw it
/// window.draw(sprite);
/// \endcode
///
/// \see sf::Texture, sf::Transformable
///
////////////////////////////////////////////////////////////

372
external/sfml23/include/SFML/Graphics/Text.hpp vendored Executable file
View File

@ -0,0 +1,372 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TEXT_HPP
#define SFML_TEXT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/VertexArray.hpp>
#include <SFML/System/String.hpp>
#include <string>
#include <vector>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Graphical text that can be drawn to a render target
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Text : public Drawable, public Transformable
{
public:
////////////////////////////////////////////////////////////
/// \brief Enumeration of the string drawing styles
///
////////////////////////////////////////////////////////////
enum Style
{
Regular = 0, ///< Regular characters, no style
Bold = 1 << 0, ///< Bold characters
Italic = 1 << 1, ///< Italic characters
Underlined = 1 << 2, ///< Underlined characters
StrikeThrough = 1 << 3 ///< Strike through characters
};
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates an empty text.
///
////////////////////////////////////////////////////////////
Text();
////////////////////////////////////////////////////////////
/// \brief Construct the text from a string, font and size
///
/// Note that if the used font is a bitmap font, it is not
/// scalable, thus not all requested sizes will be available
/// to use. This needs to be taken into consideration when
/// setting the character size. If you need to display text
/// of a certain size, make sure the corresponding bitmap
/// font that supports that size is used.
///
/// \param string Text assigned to the string
/// \param font Font used to draw the string
/// \param characterSize Base size of characters, in pixels
///
////////////////////////////////////////////////////////////
Text(const String& string, const Font& font, unsigned int characterSize = 30);
////////////////////////////////////////////////////////////
/// \brief Set the text's string
///
/// The \a string argument is a sf::String, which can
/// automatically be constructed from standard string types.
/// So, the following calls are all valid:
/// \code
/// text.setString("hello");
/// text.setString(L"hello");
/// text.setString(std::string("hello"));
/// text.setString(std::wstring(L"hello"));
/// \endcode
/// A text's string is empty by default.
///
/// \param string New string
///
/// \see getString
///
////////////////////////////////////////////////////////////
void setString(const String& string);
////////////////////////////////////////////////////////////
/// \brief Set the text's font
///
/// The \a font argument refers to a font that must
/// exist as long as the text uses it. Indeed, the text
/// doesn't store its own copy of the font, but rather keeps
/// a pointer to the one that you passed to this function.
/// If the font is destroyed and the text tries to
/// use it, the behavior is undefined.
///
/// \param font New font
///
/// \see getFont
///
////////////////////////////////////////////////////////////
void setFont(const Font& font);
////////////////////////////////////////////////////////////
/// \brief Set the character size
///
/// The default size is 30.
///
/// Note that if the used font is a bitmap font, it is not
/// scalable, thus not all requested sizes will be available
/// to use. This needs to be taken into consideration when
/// setting the character size. If you need to display text
/// of a certain size, make sure the corresponding bitmap
/// font that supports that size is used.
///
/// \param size New character size, in pixels
///
/// \see getCharacterSize
///
////////////////////////////////////////////////////////////
void setCharacterSize(unsigned int size);
////////////////////////////////////////////////////////////
/// \brief Set the text's style
///
/// You can pass a combination of one or more styles, for
/// example sf::Text::Bold | sf::Text::Italic.
/// The default style is sf::Text::Regular.
///
/// \param style New style
///
/// \see getStyle
///
////////////////////////////////////////////////////////////
void setStyle(Uint32 style);
////////////////////////////////////////////////////////////
/// \brief Set the global color of the text
///
/// By default, the text's color is opaque white.
///
/// \param color New color of the text
///
/// \see getColor
///
////////////////////////////////////////////////////////////
void setColor(const Color& color);
////////////////////////////////////////////////////////////
/// \brief Get the text's string
///
/// The returned string is a sf::String, which can automatically
/// be converted to standard string types. So, the following
/// lines of code are all valid:
/// \code
/// sf::String s1 = text.getString();
/// std::string s2 = text.getString();
/// std::wstring s3 = text.getString();
/// \endcode
///
/// \return Text's string
///
/// \see setString
///
////////////////////////////////////////////////////////////
const String& getString() const;
////////////////////////////////////////////////////////////
/// \brief Get the text's font
///
/// If the text has no font attached, a NULL pointer is returned.
/// The returned pointer is const, which means that you
/// cannot modify the font when you get it from this function.
///
/// \return Pointer to the text's font
///
/// \see setFont
///
////////////////////////////////////////////////////////////
const Font* getFont() const;
////////////////////////////////////////////////////////////
/// \brief Get the character size
///
/// \return Size of the characters, in pixels
///
/// \see setCharacterSize
///
////////////////////////////////////////////////////////////
unsigned int getCharacterSize() const;
////////////////////////////////////////////////////////////
/// \brief Get the text's style
///
/// \return Text's style
///
/// \see setStyle
///
////////////////////////////////////////////////////////////
Uint32 getStyle() const;
////////////////////////////////////////////////////////////
/// \brief Get the global color of the text
///
/// \return Global color of the text
///
/// \see setColor
///
////////////////////////////////////////////////////////////
const Color& getColor() const;
////////////////////////////////////////////////////////////
/// \brief Return the position of the \a index-th character
///
/// This function computes the visual position of a character
/// from its index in the string. The returned position is
/// in global coordinates (translation, rotation, scale and
/// origin are applied).
/// If \a index is out of range, the position of the end of
/// the string is returned.
///
/// \param index Index of the character
///
/// \return Position of the character
///
////////////////////////////////////////////////////////////
Vector2f findCharacterPos(std::size_t index) const;
////////////////////////////////////////////////////////////
/// \brief Get the local bounding rectangle of the entity
///
/// The returned rectangle is in local coordinates, which means
/// that it ignores the transformations (translation, rotation,
/// scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// entity in the entity's coordinate system.
///
/// \return Local bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
FloatRect getLocalBounds() const;
////////////////////////////////////////////////////////////
/// \brief Get the global bounding rectangle of the entity
///
/// The returned rectangle is in global coordinates, which means
/// that it takes into account the transformations (translation,
/// rotation, scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// text in the global 2D world's coordinate system.
///
/// \return Global bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
FloatRect getGlobalBounds() const;
private:
////////////////////////////////////////////////////////////
/// \brief Draw the text to a render target
///
/// \param target Render target to draw to
/// \param states Current render states
///
////////////////////////////////////////////////////////////
virtual void draw(RenderTarget& target, RenderStates states) const;
////////////////////////////////////////////////////////////
/// \brief Make sure the text's geometry is updated
///
/// All the attributes related to rendering are cached, such
/// that the geometry is only updated when necessary.
///
////////////////////////////////////////////////////////////
void ensureGeometryUpdate() const;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
String m_string; ///< String to display
const Font* m_font; ///< Font used to display the string
unsigned int m_characterSize; ///< Base size of characters, in pixels
Uint32 m_style; ///< Text style (see Style enum)
Color m_color; ///< Text color
mutable VertexArray m_vertices; ///< Vertex array containing the text's geometry
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
};
} // namespace sf
#endif // SFML_TEXT_HPP
////////////////////////////////////////////////////////////
/// \class sf::Text
/// \ingroup graphics
///
/// sf::Text is a drawable class that allows to easily display
/// some text with custom style and color on a render target.
///
/// It inherits all the functions from sf::Transformable:
/// position, rotation, scale, origin. It also adds text-specific
/// properties such as the font to use, the character size,
/// the font style (bold, italic, underlined, strike through), the
/// global color and the text to display of course.
/// It also provides convenience functions to calculate the
/// graphical size of the text, or to get the global position
/// of a given character.
///
/// sf::Text works in combination with the sf::Font class, which
/// loads and provides the glyphs (visual characters) of a given font.
///
/// The separation of sf::Font and sf::Text allows more flexibility
/// and better performances: indeed a sf::Font is a heavy resource,
/// and any operation on it is slow (often too slow for real-time
/// applications). On the other side, a sf::Text is a lightweight
/// object which can combine the glyphs data and metrics of a sf::Font
/// to display any text on a render target.
///
/// It is important to note that the sf::Text instance doesn't
/// copy the font that it uses, it only keeps a reference to it.
/// Thus, a sf::Font must not be destructed while it is
/// used by a sf::Text (i.e. never write a function that
/// uses a local sf::Font instance for creating a text).
///
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
///
/// Usage example:
/// \code
/// // Declare and load a font
/// sf::Font font;
/// font.loadFromFile("arial.ttf");
///
/// // Create a text
/// sf::Text text("hello", font);
/// text.setCharacterSize(30);
/// text.setStyle(sf::Text::Bold);
/// text.setColor(sf::Color::Red);
///
/// // Draw it
/// window.draw(text);
/// \endcode
///
/// \see sf::Font, sf::Transformable
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,618 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TEXTURE_HPP
#define SFML_TEXTURE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Window/GlResource.hpp>
namespace sf
{
class Window;
class RenderTarget;
class RenderTexture;
class InputStream;
////////////////////////////////////////////////////////////
/// \brief Image living on the graphics card that can be used for drawing
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Texture : GlResource
{
public:
////////////////////////////////////////////////////////////
/// \brief Types of texture coordinates that can be used for rendering
///
////////////////////////////////////////////////////////////
enum CoordinateType
{
Normalized, ///< Texture coordinates in range [0 .. 1]
Pixels ///< Texture coordinates in range [0 .. size]
};
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates an empty texture.
///
////////////////////////////////////////////////////////////
Texture();
////////////////////////////////////////////////////////////
/// \brief Copy constructor
///
/// \param copy instance to copy
///
////////////////////////////////////////////////////////////
Texture(const Texture& copy);
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~Texture();
////////////////////////////////////////////////////////////
/// \brief Create the texture
///
/// If this function fails, the texture is left unchanged.
///
/// \param width Width of the texture
/// \param height Height of the texture
///
/// \return True if creation was successful
///
////////////////////////////////////////////////////////////
bool create(unsigned int width, unsigned int height);
////////////////////////////////////////////////////////////
/// \brief Load the texture from a file on disk
///
/// This function is a shortcut for the following code:
/// \code
/// sf::Image image;
/// image.loadFromFile(filename);
/// texture.loadFromImage(image, area);
/// \endcode
///
/// The \a area argument can be used to load only a sub-rectangle
/// of the whole image. If you want the entire image then leave
/// the default value (which is an empty IntRect).
/// If the \a area rectangle crosses the bounds of the image, it
/// is adjusted to fit the image size.
///
/// The maximum size for a texture depends on the graphics
/// driver and can be retrieved with the getMaximumSize function.
///
/// If this function fails, the texture is left unchanged.
///
/// \param filename Path of the image file to load
/// \param area Area of the image to load
///
/// \return True if loading was successful
///
/// \see loadFromMemory, loadFromStream, loadFromImage
///
////////////////////////////////////////////////////////////
bool loadFromFile(const std::string& filename, const IntRect& area = IntRect());
////////////////////////////////////////////////////////////
/// \brief Load the texture from a file in memory
///
/// This function is a shortcut for the following code:
/// \code
/// sf::Image image;
/// image.loadFromMemory(data, size);
/// texture.loadFromImage(image, area);
/// \endcode
///
/// The \a area argument can be used to load only a sub-rectangle
/// of the whole image. If you want the entire image then leave
/// the default value (which is an empty IntRect).
/// If the \a area rectangle crosses the bounds of the image, it
/// is adjusted to fit the image size.
///
/// The maximum size for a texture depends on the graphics
/// driver and can be retrieved with the getMaximumSize function.
///
/// If this function fails, the texture is left unchanged.
///
/// \param data Pointer to the file data in memory
/// \param size Size of the data to load, in bytes
/// \param area Area of the image to load
///
/// \return True if loading was successful
///
/// \see loadFromFile, loadFromStream, loadFromImage
///
////////////////////////////////////////////////////////////
bool loadFromMemory(const void* data, std::size_t size, const IntRect& area = IntRect());
////////////////////////////////////////////////////////////
/// \brief Load the texture from a custom stream
///
/// This function is a shortcut for the following code:
/// \code
/// sf::Image image;
/// image.loadFromStream(stream);
/// texture.loadFromImage(image, area);
/// \endcode
///
/// The \a area argument can be used to load only a sub-rectangle
/// of the whole image. If you want the entire image then leave
/// the default value (which is an empty IntRect).
/// If the \a area rectangle crosses the bounds of the image, it
/// is adjusted to fit the image size.
///
/// The maximum size for a texture depends on the graphics
/// driver and can be retrieved with the getMaximumSize function.
///
/// If this function fails, the texture is left unchanged.
///
/// \param stream Source stream to read from
/// \param area Area of the image to load
///
/// \return True if loading was successful
///
/// \see loadFromFile, loadFromMemory, loadFromImage
///
////////////////////////////////////////////////////////////
bool loadFromStream(InputStream& stream, const IntRect& area = IntRect());
////////////////////////////////////////////////////////////
/// \brief Load the texture from an image
///
/// The \a area argument can be used to load only a sub-rectangle
/// of the whole image. If you want the entire image then leave
/// the default value (which is an empty IntRect).
/// If the \a area rectangle crosses the bounds of the image, it
/// is adjusted to fit the image size.
///
/// The maximum size for a texture depends on the graphics
/// driver and can be retrieved with the getMaximumSize function.
///
/// If this function fails, the texture is left unchanged.
///
/// \param image Image to load into the texture
/// \param area Area of the image to load
///
/// \return True if loading was successful
///
/// \see loadFromFile, loadFromMemory
///
////////////////////////////////////////////////////////////
bool loadFromImage(const Image& image, const IntRect& area = IntRect());
////////////////////////////////////////////////////////////
/// \brief Return the size of the texture
///
/// \return Size in pixels
///
////////////////////////////////////////////////////////////
Vector2u getSize() const;
////////////////////////////////////////////////////////////
/// \brief Copy the texture pixels to an image
///
/// This function performs a slow operation that downloads
/// the texture's pixels from the graphics card and copies
/// them to a new image, potentially applying transformations
/// to pixels if necessary (texture may be padded or flipped).
///
/// \return Image containing the texture's pixels
///
/// \see loadFromImage
///
////////////////////////////////////////////////////////////
Image copyToImage() const;
////////////////////////////////////////////////////////////
/// \brief Update the whole texture from an array of pixels
///
/// The \a pixel array is assumed to have the same size as
/// the \a area rectangle, and to contain 32-bits RGBA pixels.
///
/// No additional check is performed on the size of the pixel
/// array, passing invalid arguments will lead to an undefined
/// behavior.
///
/// This function does nothing if \a pixels is null or if the
/// texture was not previously created.
///
/// \param pixels Array of pixels to copy to the texture
///
////////////////////////////////////////////////////////////
void update(const Uint8* pixels);
////////////////////////////////////////////////////////////
/// \brief Update a part of the texture from an array of pixels
///
/// The size of the \a pixel array must match the \a width and
/// \a height arguments, and it must contain 32-bits RGBA pixels.
///
/// No additional check is performed on the size of the pixel
/// array or the bounds of the area to update, passing invalid
/// arguments will lead to an undefined behavior.
///
/// This function does nothing if \a pixels is null or if the
/// texture was not previously created.
///
/// \param pixels Array of pixels to copy to the texture
/// \param width Width of the pixel region contained in \a pixels
/// \param height Height of the pixel region contained in \a pixels
/// \param x X offset in the texture where to copy the source pixels
/// \param y Y offset in the texture where to copy the source pixels
///
////////////////////////////////////////////////////////////
void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);
////////////////////////////////////////////////////////////
/// \brief Update the texture from an image
///
/// Although the source image can be smaller than the texture,
/// this function is usually used for updating the whole texture.
/// The other overload, which has (x, y) additional arguments,
/// is more convenient for updating a sub-area of the texture.
///
/// No additional check is performed on the size of the image,
/// passing an image bigger than the texture will lead to an
/// undefined behavior.
///
/// This function does nothing if the texture was not
/// previously created.
///
/// \param image Image to copy to the texture
///
////////////////////////////////////////////////////////////
void update(const Image& image);
////////////////////////////////////////////////////////////
/// \brief Update a part of the texture from an image
///
/// No additional check is performed on the size of the image,
/// passing an invalid combination of image size and offset
/// will lead to an undefined behavior.
///
/// This function does nothing if the texture was not
/// previously created.
///
/// \param image Image to copy to the texture
/// \param x X offset in the texture where to copy the source image
/// \param y Y offset in the texture where to copy the source image
///
////////////////////////////////////////////////////////////
void update(const Image& image, unsigned int x, unsigned int y);
////////////////////////////////////////////////////////////
/// \brief Update the texture from the contents of a window
///
/// Although the source window can be smaller than the texture,
/// this function is usually used for updating the whole texture.
/// The other overload, which has (x, y) additional arguments,
/// is more convenient for updating a sub-area of the texture.
///
/// No additional check is performed on the size of the window,
/// passing a window bigger than the texture will lead to an
/// undefined behavior.
///
/// This function does nothing if either the texture or the window
/// was not previously created.
///
/// \param window Window to copy to the texture
///
////////////////////////////////////////////////////////////
void update(const Window& window);
////////////////////////////////////////////////////////////
/// \brief Update a part of the texture from the contents of a window
///
/// No additional check is performed on the size of the window,
/// passing an invalid combination of window size and offset
/// will lead to an undefined behavior.
///
/// This function does nothing if either the texture or the window
/// was not previously created.
///
/// \param window Window to copy to the texture
/// \param x X offset in the texture where to copy the source window
/// \param y Y offset in the texture where to copy the source window
///
////////////////////////////////////////////////////////////
void update(const Window& window, unsigned int x, unsigned int y);
////////////////////////////////////////////////////////////
/// \brief Enable or disable the smooth filter
///
/// When the filter is activated, the texture appears smoother
/// so that pixels are less noticeable. However if you want
/// the texture to look exactly the same as its source file,
/// you should leave it disabled.
/// The smooth filter is disabled by default.
///
/// \param smooth True to enable smoothing, false to disable it
///
/// \see isSmooth
///
////////////////////////////////////////////////////////////
void setSmooth(bool smooth);
////////////////////////////////////////////////////////////
/// \brief Tell whether the smooth filter is enabled or not
///
/// \return True if smoothing is enabled, false if it is disabled
///
/// \see setSmooth
///
////////////////////////////////////////////////////////////
bool isSmooth() const;
////////////////////////////////////////////////////////////
/// \brief Enable or disable repeating
///
/// Repeating is involved when using texture coordinates
/// outside the texture rectangle [0, 0, width, height].
/// In this case, if repeat mode is enabled, the whole texture
/// will be repeated as many times as needed to reach the
/// coordinate (for example, if the X texture coordinate is
/// 3 * width, the texture will be repeated 3 times).
/// If repeat mode is disabled, the "extra space" will instead
/// be filled with border pixels.
/// Warning: on very old graphics cards, white pixels may appear
/// when the texture is repeated. With such cards, repeat mode
/// can be used reliably only if the texture has power-of-two
/// dimensions (such as 256x128).
/// Repeating is disabled by default.
///
/// \param repeated True to repeat the texture, false to disable repeating
///
/// \see isRepeated
///
////////////////////////////////////////////////////////////
void setRepeated(bool repeated);
////////////////////////////////////////////////////////////
/// \brief Tell whether the texture is repeated or not
///
/// \return True if repeat mode is enabled, false if it is disabled
///
/// \see setRepeated
///
////////////////////////////////////////////////////////////
bool isRepeated() const;
////////////////////////////////////////////////////////////
/// \brief Overload of assignment operator
///
/// \param right Instance to assign
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
Texture& operator =(const Texture& right);
////////////////////////////////////////////////////////////
/// \brief Get the underlying OpenGL handle of the texture.
///
/// You shouldn't need to use this function, unless you have
/// very specific stuff to implement that SFML doesn't support,
/// or implement a temporary workaround until a bug is fixed.
///
/// \return OpenGL handle of the texture or 0 if not yet created
///
////////////////////////////////////////////////////////////
unsigned int getNativeHandle() const;
////////////////////////////////////////////////////////////
/// \brief Bind a texture for rendering
///
/// This function is not part of the graphics API, it mustn't be
/// used when drawing SFML entities. It must be used only if you
/// mix sf::Texture with OpenGL code.
///
/// \code
/// sf::Texture t1, t2;
/// ...
/// sf::Texture::bind(&t1);
/// // draw OpenGL stuff that use t1...
/// sf::Texture::bind(&t2);
/// // draw OpenGL stuff that use t2...
/// sf::Texture::bind(NULL);
/// // draw OpenGL stuff that use no texture...
/// \endcode
///
/// The \a coordinateType argument controls how texture
/// coordinates will be interpreted. If Normalized (the default), they
/// must be in range [0 .. 1], which is the default way of handling
/// texture coordinates with OpenGL. If Pixels, they must be given
/// in pixels (range [0 .. size]). This mode is used internally by
/// the graphics classes of SFML, it makes the definition of texture
/// coordinates more intuitive for the high-level API, users don't need
/// to compute normalized values.
///
/// \param texture Pointer to the texture to bind, can be null to use no texture
/// \param coordinateType Type of texture coordinates to use
///
////////////////////////////////////////////////////////////
static void bind(const Texture* texture, CoordinateType coordinateType = Normalized);
////////////////////////////////////////////////////////////
/// \brief Get the maximum texture size allowed
///
/// This maximum size is defined by the graphics driver.
/// You can expect a value of 512 pixels for low-end graphics
/// card, and up to 8192 pixels or more for newer hardware.
///
/// Note: The first call to this function, whether by your
/// code or SFML will result in a context switch.
///
/// \return Maximum size allowed for textures, in pixels
///
////////////////////////////////////////////////////////////
static unsigned int getMaximumSize();
private:
friend class RenderTexture;
friend class RenderTarget;
////////////////////////////////////////////////////////////
/// \brief Get a valid image size according to hardware support
///
/// This function checks whether the graphics driver supports
/// non power of two sizes or not, and adjusts the size
/// accordingly.
/// The returned size is greater than or equal to the original size.
///
/// \param size size to convert
///
/// \return Valid nearest size (greater than or equal to specified size)
///
////////////////////////////////////////////////////////////
static unsigned int getValidSize(unsigned int size);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Vector2u m_size; ///< Public texture size
Vector2u m_actualSize; ///< Actual texture size (can be greater than public size because of padding)
unsigned int m_texture; ///< Internal texture identifier
bool m_isSmooth; ///< Status of the smooth filter
bool m_isRepeated; ///< Is the texture in repeat mode?
mutable bool m_pixelsFlipped; ///< To work around the inconsistency in Y orientation
bool m_fboAttachment; ///< Is this texture owned by a framebuffer object?
Uint64 m_cacheId; ///< Unique number that identifies the texture to the render target's cache
};
} // namespace sf
#endif // SFML_TEXTURE_HPP
////////////////////////////////////////////////////////////
/// \class sf::Texture
/// \ingroup graphics
///
/// sf::Texture stores pixels that can be drawn, with a sprite
/// for example. A texture lives in the graphics card memory,
/// therefore it is very fast to draw a texture to a render target,
/// or copy a render target to a texture (the graphics card can
/// access both directly).
///
/// Being stored in the graphics card memory has some drawbacks.
/// A texture cannot be manipulated as freely as a sf::Image,
/// you need to prepare the pixels first and then upload them
/// to the texture in a single operation (see Texture::update).
///
/// sf::Texture makes it easy to convert from/to sf::Image, but
/// keep in mind that these calls require transfers between
/// the graphics card and the central memory, therefore they are
/// slow operations.
///
/// A texture can be loaded from an image, but also directly
/// from a file/memory/stream. The necessary shortcuts are defined
/// so that you don't need an image first for the most common cases.
/// However, if you want to perform some modifications on the pixels
/// before creating the final texture, you can load your file to a
/// sf::Image, do whatever you need with the pixels, and then call
/// Texture::loadFromImage.
///
/// Since they live in the graphics card memory, the pixels of a texture
/// cannot be accessed without a slow copy first. And they cannot be
/// accessed individually. Therefore, if you need to read the texture's
/// pixels (like for pixel-perfect collisions), it is recommended to
/// store the collision information separately, for example in an array
/// of booleans.
///
/// Like sf::Image, sf::Texture can handle a unique internal
/// representation of pixels, which is RGBA 32 bits. This means
/// that a pixel must be composed of 8 bits red, green, blue and
/// alpha channels -- just like a sf::Color.
///
/// Usage example:
/// \code
/// // This example shows the most common use of sf::Texture:
/// // drawing a sprite
///
/// // Load a texture from a file
/// sf::Texture texture;
/// if (!texture.loadFromFile("texture.png"))
/// return -1;
///
/// // Assign it to a sprite
/// sf::Sprite sprite;
/// sprite.setTexture(texture);
///
/// // Draw the textured sprite
/// window.draw(sprite);
/// \endcode
///
/// \code
/// // This example shows another common use of sf::Texture:
/// // streaming real-time data, like video frames
///
/// // Create an empty texture
/// sf::Texture texture;
/// if (!texture.create(640, 480))
/// return -1;
///
/// // Create a sprite that will display the texture
/// sf::Sprite sprite(texture);
///
/// while (...) // the main loop
/// {
/// ...
///
/// // update the texture
/// sf::Uint8* pixels = ...; // get a fresh chunk of pixels (the next frame of a movie, for example)
/// texture.update(pixels);
///
/// // draw it
/// window.draw(sprite);
///
/// ...
/// }
///
/// \endcode
///
/// Like sf::Shader that can be used as a raw OpenGL shader,
/// sf::Texture can also be used directly as a raw texture for
/// custom OpenGL geometry.
/// \code
/// sf::Texture::bind(&texture);
/// ... render OpenGL geometry ...
/// sf::Texture::bind(NULL);
/// \endcode
///
/// \see sf::Sprite, sf::Image, sf::RenderTexture
///
////////////////////////////////////////////////////////////

View File

@ -0,0 +1,450 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TRANSFORM_HPP
#define SFML_TRANSFORM_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector2.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Define a 3x3 transform matrix
///
////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Transform
{
public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// Creates an identity transform (a transform that does nothing).
///
////////////////////////////////////////////////////////////
Transform();
////////////////////////////////////////////////////////////
/// \brief Construct a transform from a 3x3 matrix
///
/// \param a00 Element (0, 0) of the matrix
/// \param a01 Element (0, 1) of the matrix
/// \param a02 Element (0, 2) of the matrix
/// \param a10 Element (1, 0) of the matrix
/// \param a11 Element (1, 1) of the matrix
/// \param a12 Element (1, 2) of the matrix
/// \param a20 Element (2, 0) of the matrix
/// \param a21 Element (2, 1) of the matrix
/// \param a22 Element (2, 2) of the matrix
///
////////////////////////////////////////////////////////////
Transform(float a00, float a01, float a02,
float a10, float a11, float a12,
float a20, float a21, float a22);
////////////////////////////////////////////////////////////
/// \brief Return the transform as a 4x4 matrix
///
/// This function returns a pointer to an array of 16 floats
/// containing the transform elements as a 4x4 matrix, which
/// is directly compatible with OpenGL functions.
///
/// \code
/// sf::Transform transform = ...;
/// glLoadMatrixf(transform.getMatrix());
/// \endcode
///
/// \return Pointer to a 4x4 matrix
///
////////////////////////////////////////////////////////////
const float* getMatrix() const;
////////////////////////////////////////////////////////////
/// \brief Return the inverse of the transform
///
/// If the inverse cannot be computed, an identity transform
/// is returned.
///
/// \return A new transform which is the inverse of self
///
////////////////////////////////////////////////////////////
Transform getInverse() const;
////////////////////////////////////////////////////////////
/// \brief Transform a 2D point
///
/// \param x X coordinate of the point to transform
/// \param y Y coordinate of the point to transform
///
/// \return Transformed point
///
////////////////////////////////////////////////////////////
Vector2f transformPoint(float x, float y) const;
////////////////////////////////////////////////////////////
/// \brief Transform a 2D point
///
/// \param point Point to transform
///
/// \return Transformed point
///
////////////////////////////////////////////////////////////
Vector2f transformPoint(const Vector2f& point) const;
////////////////////////////////////////////////////////////
/// \brief Transform a rectangle
///
/// Since SFML doesn't provide support for oriented rectangles,
/// the result of this function is always an axis-aligned
/// rectangle. Which means that if the transform contains a
/// rotation, the bounding rectangle of the transformed rectangle
/// is returned.
///
/// \param rectangle Rectangle to transform
///
/// \return Transformed rectangle
///
////////////////////////////////////////////////////////////
FloatRect transformRect(const FloatRect& rectangle) const;
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with another one
///
/// The result is a transform that is equivalent to applying
/// *this followed by \a transform. Mathematically, it is
/// equivalent to a matrix multiplication.
///
/// \param transform Transform to combine with this transform
///
/// \return Reference to *this
///
////////////////////////////////////////////////////////////
Transform& combine(const Transform& transform);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a translation
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.translate(100, 200).rotate(45);
/// \endcode
///
/// \param x Offset to apply on X axis
/// \param y Offset to apply on Y axis
///
/// \return Reference to *this
///
/// \see rotate, scale
///
////////////////////////////////////////////////////////////
Transform& translate(float x, float y);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a translation
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.translate(sf::Vector2f(100, 200)).rotate(45);
/// \endcode
///
/// \param offset Translation offset to apply
///
/// \return Reference to *this
///
/// \see rotate, scale
///
////////////////////////////////////////////////////////////
Transform& translate(const Vector2f& offset);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a rotation
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.rotate(90).translate(50, 20);
/// \endcode
///
/// \param angle Rotation angle, in degrees
///
/// \return Reference to *this
///
/// \see translate, scale
///
////////////////////////////////////////////////////////////
Transform& rotate(float angle);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a rotation
///
/// The center of rotation is provided for convenience as a second
/// argument, so that you can build rotations around arbitrary points
/// more easily (and efficiently) than the usual
/// translate(-center).rotate(angle).translate(center).
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.rotate(90, 8, 3).translate(50, 20);
/// \endcode
///
/// \param angle Rotation angle, in degrees
/// \param centerX X coordinate of the center of rotation
/// \param centerY Y coordinate of the center of rotation
///
/// \return Reference to *this
///
/// \see translate, scale
///
////////////////////////////////////////////////////////////
Transform& rotate(float angle, float centerX, float centerY);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a rotation
///
/// The center of rotation is provided for convenience as a second
/// argument, so that you can build rotations around arbitrary points
/// more easily (and efficiently) than the usual
/// translate(-center).rotate(angle).translate(center).
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.rotate(90, sf::Vector2f(8, 3)).translate(sf::Vector2f(50, 20));
/// \endcode
///
/// \param angle Rotation angle, in degrees
/// \param center Center of rotation
///
/// \return Reference to *this
///
/// \see translate, scale
///
////////////////////////////////////////////////////////////
Transform& rotate(float angle, const Vector2f& center);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a scaling
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.scale(2, 1).rotate(45);
/// \endcode
///
/// \param scaleX Scaling factor on the X axis
/// \param scaleY Scaling factor on the Y axis
///
/// \return Reference to *this
///
/// \see translate, rotate
///
////////////////////////////////////////////////////////////
Transform& scale(float scaleX, float scaleY);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a scaling
///
/// The center of scaling is provided for convenience as a second
/// argument, so that you can build scaling around arbitrary points
/// more easily (and efficiently) than the usual
/// translate(-center).scale(factors).translate(center).
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.scale(2, 1, 8, 3).rotate(45);
/// \endcode
///
/// \param scaleX Scaling factor on X axis
/// \param scaleY Scaling factor on Y axis
/// \param centerX X coordinate of the center of scaling
/// \param centerY Y coordinate of the center of scaling
///
/// \return Reference to *this
///
/// \see translate, rotate
///
////////////////////////////////////////////////////////////
Transform& scale(float scaleX, float scaleY, float centerX, float centerY);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a scaling
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.scale(sf::Vector2f(2, 1)).rotate(45);
/// \endcode
///
/// \param factors Scaling factors
///
/// \return Reference to *this
///
/// \see translate, rotate
///
////////////////////////////////////////////////////////////
Transform& scale(const Vector2f& factors);
////////////////////////////////////////////////////////////
/// \brief Combine the current transform with a scaling
///
/// The center of scaling is provided for convenience as a second
/// argument, so that you can build scaling around arbitrary points
/// more easily (and efficiently) than the usual
/// translate(-center).scale(factors).translate(center).
///
/// This function returns a reference to *this, so that calls
/// can be chained.
/// \code
/// sf::Transform transform;
/// transform.scale(sf::Vector2f(2, 1), sf::Vector2f(8, 3)).rotate(45);
/// \endcode
///
/// \param factors Scaling factors
/// \param center Center of scaling
///
/// \return Reference to *this
///
/// \see translate, rotate
///
////////////////////////////////////////////////////////////
Transform& scale(const Vector2f& factors, const Vector2f& center);
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static const Transform Identity; ///< The identity transform (does nothing)
private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
float m_matrix[16]; ///< 4x4 matrix defining the transformation
};
////////////////////////////////////////////////////////////
/// \relates sf::Transform
/// \brief Overload of binary operator * to combine two transforms
///
/// This call is equivalent to calling Transform(left).combine(right).
///
/// \param left Left operand (the first transform)
/// \param right Right operand (the second transform)
///
/// \return New combined transform
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Transform operator *(const Transform& left, const Transform& right);
////////////////////////////////////////////////////////////
/// \relates sf::Transform
/// \brief Overload of binary operator *= to combine two transforms
///
/// This call is equivalent to calling left.combine(right).
///
/// \param left Left operand (the first transform)
/// \param right Right operand (the second transform)
///
/// \return The combined transform
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Transform& operator *=(Transform& left, const Transform& right);
////////////////////////////////////////////////////////////
/// \relates sf::Transform
/// \brief Overload of binary operator * to transform a point
///
/// This call is equivalent to calling left.transformPoint(right).
///
/// \param left Left operand (the transform)
/// \param right Right operand (the point to transform)
///
/// \return New transformed point
///
////////////////////////////////////////////////////////////
SFML_GRAPHICS_API Vector2f operator *(const Transform& left, const Vector2f& right);
} // namespace sf
#endif // SFML_TRANSFORM_HPP
////////////////////////////////////////////////////////////
/// \class sf::Transform
/// \ingroup graphics
///
/// A sf::Transform specifies how to translate, rotate, scale,
/// shear, project, whatever things. In mathematical terms, it defines
/// how to transform a coordinate system into another.
///
/// For example, if you apply a rotation transform to a sprite, the
/// result will be a rotated sprite. And anything that is transformed
/// by this rotation transform will be rotated the same way, according
/// to its initial position.
///
/// Transforms are typically used for drawing. But they can also be
/// used for any computation that requires to transform points between
/// the local and global coordinate systems of an entity (like collision
/// detection).
///
/// Example:
/// \code
/// // define a translation transform
/// sf::Transform translation;
/// translation.translate(20, 50);
///
/// // define a rotation transform
/// sf::Transform rotation;
/// rotation.rotate(45);
///
/// // combine them
/// sf::Transform transform = translation * rotation;
///
/// // use the result to transform stuff...
/// sf::Vector2f point = transform.transformPoint(10, 20);
/// sf::FloatRect rect = transform.transformRect(sf::FloatRect(0, 0, 10, 100));
/// \endcode
///
/// \see sf::Transformable, sf::RenderStates
///
////////////////////////////////////////////////////////////

Some files were not shown because too many files have changed in this diff Show More