Esempio n. 1
0
Color matGetDiffuse( Material material, Vector textureCoordinate )
{
	int x;
	int y;
	int width;
	int height;

	if( material->texture == NULL )
	{
		return material->diffuseColor;
	}

	imageGetDimensions( material->texture, &width, &height );
	
	x = ( (int)( textureCoordinate.x * ( width - 1 ) ) % width );
	y = ( (int)( textureCoordinate.y * ( height - 1 ) ) % height );

	return imageGetPixel( material->texture, x, y );
}
Esempio n. 2
0
void create_subimage(subimage_t * destsi, pngimage_t * origimg, int slices, int theslicenumber, int pixelborder)
{
   int xstart, i, j, wth, w, n, wth2;

   wth = origimg->imgWidth / slices;
   if((wth * slices < origimg->imgWidth) && (origimg->imgWidth % slices > theslicenumber))
   {
      wth ++;
   }
   w = wth + ( ((theslicenumber==0)||(theslicenumber==slices-1)) ? pixelborder : 2*pixelborder );
   destsi->w = w;
   destsi->h = origimg->imgHeight;
   destsi->Bpp = 3;
   destsi->bytesAllocated = next16multiple(destsi->w * destsi->h * destsi->Bpp);
   destsi->data = (unsigned char *) memalign(16, destsi->bytesAllocated);
   destsi->dataLS = 0;

   xstart = 0;
   for(n=0; n<theslicenumber; n++)
   {
     wth2 = origimg->imgWidth / slices;
     if((wth2 * slices < origimg->imgWidth) && (origimg->imgWidth % slices > n))
     {
        wth2 ++;
     }

     xstart += wth2;
   }
   // printf("AAA slices=%d tsn=%d wth=%d w=%d xstart=%d\n", slices, theslicenumber, wth, w, xstart);
   for(i=0; i<destsi->h; i++)
   {
     for(j=0; j<w; j++)
     {
        unsigned char r, g, b;
        imageGetPixel(origimg, xstart + j - ( theslicenumber==0 ? 0 : pixelborder ), i, &r, &g, &b);
        subimage_setpixel(destsi, j, i, r, g, b);
     }

   }

}
Esempio n. 3
0
/* - Callback de repaint do canvas  */
int repaint_cb(Ihandle *self)
{
	int w,h;
	int x,y;
	Color rgb;

	if (yc==0){  /* e' a primeira vez: limpa o canvas */
		IupGLMakeCurrent(self);
		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		glClear(GL_COLOR_BUFFER_BIT);
		IupGLSwapBuffers(self);  /* change the back buffer with the front buffer */
		glFlush();
	}

	if (yc!=height) { /* esta callback so'desenha depois que o algoritmo termina a imagem */
		return IUP_DEFAULT; 
	}

	w = imgGetWidth(image);
	h = imgGetHeight(image);
	IupGLMakeCurrent(self);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	glBegin(GL_POINTS);
	for (y=0;y<h;y++) {
		for (x=0; x<w; x++) {
			rgb = imageGetPixel(image, x, y);
			glColor3f((float)rgb.red,(float)rgb.green,(float)rgb.blue);
			glVertex2i(x,y);
		}
	}
	glEnd();

	IupGLSwapBuffers(self);  /* change the back buffer with the front buffer */

	glFlush();
	return IUP_DEFAULT; /* retorna o controle para o gerenciador de eventos */
}