Kinect & OpenGL Integration

Jul 17, 2013 at 4:36 AM
Hi everybody,

I have no experience on kinect, neither OpenGL. Both are new for me . I am trying to integrate the Kinect's video input over a opengl control. But i am having some troubles with this.

As I read on some forums, It seems to be that I need to use a method called TexSubImage2D.

But there is some type conversion error. As i see, this method on the last parameter is waiting for int[] pixels type, and the video input is int [] (this.colorImageWritableBitmap) .
I would like to know if there is something that i missing , or simply a way to make this type convertion.

Thanks a lot for any help !

Here is part of my code :
        private void KinectSensorOnAllFramesReady(object sender, AllFramesReadyEventArgs allFramesReadyEventArgs)
            using (var colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame())
                if (colorImageFrame == null)

                // Make a copy of the color frame for displaying.
                var haveNewFormat = this.currentColorImageFormat != colorImageFrame.Format;
                if (haveNewFormat)
                    this.currentColorImageFormat = colorImageFrame.Format;
                    this.colorImageData = new byte[colorImageFrame.PixelDataLength];
                    this.colorImageWritableBitmap = new WriteableBitmap(
                        colorImageFrame.Width, colorImageFrame.Height, 96, 96, PixelFormats.Bgr32, null);
                    ColorImage.Source = this.colorImageWritableBitmap;

                    new Int32Rect(0, 0, colorImageFrame.Width, colorImageFrame.Height),
                    colorImageFrame.Width * Bgr32BytesPerPixel,
 private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL; 
            //  Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Load the identity matrix.

             gl.TexSubImage2D(OpenGL.GL_TEXTURE_2D, 0, 0, 0, 100, 100, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, this.colorImageWritableBitmap);

My main window :
<Window x:Class="KinectSharpGL.MainWindow"
        Title="SharpGL WPF Application" Height="291" Width="738" 
        <SolidColorBrush x:Key="MediumGreyBrush" Color="#ff6e6e6e"/>
        <SolidColorBrush x:Key="KinectPurpleBrush" Color="#ff52318f"/>
        <SolidColorBrush x:Key="KinectBlueBrush" Color="#ff00BCF2"/>
        <Style TargetType="{x:Type Image}">
            <Setter Property="SnapsToDevicePixels" Value="True"/>

        <Image Name="ColorImage" Height="200" Margin="320,26,95,26" />
        <local:FaceTrackingViewer x:Name="FaceTrackingViewer" />

        <!-- The OpenGL control provides a OpenGL drawing surface. -->
            Name="openGLControl" OpenGLDraw="openGLControl_OpenGLDraw" 
            DrawFPS="False" RenderContextType="FBO" FrameRate="20" Margin="24,12,451,15" Resized="openGLControl_Resized" Loaded="openGLControl_Loaded" />