Fix Windows & Python 3.x building

This commit is contained in:
Runar Tenfjord 2012-11-23 15:04:53 +01:00
parent c60882bf54
commit ed2b6b9a07
21 changed files with 2094 additions and 1939 deletions

9
MANIFEST.in Normal file
View file

@ -0,0 +1,9 @@
include Makefile
include setup_build.py
include setup_docs.py
include version.py
include MANIFEST.in
include README.rst
include LICENSE.txt
recursive-include gltools *.py *.pyx *.pxi *.pxd *.rst
prune gltools/@arch

38
Makefile Normal file
View file

@ -0,0 +1,38 @@
#
# File: Makefile (for library)
#
# The variables 'PYTHON' and 'PYVER' can be modified by
# passing parameters to make: make PYTHON=python PYVER=2.6
#
PYTHON=python2
PYVER=2.7
.PHONY: all docs test install clean
all:
@echo lib Makefile - building python extension
$(PYTHON) setup_build.py build_ext --inplace
docs: all
@echo lib Makefile - building documentation
@cd gltools/@docs ; $(PYTHON) ../../setup_docs.py build_sphinx
@cp -rf gltools/@docs/build/sphinx/html/* gltools/@docs/html/
install: all
@cp gltools.so ~/.local/lib/python$(PYVER)/site-packages/
@cp gltools/gltools.pxd ~/.local/lib/python$(PYVER)/site-packages/
sdist: clean
@echo lib Makefile - creating source distribution
$(PYTHON) setup_build.py sdist --formats=gztar,zip
clean:
-rm -rf build dist
-rm -rf gltools/@docs/build
-rm -rf gltools/@docs/html
-rm gltools/@src/Config.pxi
-rm gltools/gltools.cpp gltools.so gltools/gltools.so MANIFEST
-find gltools -iname '*.so' -exec rm {} \;
-find gltools -iname '*.pyc' -exec rm {} \;
-find gltools -iname '*.pyo' -exec rm {} \;
-find gltools -iname '*.pyd' -exec rm {} \;

View file

@ -19,12 +19,17 @@ The license is GPL v2.
Building
========
* Python 2.6 or later and Cython 0.17.
* Python 2.7/3.x and Cython 0.17 or later.
* The geotools_ library.
* GLFW_ v3.0 (not released, must be build from repo)
* GLFW_ v3.0 (not released, must be build from GIT repo)
* OpenGL headers
The extension have only been build on the Linux platform.
Prebuild installers are available on the pypi_ site
for the Windows platform.
Note that currently I can not find a way to install the required
Cython 'pxd' files with distutils and this file has to be copied
manually.
Documentation
=============
@ -35,4 +40,6 @@ See online Sphinx docs_
.. _geotools: http://github.com/tenko/geotools
.. _GLFW: http://github.com/elmindreda/glfw
.. _GLFW: http://github.com/elmindreda/glfw
.. _pypi: http://pypi.python.org/pypi/gltools

View file

@ -20,6 +20,10 @@
#include <stdlib.h>
#include <string.h>
#if _WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
// default font

View file

@ -23,9 +23,36 @@
#include <math.h>
#include "imgui.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
#ifdef _MSC_VER
#include <stdarg.h>
#define snprintf c99_snprintf
inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
{
int count = -1;
if (size != 0)
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
inline int c99_snprintf(char* str, size_t size, const char* format, ...)
{
int count;
va_list ap;
va_start(ap, format);
count = c99_vsnprintf(str, size, format, ap);
va_end(ap);
return count;
}
#endif // _MSC_VER
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -473,8 +500,7 @@ void imguiEndArea()
g_state.insideCurrentScroll = false;
}
bool imguiButton(const char* text, bool enabled, int x = -1, int y = -1,
int w = -1, int h = -1)
bool imguiButton(const char* text, bool enabled, int x, int y, int w, int h)
{
g_state.widgetId++;
unsigned int id = (g_state.areaId<<16) | g_state.widgetId;

View file

@ -205,7 +205,6 @@ void imguiRenderGLInit(void)
g_circleVerts[i*2+0] = cosf(a);
g_circleVerts[i*2+1] = sinf(a);
}
return true;
}
static void drawText(float x, float y, const char *text, int align, unsigned int col)

File diff suppressed because it is too large Load diff

View file

@ -20,7 +20,7 @@ void setErrorMessage(const char *err);
int glCheck();
// opengl font
extern void *_fonts;
extern struct sth_stash *_fonts;
int initText(void);
int beginText(void);
int endText(void);
@ -29,6 +29,7 @@ int drawText(int idx, float size, float x, float y, const char *text, float *dx)
/* OpenGL 2.1 function pointers */
extern int isGLExtLoaded;
static PFNGLACTIVETEXTUREPROC pglActiveTexture = NULL;
static PFNGLGENBUFFERSPROC pglGenBuffers = NULL;
static PFNGLDELETEBUFFERSPROC pglDeleteBuffers = NULL;
static PFNGLCREATESHADERPROC pglCreateShader = NULL;

