// textfile.cpp // // simple reading and writing for text files // // www.lighthouse3d.com // // You may use these functions freely. // they are provided as is, and no warranties, either implicit, // or explicit are given ////////////////////////////////////////////////////////////////////// import std.stdio; import std.string; import std.file; import glee; import glut; version(Windows) { extern(Windows): pragma(lib,"..\\opengl32.lib"); pragma(lib,"..\\glut32.lib"); pragma(lib,"..\\glu32.lib"); } //version(linux) extern(C): //is this necessary (does crazy things) GLuint v,f,f2,p; static float lpos[4] = [1,0.5,1,0]; extern (C) void changeSize(int w, int h) { // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if(h == 0) h = 1; float ratio = 1.0* w / h; // Reset the coordinate system before modifying glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set the viewport to be the entire window glViewport(0, 0, w, h); // Set the correct perspective. gluPerspective(45,ratio,1,1000); glMatrixMode(GL_MODELVIEW); } extern (C) void renderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f); glLightfv(GL_LIGHT0, GL_POSITION, lpos); glutSolidTeapot(1); glutSwapBuffers(); } extern (C) void processNormalKeys(ubyte key, int x, int y) { //if (key == 27) //exit(0); } void setShaders() { v = glCreateShader(GL_VERTEX_SHADER); f = glCreateShader(GL_FRAGMENT_SHADER); f2 = glCreateShader(GL_FRAGMENT_SHADER); char[] vs = (cast(char[])read("toon.vert"))~"\0"; char[] fs = (cast(char[])read("toon.frag"))~"\0"; char[] fs2 = (cast(char[])read("toon2.frag"))~"\0"; char * a=vs.ptr,b=fs.ptr,c=fs2.ptr; glShaderSource(v, 1, &a,null); glShaderSource(f, 1, &b,null); glShaderSource(f2, 1, &c,null); glCompileShader(v); glCompileShader(f); glCompileShader(f2); p = glCreateProgram(); glAttachShader(p,f); glAttachShader(p,f2); glAttachShader(p,v); glLinkProgram(p); glUseProgram(p); } void d_glutInit(inout char[][] args) { int argc = args.length; char **argv = new char*[argc]; for(int i = 0; i < argc; i++) argv[i] = toStringz(args[i]); glutInit(&argc, argv); args.length = argc; for(int i = 0; i < argc; i++) args[i] = toString(argv[i]); } int main(char[][] argv) { int a=0; d_glutInit(argv); //glutInit(&a,null); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(320,320); glutCreateWindow("MM 2004-05"); glutDisplayFunc(&renderScene); glutIdleFunc(&renderScene); glutReshapeFunc(&changeSize); glutKeyboardFunc(&processNormalKeys); glEnable(GL_DEPTH_TEST); glClearColor(1.0,1.0,1.0,1.0); glEnable(GL_CULL_FACE); // GLeeInit(); //not neccessary setShaders(); glutMainLoop(); // just for compatibiliy purposes return 0; }