PDA

View Full Version : Array image redering aliasing???



Shintai
10-01-2014, 03:05 AM
Hi, I'm trying to render a array image on a cube,
Here is the result and the real image that i would like to render it.
14581459

For example, i have a black and white array image, what is the problem makes my image like this??

Anyone could help me?
Thanks



double[] slice = new double[]
{
0,0,0,0,0,0,0,
0,0,0,0,0,0,0,
0,0,1,1,1,0,0,
0,0,1,1,1,0,0,
0,0,1,1,1,0,0,
0,0,0,0,0,0,0,
0,0,0,0,0,0,0
}

gl.Enable(OpenGL.GL_TEXTURE_2D);
gl.ShadeModel(OpenGL.GL_SMOOTH);
gl.Enable(OpenGL.GL_DEPTH_TEST);
gl.DepthFunc(OpenGL.GL_LEQUAL);
gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);

uint[] texture = new uint[1];
gl.GenTextures(1, texture);
gl.BindTexture(OpenGL.GL_TEXTURE_2D, texture[0]);


Bitmap texslice = new Bitmap(7, 7 ,PixelFormat.Format24bppRgb);

// Create the converter to create a Bitmap from the array
ArrayToImage conv = new ArrayToImage(7, 7);

// Declare an image and store the pixels on it
conv.Convert(slice, out texslice);

gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 1, texslice.Height, texslice.Width, 0, OpenGL.GL_LUMINANCE, OpenGL.GL_UNSIGNED_BYTE,
texslice.LockBits(new Rectangle(0, 0, texslice.Width, texslice.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0);


gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR); // Linear Filtering
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); // Linear Filtering
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP_TO_EDGE);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP_TO_EDGE);

GClements
10-01-2014, 03:39 AM
gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 1, texslice.Height, texslice.Width, 0, OpenGL.GL_LUMINANCE, OpenGL.GL_UNSIGNED_BYTE,
texslice.LockBits(new Rectangle(0, 0, texslice.Width, texslice.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0);


I have no idea what texslice.LockBits() does (not being part of OpenGL), but PixelFormat.Format24bppRgb looks suspicious. Are you passing 3-component (RGB, 24-bpp) data where 1-component (luminance, 8-bpp) data is expected? That would produce artefacts similar to the ones you're getting.

Shintai
10-01-2014, 04:52 AM
Thanks for you suggestion!
It's worked before i changed it to PixelFormat.Format8bppIndexed!!