Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7898201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:22:11+00:00 2026-06-03T08:22:11+00:00

I want to draw a simple 2D quad with a texture from the Kinect’s

  • 0

I want to draw a simple 2D quad with a texture from the Kinect’s video input but my code isn’t working.

Here is my ColorFrameReady event:

    void Sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
    {
        ColorImageFrame cif = e.OpenColorImageFrame();

        if (cif != null)
        {
            middleBitmapSource = cif.ToBitmapSource();
            cif.Dispose();
        }
    }

This is my OpenGL draw method:

    private void OpenGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
    {
        // Get the OpenGL instance being pushed to us.
        gl = args.OpenGL;

        // Clear the colour and depth buffers.
        gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

        // Enable textures
        gl.Enable(OpenGL.GL_TEXTURE_2D);

        // Reset the modelview matrix.
        gl.LoadIdentity();

        // Load textures
        if (middleBitmapSource != null)
        {
            middleBitmap = getBitmap(middleBitmapSource, quadMiddleWidth, quadMiddleHeight);
            //middleBitmap = new System.Drawing.Bitmap("C:\\Users\\Bobble\\Pictures\\Crate.bmp"); // When I use this texture, it works fine
            gl.GenTextures(1, textures);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, middleBitmap.Width, middleBitmap.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE,
                middleBitmap.LockBits(new System.Drawing.Rectangle(0, 0, middleBitmap.Width, middleBitmap.Height),
                System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb).Scan0);

            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
        }

        // Move back a bit
        gl.Translate(0.0f, 0.0f, -25.0f);

        gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);

        // Draw a quad.
        gl.Begin(OpenGL.GL_QUADS);

            // Draw centre quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-(quadMiddleWidth / 2), quadMiddleHeight / 2, quadDepthFar);
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(quadMiddleWidth / 2, quadMiddleHeight / 2, quadDepthFar);
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(quadMiddleWidth / 2, -(quadMiddleHeight / 2), quadDepthFar);
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-(quadMiddleWidth / 2), -(quadMiddleHeight / 2), quadDepthFar);

        gl.End();

        gl.Flush();
    }

And here is a helper method which converts a BitmapSource to a Bitmap of a given size:

    private System.Drawing.Bitmap getBitmap(BitmapSource bitmapSource, double rectangleWidth, double rectangleHeight)
    {
        double newWidthRatio = rectangleWidth / (double)bitmapSource.PixelWidth;
        double newHeightRatio = ((rectangleWidth * bitmapSource.PixelHeight) / (double)bitmapSource.PixelWidth) / (double)bitmapSource.PixelHeight;

        BitmapSource transformedBitmapSource = new TransformedBitmap(bitmapSource, new ScaleTransform(newWidthRatio, newHeightRatio));

        int width = transformedBitmapSource.PixelWidth;
        int height = transformedBitmapSource.PixelHeight;
        //int stride = width * ((transformedBitmapSource.Format.BitsPerPixel + 7) / 8);
        int stride = ((width * transformedBitmapSource.Format.BitsPerPixel + 31) & ~31) / 8; // See: http://stackoverflow.com/questions/1983781/why-does-bitmapsource-create-throw-an-argumentexception/1983886#1983886

        byte[] bits = new byte[height * stride];

        transformedBitmapSource.CopyPixels(bits, stride, 0);

        unsafe
        {
            fixed (byte* pBits = bits)
            {
                IntPtr ptr = new IntPtr(pBits);

                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(
                    width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppArgb, ptr);

                return bitmap;
            }
        }
    }

The quad renders but it is just white, no texture on it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:22:12+00:00Added an answer on June 3, 2026 at 8:22 am

    This turned out to be an issue with SharpGL – the OpenGL library I was using.

    http://sharpgl.codeplex.com/discussions/348278 – discussion on CodePlex which led to the issue being resolved by the SharpGL developers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code. I'm attempting to draw a simple quadrilateral, and place a
Let's say I want to draw a simple quad like this: glBegin(GL_QUADS); glVertex2f(-1.0,-1.0); glVertex2f(1.0,-1.0);
Lets say I want to draw a simple 3D hero with OpenGL. Here are
I draw a simple triangle and I want to learn how to rotate it
I want to draw line on UIImageView. I already draw line on UIImageView but
I want to draw a line in Crystal report. I can do that from
In my program I want to draw a simple score line graph. I have
I'm building a simple ControlTemplate for a Button. I want to draw a 2
I want to draw a simple graph like this in android. Can it be
I want to draw a rectangle using OPENGL in Android... Just a simple rectangle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.