The MASM Forum

General => The Campus => Topic started by: mabdelouahab on January 03, 2014, 12:33:50 PM

Title: OpenGL
Post by: mabdelouahab on January 03, 2014, 12:33:50 PM
Hello everyone
The members of the Forum helped me To find
a solution to the problem of transparency with GDIPLUS in :http://masm32.com/board/index.php?topic=2513.msg26303#msg26303
I express my thanks to all members of the forum to provide assistance

so
I want to do the same job but with OpenGL
I found some of the ideas in

      http://users.freebasic-portal.de/volta/window9/Beispiele_7.html
      http://www.codeproject.com/Tips/141076/Transparent-OpenGL-window
      http://www.rsdn.ru/article/opengl/layeredopengl.xml

Can anyone help me in converting The idea to MASM32, Because I failed to do this
thanks ...

(http://www.rsdn.ru/article/opengl/layeredopengl%5Ctransp_teapot.PNG)
Title: Re: OpenGL
Post by: Farabi on January 03, 2014, 08:51:23 PM
Transparency on OpenGL can be done by enabling the GL_MATERIAL_COLOR and using glColor4f where you set the transparency value to the alpha value. The problem on OpenGL is, the transparent vertex should be drawn last after all vertex is drawn.
Title: Re: OpenGL
Post by: mabdelouahab on January 03, 2014, 10:21:54 PM
Quote from: Farabi on January 03, 2014, 08:51:23 PM
Transparency on OpenGL can be done by enabling the GL_MATERIAL_COLOR and using glColor4f where you set the transparency value to the alpha value. The problem on OpenGL is, the transparent vertex should be drawn last after all vertex is drawn.
Hy Farabi
I use ( glEnable, GL_BLEND)+(glBlendFunc) and (glColor4b) for transparency

(http://drive.google.com/uc?export=view&id=0B5q3H3sB5u6QamFxYXduNjJsVTA) 


        invoke  glLoadIdentity
        invoke glEnable, GL_BLEND
        invoke glDisable, GL_DEPTH_TEST
    invoke  glBegin,GL_POLYGON
    invoke glBlendFunc,GL_SRC_ALPHA, GL_ZERO
invoke  glColor4b,CA_,0,127,CA_
    invoke  glVertex3f,0,3f800000h,0c0800000h
invoke  glColor4b,127,127,0,CB_
invoke  glVertex3f,0bf800000h,0,0c0800000h
invoke  glColor4b,127,0,127,CC_
invoke  glVertex3f,3f800000h,0,0c0800000h
    invoke  glEnd
    invoke  glBegin,GL_POLYGON
invoke glBlendFunc,GL_SRC_ALPHA, GL_ONE
invoke  glColor4b,0,0,127,CC_
    invoke  glVertex3f,0,0,0c0800000h
invoke  glColor4b,127,0,0,CA_
invoke  glVertex3f,3f800000h,3f000000h,0c0800000h
invoke  glColor4b,0,127,0,CB_
invoke  glVertex3f,0bf800000h,3f000000h,0c0800000h
    invoke  glEnd
    invoke  SwapBuffers,MainHDC


But I'm looking for transparency in the background with Desktop
For example (But this is by GDIPLUS)


(http://drive.google.com/uc?export=view&id=0B5q3H3sB5u6QNUxpRXk1aU15N3c)
Title: Re: OpenGL
Post by: qWord on January 03, 2014, 11:20:09 PM
The layered window is still descried through a memory DC thus you only need to replace the GDI+ stuff with OGL (something like SetPixelFormat,hMemDC,...). For per-pixel alpha values, the DC must be filled with premultiplied ARGB (http://msdn.microsoft.com/en-us/library/windows/desktop/dd183393%28v=vs.85%29.aspx) values (probably glBlendFunc (http://msdn.microsoft.com/en-us/library/windows/desktop/dd318368%28v=vs.85%29.aspx)(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)).
Title: Re: OpenGL
Post by: mabdelouahab on January 04, 2014, 09:38:06 AM
Remained half the work  :redface:
Title: Re: OpenGL
Post by: dedndave on January 05, 2014, 05:06:58 AM
ok - i see 1 thing that is about the program, in general

i removed these lines
.386
.387
.model flat,stdcall
option casemap:none


and i replaced this line
include masm32rt.inc

with this line
include \masm32\include\masm32rt.inc

as for the layered window, i found 2 problems
1) you should call SetLayeredWindowAttributes BEFORE initializing OpenGL, not AFTER
        .ELSEIF uMsg==WM_CREATE
                invoke SetLayeredWindowAttributes,hWnd,0,0,LWA_COLORKEY
                invoke InitGl,hWnd
     ;           invoke SetLayeredWindowAttributes,hWnd, 0, 0,LWA_COLORKEY


2) you should not call glClearColor between glBegin and glEnd
in fact, you only need to call it once during InitGl

remove this line in the DrawScene PROC
    ;    invoke glClearColor, FP4(0.0),FP4(0.0),FP4(0.0),FP4(0.0)

and add it to the InitGl PROC
        invoke glEnable, GL_DEPTH_TEST

        invoke glClearColor,FP4(0.0),FP4(0.0),FP4(0.0),FP4(0.0)

NoPixelFmt:
        xor eax,eax
        ret


(http://img35.imageshack.us/img35/3566/b14w.png)
Title: Re: OpenGL
Post by: dedndave on January 05, 2014, 05:14:57 AM
when the program is first executed, a white background flashes before the image shows up
so, you may want to call glClearColor earlier in the InitGl proc
and - you may have to change the order some other things are executed in InitGl, as well

i'll let you play with that   :P