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 6172051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:19:35+00:00 2026-05-23T23:19:35+00:00

I have a following picture: Window displays two textures, the left texture is generated

  • 0

I have a following picture:

enter image description here

Window displays two textures, the left texture is generated by binding it to a FBO and rendering to FBO, 50 random triangles.

The right texture is generated by glTexImage2D with full-color image of Mona Lisa, but as you can see the image is lacking red colors, I think the problem is in OpenGL part, since I’ve investigated bytes that are passed to glTexImage2D and they do contain Red…

Here is C#/Mono/OpenTK source

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
using OpenTK.Platform.X11;
using OpenTK.Input;

using ManOCL;


namespace GlTest
{
    public class MainClass: GameWindow
    {
        public MainClass()
            : base(800, 600, new GraphicsMode(new ColorFormat(0, 0, 0, 0), 32, 0))
        {
            this.VSync = VSyncMode.Off;
        }

        public uint fbo;
        public uint textureA;
        public uint textureB;

        public int textureAWidth = 1024;
        public int textureAHeight = 1024;

        public int textureBWidth;
        public int textureBHeight;

        Random rand = new Random();

        protected override void OnLoad(EventArgs e)
        {
            GL.Enable(EnableCap.Blend);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);

//            GL.PolygonMode(MaterialFace.Back, PolygonMode.Line);

            // Create Color Tex
            GL.GenTextures(1, out textureA);
            GL.BindTexture(TextureTarget.Texture2D, textureA);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, textureAWidth, textureAHeight, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) TextureWrapMode.ClampToBorder);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) TextureWrapMode.ClampToBorder);

            GL.GenTextures(1, out textureB);
            GL.BindTexture(TextureTarget.Texture2D, textureB);

            Bitmap bmp = new Bitmap("/Projects/MonaLisa/MonaLisa.bmp");

            Console.WriteLine(textureBWidth = bmp.Width);
            Console.WriteLine(textureBHeight = bmp.Height);

            //get the data out of the bitmap
            System.Drawing.Imaging.BitmapData bmpBits = bmp.LockBits
            (
                new System.Drawing.Rectangle(0,0,textureBWidth, textureBHeight),
                System.Drawing.Imaging.ImageLockMode.ReadOnly,
                System.Drawing.Imaging.PixelFormat.Format32bppRgb
            );

            for (int row = 0; row < 1; row++)
            {
                for (int col = 0; col < 32; col++)
                {
                    Console.WriteLine
                    (
                        "{0}, {1}, {2}, {3}",
                        Marshal.ReadByte(bmpBits.Scan0, (row * textureBWidth + col) * 4 + 0),
                        Marshal.ReadByte(bmpBits.Scan0, (row * textureBWidth + col) * 4 + 1),
                        Marshal.ReadByte(bmpBits.Scan0, (row * textureBWidth + col) * 4 + 2),
                        Marshal.ReadByte(bmpBits.Scan0, (row * textureBWidth + col) * 4 + 3)
                    );

                }
            }

            Console.WriteLine(bmpBits.Width);
            Console.WriteLine(bmpBits.Height);


            GL.TexImage2D
            (
                TextureTarget.Texture2D,
                0,
                PixelInternalFormat.Rgba,
                textureBWidth,
                textureBHeight,
                0,
                OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
                PixelType.UnsignedByte,
                bmpBits.Scan0
            );

