' Window Extended Style
dwExStyle = %WS_EX_LAYERED OR %WS_EX_TOPMOST OR %WS_EX_TOOLWINDOW
' Windows Style, avoid using %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN with the Skin Engine
dwStyle = %WS_POPUP ' OR %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS
'
CALL SetRect(rc, 0, 0, %FRAME_SizeX, %FRAME_SizeY)
' // Note: indeed we don't need AdjustWindowRectEx, because we use do not use a non-client area
' // but it won't hurt anything to keep it, in case we change our mind ;)
CALL AdjustWindowRectEx(rc, dwStyle, %FALSE, dwExStyle) ' Adjust Window To True Requested Size
'
x = MAX&((GetSystemMetrics(%SM_CXSCREEN) - rc.nRight - rc.nLeft) \ 2, 0)
y = MAX&((GetSystemMetrics(%SM_CYSCREEN) - rc.nBottom - rc.nTop) \ 2, 0)
'
' Create The Window
MyTitle$ = "AeroGL"
hMain = CreateWindowEx(dwExStyle, _ ' Extended Style For The Window
zClass, _ ' Class Name
(MyTitle$), _ ' Window Title
dwStyle, _ ' Defined Window Style
x, y, _ ' Window Position
rc.nRight - rc.nLeft, _ ' Calculate Window Width
rc.nBottom - rc.nTop, _ ' Calculate Window Height
%NULL, _ ' No Parent Window
%NULL, _ ' No Menu
wc.hInstance, _ ' Instance
BYVAL %NULL) ' Dont Pass Anything To WM_CREATE
CALL SetTimer(hMain, 1, 50, %NULL)
WHILE GetMessage(Msg, %NULL, 0, 0)
CALL TranslateMessage(Msg)
CALL DispatchMessage(Msg)
WEND
CALL KillTimer(hMain, 1)
FUNCTION zSetupPixelFormat(BYVAL hDC AS LONG) AS LONG
LOCAL pfd AS PIXELFORMATDESCRIPTOR
LOCAL pixelformat AS LONG
LOCAL lRet AS LONG
lRet = %TRUE
pfd.nSize = SIZEOF(pfd)
pfd.nVersion = 1
pfd.dwFlags = %PFD_SUPPORT_OPENGL OR %PFD_DRAW_TO_BITMAP OR %PFD_SUPPORT_GDI
pfd.iPixelType = %PFD_TYPE_RGBA
pfd.cColorBits = 32
pfd.cDepthBits = 32
pixelformat = ChoosePixelFormat(hDC, pfd)
IF pixelformat THEN
IF SetPixelFormat(hDC, pixelformat, pfd) = 0 THEN lRet = %FALSE
ELSE
lRet = %FALSE
END IF
FUNCTION = lRet
END FUNCTION
FUNCTION CreateGLcontext(BYVAL nWidth AS LONG, BYVAL nHeight AS LONG, BYREF hGLDC AS LONG, BYREF hGLRC AS LONG) AS LONG
LOCAL nRet, DesktopDC, hGLBMP AS LONG
IF nWidth > 0 AND nHeight > 0 THEN
DesktopDC = GetDC(0)
hGLDC = CreateCompatibleDC(DesktopDC)
hGLBMP = zCreateDIBSection(DesktopDC, nWidth, nHeight, 32)
CALL SelectObject(hGLDC, hGLBMP)
CALL ReleaseDC(0, DesktopDC)
IF hGLBMP THEN
IF zSetupPixelFormat(hGLDC) THEN
hGLRC = wglCreateContext(hGLDC)
IF hGLRC THEN
IF wglMakeCurrent(hGLDC, hGLRC) THEN
CALL glClearColor(0.0, 0.0, 0.0, 0.0)
CALL glClearDepth(1.0)
CALL glDepthFunc(%GL_LESS)
CALL glEnable(%GL_DEPTH_TEST)
CALL glShadeModel(%GL_SMOOTH)
CALL glMatrixMode(%GL_PROJECTION)
CALL glViewport(0, 0, nWidth, nHeight)
CALL glEnable(%GL_TEXTURE_2D)
nRet = -1
END IF
END IF
END IF
END IF
END IF
FUNCTION = nRet
END FUNCTION
SUB SetImage(BYVAL hWnd AS LONG)
LOCAL DesktopDC, hMemDC, hBmp LONG
LOCAL rw AS RECT
LOCAL bf AS BLENDFUNCTION
LOCAL lp, ptSrc AS POINTAPI
LOCAL lpSize AS SIZEL
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
hMemDC = CreateCompatibleDC(DesktopDC)
hBmp = zCreateDIBSection(DesktopDC, lpSize.Cx, lpSize.CY, 32)
CALL SelectObject(hMemDC, hBmp)
' // Draw the OpenGL scene
CALL DrawTheScene()
CALL DrawAndSetupAlphaChannel(hMemDC, 60, 109)
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, hMemDC, ptSrc, 0, bf, %ULW_ALPHA)
CALL DeleteObject(hBmp)
CALL DeleteDC(hMemDC)
CALL ReleaseDC(0, DesktopDC)
END SUB
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 convertion 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)
pBits = pBits + 4
NEXT
CALL BitBlt(hMemDC, x, y, bm.bmWidth, bm.bmHeight, hGLDC, 0, 0, %SRCCOPY)
END SUB
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
QuoteI thought you left this idea but you just finished itIt was on my back burner :)
SUB SetImage(BYVAL hWnd AS LONG) LOCAL x, y, DIS_IC, ImgAttr AS LONG LOCAL rw AS RECT LOCAL bf AS BLENDFUNCTION LOCAL lp, ptSrc AS POINTAPI LOCAL lpSize AS SIZEL CALL GetWindowRect(hWnd, rw) lpSize.Cx = rw.nRight - rw.nLeft: lpSize.Cy = rw.nBottom - rw.nTop lp.X = rw.nLeft: lp.Y = rw.nTop ' // Draw the OpenGL scene CALL DrawTheScene() CALL wglMakeCurrent(hGLDC, hGLRC) ' CALL wglSwapBuffers(hGLDC) CALL SetupAlphaChannel(hGLDC) ' // Update the layered window bf.BlendOp = %AC_SRC_OVER bf.BlendFlags = 0 bf.AlphaFormat = %AC_SRC_ALPHA '// Use source alpha bf.SourceConstantAlpha = JH_AlphaLevel(0,0) '// Setup the alpha level DIS_IC = CreateIC("DISPLAY", BYVAL 0, BYVAL 0, BYVAL 0) CALL UpdateLayeredWindow (hWnd, DIS_IC, lp, lpSize, hGLDC, ptSrc, 0, bf, &H00000002) ' CALL DeleteDC(DIS_IC) CALL glFlush() END SUB |