public void RenderSubImage(GLBitmap bmp, float[] srcDestList, float scale) { SetCurrent(); CheckViewMatrix(); //------------------------------------------------------------------------------------- // Bind the texture... GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, bmp.GetServerTextureId()); // Set the texture sampler to texture unit to 0 s_texture.SetValue(0); OnSetVarsBeforeRenderer(); int j = srcDestList.Length; for (int i = 0; i < j;) { float srcLeft = srcDestList[i]; float srcTop = srcDestList[i + 1]; float srcW = srcDestList[i + 2]; float srcH = srcDestList[i + 3]; float targetLeft = srcDestList[i + 4]; float targetTop = srcDestList[i + 5]; i += 6; //------------------------------- float srcBottom = srcTop - srcH; float srcRight = srcLeft + srcW; float orgBmpW = bmp.Width; float orgBmpH = bmp.Height; unsafe { float *imgVertices = stackalloc float[5 * 4]; { imgVertices[0] = targetLeft; imgVertices[1] = targetTop; imgVertices[2] = 0; //coord 0 imgVertices[3] = srcLeft / orgBmpW; imgVertices[4] = srcBottom / orgBmpH; //texture coord 0 //--------------------- imgVertices[5] = targetLeft; imgVertices[6] = targetTop - (srcH * scale); imgVertices[7] = 0; //coord 1 imgVertices[8] = srcLeft / orgBmpW; imgVertices[9] = srcTop / orgBmpH; //texture coord 1 //--------------------- imgVertices[10] = targetLeft + (srcW * scale); imgVertices[11] = targetTop; imgVertices[12] = 0; //coord 2 imgVertices[13] = srcRight / orgBmpW; imgVertices[14] = srcBottom / orgBmpH; //texture coord 2 //--------------------- imgVertices[15] = targetLeft + (srcW * scale); imgVertices[16] = targetTop - (srcH * scale); imgVertices[17] = 0; //coord 3 imgVertices[18] = srcRight / orgBmpW; imgVertices[19] = srcTop / orgBmpH; //texture coord 3 }; a_position.UnsafeLoadMixedV3f(imgVertices, 5); a_texCoord.UnsafeLoadMixedV2f(imgVertices + 3, 5); } GL.DrawElements(BeginMode.TriangleStrip, 4, DrawElementsType.UnsignedShort, indices); } }
protected override void OnGLRender(object sender, EventArgs args) { //------------------------------------------------------------------------------------------------ float[] vertices = { 50,100f, //2d coord 1, 0, 0, 0.5f, //r 200f,100f, //2d coord 0, 1, 0, 0.5f, //g 150f,200, //2d corrd 0, 0, 1, 0.5f, //b }; //--------------------------------------------------------- GL.Clear(ClearBufferMask.ColorBufferBit); shaderProgram.UseProgram(); //--------------------------------------------------------- u_matrix.SetData(orthoView.data); //--------------------------------------------------------- //triangle shape //x,y,r,g,b,a u_useSolidColor.SetValue(0); unsafe { fixed(float *head = &vertices[0]) { a_position.UnsafeLoadMixedV2f(head, 5); a_color.UnsafeLoadMixedV3f(head + 3, 5); } } GL.DrawArrays(BeginMode.Triangles, 0, 6); //--------------------------------------------------------- //rect shape //float[] quadVertices3 = CreateRectCoords(250f, 450f, 100f, 100f); //FillPolygonWithSolidColor(quadVertices3, 6, PixelFarm.Drawing.Color.Red); //float[] quadVertices2 = CreateRectCoords(250f, 450f, 100f, 100f); float[] quadVertices2 = CreateRectCoords(260f, 160f, 100f, 100f); float[] textureCoords = CreateRectTextureCoords(); //FillPolygonWithSolidColor2(quadVertices2, textureCoords, 6, PixelFarm.Drawing.Color.Blue); FillPolygonWithSolidColor(quadVertices2, 6, PixelFarm.Drawing.Color.Blue); //--------------------------------------------------------- float[] quadVertices3 = CreateRectCoords(280f, 180f, 100f, 100f); float[] textureCoords3 = CreateRectTextureCoords(); FillPolygonWithSolidColor2(quadVertices3, textureCoords3, 6, PixelFarm.Drawing.Color.Blue); //--------------------------------------------------------- float[] quadVertices = CreateRectCoords(250f, 150f, 100f, 100f); FillPolygonWithSolidColor(quadVertices, 6, PixelFarm.Drawing.Color.Yellow); //--------------------------------------------------------- // DrawLines(0, 0, 300, 300); //--------------------------------------------------------- SwapBuffers(); }
internal unsafe void UnsafeDrawSubImages(float *srcDestList, int arrLen, float scale) { //------------------------------------------------------------------------------------- SetVarsBeforeRender(); //------------------------------------------------------------------------------------- float orgBmpW = _latestBmpW; float orgBmpH = _latestBmpH; for (int i = 0; i < arrLen;) { float srcLeft = srcDestList[i]; float srcTop = srcDestList[i + 1]; float srcW = srcDestList[i + 2]; float srcH = srcDestList[i + 3]; float targetLeft = srcDestList[i + 4]; float targetTop = srcDestList[i + 5]; i += 6;//*** //------------------------------- float srcBottom = srcTop + srcH; float srcRight = srcLeft + srcW; unsafe { if (!_latestBmpYFlipped) { float *imgVertices = stackalloc float[5 * 4]; { imgVertices[0] = targetLeft; imgVertices[1] = targetTop; imgVertices[2] = 0; //coord 0 (left,top) imgVertices[3] = srcLeft / orgBmpW; imgVertices[4] = srcBottom / orgBmpH; //texture coord 0 (left,bottom) //--------------------- imgVertices[5] = targetLeft; imgVertices[6] = targetTop - (srcH * scale); imgVertices[7] = 0; //coord 1 (left,bottom) imgVertices[8] = srcLeft / orgBmpW; imgVertices[9] = srcTop / orgBmpH; //texture coord 1 (left,top) //--------------------- imgVertices[10] = targetLeft + (srcW * scale); imgVertices[11] = targetTop; imgVertices[12] = 0; //coord 2 (right,top) imgVertices[13] = srcRight / orgBmpW; imgVertices[14] = srcBottom / orgBmpH; //texture coord 2 (right,bottom) //--------------------- imgVertices[15] = targetLeft + (srcW * scale); imgVertices[16] = targetTop - (srcH * scale); imgVertices[17] = 0; //coord 3 (right, bottom) imgVertices[18] = srcRight / orgBmpW; imgVertices[19] = srcTop / orgBmpH; //texture coord 3 (right,top) } a_position.UnsafeLoadMixedV3f(imgVertices, 5); a_texCoord.UnsafeLoadMixedV2f(imgVertices + 3, 5); } else { float *imgVertices = stackalloc float[5 * 4]; { imgVertices[0] = targetLeft; /**/ imgVertices[1] = targetTop; /**/ imgVertices[2] = 0; //coord 0 (left,top) imgVertices[3] = srcLeft / orgBmpW; /**/ imgVertices[4] = srcTop / orgBmpH; /**/ //texture coord 0 (left,top) //--------------------- imgVertices[5] = targetLeft; /**/ imgVertices[6] = targetTop - (srcH * scale); /**/ imgVertices[7] = 0; //coord 1 (left,bottom) imgVertices[8] = srcLeft / orgBmpW; /**/ imgVertices[9] = srcBottom / orgBmpH; /**/ //texture coord 1 (left,bottom) //--------------------- imgVertices[10] = targetLeft + (srcW * scale); /**/ imgVertices[11] = targetTop; /**/ imgVertices[12] = 0; //coord 2 (right,top) imgVertices[13] = srcRight / orgBmpW; /**/ imgVertices[14] = srcTop / orgBmpH; //texture coord 2 (right,top) //--------------------- imgVertices[15] = targetLeft + (srcW * scale); /**/ imgVertices[16] = targetTop - (srcH * scale); /**/ imgVertices[17] = 0; //coord 3 (right, bottom) imgVertices[18] = srcRight / orgBmpW; /**/ imgVertices[19] = srcBottom / orgBmpH; //texture coord 3 (right,bottom) } a_position.UnsafeLoadMixedV3f(imgVertices, 5); a_texCoord.UnsafeLoadMixedV2f(imgVertices + 3, 5); } } GL.DrawElements(BeginMode.TriangleStrip, 4, DrawElementsType.UnsignedShort, indices); } }