Esempio n. 1
0
        public void UpdateParticles(SpriteSurface s, List <AnimationParticle> l)
        {
            if (l.Count == 0)
            {
                s.NumElements = 0;
                s.Disabled    = true;
                return;
            }
            GL.BindBuffer(BufferTarget.ArrayBuffer, s.ArrayBufferID);
            int count = l.Count;

            s.NumElements = count * 6;
            List <float> all_values = new List <float>(4 * s.TotalVertexAttribSize * count);

            int[] indices = new int[s.NumElements];
            for (int i = 0; i < count; ++i)
            {
                float   tex_start_h = s.SpriteHeight * (float)l[i].sprite_pixel_row;
                float   tex_start_w = s.SpriteWidth * (float)l[i].sprite_pixel_col;
                float   tex_end_h   = tex_start_h + s.SpriteHeight * (float)l[i].sprite_h;
                float   tex_end_w   = tex_start_w + s.SpriteWidth * (float)l[i].sprite_w;
                float   flipped_row = (float)(s.Rows - 1) - l[i].row;
                float   col         = l[i].col;
                float   fi          = screen_multiplier_h * ((flipped_row / s.HeightScale) + s.GLCoordHeightOffset);
                float   fj          = screen_multiplier_w * ((col / s.WidthScale) + s.GLCoordWidthOffset);
                float   fi_plus1    = screen_multiplier_h * (((flipped_row + ((float)l[i].sprite_h / (float)s.TileHeight)) / s.HeightScale) + s.GLCoordHeightOffset);
                float   fj_plus1    = screen_multiplier_w * (((col + ((float)l[i].sprite_w / (float)s.TileWidth)) / s.WidthScale) + s.GLCoordWidthOffset);
                float[] values      = new float[4 * s.TotalVertexAttribSize];
                values[0] = fj;
                values[1] = fi;
                values[2] = tex_start_w;
                values[3] = tex_end_h;
                values[s.TotalVertexAttribSize]         = fj;
                values[1 + s.TotalVertexAttribSize]     = fi_plus1;
                values[2 + s.TotalVertexAttribSize]     = tex_start_w;
                values[3 + s.TotalVertexAttribSize]     = tex_start_h;
                values[s.TotalVertexAttribSize * 2]     = fj_plus1;
                values[1 + s.TotalVertexAttribSize * 2] = fi_plus1;
                values[2 + s.TotalVertexAttribSize * 2] = tex_end_w;
                values[3 + s.TotalVertexAttribSize * 2] = tex_start_h;
                values[s.TotalVertexAttribSize * 3]     = fj_plus1;
                values[1 + s.TotalVertexAttribSize * 3] = fi;
                values[2 + s.TotalVertexAttribSize * 3] = tex_end_w;
                values[3 + s.TotalVertexAttribSize * 3] = tex_end_h;
                int total_of_previous_attribs = 4;
                int k = 0;
                foreach (float attrib in l[i].primary_color.GetFloatValues())
                {
                    values[total_of_previous_attribs + k] = attrib;
                    values[total_of_previous_attribs + k + s.TotalVertexAttribSize]       = attrib;
                    values[total_of_previous_attribs + k + (s.TotalVertexAttribSize * 2)] = attrib;
                    values[total_of_previous_attribs + k + (s.TotalVertexAttribSize * 3)] = attrib;
                    ++k;
                }
                total_of_previous_attribs += 4;
                k = 0;
                foreach (float attrib in l[i].secondary_color.GetFloatValues())
                {
                    values[total_of_previous_attribs + k] = attrib;
                    values[total_of_previous_attribs + k + s.TotalVertexAttribSize]       = attrib;
                    values[total_of_previous_attribs + k + (s.TotalVertexAttribSize * 2)] = attrib;
                    values[total_of_previous_attribs + k + (s.TotalVertexAttribSize * 3)] = attrib;
                    ++k;
                }
                all_values.AddRange(values);
                int idx4 = i * 4;
                int idx6 = i * 6;
                indices[idx6]     = idx4;
                indices[idx6 + 1] = idx4 + 1;
                indices[idx6 + 2] = idx4 + 2;
                indices[idx6 + 3] = idx4;
                indices[idx6 + 4] = idx4 + 2;
                indices[idx6 + 5] = idx4 + 3;
            }
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeof(float) * 4 * s.TotalVertexAttribSize * count), all_values.ToArray(), BufferUsageHint.StreamDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, s.ElementArrayBufferID);
            GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(sizeof(int) * indices.Length), indices, BufferUsageHint.StreamDraw);
        }
 public void UpdateParticles(SpriteSurface s,List<AnimationParticle> l)
 {
     if(l.Count == 0){
         s.NumElements = 0;
         s.Disabled = true;
         return;
     }
     GL.BindBuffer(BufferTarget.ArrayBuffer,s.ArrayBufferID);
     int count = l.Count;
     s.NumElements = count * 6;
     List<float> all_values = new List<float>(4 * s.TotalVertexAttribSize * count);
     int[] indices = new int[s.NumElements];
     for(int i=0;i<count;++i){
         float tex_start_h = s.SpriteHeight * (float)l[i].sprite_pixel_row;
         float tex_start_w = s.SpriteWidth * (float)l[i].sprite_pixel_col;
         float tex_end_h = tex_start_h + s.SpriteHeight * (float)l[i].sprite_h;
         float tex_end_w = tex_start_w + s.SpriteWidth * (float)l[i].sprite_w;
         float flipped_row = (float)(s.Rows-1) - l[i].row;
         float col = l[i].col;
         float fi = screen_multiplier_h * ((flipped_row / s.HeightScale) + s.GLCoordHeightOffset);
         float fj = screen_multiplier_w * ((col / s.WidthScale) + s.GLCoordWidthOffset);
         float fi_plus1 = screen_multiplier_h * (((flipped_row+((float)l[i].sprite_h / (float)s.TileHeight)) / s.HeightScale) + s.GLCoordHeightOffset);
         float fj_plus1 = screen_multiplier_w * (((col+((float)l[i].sprite_w / (float)s.TileWidth)) / s.WidthScale) + s.GLCoordWidthOffset);
         float[] values = new float[4 * s.TotalVertexAttribSize];
         values[0] = fj;
         values[1] = fi;
         values[2] = tex_start_w;
         values[3] = tex_end_h;
         values[s.TotalVertexAttribSize] = fj;
         values[1 + s.TotalVertexAttribSize] = fi_plus1;
         values[2 + s.TotalVertexAttribSize] = tex_start_w;
         values[3 + s.TotalVertexAttribSize] = tex_start_h;
         values[s.TotalVertexAttribSize*2] = fj_plus1;
         values[1 + s.TotalVertexAttribSize*2] = fi_plus1;
         values[2 + s.TotalVertexAttribSize*2] = tex_end_w;
         values[3 + s.TotalVertexAttribSize*2] = tex_start_h;
         values[s.TotalVertexAttribSize*3] = fj_plus1;
         values[1 + s.TotalVertexAttribSize*3] = fi;
         values[2 + s.TotalVertexAttribSize*3] = tex_end_w;
         values[3 + s.TotalVertexAttribSize*3] = tex_end_h;
         int total_of_previous_attribs = 4;
         int k=0;
         foreach(float attrib in l[i].primary_color.GetFloatValues()){
             values[total_of_previous_attribs+k] = attrib;
             values[total_of_previous_attribs+k+s.TotalVertexAttribSize] = attrib;
             values[total_of_previous_attribs+k+(s.TotalVertexAttribSize*2)] = attrib;
             values[total_of_previous_attribs+k+(s.TotalVertexAttribSize*3)] = attrib;
             ++k;
         }
         total_of_previous_attribs += 4;
         k=0;
         foreach(float attrib in l[i].secondary_color.GetFloatValues()){
             values[total_of_previous_attribs+k] = attrib;
             values[total_of_previous_attribs+k+s.TotalVertexAttribSize] = attrib;
             values[total_of_previous_attribs+k+(s.TotalVertexAttribSize*2)] = attrib;
             values[total_of_previous_attribs+k+(s.TotalVertexAttribSize*3)] = attrib;
             ++k;
         }
         all_values.AddRange(values);
         int idx4 = i * 4;
         int idx6 = i * 6;
         indices[idx6] = idx4;
         indices[idx6 + 1] = idx4 + 1;
         indices[idx6 + 2] = idx4 + 2;
         indices[idx6 + 3] = idx4;
         indices[idx6 + 4] = idx4 + 2;
         indices[idx6 + 5] = idx4 + 3;
     }
     GL.BufferData(BufferTarget.ArrayBuffer,new IntPtr(sizeof(float)* 4 * s.TotalVertexAttribSize * count),all_values.ToArray(),BufferUsageHint.StreamDraw);
     GL.BindBuffer(BufferTarget.ElementArrayBuffer,s.ElementArrayBufferID);
     GL.BufferData(BufferTarget.ElementArrayBuffer,new IntPtr(sizeof(int)*indices.Length),indices,BufferUsageHint.StreamDraw);
 }
