vaps RGB畫素顯示控制元件 (glTexSubImage2D方式)
阿新 • • 發佈:2018-12-15
1. 開啟 vxtPLDisplay 工程
修改 vxtPLImage.cpp,修改下面函式
void vxtPLImageContext_OpenGLTexture::SingleTexture::vDrawImage ( const vxtRRegion &a_rDest, const vxtColorRGBA &a_rColor ) const { VXT_START_PERFORMANCE_TIMER(pGetImageStat()); VXT_PRE(m_rContext.IsActive()); VXT_PRE( (VXT_RT_GEOMETRY_MIN <= a_rDest.Lt) && (a_rDest.Lt <= VXT_RT_GEOMETRY_MAX) ); VXT_PRE( (VXT_RT_GEOMETRY_MIN <= a_rDest.Rt) && (a_rDest.Rt <= VXT_RT_GEOMETRY_MAX) ); VXT_PRE( (VXT_RT_GEOMETRY_MIN <= a_rDest.Bm) && (a_rDest.Bm <= VXT_RT_GEOMETRY_MAX) ); VXT_PRE( (VXT_RT_GEOMETRY_MIN <= a_rDest.Tp) && (a_rDest.Tp <= VXT_RT_GEOMETRY_MAX) ); VXT_TRACE("vxtPLImage", "vDrawImage"); VXT_TRACE_RREGION("vxtPLImage", "a_rDest", a_rDest); VXT_TRACE_COLOR("vxtPLImage", "a_rColor", a_rColor); vxtPLGraphicsImpl &rGraphics = m_rContext.rGetActiveGraphics(); #if 1 memset(g_pMemRenderTarget, 0, 512 * 512 * 3); static int n = 0; int r, g, b; if (n < 3) { r = 255; g = 0; b = 0; } else if(n < 6) { r = 0; g = 255; b = 0; } else if(n < 9) { r = 0; g = 0; b = 255; } n++; if (n >= 9) n = 0; for (int i = 0; i < 512 * 512 * 3; i++) { if (i % 3 == 0) g_pMemRenderTarget[i] = r; else if (i % 3 == 1) g_pMemRenderTarget[i] = g; else if (i % 3 == 2) g_pMemRenderTarget[i] = b; } #endif if(rGraphics.IsTopMatrixValid()) // INLINE-BRANCH { vPrepareToDraw(); rGraphics.vDisablePattern(); // INLINE-BRANCH rGraphics.vSetColorRGBA(a_rColor); if (a_rColor.A == CREATE_VIDEO_IMAGE_1 && g_pMemRenderTarget != NULL) { vxtColorRGBA ImageColor = { a_rColor.R, a_rColor.G, a_rColor.B, 255 }; rGraphics.vSetColorRGBA(ImageColor); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, g_pMemRenderTarget); } glBegin(GL_TRIANGLE_FAN); glMultiTexCoord2f(GL_TEXTURE0, 0.0F, 0.0F); rGraphics.vVertex2f(a_rDest.Lt, a_rDest.Tp); //vertically-flipped glMultiTexCoord2f(GL_TEXTURE0, 0.0F, m_TexFactor.Y); rGraphics.vVertex2f(a_rDest.Lt, a_rDest.Bm); //vertically-flipped glMultiTexCoord2f(GL_TEXTURE0, m_TexFactor.X, m_TexFactor.Y); rGraphics.vVertex2f(a_rDest.Rt, a_rDest.Bm); //vertically-flipped glMultiTexCoord2f(GL_TEXTURE0, m_TexFactor.X, 0.0F); rGraphics.vVertex2f(a_rDest.Rt, a_rDest.Tp); //vertically-flipped glEnd(); } }
增加下面程式碼,在SingleTexture的建構函式和解構函式裡呼叫下面兩個函式
#define CREATE_VIDEO_IMAGE_1 50 unsigned char *g_pMemRenderTarget = NULL; HANDLE g_hMemRenderTarget = NULL; void CreateRenderTargetShareMemory(int size, TCHAR* name) { static bool bFirst = false; if(bFirst == true) return; g_hMemRenderTarget = CreateFileMapping((HANDLE)0xffffffffffffffff, NULL, PAGE_READWRITE, 0, size, name); g_pMemRenderTarget = (unsigned char *)MapViewOfFile(g_hMemRenderTarget, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); bFirst = true; } void FreeShareMemory() { static bool bFirst = false; if(bFirst == true) return; UnmapViewOfFile(g_pMemRenderTarget); CloseHandle(g_hMemRenderTarget); bFirst = true; }
2.開啟vxtCLImage工程,修改vxtCLImage.cpp
修改下面函式
void vxtClsImage::vDraw(vxtRTDrawMode & a_rMode) { #if VXT_CGRUNTIME_MODE VXT_PRE_GROBJECT_VDRAW_PARAM_PRECONDITION; VXT_PRE(IsVisible()); /// @pre This function must only be called from functions of ::vxtRTDrawMode. #endif if( 0 != mp_AlphaValue ) { vxtPLGraphics& rGraphics = a_rMode.rGetGraphics(); const vxtRTImage &rImage = mp_Index->rGetImage(); if(rImage.IsAllocated()) { vxtColorRGBA ImageColor = { VXT_MAX_PIXEL_LEVEL, VXT_MAX_PIXEL_LEVEL, VXT_MAX_PIXEL_LEVEL, mp_AlphaValue }; //-------------------------------------------------------------------- // Coding Standard Deviation: MISRA C++ 2008 6-2-2 // Description: Floating-point expressions shall not be directly or // indirectly tested for equality or inequality. // Rationale: Direct equality test is used as a fast way to single // out and optimize the most-used no-rotation case. //-------------------------------------------------------------------- // PRQA S 3270 1 if (0.0F == mp_RotationAngle) { vxtRCoord Point1 = {mp_Position.GetFieldX(), mp_Position.GetFieldY()}; // SCS.LAN.EXPR.ARITH.ERROR // DC1.RT.GENERAL.EXTENT_LIMIT.01 impose all graphics to be located // inside the maximum extent bounding box (+- VXT_RT_GEOMETRY_MAX), // therefore limiting the values of mp_Position and mp_Size to that range. // Adding two floats in that interval cannot overflow. vxtRCoord Point2 = {mp_Position.GetFieldX() + mp_Size.GetFieldX(), mp_Position.GetFieldY() + mp_Size.GetFieldY() }; rGraphics.vDrawImage(rImage, Point1, Point2, ImageColor); if(mp_AlphaValue == CREATE_VIDEO_IMAGE_1) vRequireUpdate(); } else { // General case of drawing a rotated image vxtRCoord Zero = { 0.0F, 0.0F}; vxtRCoord Size = { mp_Size.GetFieldX(), mp_Size.GetFieldY() }; rGraphics.vPushTrans(); rGraphics.vTranslate(mp_Position.GetFieldX(), mp_Position.GetFieldY()); rGraphics.vRotate(mp_RotationAngle); rGraphics.vDrawImage(rImage, Zero, Size, ImageColor); rGraphics.vPopTrans(); } } } }
void vxtClsImage::vUpdate(const vxtRTTopContext & a_rTopContext)
{
vFixSizeIfNeeded(a_rTopContext, VXT_FALSE);
if (mp_AlphaValue == CREATE_VIDEO_IMAGE_1)
vRequireDraw(a_rTopContext);
}
增加下面程式碼
#define CREATE_VIDEO_IMAGE_1 50
3. 用windows自帶的畫圖板隨便建立一張574*574的24位bmp圖片
修改vaps xt裡,image控制元件的預設圖片