Example #1
0
void newScenes(int sc1, int sc2)
{
    sprintf(fileName, "cg_%d_%d.txt", sc1, sc2);
    fileName[10] = '\0';
    
    if((pts = fopen(fileName, "r")) == NULL){
        printf("Couldn't open file: %s\n", fileName);
        exit(EXIT_FAILURE);
    }
    char *ln;
    size_t sz;
	posLen = 0;
    while((ln = fgetln(pts, &sz)) != NULL)
    {
        fillPoint(&(posList[posLen]), ln);
        posLen++;
    }
    fclose(pts);
	
	sprintf(progName, "cg_%d_%d.cg", sc1, sc2);
	cgGLUnbindProgram(f_prof);
	cgGLEnableProfile(f_prof);
	gen = cgCreateProgramFromFile(context, CG_SOURCE, progName, f_prof, "main", NULL);
	cgGLLoadProgram(gen);
	cgGLBindProgram(gen);
	cgGLEnableProfile(f_prof);
}
Example #2
0
int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitWindowSize(1000, 1000);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    glutCreateWindow("Fractal Shader");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(mouseMove);
    glutMouseFunc(mouseAction);
    glutIdleFunc(OnIdle);
    glutKeyboardFunc(keyAction);
    glutKeyboardUpFunc(keyUp);
    glClearColor(0, 0, 0, 1);
    CGcontext context = cgCreateContext();
    if(context == NULL){
        printf("Failed to create CGcontext\n");
        return 1;
    }
	f_prof = cgGLGetLatestProfile(CG_GL_FRAGMENT); 
	v_prof = cgGLGetLatestProfile(CG_GL_VERTEX);
	printf("%d, %d\n", f_prof, v_prof);
    chdir("/Users/peter/Desktop/CG/cgtest");
    julia = cgCreateProgramFromFile(context, CG_SOURCE, "Julia.cg", f_prof, "main", NULL);
    newton = cgCreateProgramFromFile(context, CG_SOURCE, "Newton.cg", f_prof, "main", NULL);
    mandel = cgCreateProgramFromFile(context, CG_SOURCE, "Mandel.cg", f_prof, "main", NULL);
    ship = cgCreateProgramFromFile(context, CG_SOURCE, "Ship.cg", f_prof, "main", NULL);
    pass = cgCreateProgramFromFile(context, CG_SOURCE, "Pass.cg", v_prof, "main", NULL);
	gen = cgCreateProgramFromFile(context, CG_SOURCE, "GenIter.cg", f_prof, "main", NULL);
    printf("%s\n", cgGetErrorString(cgGetError()));
    cgGLLoadProgram(julia);
    cgGLLoadProgram(newton);
    cgGLLoadProgram(mandel);
    cgGLLoadProgram(ship);
	cgGLLoadProgram(gen);
    cgGLLoadProgram(pass);
    //printf("%s\n", cgGetErrorString(cgGetError()));
    cgGLEnableProfile(f_prof);
    cgGLEnableProfile(v_prof);
    printf("%s\n", cgGetErrorString(cgGetError()));
	
	Position demoList[7];
	fillPoint(&demoList[0], 0.297205, 0.063085, 0.001157, 1.012991, 15.0, 7);
	fillPoint(&demoList[1], 0.134370, 0.042840, 0.043976, 1.008928, 15.0, 7);
	fillPoint(&demoList[2], -0.129831, -0.637758, 0.507148, 1.103996, 15.0, 7);
	fillPoint(&demoList[3], -0.162030, -1.02009, 0.041826, 0.983991, 15.0, 7);
	fillPoint(&demoList[4], -0.139263, -1.846086, 0.002345, 0.516934, 15.0, 7);
	fillPoint(&demoList[5], -0.138215, -1.910406, 0.001638, 0.495934, 15.0, 7);
	fillPoint(&demoList[6], -0.138215, -3.552904, 0.302149, 0.149937, 15.0, 7);
	
	posList = demoList;
	zoom = 0.001157;
	
    glutMainLoop();
    return 0;
}
Example #3
0
void PipeLine::drawLine(int x1,int y1,int x2,int y2,uint32_t c,uint32_t depth){

    if( clipLine(x1,y1,x2,y2) == false)
		return;
        


    int x, y, rem = 0;
    if (x1 == x2 && y1 == y2) {
        fillPoint( x1, y1, c,depth);
    }else if (x1 == x2) {
        int inc = (y1 <= y2)? 1 : -1;
        for (y = y1; y != y2; y += inc) fillPoint( x1, y, c,depth);
        fillPoint( x2, y2, c,depth);
    }else if (y1 == y2) {
        int inc = (x1 <= x2)? 1 : -1;
        for (x = x1; x != x2; x += inc) fillPoint( x, y1, c,depth);
        fillPoint( x2, y2, c,depth);
    }else {
        // Bresenham line
        int dx = (x1 < x2)? (x2 - x1) : (x1 - x2);
        int dy = (y1 < y2)? (y2 - y1) : (y1 - y2);
        if (dx >= dy) {
            /* x axis 每次加1 y + dy 如果大于 dx需要矫正
			*/
			if (x2 < x1) { std::swap(x1, x2);std::swap(y1, y2); }
            int delta = (y2 >= y1)? 1 : -1;
            for (x = x1, y = y1; x <= x2; x++/* x 每次加1 */) {
                rem += dy;
                if (rem >= dx) {
                    rem -= dx;
                    y += delta;
                }
                fillPoint(x,y,c,depth);
            }
        }else {
            if (y2 < y1) std::swap(x1,x2),std::swap(y1,y2);
            int delta = (x2 >= x1)? 1 : -1;
            for (x = x1, y = y1; y <= y2; y++) {
                rem += dx;
                if (rem >= dy) {
                    rem -= dy;
                    x += delta;
                }
                fillPoint(x, y,c,depth);
            }
        }
        fillPoint(x2,y2,c,depth);
    }
}