Is creating an opengl gadget with a transparent background allowing objects behind to be visible possible?

Everything related to 3D programming
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

Is creating an opengl gadget with a transparent background allowing objects behind to be visible possible?

Post by skinkairewalker »

Hello guys, currently I would like to know if it is possible to create an opengl gadget, however, with a transparent background so that objects behind are visible. I would like to integrate the SteamWorks SDK with purebasic...
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

Re: Is creating an opengl gadget with a transparent background allowing objects behind to be visible possible?

Post by minimy »

Hello skinkairewalker, may be this work if background color is RGB(255,0,0)
Not tested.

Interesting use steam sdk with PB for games. Tell me more please if you create the code.
Have nice day!

Code: Select all

OpenWindow(0,0,0,500,400,"Window",#PB_Window_SystemMenu)
ButtonGadget(1,10,10,100,20,"Button",0)

SetWindowColor(0,RGB(255,0,0))
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
SetLayeredWindowAttributes_(WindowID(0),RGB(255,0,0),0,#LWA_COLORKEY)

Repeat
  EventID=WaitWindowEvent()
  If EventID=#PB_Event_Gadget
    Select EventGadget()
      Case 1
        Break
    EndSelect
  EndIf
  If EventID = #PB_Event_CloseWindow
    Break
  EndIf
ForEver

End

If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

Re: Is creating an opengl gadget with a transparent background allowing objects behind to be visible possible?

Post by minimy »

Hello again, tested with example included in pb like work... hehe
But need use 2 windows, one for background and the other for transparent foreground.
I know is a bad trick but work.
In fullscreen mode maybe work good. :mrgreen:


Code: Select all

Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f = 1.0
Global RotateSpeedY.f
Global RotateSpeedZ.f = 1.0

Global ZoomFactor.f = 1.0 ; Distance of the camera. Negative value = zoom back

Procedure DrawCube(Gadget)
  SetGadgetAttribute(Gadget, #PB_OpenGL_SetContext, #True)
  
  glPushMatrix_()                  ; Save the original Matrix coordinates
  glMatrixMode_(#GL_MODELVIEW)

  glTranslatef_(0, 0, ZoomFactor)  ;  move it forward a bit

  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
 
  RollAxisX + RotateSpeedX
  RollAxisY + RotateSpeedY
  RollAxisZ + RotateSpeedZ

  ; clear framebuffer And depth-buffer

  glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)

  ; draw the faces of a cube
  
  ; draw colored faces

  glDisable_(#GL_LIGHTING)
  glBegin_  (#GL_QUADS)
  
  ; Build a face, composed of 4 vertex !
  ; glBegin() specify how the vertexes are considered. Here a group of
  ; 4 vertexes (GL_QUADS) form a rectangular surface.

  ; Now, the color stuff: It's r,v,b but with float values which
  ; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity)
  
  glNormal3f_ (0,0,1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (0.5,0.5,0.5)
  glColor3f_  (0,1.0,1.0)
  glVertex3f_ (-0.5,0.5,0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (-0.5,-0.5,0.5)
  glColor3f_  (0,0,0)
  glVertex3f_ (0.5,-0.5,0.5)

  ; The other face is the same than the previous one
  ; except the colour which is nice blue To white gradiant

  glNormal3f_ (0,0,-1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,0.5,-0.5)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (0.5,0.5,-0.5)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (0.5,-0.5,-0.5)
  
  glEnd_()
  
  ; draw shaded faces

  glEnable_(#GL_LIGHTING)
  glEnable_(#GL_LIGHT0)
  glBegin_ (#GL_QUADS)

  glNormal3f_ (   0, 1.0,   0)
  glVertex3f_ ( 0.5, 0.5, 0.5)
  glVertex3f_ ( 0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)

  glNormal3f_ (0,-1.0,0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (-0.5,-0.5,0.5)

  glNormal3f_ (1.0,0,0)
  glVertex3f_ (0.5,0.5,0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,0.5,-0.5)

  glNormal3f_ (-1.0,   0,   0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (-0.5,-0.5, 0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)

  glEnd_()

  glPopMatrix_()
  glFinish_()

  SetGadgetAttribute(Gadget, #PB_OpenGL_FlipBuffers, #True)
EndProcedure


Procedure SetupGL()
    
  glMatrixMode_(#GL_PROJECTION)
  gluPerspective_(30.0, 200/200, 1.0, 10.0)
  
  ; position viewer
  glMatrixMode_(#GL_MODELVIEW)
  
  glTranslatef_(0, 0, -5.0)
  
  glEnable_(#GL_DEPTH_TEST)   ; Enabled, it slowdown a lot the rendering. It's to be sure than the
                              ; rendered objects are inside the z-buffer.
  
  glEnable_(#GL_CULL_FACE)    ; This will enhance the rendering speed as all the back face will be
                              ; ignored. This works only with CLOSED objects like a cube... Singles
                              ; planes surfaces will be visibles only on one side.
    
  glShadeModel_(#GL_SMOOTH)
EndProcedure


Procedure HandleError (Result, Text$)
  If Result = 0
    MessageRequester("Error", Text$, 0)
    End
  EndIf
EndProcedure

OpenWindow(0, 0, 0, 530, 320, "OpenGL Gadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,RGB(0,0,255))
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
SetLayeredWindowAttributes_(WindowID(0),RGB(0,0,255),0,#LWA_COLORKEY)


OpenGLGadget(0, 10, 10, 200, 200)
SetupGL()

OpenGLGadget(1, 220, 10, 300, 300)
SetupGL()

SetGadgetColor(1,#PB_Gadget_BackColor,$ff0000)

AddWindowTimer(0, 1, 16) ; about 60 fps

Repeat
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Timer
      If EventTimer() = 1
        DrawCube(0)
        DrawCube(1)
      EndIf
  EndSelect
  
Until Event = #PB_Event_CloseWindow

If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

Re: Is creating an opengl gadget with a transparent background allowing objects behind to be visible possible?

Post by skinkairewalker »

wooow, awesome !!!!
opengl is really interesting xD
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 627
Joined: Fri Dec 04, 2015 9:26 pm

Re: Is creating an opengl gadget with a transparent background allowing objects behind to be visible possible?

Post by skinkairewalker »

using this concept as a base, then you can actually create a layer using opengl to render the "steamOverlay", and then the content remains...
Patrice Terrier
User
User
Posts: 21
Joined: Sun Aug 10, 2003 11:45 am
Location: France
Contact:

Re: Is creating an opengl gadget with a transparent background allowing objects behind to be visible possible?

Post by Patrice Terrier »

The best solution is to work in DWM composited mode (using the DirectDraw surface).

Here is a video showing a Win32 application working in full composited mode.
http://www.objreader.com/download/video/Mbox64.webm

The GUI interface is using the WinLIFT64.dll, and the GDImage64.dll.

The other solution is to use the UpdateLayeredWindow API.
You can see a C++ source code example here:
http://www.objreader.com/index.php?topi ... 619#msg619
Sorry I am not a PB programmer, but the core API is the same for all Win32 languages.
Patrice Terrier
objreader@gmail.com
http://www.objreader.com
Addon: WinLIFT (Skin Engine), GDImage (Graphic library), ObjReader (3D engine)
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

Re: Is creating an opengl gadget with a transparent background allowing objects behind to be visible possible?

Post by minimy »

skinkairewalker wrote: Wed Jan 10, 2024 6:44 pm using this concept as a base, then you can actually create a layer using opengl to render the "steamOverlay", and then the content remains...
May work... not tested.
But Patrice solution is really better.
Thanks Patrice for teach us about layers.
If translation=Error: reply="Sorry, Im Spanish": Endif
Post Reply