//          GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, textureBWidth, textureBHeight, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) TextureWrapMode.ClampToBorder);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) TextureWrapMode.ClampToBorder);

            //free the bitmap data (we dont need it anymore because it has been passed to the OpenGL driver
            bmp.UnlockBits(bmpBits);

            // Create a FBO and attach the textures
            GL.Ext.GenFramebuffers(1, out fbo);
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fbo);
            GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, textureA, 0);

            #region Test for Error
            switch (GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt))
            {
            case FramebufferErrorCode.FramebufferCompleteExt:
                {
                    Console.WriteLine("FBO: The framebuffer is complete and valid for rendering.");
                    break;
                }
            case FramebufferErrorCode.FramebufferIncompleteAttachmentExt:
                {
                    Console.WriteLine("FBO: One or more attachment points are not framebuffer attachment complete. This could mean there’s no texture attached or the format isn’t renderable. For color textures this means the base format must be RGB or RGBA and for depth textures it must be a DEPTH_COMPONENT format. Other causes of this error are that the width or height is zero or the z-offset is out of range in case of render to volume.");
                    break;
                }
            case FramebufferErrorCode.FramebufferIncompleteMissingAttachmentExt:
                {
                    Console.WriteLine("FBO: There are no attachments.");
                    break;
                }
            /* case  FramebufferErrorCode.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: 
                 {
                     Console.WriteLine("FBO: An object has been attached to more than one attachment point.");
                     break;
                 }*/
            case FramebufferErrorCode.FramebufferIncompleteDimensionsExt:
                {
                    Console.WriteLine("FBO: Attachments are of different size. All attachments must have the same width and height.");
                    break;
                }
            case FramebufferErrorCode.FramebufferIncompleteFormatsExt:
                {
                    Console.WriteLine("FBO: The color attachments have different format. All color attachments must have the same format.");
                    break;
                }
            case FramebufferErrorCode.FramebufferIncompleteDrawBufferExt:
                {
                    Console.WriteLine("FBO: An attachment point referenced by GL.DrawBuffers() doesn’t have an attachment.");
                    break;
                }
            case FramebufferErrorCode.FramebufferIncompleteReadBufferExt:
                {
                    Console.WriteLine("FBO: The attachment point referenced by GL.ReadBuffers() doesn’t have an attachment.");
                    break;
                }
            case FramebufferErrorCode.FramebufferUnsupportedExt:
                {
                    Console.WriteLine("FBO: This particular FBO configuration is not supported by the implementation.");
                    break;
                }
            default:
                {
                    Console.WriteLine("FBO: Status unknown. (yes, this is really bad.)");
                    break;
                }
            }

            // using FBO might have changed states, e.g. the FBO might not support stereoscopic views or double buffering
            int[] queryinfo = new int[6];
            GL.GetInteger(GetPName.MaxColorAttachmentsExt, out queryinfo[0]);
            GL.GetInteger(GetPName.AuxBuffers, out queryinfo[1]);
            GL.GetInteger(GetPName.MaxDrawBuffers, out queryinfo[2]);
            GL.GetInteger(GetPName.Stereo, out queryinfo[3]);
            GL.GetInteger(GetPName.Samples, out queryinfo[4]);
            GL.GetInteger(GetPName.Doublebuffer, out queryinfo[5]);
            Console.WriteLine("max. ColorBuffers: " + queryinfo[0] + " max. AuxBuffers: " + queryinfo[1] + " max. DrawBuffers: " + queryinfo[2] +
                               "\nStereo: " + queryinfo[3] + " Samples: " + queryinfo[4] + " DoubleBuffer: " + queryinfo[5]);

            Console.WriteLine("Last GL Error: " + GL.GetError());
            #endregion Test for Error


            GL.PushAttrib(AttribMask.ViewportBit);
            {
                GL.Viewport(0, 0, textureAWidth, textureAHeight);

                OpenTK.Matrix4 orthogonal = OpenTK.Matrix4.CreateOrthographicOffCenter(0, 1, 0, 1, -3, 3);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadMatrix(ref orthogonal);

                Matrix4 lookat = Matrix4.LookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadMatrix(ref lookat);


                // clear the screen in red, to make it very obvious what the clear affected. only the FBO, not the real framebuffer
                GL.ClearColor(0f, 0f, 0f, 0f);
                GL.Clear(ClearBufferMask.ColorBufferBit);

                // smack 50 random triangles into the FBO's textures
                GL.Begin(BeginMode.Triangles);
                {
                    for (int i = 0; i < 50; i++)
                    {
                        GL.Color4(((float)(rand.NextDouble())), ((float)(rand.NextDouble())), ((float)(rand.NextDouble())), ((float)(rand.NextDouble())));
                        GL.Vertex3(((float)(rand.NextDouble())), ((float)(rand.NextDouble())), 0);
                        GL.Color4(((float)(rand.NextDouble())), ((float)(rand.NextDouble())), ((float)(rand.NextDouble())), ((float)(rand.NextDouble())));
                        GL.Vertex3(((float)(rand.NextDouble())), ((float)(rand.NextDouble())), 0);
                        GL.Color4(((float)(rand.NextDouble())), ((float)(rand.NextDouble())), ((float)(rand.NextDouble())), ((float)(rand.NextDouble())));
                        GL.Vertex3(((float)(rand.NextDouble())), ((float)(rand.NextDouble())), 0);
                    }
                }
                GL.End();
            }
            GL.PopAttrib();         
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); // disable rendering into the FBO

            GL.ClearColor(1f, 1f, 1f, 0.0f);
            GL.Color3(1f, 1f, 1f);

            GL.Enable(EnableCap.Texture2D); // enable Texture Mapping
            GL.BindTexture(TextureTarget.Texture2D, 0); // bind default texture

