コード例 #1
0
ファイル: mainIUP.c プロジェクト: juliords/pucrio-cg-20112
/* calcula uma linha da imagem a cada camada de idle */
int idle_cb(void)
{
	int x;
	/* Faz uma linha de pixels por vez */
	if (yc<height) {
		IupGLMakeCurrent(canvas);
		glBegin(GL_POINTS);
		for( x = 0; x < width; ++x ) {
			Color pixel;
			Vector ray;				

			ray = camGetRay( camera, x, yc );
			pixel = rayTrace( scene, eye, ray, 0 );

			imageSetPixel( image, x, yc, pixel );
			glColor3f((float)pixel.red,(float)pixel.green,(float)pixel.blue);
			glVertex2i(x,yc);

		}
		glEnd();
		glFlush();
		IupGLSwapBuffers(canvas);  /* change the back buffer with the front buffer */
		yc++;
	}
	else {
		IupSetFunction (IUP_IDLE_ACTION, (Icallback) NULL); /* a imagem ja' esta' completa */
		finish_time = clock();
		duration = (double)(finish_time - start_time)/CLOCKS_PER_SEC;
		IupSetfAttribute(label, "TITLE", "tempo=%.3lf s", duration);
	}

	return IUP_DEFAULT;
}
コード例 #2
0
ファイル: mainIUP.c プロジェクト: lfmachadodasilva/raytracing
/* calcula uma linha da imagem a cada camada de idle */
int idle_cb(void)
{
	int x;
	double ray[VECTOR];
	float pixel[COLOR];

  /* Faz uma linha de pixels por vez */
  if (yc < height) {

    IupGLMakeCurrent(canvas);
    glBegin(GL_POINTS);
    {
      for (x = 0; x < width; ++x) {

        camGetRay(camera, x, yc, ray);
        rayTrace(scene, eye, ray, 0, pixel);

        imageSetPixel(image, x, yc, pixel);
        glColor3f((float) pixel[RED], (float) pixel[GREEN], (float) pixel[BLUE]);
        glVertex2i(x, yc);

      }
    }
    glEnd();

    glFlush();

    IupGLSwapBuffers(canvas);
    
    yc++;
  } else {

		IupSetFunction (IUP_IDLE_ACTION, (Icallback) NULL); /* a imagem ja' esta' completa */
		finish_time = clock();
		duration = (double)(finish_time - start_time)/CLOCKS_PER_SEC;
		IupSetfAttribute(label, "TITLE", "tempo=%.3lf s", duration);

		glFlush();
	}


	return IUP_DEFAULT;
}