This project is read-only.

drawPixels Example

May 14, 2012 at 6:16 PM

Hello

Can someone give an example to use drawPixels in WPF

 I have tried many examples available on the internet, but all I get is a black screen with random pixels on it. :(

Any Ideas?

May 18, 2012 at 2:45 PM
Hi,
I never use drwapixels in wpf, but maybe i could give you a suggestion,here:
function gl.DrawPixels:
glDrawPixels(int width, int height, uint format, uint type,  float[] pixels)
you can try to change param 3 "uint type" : GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT
maybe solve your problem.
I think you maybe use gl.DrawElements & gl.InterleavedArrays .It's faster than gl.drawpixels. like below:
gl.InterleavedArrays(OpenGL.GL_C3F_V3F, 0, Vect);
                IntPtr intPtr, pp;
                gl.GenBuffers(1, Buffers);
                gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, Buffers[0]);
                intPtr = IntPtr.Zero;
                pp = IntPtr.Zero;

                unsafe
                {
                    try
                    {
                        fixed (float* pImageDate = Vect)
                            intPtr = new IntPtr((void*)pImageDate);
                        gl.BufferData(OpenGL.GL_ELEMENT_ARRAY_BUFFER, Vect.Length * 4, intPtr, OpenGL.GL_STATIC_DRAW);
                      }
                    finally
                    {
                        Marshal.FreeHGlobal(intPtr);
                    }
                }
     
                gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
                gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
               
                float[] Vect2=new float [Vect.Length-3];
              unsafe
                {
                    try
                    {
                        fixed (float* pl = &Vect[3])
                            intPtr = new IntPtr((void*)pl);
                        Marshal.Copy(intPtr, Vect2, 0, Vect.Length - 3);
                        gl.VertexPointer(3, OpenGL.GL_FLOAT, 6 * sizeof(float), Vect2);
                     }
                    finally
                    {
                        Marshal.FreeHGlobal(intPtr);
                    }

               }
             // gl.ColorPointer(3, OpenGL.GL_FLOAT, 6 * sizeof(float), Vect);
                uint[] triangleVBO = new uint[1];

                gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, triangleVBO[0]);

                unsafe
                {
                    try
                    {
                        fixed (int* pImageDate = PindexData)
                            pp = new IntPtr((void*)pImageDate);
                        gl.BufferData(OpenGL.GL_ELEMENT_ARRAY_BUFFER, PindexData.Length, pp, OpenGL.GL_STATIC_DRAW);
                      }
                      
                    finally
                    {
                        Marshal.FreeHGlobal(pp);
                    }
                }

                gl.DrawElements(OpenGL.GL_TRIANGLES, PindexData.Length, OpenGL.GL_UNSIGNED_INT, PindexData);   //The starting point of the IBO
                gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
                gl.DisableClientState(OpenGL.GL_COLOR_ARRAY);
                gl.DeleteBuffers(1, Buffers);
and you can refrence here:
http://www.felixgers.de/teaching/jogl/vertexArrayInterleaved.html