//          IntPtr cglContext = Monobjc.OpenGL.CGL.GetCurrentContext();
//          
//          IntPtr cglShareGroup = Monobjc.OpenGL.CGL.GetShareGroup(cglContext);
//          
//          ManOCL.Context.ShareWithCGL(cglShareGroup);
//          
//          Kernel kernel = ManOCL.Kernel.Create
//          (
//              "kernel1",
//              @"__kernel void kernel1(__global int *srcimg, __global int * output, __global int *smp)
//              {
//              }",
//              new Argument[]
//              {
//                  DeviceGlobalMemory.CreateFromArray(new int[1]),
//                  DeviceGlobalMemory.CreateFromArray(new int[2]),
//                  DeviceGlobalMemory.CreateFromArray(new int[1])
//              }
//          );

//          Console.WriteLine("Success!");
//          Console.WriteLine(kernel);
        }

        protected override void OnUnload(EventArgs e)
        {
            // Clean up what we allocated before exiting
            GL.DeleteTextures(1, ref textureA);
            GL.DeleteTextures(1, ref textureB);
            GL.Ext.DeleteFramebuffers(1, ref fbo);

            base.OnUnload(e);
        }

        protected override void OnResize (EventArgs e)
        {
            GL.Viewport(0, 0, Width, Height);

            double aspect_ratio = Width / (double)Height;

            OpenTK.Matrix4 perspective = OpenTK.Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4 * 3 / 2, (float)aspect_ratio, 1, 64);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref perspective);

            Matrix4 lookat = Matrix4.LookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref lookat);

            base.OnResize(e);
        }

        protected override void OnUpdateFrame (FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (Keyboard[Key.Escape])
            {
                this.Exit();
            }
        }

        protected override void OnRenderFrame(FrameEventArgs e)
        {
            this.Title = "Frames per Second: " + (1.0 / e.Time);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.PushMatrix();
            {
                // Draw the Color Texture
                GL.Translate(-1f, 0f, 0f);
                GL.BindTexture(TextureTarget.Texture2D, textureA);
                GL.Begin(BeginMode.Quads);
                {
                    GL.TexCoord2(0f, 1f);
                    GL.Vertex2(-1.0f, 1.0f);
                    GL.TexCoord2(0.0f, 0.0f);
                    GL.Vertex2(-1.0f, -1.0f);
                    GL.TexCoord2(1.0f, 0.0f);
                    GL.Vertex2(1.0f, -1.0f);
                    GL.TexCoord2(1.0f, 1.0f);
                    GL.Vertex2(1.0f, 1.0f);
                }
                GL.End();

                GL.Translate(2f, 0f, 0f);
                GL.BindTexture(TextureTarget.Texture2D, textureB);
                GL.Begin(BeginMode.Quads);
                {
                    GL.TexCoord2(0f, 0f);
                    GL.Vertex2(-1.0f, 1.0f);

                    GL.TexCoord2(0.0f, 1.0f);
                    GL.Vertex2(-1.0f, -1.0f);

                    GL.TexCoord2(1.0f, 1.0f);
                    GL.Vertex2(1.0f, -1.0f);

                    GL.TexCoord2(1.0f, 0.0f);
                    GL.Vertex2(1.0f, 1.0f);
                }
                GL.End();
                GL.Translate(0f, 0f, 0f);               
            }
            GL.PopMatrix();

            this.SwapBuffers();
        }

        #region public static void Main()

        /// <summary>
        /// Entry point of this example.
        /// </summary>
        [STAThread]
        public static void Main()
        {           
            using (MainClass example = new MainClass())
            {
                example.Title = "FrameBufferObjects";
                example.Run(1.0, 0.0);
            }
        }

        #endregion
    }
}
  • 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-05-23T23:19:37+00:00Added an answer on May 23, 2026 at 11:19 pm

    In the bit of code where you set your texture data:

            GL.TexImage2D
            (
                TextureTarget.Texture2D,
                0,
                PixelInternalFormat.Rgba,
                textureBWidth,
                textureBHeight,
                0,
                OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
                PixelType.UnsignedByte,
                bmpBits.Scan0
            );
    

    Change your pixel format to

    OpenTK.Graphics.OpenGL.PixelFormat.Bgra;
    

    Windows bitmaps and opengl have a different endianess on pixels i.e. the bytes are reversed.

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

Sidebar

Related Questions

I have the following XAML code, which displays a picture (image inside borders) and
I have a graph created with MS Chart like the following picture. As you
I have the following situation, presented in the picture. Grey div is the parent
Picture the following situation. I have an XML document as follows, <Form> <Control Type=Text
In Excel I have attached a picture to a cell using the following Sub
I trying to display image in picture box. The application have two part. First
I have the following Picture: And you guessed it: I want to extract all
I have a data structure similar to the following picture. Table A has_many Table
As show in the picture I have following structures to store set of closet
i have a window in Qt, on that i am drawing a picture. now

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.