View file

@ -166,20 +166,6 @@ cdef class Window:
raise GLError('window size not valid')
glfwSetWindowSize(<GLFWwindow>self.thisptr, width, height)
cpdef tuple getPos(self):
'''
Get current window position
'''
cdef int x, y
glfwGetWindowPos(<GLFWwindow>self.thisptr, &x, &y)
return x, y
cpdef setPos(self, int x, int y):
'''
Set current window position
'''
glfwSetWindowPos(<GLFWwindow>self.thisptr, x, y)
cpdef setClipboard(self, content):
'''
Set clipboard text
@ -190,7 +176,7 @@ cdef class Window:
'''
Get clipboard text
'''
cdef char *content = glfwGetClipboardString(<GLFWwindow>self.thisptr)
cdef const_char *content = glfwGetClipboardString(<GLFWwindow>self.thisptr)
return content
cpdef iconify(self):

View file

@ -42,7 +42,7 @@ int glCheck() {
}
// load font
void *_fonts;
struct sth_stash *_fonts;
void destroyFont(void)
{
@ -113,7 +113,7 @@ int drawText(int idx, float size, float x, float y, const char *text, float *dx)
}
// opengl 2.1 extensions
#define GLEXTPROCSIZE 27
#define GLEXTPROCSIZE 28
int isGLExtLoaded = 0;
int initGLExt(void)
@ -121,6 +121,9 @@ int initGLExt(void)
// OpenGL 2.1 functions
int status = 0;
pglActiveTexture = (PFNGLACTIVETEXTUREPROC) glfwGetProcAddress("glActiveTexture");
if (pglActiveTexture) status++;
pglCreateShader = (PFNGLCREATESHADERPROC) glfwGetProcAddress("glCreateShader");
if (pglCreateShader) status++;
@ -258,7 +261,7 @@ TextureRect2D::~TextureRect2D() {
void TextureRect2D::blit(float x, float y) {
glEnable(GL_TEXTURE_RECTANGLE);
glActiveTexture(GL_TEXTURE0);
pglActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE, m_id);
glColor3ub(255,255,255);
@ -280,7 +283,7 @@ void TextureRect2D::blit(float x, float y) {
void TextureRect2D::copy(GLenum mode = GL_BACK) {
glReadBuffer(mode);
glEnable(GL_TEXTURE_RECTANGLE);
glActiveTexture(GL_TEXTURE0);
pglActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE, m_id);
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE,0,0,0,0,0,m_width, m_height);
glBindTexture(GL_TEXTURE_RECTANGLE, 0);

View file

@ -91,6 +91,12 @@ cdef class ShaderProgram:
if vertex_src is None and fragment_src is None:
ret = prog.build(NULL,NULL)
else:
if not isinstance(vertex_src, bytes):
vertex_src = vertex_src.encode('ascii')
if not isinstance(fragment_src, bytes):
fragment_src = fragment_src.encode('ascii')
ret = prog.build(vertex_src, fragment_src)
if not ret:
@ -110,7 +116,7 @@ cdef class ShaderProgram:
raise GLError('lights must be between 1 and 8')
INIT = "#define MAX_LIGHTS %d" % lights
FRAG_SRC = "\n".join((INIT, GLSL_FRAG_PONG_COMMON, GLSL_FRAG_PONG_DIFFUSE))
FRAG_SRC = b"\n".join((INIT.encode('ascii'), GLSL_FRAG_PONG_COMMON, GLSL_FRAG_PONG_DIFFUSE))
ret.build(GLSL_VERTEX_PONG, FRAG_SRC)
return ret
@ -123,7 +129,7 @@ cdef class ShaderProgram:
raise GLError('lights must be between 1 and 8')
INIT = "#define MAX_LIGHTS %d" % lights
FRAG_SRC = "\n".join((INIT, GLSL_FRAG_PONG_COMMON, GLSL_FRAG_PONG_SPECULAR))
FRAG_SRC = b"\n".join((INIT.encode('ascii'), GLSL_FRAG_PONG_COMMON, GLSL_FRAG_PONG_SPECULAR))
ret.build(GLSL_VERTEX_PONG, FRAG_SRC)
return ret

View file

@ -146,16 +146,19 @@ cdef class UI:
return imguiCheck(c_text, checked, enabled)
cpdef bint collapse(self, text, char* subtext, bint checked, bint enabled):
cpdef bint collapse(self, text, subtext, bint checked, bint enabled):
'''
Collapse element
'''
cdef char *c_text
cdef char *c_text, *c_subtext
bytetext = unicode(text).encode('UTF-8','ignore')
c_text = bytetext
return imguiCollapse(c_text, subtext, checked, enabled)
bytetext = unicode(subtext).encode('UTF-8','ignore')
c_subtext = bytetext
return imguiCollapse(c_text, c_subtext, checked, enabled)
cpdef label(self, text):
'''

