Пример #1
0
 public static void UpdateTexture(TContext tr, Bitmap texImage)
 {
     Gl.glGenTextures(1, out tex);
     Gl.glBindTexture(Gl.GL_TEXTURE_2D, tex);
     Data        = texImage.LockBits(new Rectangle(0, 0, texImage.Width, texImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
     tr.TexImage = Data.Scan0;
     Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, texImage.Width, texImage.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, tr.TexImage);
     texImage.UnlockBits(Data);
     texImage.Dispose();
     Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
     Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
 }
Пример #2
0
 public static bool DrawTexture(TContext tr, TexCod texture)
 {
     tr.Texture = texture;
     ComputeTileRange(tr);
     // calculate tile statrting address
     tr.TileAdrs.X = texture.LLx / tr.TileWidth;
     tr.TileAdrs.Y = texture.LLy / tr.TileHeight;
     if (TileDraw(tr))
     {
         return((bool)true);
     }
     return(false);
 }
Пример #3
0
        private static bool TileDraw(TContext tr)
        {
            // choose tile lowleft coordinate

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, tex);
            Gl.glReadBuffer(Gl.GL_BACK);
            while (tr.TileRange.LLy <= tr.TileAdrs.Y && tr.TileAdrs.Y <= tr.TileRange.TRy)
            {
                while (tr.TileRange.LLx <= tr.TileAdrs.X && tr.TileAdrs.X <= tr.TileRange.TRx)
                {
                    // Console.WriteLine(tr.TileAdrs.ToString());
                    tr.LLTileCod.X = tr.TileAdrs.X * tr.TileWidth;
                    tr.LLTileCod.Y = tr.TileAdrs.Y * tr.TileHeight;
                    tr.TRTileCod.X = tr.LLTileCod.X + tr.TileWidth - 1;
                    tr.TRTileCod.Y = tr.LLTileCod.Y + tr.TileHeight - 1;
                    // overalpping coorfinate
                    tr.OverlapLL = CalOverlap(tr.LLTileCod, tr.Texture);
                    tr.OverlapTR = CalOverlap(tr.TRTileCod, tr.Texture);
                    //  Console.WriteLine("overlap " + tr.OverlapLL.ToString() +"*"+ tr.OverlapTR.ToString());

                    // calulate texmap coordinate
                    CalTexMap(tr);
                    //  Console.WriteLine(tr.TexMapCod.ToString());
                    // re- calculate overlap as per rendering viewport
                    RecalView(tr);
                    //  Console.WriteLine("viewport " + tr.OverlapLL.ToString() + "*" + tr.OverlapTR.ToString());

                    TileRender(tr);
                    // reading into PBO genrated before
                    Gl.glPixelStorei(Gl.GL_PACK_ROW_LENGTH, tr.CanvWidth);
                    Gl.glPixelStorei(Gl.GL_PACK_SKIP_ROWS, tr.TileAdrs.Y * tr.TileHeight);
                    Gl.glPixelStorei(Gl.GL_PACK_SKIP_PIXELS, tr.TileAdrs.X * tr.TileWidth);
                    Gl.glReadPixels(0, 0, tr.TileWidth, tr.TileWidth, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, IntPtr.Zero);
                    // choose the next tile to be rendered
                    // shift right
                    tr.TileAdrs.X = tr.TileAdrs.X + 1;
                }

                tr.TileAdrs.X = tr.TileRange.LLx;
                tr.TileAdrs.Y = tr.TileAdrs.Y + 1;
            }


            Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
            return((bool)true);
        }
Пример #4
0
        public static void TileRender(TContext tr) // render and store
        {
            Gl.glClearColor(0f, 0f, 0f, 0f);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glViewport(0, 0, tr.TileWidth, tr.TileHeight);
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBegin(Gl.GL_QUADS);

            x0 = Utility.Map((float)tr.OverlapLL.X, 0f, (float)tr.TileWidth, -1f, 1f);
            y0 = Utility.Map((float)tr.OverlapLL.Y, 0f, (float)tr.TileHeight, -1f, 1f);
            x1 = Utility.Map((float)tr.OverlapTR.X, 0f, (float)tr.TileWidth, -1f, 1f);
            y1 = Utility.Map((float)tr.OverlapTR.Y, 0f, (float)tr.TileHeight, -1f, 1f);
            Gl.glTexCoord2f(tr.TexMapCod.X0, tr.TexMapCod.Y0); Gl.glVertex2f(x0, y1);
            Gl.glTexCoord2f(tr.TexMapCod.X0, tr.TexMapCod.Y1); Gl.glVertex2f(x0, y0);
            Gl.glTexCoord2f(tr.TexMapCod.X1, tr.TexMapCod.Y1); Gl.glVertex2f(x1, y0);
            Gl.glTexCoord2f(tr.TexMapCod.X1, tr.TexMapCod.Y0); Gl.glVertex2f(x1, y1);
            Gl.glEnd();

            Gl.glFlush();
        }
Пример #5
0
 public static void Setup(TContext tr, int canvasW, int canvasH, int tileWidth, int tileHeight)
 {
     tr.CanvWidth = canvasW; tr.CanvHeight = canvasH;
     tr.TileWidth = tileWidth; tr.TileHeight = tileHeight;
 }