Commit 81c1cfc7 authored by Denis Salem's avatar Denis Salem

setup cmake environment

parent 4c8214ac
cmake_minimum_required (VERSION 3.7)
project (UNIVERSE)
add_subdirectory(gl3w)
set(EXTERNAL_DEPENDENCIES "-lGL -ldl -lglfw")
add_executable(UNIVERSE main.cpp)
target_link_libraries (UNIVERSE gl3w ${EXTERNAL_DEPENDENCIES})
#include "ProceduralEngine.hpp"
namespace ProceduralEngine {
HeightmapBrushes::HeightmapBrushes(int * seed) {
m_Seed = seed;
memset( m_VoronoiBrush0, 0, sizeof(float) * HEIGHTMAP_BRUSHES_COUNT * HEIGHTMAP_AREA);
memset( m_VoronoiBrush1, 0, sizeof(float) * HEIGHTMAP_BRUSHES_COUNT * HEIGHTMAP_AREA);
memset( m_VoronoiBrush2, 0, sizeof(float) * HEIGHTMAP_BRUSHES_COUNT * HEIGHTMAP_AREA);
}
}
class HeightmapBrushes {
public:
HeightmapBrushes(int * seed);
~HeightmapBrushes();
#include <cstring>
#include "dataType.hpp"
private:
};
namespace ProceduralEngine {
class HeightmapBrushes {
public:
HeightmapBrushes(int * seed);
~HeightmapBrushes();
Heightmap * GetNonOrientableBrush(int id);
Heightmap * GetVoronoiBrush0(int id);
Heightmap * GetVoronoiBrush1(int id);
Heightmap * GetVoronoiBrush2(int id);
Heightmap * GetPerlinBrush(int id);
Heightmap * GetWarpBrush(int id);
Heightmap * GetTurbulenceBrush(int id);
int GetScale();
private:
Heightmap m_NonOrientableBrush[HEIGHTMAP_BRUSHES_COUNT];
Heightmap m_VoronoiBrush0[HEIGHTMAP_BRUSHES_COUNT];
Heightmap m_VoronoiBrush1[HEIGHTMAP_BRUSHES_COUNT];
Heightmap m_VoronoiBrush2[HEIGHTMAP_BRUSHES_COUNT];
Heightmap m_PerlinBrush[HEIGHTMAP_BRUSHES_COUNT];
Heightmap m_WarpBrush[HEIGHTMAP_BRUSHES_COUNT];
Heightmap m_TurbulenceBrush[HEIGHTMAP_BRUSHES_COUNT];
int * m_seed;
int m_scale;
};
}
......@@ -4,11 +4,6 @@
#define HEIGHTMAP_AREA 262144
#define HEIGHTMAP_SCALE 512
#include "dataType.hpp"
#include "HeightmapBrushes.hpp"
#include "Planet.hpp"
#include "Observatory.hpp"
#include "ProceduralConductor.hpp"
#define HEIGHTMAP_BRUSHES_COUNT 8
#endif
typedef float Heightmap[HEIGHTMAP_AREA];
#ifndef INC_PROCEDURAL_ENGINE_DATA_TYPE
typedef struct Chunk {
Heightmap heightmap;
Chunk * ne;
Chunk * nw;
Chunk * se;
Chunk * sw;
bool allocated;
float centerX;
float centerY;
float halfScale;
} Chunk;
#define INC_PROCEDURAL_ENGINE_DATA_TYPE
namespace ProceduralEngine {
typedef float Heightmap[HEIGHTMAP_AREA];
typedef struct Chunk {
Heightmap heightmap;
Chunk * ne;
Chunk * nw;
Chunk * se;
Chunk * sw;
bool allocated;
float centerX;
float centerY;
float halfScale;
} Chunk;
}
#endif
cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)
project(gl3w)
set(CMAKE_VERBOSE_MAKEFILE false)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # -fPIC
set(SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src)
set(HEADER_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
set(HEADER_FILES
"${HEADER_DIR}/GL/gl3w.h"
"${HEADER_DIR}/GL/glcorearb.h"
)
set(SOURCE_FILES
"${SOURCE_DIR}/gl3w.c"
)
# add and depend on OpenGL
find_package(OpenGL REQUIRED)
set(EXTERNAL_INCLUDE_DIRS ${EXTERNAL_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR})
set(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} ${OPENGL_LIBRARIES})
# add command to create the header and source files
add_custom_command(
OUTPUT
"${SOURCE_DIR}/gl3w.c"
"${HEADER_DIR}/GL/gl3w.h"
"${HEADER_DIR}/GL/glcorearb.h"
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/gl3w_gen.py
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gl3w_gen.py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
# add pseudo target that depends on the generated files
add_custom_target(
gl3w_gen ALL
DEPENDS
"${SOURCE_DIR}/gl3w.c"
"${HEADER_DIR}/GL/gl3w.h"
"${HEADER_DIR}/GL/glcorearb.h"
)
# create gl3w target
add_library(${PROJECT_NAME} INTERFACE)
# make gl3w target depend on the generator target
add_dependencies(${PROJECT_NAME} gl3w_gen)
# let remote project know about source and header files
target_sources(${PROJECT_NAME} INTERFACE ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${HEADER_DIR}>
$<INSTALL_INTERFACE:include>
)
target_include_directories(${PROJECT_NAME} INTERFACE ${EXTERNAL_INCLUDE_DIRS})
# let remote project know which libraries need to be linked
target_link_libraries(${PROJECT_NAME} INTERFACE ${EXTERNAL_LIBRARIES} ${CMAKE_DL_LIBS})
set(MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(BUILD_CMAKE_DIR "${CMAKE_CURRENT_BINARY_DIR}/cmake")
# export targets for remote projects (i.e. make find_package(gl3w) work)
configure_file(
"${MODULE_PATH}/${PROJECT_NAME}-config.cmake"
"${BUILD_CMAKE_DIR}/${PROJECT_NAME}-config.cmake"
COPYONLY
)
export(
TARGETS ${PROJECT_NAME}
FILE "${BUILD_CMAKE_DIR}/${PROJECT_NAME}-targets.cmake"
)
export(PACKAGE ${PROJECT_NAME})
========================================
gl3w: Simple OpenGL core profile loading
========================================
Introduction
------------
gl3w_ is the easiest way to get your hands on the functionality offered by the
OpenGL core profile specification.
Its main part is a simple gl3w_gen.py_ Python script that downloads the
Khronos_ supported glcorearb.h_ header and generates gl3w.h and gl3w.c from it.
Those files can then be added and linked (statically or dynamically) into your
project.
Requirements
------------
gl3w_gen.py_ requires Python version 2.6 or newer, with SSL support.
It is also compatible with Python 3.x.
Example
-------
Here is a simple example of using gl3w_ with glut. Note that GL/gl3w.h must be
included before any other OpenGL related headers::
#include <stdio.h>
#include <GL/gl3w.h>
#include <GL/glut.h>
// ...
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(width, height);
glutCreateWindow("cookie");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMotionFunc(motion);
if (gl3wInit()) {
fprintf(stderr, "failed to initialize OpenGL\n");
return -1;
}
if (!gl3wIsSupported(3, 2)) {
fprintf(stderr, "OpenGL 3.2 not supported\n");
return -1;
}
printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION),
glGetString(GL_SHADING_LANGUAGE_VERSION));
// ...
glutMainLoop();
return 0;
}
API Reference
-------------
The gl3w_ API consists of just three functions:
``int gl3wInit(void)``
Initializes the library. Should be called once after an OpenGL context has
been created. Returns ``0`` when gl3w_ was initialized successfully,
``-1`` if there was an error.
``int gl3wIsSupported(int major, int minor)``
Returns ``1`` when OpenGL core profile version *major.minor* is available
and ``0`` otherwise.
``GL3WglProc gl3wGetProcAddress(const char *proc)``
Returns the address of an OpenGL extension function. Generally, you won't
need to use it since gl3w_ loads all functions defined in the OpenGL core
profile on initialization. It allows you to load OpenGL extensions outside
of the core profile.
License
-------
.. image:: public-domain-mark.png
gl3w_ is in the public domain. See the file UNLICENSE for more information.
Credits
-------
Slavomir Kaslev <slavomir.kaslev@gmail.com>
Initial implementation
Kelvin McDowell
Mac OS X support
Sjors Gielen
Mac OS X support
Travis Gesslein
Patches regarding glcorearb.h
Arthur Tombs
Port to Python 3
Daniel Cousens [https://github.com/dcousens]
Code contributions
Copyright
---------
OpenGL_ is a registered trademark of SGI_.
.. _gl3w: https://github.com/skaslev/gl3w
.. _gl3w_gen.py: https://github.com/skaslev/gl3w/blob/master/gl3w_gen.py
.. _glcorearb.h: https://www.opengl.org/registry/api/GL/glcorearb.h
.. _OpenGL: http://www.opengl.org/
.. _Khronos: http://www.khronos.org/
.. _SGI: http://www.sgi.com/
import os
import platform
import shutil
env = Environment()
if env.GetOption('clean'):
for d in ['bin', 'include', 'lib']:
shutil.rmtree(d, True)
try:
os.unlink('src/gl3w.c')
except:
pass
else:
print 'Generating gl3w...'
os.system('./gl3w_gen.py')
libs = []
if platform.system() == 'Darwin':
env.Append(CFLAGS=['-Wno-deprecated-declarations'],
FRAMEWORKS=['CoreFoundation', 'GLUT'])
else:
libs = ['glut', 'dl']
env.Append(CFLAGS=['-Wall', '-pedantic', '-O2'])
env.Append(CPPPATH='include')
env.SharedLibrary('lib/gl3w', 'src/gl3w.c')
o = env.Object('src/glut_test', 'src/glut_test.c')
env.Program('bin/glut_test_static', [o, 'src/gl3w.c'], LIBS=libs)
env.Program('bin/glut_test_shared', o, LIBS=libs + ['gl3w'],
LIBPATH='lib', RPATH=os.path.abspath('lib'))
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
#!/usr/bin/env python
# This file is part of gl3w, hosted at https://github.com/skaslev/gl3w
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# Allow Python 2.6+ to use the print() function
from __future__ import print_function
import re
import os
import sys
# Try to import Python 3 library urllib.request
# and if it fails, fall back to Python 2 urllib2
try:
import urllib.request as urllib2
except ImportError:
import urllib2
# UNLICENSE copyright header
UNLICENSE = br'''/*
This file was generated with gl3w_gen.py, part of gl3w
(hosted at https://github.com/skaslev/gl3w)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
'''
root_dir = ''
if len(sys.argv) > 1:
root_dir = sys.argv[1]
# Create directories
if not os.path.exists(os.path.join(root_dir, 'include/GL')):
os.makedirs(os.path.join(root_dir, 'include/GL'))
if not os.path.exists(os.path.join(root_dir, 'src')):
os.makedirs(os.path.join(root_dir, 'src'))
# Download glcorearb.h
if not os.path.exists(os.path.join(root_dir, 'include/GL/glcorearb.h')):
print('Downloading glcorearb.h to ' + os.path.join(root_dir, 'include/GL/glcorearb.h'))
web = urllib2.urlopen('http://www.opengl.org/registry/api/GL/glcorearb.h')
with open(os.path.join(root_dir, 'include/GL/glcorearb.h'), 'wb') as f:
f.writelines(web.readlines())
else:
print('Reusing glcorearb.h from ' + os.path.join(root_dir, 'include/GL') + '...')
# Parse function names from glcorearb.h
print('Parsing glcorearb.h header...')
procs = []
p = re.compile(r'GLAPI.*APIENTRY\s+(\w+)')
with open(os.path.join(root_dir, 'include/GL/glcorearb.h'), 'r') as f:
for line in f:
m = p.match(line)
if m:
procs.append(m.group(1))
procs.sort()
def proc_t(proc):
return {
'p': proc,
'p_s': 'gl3w' + proc[2:],
'p_t': 'PFN' + proc.upper() + 'PROC'
}
# Generate gl3w.h
print('Generating gl3w.h in ' + os.path.join(root_dir, 'include/GL') + '...')
with open(os.path.join(root_dir, 'include/GL/gl3w.h'), 'wb') as f:
f.write(UNLICENSE)
f.write(br'''#ifndef __gl3w_h_
#define __gl3w_h_
#include <GL/glcorearb.h>
#ifndef __gl_h_
#define __gl_h_
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*GL3WglProc)(void);
typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
/* gl3w api */
int gl3wInit(void);
int gl3wInit2(GL3WGetProcAddressProc proc);
int gl3wIsSupported(int major, int minor);
GL3WglProc gl3wGetProcAddress(const char *proc);
/* OpenGL functions */
''')
for proc in procs:
f.write('extern {0[p_t]: <52} {0[p_s]};\n'.format(proc_t(proc)).encode('utf-8'))
f.write(b'\n')
for proc in procs:
f.write('#define {0[p]: <45} {0[p_s]}\n'.format(proc_t(proc)).encode('utf-8'))
f.write(br'''
#ifdef __cplusplus
}
#endif
#endif
''')
# Generate gl3w.c
print('Generating gl3w.c in src...')
with open(os.path.join(root_dir, 'src/gl3w.c'), 'wb') as f:
f.write(UNLICENSE)
f.write(br'''#include <GL/gl3w.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
static HMODULE libgl;
static void open_libgl(void)
{
libgl = LoadLibraryA("opengl32.dll");
}
static void close_libgl(void)
{
FreeLibrary(libgl);
}
static GL3WglProc get_proc(const char *proc)
{
GL3WglProc res;
res = (GL3WglProc)wglGetProcAddress(proc);
if (!res)
res = (GL3WglProc)GetProcAddress(libgl, proc);
return res;
}
#elif defined(__APPLE__) || defined(__APPLE_CC__)
#include <Carbon/Carbon.h>
CFBundleRef bundle;
CFURLRef bundleURL;
static void open_libgl(void)
{
bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
CFSTR("/System/Library/Frameworks/OpenGL.framework"),
kCFURLPOSIXPathStyle, true);
bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
assert(bundle != NULL);
}
static void close_libgl(void)
{
CFRelease(bundle);
CFRelease(bundleURL);
}
static GL3WglProc get_proc(const char *proc)
{
GL3WglProc res;
CFStringRef procname = CFStringCreateWithCString(kCFAllocatorDefault, proc,
kCFStringEncodingASCII);
*(void **)(&res) = CFBundleGetFunctionPointerForName(bundle, procname);
CFRelease(procname);
return res;
}
#else
#include <dlfcn.h>
#include <GL/glx.h>
static void *libgl;
static PFNGLXGETPROCADDRESSPROC glx_get_proc_address;
static void open_libgl(void)
{
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL);
*(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
}
static void close_libgl(void)
{
dlclose(libgl);
}
static GL3WglProc get_proc(const char *proc)
{
GL3WglProc res;
res = glx_get_proc_address((const GLubyte *)proc);
if (!res)
*(void **)(&res) = dlsym(libgl, proc);
return res;
}
#endif
static struct {
int major, minor;
} version;
static int parse_version(void)
{
if (!glGetIntegerv)
return -1;
glGetIntegerv(GL_MAJOR_VERSION, &version.major);
glGetIntegerv(GL_MINOR_VERSION, &version.minor);
if (version.major < 3)
return -1;
return 0;
}
static void load_procs(GL3WGetProcAddressProc proc);
int gl3wInit(void)
{
open_libgl();
load_procs(get_proc);
close_libgl();
return parse_version();
}
int gl3wInit2(GL3WGetProcAddressProc proc)
{
load_procs(proc);
return parse_version();
}
int gl3wIsSupported(int major, int minor)
{
if (major < 3)
return 0;
if (version.major == major)
return version.minor >= minor;
return version.major >= major;
}
GL3WglProc gl3wGetProcAddress(const char *proc)
{
return get_proc(proc);
}
''')
for proc in procs:
f.write('{0[p_t]: <52} {0[p_s]};\n'.format(proc_t(proc)).encode('utf-8'))
f.write(br'''
static void load_procs(GL3WGetProcAddressProc proc)
{
''')
for proc in procs:
f.write('\t{0[p_s]} = ({0[p_t]})proc("{0[p]}");\n'.format(proc_t(proc)).encode('utf-8'))
f.write(b'}\n')
/*
This file is part of gl3w, hosted at https://github.com/skaslev/gl3w
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl3w.h>
#include <GLFW/glfw3.h>
static int width = 600, height = 600;
static float randf()
{
return (float) rand() / ((float) RAND_MAX + 1);
}
static void display(GLFWwindow *window)
{
glClearColor(randf(), randf(), randf(), 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window);
}
static void reshape(GLFWwindow *window, int w, int h)
{
width = w > 1 ? w : 1;
height = h > 1 ? h : 1;
glViewport(0, 0, width, height);
glClearDepth(1.0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
}
int main(int argc, char **argv)
{
GLFWwindow *window;
glfwInit();
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
window = glfwCreateWindow(width, height, "cookie", NULL, NULL);
glfwSetFramebufferSizeCallback(window, reshape);
glfwSetWindowRefreshCallback(window, display);
glfwMakeContextCurrent(window);
if (gl3wInit()) {
fprintf(stderr, "failed to initialize OpenGL\n");
return -1;
}