#include #include #include #include #include #include "Stroke.h" #include "noise.h" //#include "polyfill.h" Stroke curve; int windowWidth = 512, windowHeight = 512; bool opaque = true; bool controlPolygon = true; GLenum checkForError(char *loc); GLubyte * texture; int texWidth,texHeight; void Redraw(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // curve.drawTexture(); if (opaque) glColor3ub(0, 64, 16); else glColor4ub(0, 64, 16, 128); curve.render(); if (controlPolygon) { glColor3ub(255,0,0); curve.drawControl(); } glutSwapBuffers(); checkForError("swap"); } void Button(int button, int state, int x, int y) { if (state != GLUT_UP) return; switch (button) { case GLUT_LEFT_BUTTON: curve.add(x,windowHeight-y); glutPostRedisplay(); break; case GLUT_RIGHT_BUTTON: curve.clear(); glutPostRedisplay(); break; } } void Reshape(int width, int height) { windowWidth = width; windowHeight = height; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, (GLfloat) windowWidth, 0.0f, (GLfloat) windowHeight, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0, 0, windowWidth, windowHeight); } void menuSelect(int value) { switch(value) { case 0: curve.curveType = CUBIC_BSPLINE; curve.forceRecompute(); glutPostRedisplay(); break; case 1: curve.curveType = FOUR_POINT; curve.forceRecompute(); glutPostRedisplay(); break; case 2: controlPolygon = !controlPolygon; glutPostRedisplay(); break; case 3: opaque = !opaque; glutPostRedisplay(); break; case 4: curve.radius += 5; glutPostRedisplay(); break; case 5: curve.radius -= 5; if (curve.radius < 1) curve.radius = 1; glutPostRedisplay(); break; case 6: exit(0); case 7: curve.useTexture = !curve.useTexture; glutPostRedisplay(); break; } } int main(int argc, char *argv[]) { glutInit(&argc, argv); // glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(windowWidth, windowHeight); glutCreateWindow("Square"); // set up world space to screen mapping glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, (GLfloat) windowWidth, 0.0f, (GLfloat) windowHeight, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0, 0, windowWidth, windowHeight); glClearColor(1.0,.95,.85,0); glutDisplayFunc(Redraw); glutReshapeFunc(Reshape); glutMouseFunc(Button); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); curve . add(100,100); curve . add(200,150); curve . add(300,100); curve . add(400,300); curve . add(100,100); curve.radius = 10; curve.curveType = CUBIC_BSPLINE; // curve.curveType = FOUR_POINT; // make a texture map texWidth = texHeight = 512; texture = new GLubyte[4*texWidth*texHeight]; for(int x=0;x