This is a BareBone version of the AeroGL, to let you check what is going on.
This version uses 0% CPU on my Dual Core 2 runnning VISTA Premium with NVIDIA GeForce Go 7600
It seems that the Windows Layered API is very CPU intensive, this is the reason why most of the layered window (Destop icons for example, or drag and drop) are using only small size.
Anyway to make your own test, in the source code, play with these parameters:
%FRAME_SizeX = 200 '// The animation frame width
%FRAME_SizeY = 200 '// The animation frame height
%TIMER_DELAY = 50 '// The timer delay (animation speed)
Also notice the changes i have done to the SetImage subroutine to focus only on the OpenGL drawing
SUB SetImage(BYVAL hWnd AS LONG)
LOCAL graphics, DesktopDC, Img, imgW, imgH, ImgAttr, x, y AS LONG
LOCAL rw AS RECT
LOCAL bf AS BLENDFUNCTION
LOCAL lp, ptSrc AS POINTAPI
LOCAL lpSize AS SIZEL
STATIC xMove3, FlipMove3 AS LONG
CALL GetWindowRect(hWnd, rw)
lpSize.Cx = rw.nRight - rw.nLeft: lpSize.Cy = rw.nBottom - rw.nTop
lp.X = rw.nLeft: lp.Y = rw.nTop
DesktopDC = GetDC(0)
'// Draw active frame to new memory DC
IF ghBmp = 0 THEN
ghMemDC = CreateCompatibleDC(DesktopDC)
ghBmp = zCreateDIBSection(DesktopDC, lpSize.Cx, lpSize.CY, 32)
CALL SelectObject(ghMemDC, ghBmp)
END IF
' // Draw the OpenGL scene
CALL DrawTheScene()
CALL wglMakeCurrent(hGLDC, hGLRC)
CALL wglSwapBuffers(hGLDC)
CALL DrawAndSetupAlphaChannel(ghMemDC, 0, 0)
' // Update the layered window
bf.BlendOp = %AC_SRC_OVER
bf.BlendFlags = 0
bf.AlphaFormat = %AC_SRC_ALPHA '// Use source alpha
bf.SourceConstantAlpha = 255 '//alpha
CALL UpdateLayeredWindow (hWnd, DesktopDC, lp, lpSize, ghMemDC, ptSrc, 0, bf, %ULW_ALPHA)
CALL ReleaseDC(0, DesktopDC)
END SUB
Note: This version uses alphablending and culing mode.
Added:
Possible enhancement to play with opacity
SUB DrawAndSetupAlphaChannel(BYVAL hMemDC AS LONG, BYVAL x AS LONG, BYVAL y AS LONG)
' // We must do this to be compatible with BitBlt
' // We compute a fake alpha channel based on color conversion to shade of gray
LOCAL pBits AS BYTE PTR, bm AS BITMAP, P AS LONG
CALL GetObject(GetCurrentObject(hGLDC, 7), SIZEOF(bm), bm)
pBits = bm.bmBits
FOR P = (bm.bmWidth * bm.bmHeight) TO 1 STEP - 1
Alpha& = Rgb2Gray(RGB(@pBits[2],@pBits[1],@pBits[0])) AND &H000000FF???
'@pBits[3] = MIN&(Alpha& * 255, 255)
IF Alpha& = 0 THEN
@pBits[3] = 0
ELSE
@pBits[3] = 200
END IF
pBits = pBits + 4
NEXT
CALL BitBlt(hMemDC, x, y, bm.bmWidth, bm.bmHeight, hGLDC, 0, 0, %SRCCOPY)
END SUB
...