View file

@ -4,14 +4,31 @@
#
# general imports
from libc.stdint cimport uintptr_t
IF UNAME_SYSNAME == "Windows":
ctypedef unsigned int uintptr_t
ELSE:
from libc.stdint cimport uintptr_t
cdef extern from *:
ctypedef char const_char "const char"
from libc.stdlib cimport malloc, free
from libc.math cimport fmin, fmax, fabs, copysign
from libc.math cimport fabs, copysign
from libc.math cimport M_PI, sqrt, sin, cos, tan
cimport cpython.array
cdef inline double fmax(double a, double b):
if a < b:
return b
return a
cdef inline double fmin(double a, double b):
if a > b:
return b
return a
# utility to get pointer from memoryview
cdef void *getVoidPtr(arr):
cdef double [::1] d_view

View file

@ -1,25 +0,0 @@
#
# File: Makefile (for library)
#
PYTHON=python2
.PHONY: all docs test install clean
all:
@echo lib Makefile - building python extension
$(PYTHON) setup_build.py build_ext --inplace
-strip --strip-all gltools.so
docs: all
@echo lib Makefile - building documentation
@cd @docs ; $(PYTHON) ../setup_docs.py build_sphinx
@cp -rf @docs/build/sphinx/html/* @docs/html/
install: all
@cp gltools.so ~/.local/lib/python2.7/site-packages/
@cp gltools.pxd ~/.local/lib/python2.7/site-packages/
clean:
-rm -rf build
-rm gltools.cpp
-rm gltools.so

View file

@ -63,8 +63,6 @@ cdef class Window:
cpdef setTitle(self, title)
cpdef tuple getSize(self)
cpdef setSize(self, int width, int height)
cpdef tuple getPos(self)
cpdef setPos(self, int x, int y)
cpdef setClipboard(self, content)
cpdef getClipboard(self)
cpdef iconify(self)
@ -122,7 +120,7 @@ cdef class UI:
int w = ?, int h = ?)
cpdef bint item(self, text, bint enabled)
cpdef bint check(self, text, bint checked, bint enabled)
cpdef bint collapse(self, text, char* subtext, bint checked, bint enabled)
cpdef bint collapse(self, text, subtext, bint checked, bint enabled)
cpdef label(self, text)
cpdef value(self, text)
cpdef float slider(self, text, float val, float vmin, float vmax,

View file

@ -3,12 +3,18 @@
#
# This file is part of gltools - See LICENSE.txt
#
import sys
if sys.hexversion > 0x03000000:
unicode = str
from geotools cimport *
from GLToolsLib cimport *
class GLError(Exception):
pass
include "Config.pxi"
include "Utilities.pxi"
include "Constants.pxi"
include "GLFW.pxi"

View file

@ -1,50 +0,0 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
#
# This file is part of gltools - See LICENSE.txt
#
import sys
import os
import glob
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
SRC = [
"gltools.pyx",
"@src/GLTools.cpp",
"@contrib/fontstash.c",
"@contrib/stb_image_write.c",
"@contrib/imgui.cpp",
"@contrib/imguiRenderGL.cpp"
]
DEP = \
["gltools.pxd",] + \
glob.glob("@src/*.pxi") + \
glob.glob("@src/*.cpp") + \
glob.glob("@include/*.pxd") + \
glob.glob("@include/*.h")
try:
setup(
name = 'gltools',
ext_modules=[
Extension("gltools",
sources=SRC,
depends = DEP,
include_dirs = ['@include','@src','@contrib'],
libraries = ["GL", "glfw"],
extra_compile_args = ["-fpermissive"],
language="c++"
),
],
cmdclass = {'build_ext': build_ext}
)
except:
print('Traceback\n:%s\n' % str(sys.exc_info()[-2]))
sys.exit(1)
else:
print('\n')

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import math
import array
@ -133,7 +134,7 @@ class MainWindow(gl.Window):
def onSize(self, w, h):
#print 'onSize ', w, h
#print('onSize ', w, h)
self.width, self.height = w - 1, h - 1
if self.width > 1 and self.height > 1:
@ -164,7 +165,7 @@ class MainWindow(gl.Window):
return False
def onRefresh(self):
#print 'onRefresh'
#print('onRefresh')
if not self.running:
return
@ -237,7 +238,7 @@ class MainWindow(gl.Window):
ui.item('Item 3', True)
ui.unindent()
if ui.button("Button 1", True):
print 'Button 1 pressed'
print('Button 1 pressed')
ui.button("Button 2", False)
ui.separator()
@ -256,7 +257,7 @@ class MainWindow(gl.Window):
ui.beginArea("Fixed Area", 10, h - 260, 200, 250)
ui.label('Message')
if ui.button("OK", True, 5, 210, 40):
print 'Button OK pressed'
print('Button OK pressed')
ui.endArea()
@ -287,14 +288,14 @@ class MainWindow(gl.Window):
cam.pan(lastx, lasty, x, y, target = self.mouseCenter)
update = True
#print 'onCursorPos ', x, y
#print('onCursorPos ', x, y)
self.lastPos = x, y
if ui or update:
self.onRefresh()
def onMouseButton(self, button, action):
#print 'onMouseButton ', button, action
#print('onMouseButton ', button, action)
if action == gl.ACTION.PRESS:
if button in {gl.MOUSE.LEFT, gl.MOUSE.RIGHT}:
# temporary rotation center to avoid exponential increase
@ -306,7 +307,7 @@ class MainWindow(gl.Window):
self.onRefresh()
def onKey(self, key, action):
#print 'onKey ', key, action
#print('onKey ', key, action)
if key == gl.KEY.ESCAPE:
self.running = False
elif key == gl.KEY.F1:
@ -317,7 +318,7 @@ class MainWindow(gl.Window):
img.writePNG('screenshot01.png')
def onChar(self, ch):
#print 'onChar ', ch
#print('onChar ', ch)
if ch == 'f':
self.cam.zoomExtents(self.near, self.far)
self.onRefresh()
@ -336,7 +337,7 @@ class MainWindow(gl.Window):
self.onRefresh()
def onClose(self):
#print 'onClose'
#print('onClose')
return True
win = MainWindow(800, 600, title = u'title')

123
setup_build.py Normal file
View file

@ -0,0 +1,123 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
#
# This file is part of gltools - See LICENSE.txt
#
import sys
import os
import glob
from distutils.core import setup
from distutils.extension import Extension
try:
from Cython.Distutils import build_ext
except ImportError:
print >>sys.stderr, "Cython is required to build geotools"
sys.exit(1)
#sys.argv.append('build_ext')
#sys.argv.extend(['sdist','--formats=gztar,zip'])
#sys.argv.append('bdist_wininst')
# create config file
sys.dont_write_bytecode = True
import version
CONFIG = 'gltools/@src/Config.pxi'
if not os.path.exists(CONFIG) and 'sdist' not in sys.argv:
with open(CONFIG, 'w') as fh:
fh.write("__version__ = '%s'\n" % version.STRING)
args = version.MAJOR, version.MINOR, version.BUILD
fh.write("__version_info__ = (%d,%d,%d)\n" % args)
# platform specific settings
OBJECTS, LIBS, LINK_ARGS, COMPILE_ARGS = [],[],[],[]
if sys.platform == 'win32':
LIBS.append('OPENGL32')
LIBS.append('glfw3')
LIBS.append('user32')
LIBS.append('gdi32')
OBJECTS.append('glfw3.lib')
elif sys.platform == 'darwin':
LINK_ARGS.extend(['-framework', 'OpenGL', '-arch', 'x86_64'])
COMPILE_ARGS.extend(['-arch', 'x86_64'])
LIBS.append('glfw')
else:
LIBS.append('GL')
LIBS.append('glfw')
COMPILE_ARGS.append("-fpermissive")
classifiers = '''\
Development Status :: 4 - Beta
Environment :: MacOS X
Environment :: Win32 (MS Windows)
Environment :: X11 Applications
Intended Audience :: Science/Research
License :: OSI Approved :: GNU General Public License v2 (GPLv2)
Operating System :: OS Independent
Programming Language :: Cython
Topic :: Scientific/Engineering :: Visualization
'''
SRC = [
"gltools/gltools.pyx",
"gltools/@src/GLTools.cpp",
"gltools/@contrib/fontstash.c",
"gltools/@contrib/stb_image_write.c",
"gltools/@contrib/imgui.cpp",
"gltools/@contrib/imguiRenderGL.cpp"
]
DEP = \
["gltools/gltools.pxd",] + \
glob.glob("gltools/@src/*.pxi") + \
glob.glob("gltools/@src/*.cpp") + \
glob.glob("gltools/@include/*.pxd") + \
glob.glob("gltools/@include/*.h")
try:
setup(
name = 'gltools',
version = version.STRING,
description = 'Library to create OpenGL based applications',
long_description = '''\
**gltools** is library for quickly creating OpenGL based
application in Python/Cython with support for:
* Access to vertex buffers and GLSL shaders
* Access to truetype fonts
* Windows handling through GLFW
* Saving framebuffer content to PNG file.
* Simple GUI controls
''',
classifiers = [value for value in classifiers.split("\n") if value],
author='Runar Tenfjord',
author_email = 'runar.tenfjord@gmail.com',
license = 'GPLv2',
download_url='http://pypi.python.org/pypi/gltools/',
url = 'http://github.com/tenko/gltools',
platforms = ['any'],
requires = ['geotools'],
ext_modules=[
Extension("gltools",
sources = SRC,
depends = DEP,
include_dirs = ['gltools/@include','gltools/@src',
'gltools/@contrib'],
library_dirs = ['gltools'],
libraries = LIBS,
extra_link_args = LINK_ARGS,
extra_compile_args = COMPILE_ARGS,
extra_objects = OBJECTS,
language="c++"
),
],
cmdclass = {'build_ext': build_ext}
)
except:
print('Traceback\n:%s\n' % str(sys.exc_info()[-2]))
sys.exit(1)

View file

@ -16,19 +16,17 @@ release = '0.1.0'
try:
setup(
name=name,
author='Runar Tenfjord',
version=release,
cmdclass=cmdclass,
command_options={
name = name,
author = 'Runar Tenfjord',
version = release,
cmdclass = cmdclass,
command_options = {
'build_sphinx': {
'builder': ('setup_docs.py', 'html'),
}
}
},
)
except:
print('Traceback\n:%s\n' % str(sys.exc_info()[-2]))
sys.exit(1)
else:
print('\n')
sys.exit(1)

5
version.py Normal file
View file

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
MAJOR = 0
MINOR = 1
BUILD = 0
STRING = "%d.%d.%d" % (MAJOR,MINOR,BUILD)