Esempio n. 1
0
        void CreateGrayscaleImage()
        {
            GLDraw drawer = new GLDraw(GI);

            byte[] lumdata = new byte[fPixmap.Width * fPixmap.Height];
            fModifiedPixels = new GLPixelData(fPixmap.Width, fPixmap.Height, TextureInternalFormat.Luminance8, GLPixelFormat.Luminance, PixelType.UnsignedByte, lumdata);

            // Make sure we get full color first
            gl.glPixelTransferf(gl.GL_RED_SCALE, 1.0f);
            gl.glPixelTransferf(gl.GL_GREEN_SCALE, 1.0f);
            gl.glPixelTransferf(gl.GL_BLUE_SCALE, 1.0f);

            //    // First draw image into color buffer
            GI.DrawPixels(0, 0, fPixmap);

            //    // Scale colors according to NSTC standard
            gl.glPixelTransferf(gl.GL_RED_SCALE, 0.3f);
            gl.glPixelTransferf(gl.GL_GREEN_SCALE, 0.59f);
            gl.glPixelTransferf(gl.GL_BLUE_SCALE, 0.11f);

            //    // Read pixles into buffer (scale above will be applied)
            GI.ReadPixels(0, 0, fModifiedPixels);

            //    // Return color scaling to normal
            gl.glPixelTransferf(gl.GL_RED_SCALE, 1.0f);
            gl.glPixelTransferf(gl.GL_GREEN_SCALE, 1.0f);
            gl.glPixelTransferf(gl.GL_BLUE_SCALE, 1.0f);
        }
Esempio n. 2
0
        public PixelDisplayModel()
        {
            fFillWindow = false;

            fUseRed = true;
            fUseGreen = true;
            fUseBlue = true;
            fUseLuminance = false;

            fRenderMode = 1;
            fModifiedPixels = null;
        }
Esempio n. 3
0
        protected override void OnSetContext()
        {
            GI.PixelStore(PixelStore.UnpackAlignment, 1);

            //fPixmap = TargaHandler.CreatePixelDataFromFile("ground.tga");
            //fPixmap = TargaHandler.CreatePixelDataFromFile("cube.tga");
            //fPixmap = TargaHandler.CreatePixelDataFromFile("fire.tga");
            fPixmap = TargaHandler.CreatePixelDataFromFile("horse.tga");
            //fPixmap = TargaHandler.CreatePixelDataFromFile("moon.tga");
            //fPixmap = TargaHandler.CreatePixelDataFromFile("star.tga");
            //fPixmap = TargaHandler.CreatePixelDataFromFile("orb.tga");

        }
Esempio n. 4
0
        public static GLTexture2D CreateTextureFromBitmap(GraphicsInterface gi, Bitmap bitmap, bool useMipMaps)
        {
            if (null == bitmap)
            {
                return (null);
            }

            byte[] pixeldata = TextureHelper.ConvertBitmapToRGBAData(bitmap);
            GLPixelData pixMap = new GLPixelData(bitmap.Width, bitmap.Height, TextureInternalFormat.Rgba8, PixelLayout.Rgba, PixelComponentType.UnsignedByte, pixeldata);

            GLTexture2D tex = CreateTextureFromPixelData(gi, pixMap, useMipMaps);

            return tex;
        }
