3D graphics programmers using Python?

Brian Quinlan brian at sweetapp.com
Tue Feb 4 21:59:39 CET 2003


> Python isn't going to give you any advantage in an exceedingly simple
> problem domain.  Any language would do.

I disagree with this statement. Python has more builtin data types and
other conveniences, which make working in simple problem domains very
easy.

As a simple example, I found a simple segment of code from one of my
OpenGL python programs and converted it to C++. The Python version is
shorter, simpler and required less thinking to create. 

def load_texture(file_name):
	from PIL import Image

	texture = Image.open(file_name)
	return texture.convert("RGBA")

for file in ['test1.jpg', 'test2.png', 'test3.gif']:
	print 'Loading', file, '...',
	load_texture(file)
	print 'ok'

#include <iostream>
#include <graphlibrary>

char * load_texture(const char * file_name)
{
	Image image(file_name);
	return image.convert("RGBA");
}

int main(int argc, char * argv[])
{
	char[][] files = {"test1.jpg", "test2.png", "test3.gif"}
	for (int i = 0; i < sizeof(files) / sizeof(char *); ++i)
	{
		cout << "Loading" << files[i] << "...";
		char * data = load_texture(files[i]);
		delete[] data;
		cout << "ok\n";
	}

	return 1;
}

Cheers,
Brian






More information about the Python-list mailing list