Esempio n. 3
0
        public void ChangeFont(int new_width)
        {
            if (new_width != cell_w)
            {
                string font       = "";
                float  previous_w = text_surface.SpriteWidthPadded;
                switch (new_width)
                {
                case 6:
                    font = "font6x12.bmp";
                    text_surface.SpriteWidthPadded = text_surface.SpriteWidth;
                    break;

                case 8:
                    font = "font8x16.bmp";
                    text_surface.SpriteWidthPadded = text_surface.SpriteWidth * 8.0f / 9.0f;
                    break;

                case 12:
                    font = "font12x24.bmp";
                    text_surface.SpriteWidthPadded = text_surface.SpriteWidth;
                    break;

                case 16:
                    font = "font16x32.bmp";
                    text_surface.SpriteWidthPadded = text_surface.SpriteWidth;
                    break;

                case 24:
                    font = "font12x24.bmp";
                    text_surface.SpriteWidthPadded = text_surface.SpriteWidth;
                    break;

                case 32:
                    font = "font16x32.bmp";
                    text_surface.SpriteWidthPadded = text_surface.SpriteWidth;
                    break;
                }
                cell_w                  = new_width;
                cell_h                  = new_width * 2;
                SnapHeight              = cell_h * CellRows;
                SnapWidth               = cell_w * CellCols;
                text_surface.TileWidth  = new_width;
                text_surface.TileHeight = new_width * 2;
                ReplaceTexture(text_surface.TextureIndex, font);
                float width_difference = text_surface.SpriteWidthPadded - previous_w;
                if (width_difference != 0.0f)
                {
                    SpriteSurface s = text_surface;
                    GL.BindBuffer(BufferTarget.ArrayBuffer, s.ArrayBufferID);
                    IntPtr vbo = GL.MapBuffer(BufferTarget.ArrayBuffer, BufferAccess.ReadWrite);
                    int    max = s.Rows * s.Cols * 4 * s.TotalVertexAttribSize;
                    for (int i = 0; i < max; i += s.TotalVertexAttribSize * 4)
                    {
                        int    offset = (i + 2 + s.TotalVertexAttribSize * 2) * 4;                    //4 bytes per float
                        byte[] bytes  = BitConverter.GetBytes(width_difference + BitConverter.ToSingle(new byte[] { Marshal.ReadByte(vbo, offset), Marshal.ReadByte(vbo, offset + 1), Marshal.ReadByte(vbo, offset + 2), Marshal.ReadByte(vbo, offset + 3) }, 0));
                        for (int j = 0; j < 4; ++j)
                        {
                            Marshal.WriteByte(vbo, offset + j, bytes[j]);
                        }
                        offset += s.TotalVertexAttribSize * 4;
                        bytes   = BitConverter.GetBytes(width_difference + BitConverter.ToSingle(new byte[] { Marshal.ReadByte(vbo, offset), Marshal.ReadByte(vbo, offset + 1), Marshal.ReadByte(vbo, offset + 2), Marshal.ReadByte(vbo, offset + 3) }, 0));
                        for (int j = 0; j < 4; ++j)
                        {
                            Marshal.WriteByte(vbo, offset + j, bytes[j]);
                        }
                    }
                    GL.UnmapBuffer(BufferTarget.ArrayBuffer);
                }
            }
        }
Esempio n. 4
0
 public static void UpdateSurface(int row,int col,SpriteSurface s,int sprite_row,int sprite_col,float r,float g,float b)
 {
     Game.gl.UpdateVertexArray(row,col,s,sprite_row,sprite_col,new float[][]{new float[]{r,g,b,1}});
 }