Esempio n. 5
0
        //public bool UpdateTextureWithBitmapData(GraphicsInterface gr, Bitmap bitmap)
        //{
        //    if (null == bitmap)
        //    {
        //        return (false);
        //    }

        //    bool result;

        //    if ((fPixelData.Width != bitmap.Width) || (fPixelData.Height != bitmap.Height))
        //    {
        //        // Uh, oh!  User submitted a bitmap which has dimensions different from the
        //        // original dimensions!  Create a new texture!
        //        result = CreateTextureFromBitmap(gr, bitmap, fUseMipMaps);
        //        return (result);
        //    }

        //    // Okay, the supplied bitmap is compatible with the current texture dimensions.
        //    // Copy bitmap data to our already-allocated byte buffer.
        //    result = GLImage.FillInAllocatedRGBADataWithBitmapData(bitmap, fPixelData.Data);
        //    if (false == result)
        //    {
        //        return (false);
        //    }

        //    SubmitModifiedInternalRGBADataToTexture(gr);

        //    return (true);
        //}

        //public bool TransferOpenGLTextureDataBackToHostMemoryAndCopyToCompatibleBitmap(GraphicsInterface gr, Bitmap bitmap)
        //{
        //    if (null == fPixelData.Data)
        //    {
        //        return (false);
        //    }

        //    TransferTextureDataBackToHostMemory(gr);

        //    if (null == bitmap)
        //    {
        //        return (false);
        //    }

        //    if ((fPixelData.Width != bitmap.Width) || (fPixelData.Height != bitmap.Height))
        //    {
        //        // Uh, oh!  User submitted a bitmap which has dimensions different from the
        //        // texture dimensions!  Give up!
        //        return (false);
        //    }

        //    bool result = GLImage.CopyRGBABufferToCompatibleBitmap(fPixelData.Data, bitmap);

        //    return (result);
        //}


        //public void SubmitModifiedInternalRGBADataToTexture(GraphicsInterface gr)
        //{
        //    if (null == fPixelData.Data)
        //    {
        //        return;
        //    }

        //    // Make sure total bytes matches RGBA * width * height.
        //    int totalBytes = ((4 * fPixelData.Width) * fPixelData.Height);
        //    if (totalBytes != fPixelData.Data.Length)
        //    {
        //        return;
        //    }


        //    gl.glBindTexture(gl.GL_TEXTURE_2D, fTextureID);



        //    if (fUseMipMaps)
        //    {
        //        // Will this work?
        //        //glu.gluBuild2DMipmaps
        //        //(
        //        //    gl.GL_TEXTURE_2D,      // target                    
        //        //    gl.GL_RGBA,            // internalFormat
        //        //    fWidth,           // width
        //        //    fHeight,          // height
        //        //    gl.GL_RGBA,            // format
        //        //    gl.GL_UNSIGNED_BYTE,   // type
        //        //    fRGBAData         // data
        //        //);
        //    }
        //    else
        //    {
        //        gl.glTexSubImage2D
        //        (
        //            gl.GL_TEXTURE_2D,      // target
        //            0,                     // level
        //            0,                     // xoffset
        //            0,                     // yoffset
        //            fPixelData.Width,           // width
        //            fPixelData.Height,          // height
        //            gl.GL_RGBA,            // format
        //            gl.GL_UNSIGNED_BYTE,   // type
        //            fPixelData.Data         // pixels
        //        );
        //    }

        //}
        #endregion

        #region Static Methods
        public static GLTexture2D CreateTextureFromPixelData(GraphicsInterface gi, GLPixelData pixeldata, bool createMipMaps)
        {
            GLTexture2D tex = new GLTexture2D(gi, pixeldata, createMipMaps);

            return tex;
        }
Esempio n. 6
0
        //public void TransferTextureDataBackToHostMemory(GraphicsInterface gr)
        //{
        //    if (null == RGBAData)
        //    {
        //        return;
        //    }

        //    try
        //    {
        //        gl.glGetTexImage
        //          (
        //          gl.GL_TEXTURE_2D,     // target
        //          0,                    // level (0 == top-most mip-map level)
        //          gl.GL_RGBA,           // internalFormat
        //          gl.GL_UNSIGNED_BYTE,  // type
        //          RGBAData        // data
        //          );
        //    }
        //    catch
        //    {
        //    }
        //}

        public static GLTexture2D CreateCheckerboardTexture(GraphicsInterface gi, int width, int height, int blockSize)
        {
            int totalBytes = ((width * 4) * height);
            byte[] databytes = new byte[totalBytes];
            //bool useMipMaps = true;

            int x = 0;
            int y = 0;
            int k = 0;
            byte val = 0;

            for (y = 0; y < height; y++)
            {
                for (x = 0; x < width; x++)
                {
                    k = ((width * 4) * y) + (x * 4);

                    val = 0;
                    if (0 == (((x / blockSize) + (y / blockSize)) % 2))
                        val = 255;

                    databytes[k + 0] = val; // red
                    databytes[k + 1] = val; // green
                    databytes[k + 2] = val; // blue
                    databytes[k + 3] = 255; // opacity (255 == opaque)
                }
            }

            GLPixelData pixMap = new GLPixelData(width, height, TextureInternalFormat.Rgba8, PixelLayout.Rgba, PixelComponentType.UnsignedByte, databytes);
            GLTexture2D tex = new GLTexture2D(gi, pixMap, false);
            
            //GCHandle data_ptr = GCHandle.Alloc(databytes, GCHandleType.Pinned);
            //IntPtr fDataPtr = (IntPtr)data_ptr.AddrOfPinnedObject();
            //GLTexture2D tex = new GLTexture2D(gi, width, height, TextureInternalFormat.Rgba8, TexturePixelFormat.Rgba, PixelComponentType.UnsignedByte, fDataPtr, false);
            //data_ptr.Free();

            return tex;
        }
