Showing posts with label compiling. Show all posts
Showing posts with label compiling. Show all posts

Thursday, August 26, 2010

Compiling boost C++ development libraries in OSX

Compiling boost c++ libraries and development headers for Mac OSX



Hi Everyone,

So I am starting to play with OpenCL. And as you all know I do love python. I have been playing with pyOpenCL package for awhile and wanted to get it set up on my Mac using OSX.

It depends on an installation of Boost C++ Libraries http://www.boost.org/

first we set up a directory, and in a terminal we need to download the boost files:


wget http://downloads.sourceforge.net/project/boost/boost/1.44.0/boost_1_44_0.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F1.44.0%2F

bzip2 -d boost_1_44_0.tar.bz2

tar -xvf boost_1_44_0.tar

cd boost_1_44_0


Configuration and Compilation



Great now we have extracted it, lets attempt to configure, compile, and install this package. Since I have build many applications on my MacOSX, I already have lots of build tools/libraries installed (eg. gcc, xorg, wine).

I was able to compile by typing at the console:


sh bootstrap.sh

./bjam


And then I waited... Its a shame there is no configure and make so I could use "make -j 4" and utilize all 4 of my cores for compiling. Maybe bjam has that option, I am not sure and too lazy to look into the documentation. Also I believe that is a bit out of the scope of this post for now.

After waiting for it to finish, we install the libraries by typing


sudo ./bjam install


And then we wait some more...

Finally after it is installed we can continue to try and install pyOpenCL.

Note: openCL unfortunately is not supported on my mac (Mac OS X 10.5.8 Leopard) and no amount of wishing will make it so :( However hopefully you are able to install this package (pyOpenCL) using Linux or Windows, or even Snow Leopard. Good luck!

Wednesday, March 3, 2010

Using GLSL programs in python pyopengl

Here is an easy straightforward example of using GLSL shader programs with pyopengl.

To use this you will need to import the following:


from OpenGL.GL import *
from OpenGL.GLU import *


Thus we will need pyopengl package installed.



##compile and link shader
vs = fs = 0

vs = glCreateShader(GL_VERTEX_SHADER)
fs = glCreateShader(GL_FRAGMENT_SHADER)

vs_source = """
void main(void) {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
"""
fs_source = """
void main (void) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
"""
glShaderSource(vs, vs_source)
glShaderSource(fs, fs_source)

glCompileShader(vs)
log = glGetShaderInfoLog(vs)
if log: print 'Vertex Shader: ', log

glCompileShader(fs)
log = glGetShaderInfoLog(fs)
if log: print 'Fragment Shader: ', log

prog = glCreateProgram()
glAttachShader(prog, vs)
glAttachShader(prog, fs)

glLinkProgram(prog)
glUseProgram(prog)


glShaderSource(shader_id, text) is a handy python function that will load our shader for us into opengl.


I also have a handy shader class I use in my engine program. Here it is:


class shader(node) :
def __init__(self, filename):
node.__init__(self)
fh = open(filename)
self.source = {'vertex': '', 'fragment':''}
write = None
for line in fh :
if line == '[[vertex-program]]\n' :
write = 'vertex'
elif line == '[[fragment-program]]\n' :
write = 'fragment'
else :
self.source[write] += line

self.draw = self.init

def init(self):
##compile and link shader
self.vs = self.fs = 0

self.vs = glCreateShader(GL_VERTEX_SHADER)
self.fs = glCreateShader(GL_FRAGMENT_SHADER)

glShaderSource(self.vs, self.source['vertex'])
glShaderSource(self.fs, self.source['fragment'])

glCompileShader(self.vs)
log = glGetShaderInfoLog(self.vs)
if log: print 'Vertex Shader: ', log

glCompileShader(self.fs)
log = glGetShaderInfoLog(self.fs)
if log: print 'Fragment Shader: ', log

self.prog = glCreateProgram()
glAttachShader(self.prog, self.vs)
glAttachShader(self.prog, self.fs)

glLinkProgram(self.prog)
self.use()
self.draw = self.use

def use(self):
glUseProgram(self.prog)

def end(self):
glUseProgram(0)

Tuesday, February 23, 2010

Compiling wine with processor optimizations

Hi everyone,

Just thought I would show you all a quick trick to compile wine to be as fast as it can be!

You need to look into your compiler (GCC) and which flags it will support for your processor. Since I have an AMD Phenom II, I used -march=amdfam10 for GCC.

Here is a link where you can find out which -march to use :

http://en.gentoo-wiki.com/wiki/Safe_Cflags/AMD

Note that link is for AMD not sure where intel info is.


CFLAGS="-march=amdfam10 -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"
export CFLAGS
export CXXFLAGS
./configure --disable-test
make depend && make
sudo make install


And we're done!