Esempio n. 7
0
        public static GLPixelData CreatePixelDataFromFile(string filename)
        {
            int tgaSize;

            // Open the file.
            if ((null == filename) || (string.Empty == filename))
                return null;

            FileStream filestream = new FileStream(filename, FileMode.Open, FileAccess.Read);
            BinaryReader reader = new BinaryReader(filestream);

            // Read the header.
            TargaHeader fHeader;
            fHeader.IDLength = reader.ReadByte();
            fHeader.ColorMapType = (TargaColorMapType)reader.ReadByte();
            fHeader.ImageType = (TargaImageType)reader.ReadByte();
            fHeader.CMapStart = reader.ReadInt16();
            fHeader.CMapLength = reader.ReadInt16();
            fHeader.CMapDepth = reader.ReadByte();
            fHeader.XOffset = reader.ReadInt16();
            fHeader.YOffset = reader.ReadInt16();
            fHeader.Width = reader.ReadInt16();
            fHeader.Height = reader.ReadInt16();
            fHeader.PixelDepth = reader.ReadByte();
            fHeader.ImageDescriptor = reader.ReadByte();


            int bytesPerPixel = fHeader.PixelDepth / 8;
            
            // This routine can only deal with the uncompressed image types.
            // So, fail if this is not the case.
            if ((TargaImageType.TrueColor != fHeader.ImageType) && (TargaImageType.Monochrome != fHeader.ImageType))
            {
                filestream.Close();
                return null;
            }

            //// calculate image size based on bytes per pixel, width and height.
            GLPixelFormat pFormat = GLPixelFormat.Bgr;
            TextureInternalFormat pIntFormat = TextureInternalFormat.Rgb8;

            switch (bytesPerPixel)
            {
                case 3:
                    pFormat = GLPixelFormat.Bgr;
                    pIntFormat = TextureInternalFormat.Rgb8;
                    break;

                case 4:
                    pFormat = GLPixelFormat.Bgra;
                    pIntFormat = TextureInternalFormat.Rgba8;
                    break;

                case 1:
                    pFormat = GLPixelFormat.Luminance;
                    pIntFormat = TextureInternalFormat.Luminance8;
                    break;
            }

            tgaSize = fHeader.Width * fHeader.Height * bytesPerPixel;

            // Load the actual image data

            byte[] imageData = reader.ReadBytes((int)tgaSize);

            // For 32 bit Targa files, the alpha byte is set to zero.
            // So, we'll subtract from 255 and set that as the alpha value.
            //byte tempColor;
            if (bytesPerPixel == 4)
            {
                for (long index = 0; index < tgaSize; index += bytesPerPixel)
                {
                    //    tempColor = imageData[index];
                    //    imageData[index] = imageData[index + 2];
                    //    imageData[index + 2] = tempColor;
                    imageData[index + 3] = (byte)(255 - imageData[index + 3]);
                }
            }

            filestream.Close();

            GLPixelData pixeldata = new GLPixelData(fHeader.Width, fHeader.Height, pIntFormat, pFormat, PixelType.UnsignedByte, imageData);

            return pixeldata;
        }
Esempio n. 8
0
 public void ReadPixels(int x, int y, GLPixelData pixMap)
 {
     gl.glReadPixels(x, y, pixMap.Width, pixMap.Height, (int)pixMap.PixelFormat, (int)pixMap.PixelType, pixMap.Pixels);
     CheckException();
 }
Esempio n. 9
0
 public GLTexture2D(GraphicsInterface gi, GLPixelData pixeldata, bool createMipMaps)
     : this(gi, pixeldata.Width, pixeldata.Height, pixeldata.InternalFormat, (TexturePixelFormat)pixeldata.PixelFormat, pixeldata.PixelType, pixeldata.Pixels, createMipMaps)
 {
 }
Esempio n. 10
0
 public virtual void AssignTexelData(GLPixelData pixData)
 {
 }