|
Post by Walt Decker on Jun 1, 2023 16:18:53 GMT -5
OPENGL is a powerful set of rendering procedures, but it takes quite a bit of study to use them, and it is difficult to trouble shoot problems when they occur.
I have done little with OPENGL for the past 20 years, preferring instead to use my own matrix procedures. However, I thought I would give LB a try. I found that LB sometimes works and sometimes does not, so I wrote a wrapper dll to alleviate the problems. The attached zip contains:
LB0GL 0-DOC.TXT: a partial list of the functions contained in LBOGL 0.DLL LB_ORTHO_C1_000._BAS: a demo-test file LBOGL 0.DLL: wrappers for OPENGL functions that properly cast LB variables
The image produced by LB_ORTHO_C1_000._BAS can be modified by either right clicking on the form or pressing CTRL + M. This activates a pop-up window in which degrees rotation can be entered for the X, Y, and Z axis and translation distances for the X, Y, and Z directions. The form is also resizable via the mouse. Feel free to play with the code.
I will endevor to produce a filled orthographic image in the next few days plus a perspective scene.
LBOBL_0.ZIP (9.11 KB)
|
|
|
Post by atomose on Jun 2, 2023 7:25:11 GMT -5
Nice ! i really would like to learn how to use openGL with LB thx !
|
|
|
OPENGL?
Jun 2, 2023 14:22:50 GMT -5
Post by Walt Decker on Jun 2, 2023 14:22:50 GMT -5
Nice ! i really would like to learn how to use openGL with LB thx ! Thank you and gaslouk. Nice to know there is some interest in the subject. I have a solid orthographic projection about complete, and have a perspective projection in the works. With these I will endevor to explain what is going on.
|
|
|
OPENGL?
Jun 2, 2023 15:10:03 GMT -5
Post by Rod on Jun 2, 2023 15:10:03 GMT -5
The more we can explore OpenGL the better. I have had one or two false starts, it is quite powerful but very different from basic. There are lessons on the LBPE but few folks ventured past the initial tutorials. Let’s hope we make more progress with Walt.
|
|
|
Post by Walt Decker on Jun 10, 2023 9:02:39 GMT -5
I must apologize. Had a little accident a week ago and have been laid up for a few days with damaged ribs. The attached zip contains
LSN1_QUADS_000._BAS LSN2_QUADS_000._BAS ORTHOGRAPHIC001.TXT LBOGL 0.ZIP
ORTHOGRAPHIC001.TXT explains what is happening in the two source code files.
I will expand the source code somewhat to show additional features.
ORTHO_000.ZIP (15.78 KB)
|
|
|
OPENGL?
Jun 10, 2023 12:38:32 GMT -5
Post by Walt Decker on Jun 10, 2023 12:38:32 GMT -5
Another example: ' '###################################### ' This is exactly the same as the examples ' in the zip except: ' quad data ' color data ' "GLShade"(GL.FLAT) changed to GL.SMOOTH ' in FN.DefineOglWindow() ' "GL3fRotate", Rx, P1, P2, P2) Rx from 1(one) ' to eight(8) for better display in ' function FN.RenderScene() '######################################
NOMAINWIN DIM Quad(-1, -1) DIM Kolr(-1, -1)
GLOBAL Wrc, _ Wdc
GLOBAL Qubnd GLOBAL App.Done
OPEN "User32.DLL" FOR DLL AS #USER OPEN "Kernel32.DLL" FOR DLL AS #KERN OPEN "LBOGL 0" FOR DLL AS #LBOGL
WinHndl = 0 GfxHndl = 0 RetVal = 0 GfxDc = 0 GfxRc = 0
Qubnd = 0 Cubnd = 0
Xw = 0 Yh = 0
[BEGIN] Qubnd = FN.QuadData() Cubnd = FN.ColorData() WinHndl = FN.CreateWindow("OPEN BOX", Xw, Yh, GfxHndl) GfxRc = FN.GetPixelFormat(GfxHndl, GfxDc) Wrc = GfxRc Wdc = GfxDc
RetVal = FN.DefineOglWindow(0, 0, Xw, Yh) RetVal = FN.RenderScene(GfxDc, Qubnd, 0) WAIT
'------------------------------- '-------------------------------
SUB CLOSE.ORTHO WinHndl$
WinRc = Wrc App.Done = 1
CALLDLL #LBOGL, "GLMakeCurrent", 0 AS ULONG, 0 AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLDeleteContext", WinRc AS ULONG, RetVal AS VOID
CLOSE #LBOGL CLOSE #USER CLOSE #KERN CLOSE #WinHndl$
END SUB
'------------------------------------ '------------------------------------
SUB ROTATE MsHndl$, Mx, My
RetVal = 0 Ubnd = Qubnd GfxDc = Wdc
RetVal = FN.RenderScene(GfxDc, Ubnd, 1) END SUB
'------------------------------------ '------------------------------------
FUNCTION FN.GetPixelFormat(WinHndl, BYREF Dc) '##################################################### ' The following commented out struct is the actual structure ' windows expects when requesting a rendering context for ' OPENGL.DLL. The structure used by LBOGL 0.DLL is a small ' part of this structure with a couple of features added. '#####################################################
'TYPEDEF STRUCT PIXELFORMATDESCRIPTOR ' nSize AS WORD <--- size of struct ' nVersion AS WORD <--- version, set to 1 ' dwFlags AS DWORD <--- constants describing ' what the format shoul look like ' iPixelType AS BYTE <--- RGBA pixels. Each pixel has ' four components: red, green, blue, and alpha ' cColorBits AS BYTE Specifies the number of color bitplanes in ' each color buffer. For RGBA pixel types, it ' is the size of the color buffer excluding the ' alpha bitplanes. For color index pixels, it ' is the size of the color index buffer. Values ' of 8, 16, 24, 32 are acceptable. ' cRedBits AS BYTE ' cRedShift AS BYTE ' cGreenBits AS BYTE ' cGreenShift AS BYTE ' cBlueBits AS BYTE ' cBlueShift AS BYTE ' cAlphaBits AS BYTE ' cAlphaShift AS BYTE ' cAccumBits AS BYTE ' cAccumRedBits AS BYTE ' cAccumGreenBits AS BYTE ' cAccumBlueBits AS BYTE ' cAccumAlphaBits AS BYTE ' cDepthBits AS BYTE ' cStencilBits AS BYTE ' cAuxBuffers AS BYTE ' iLayerType AS BYTE ' bReserved AS BYTE ' dwLayerMask AS DWORD <--- Specifies the type of layer. The ' current version supports only the main ' plane (there is no support for overlay or ' underlay planes) ' dwVisibleMask AS DWORD ' dwDamageMask AS DWORD
PFD.DOUBLEBUFFER = HEXDEC("&H00000001") PFD.STEREO = HEXDEC("&H00000002") PFD.DRAW.TO.WINDOW = HEXDEC("&H00000004") PFD.DRAW.TO.BITMAP = HEXDEC("&H00000008") PFD.SUPPORT.GDI = HEXDEC("&H00000010") PFD.SUPPORT.OPENGL = HEXDEC("&H00000020")
PFD.TYPE.RGBA = 0 PFD.MAIN.PLANE = 0
STRUCT tOgl, _ WinHndl AS ULONG, _ '<--- INPUT; handle of target window WinDc AS ULONG, _ '<--- RETURN; device context used for drawing WinRc AS ULONG, _ '<--- RETURN; rendering context for OPENGL. dwFlags AS ULONG, _ '<--- symbolic names(tags) iPixelType AS USHORT, _ '<--- type of pixel format cColorBits AS USHORT, _ '<--- # of bits required to display colors; _ 'accepted values: 8, 16, 24, 32 cDepthBits AS USHORT, _ '<--- # of bits for color depth calculations; _ 'accepted values: 8, 16, 24, 32 dwLayerMask AS ULONG '<--- which plain to draw on; one valid value: 'PFD.MAIN.PLANE
Dc = 0 WinRc = 0
tOgl.WinHndl.struct = WinHndl tOgl.dwFlags.struct = PFD.DRAW.TO.WINDOW OR PFD.SUPPORT.OPENGL OR PFD.DOUBLEBUFFER tOgl.dwLayerMask.struct = PFD.MAIN.PLANE tOgl.iPixelType.struct = PFD.TYPE.RGBA tOgl.cColorBits.struct = 32 tOgl.cDepthBits.struct = 32
CALLDLL #LBOGL, "FN_GLContext", tOgl AS STRUCT, RetVal AS LONG Dc = tOgl.WinDc.struct WinRc = tOgl.WinRc.struct
FN.GetPixelFormat = WinRc END FUNCTION
'----------------------------- '-----------------------------
FUNCTION FN.CreateWindow(Title$, BYREF Xwide, BYREF Yhigh, BYREF CtlHndl)
WS.BORDER = HEXDEC("&H00800000")
WinHndl = 0
Xwide = 300 Yhigh = 310
RetVal = 0
Ux = 0 Uy = 0 Cx = 0 Cy = 0
STYLEBITS #ORTHO.GFX, 0, WS.BORDER, 0, 0 GRAPHICBOX #ORTHO.GFX, 0, 0, 290, 270
RetVal = FN.ScreenCenter(Cx, Cy) Ux = INT(Cx - Xwide / 2) Uy = INT(Cy - Yhigh / 2) RetVal = FN.SetWinPos(Ux, Uy) RetVal = FN.SetWinSize(Xwide, Yhigh)
OPEN Title$ FOR WINDOW AS #ORTHO
WinHndl = HWND(#ORTHO) RetVal = FN.ClientSize(WinHndl, Xwide, Yhigh)
#ORTHO.GFX, "LOCATE 0 0 ";Xwide; " "; Yhigh #ORTHO, "REFRESH" #ORTHO, "TRAPCLOSE CLOSE.ORTHO" #ORTHO.GFX, "when leftButtonDown ROTATE" CtlHndl = HWND(#ORTHO.GFX) FN.CreateWindow = WinHndl END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.DefineOglWindow(Xleft, Ytop, Wide, High)
GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
GL.MODELVIEW = HEXDEC("&H1700") GL.PROJECTION = HEXDEC("&H1701")
GL.FRONT = HEXDEC("&H0404") GL.BACK = HEXDEC("&H0405") GL.FRONT.AND.BACK = HEXDEC("&H0408")
GL.POINT = HEXDEC("&H1B00") GL.LINE = HEXDEC("&H1B01") GL.FILL = HEXDEC("&H1B02")
GL.FLAT = HEXDEC("&H1D00") GL.SMOOTH = HEXDEC("&H1D01") GL.DEPTH.TEST = HEXDEC("&H0B71")
R = 0.75 G = 0.5 B = 0.0
ClearBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR GL.ACCUM.BUFFER.BIT OR _ GL.STENCIL.BUFFER.BIT
CALLDLL #LBOGL, "GLBkgColor", R AS DOUBLE, G AS DOUBLE, _ B AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GLEnableFunc", GL.DEPTH.TEST AS ULONG, RetVal AS VOID
'<======== changed from GL.FLAT ========================> CALLDLL #LBOGL, "GLShade", GL.SMOOTH AS ULONG, RetVal AS VOID
CALLDLL #LBOGL, "GLPolyMode", GL.FRONT.AND.BACK AS ULONG, GL.FILL AS ULONG, _ RetVal AS VOID CALLDLL #LBOGL, "GLView", Xleft AS LONG, Ytop AS LONG, Wide AS LONG, _ High AS LONG, RetVal AS VOID CALLDLL #LBOGL, "GLMatMode", GL.PROJECTION AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID Lft = VAL(USING("###.####", -15.0)) Rgt = VAL(USING("###.####", 15.0)) Btm = VAL(USING("###.####", -15.0)) Top = VAL(USING("###.####", 15.0)) Ner = VAL(USING("###.####", -20.0)) Far = VAL(USING("###.####", 20.0)) CALLDLL #LBOGL, "OrthoGL", Lft AS DOUBLE, Rgt AS DOUBLE, Btm AS DOUBLE, _ Top AS DOUBLE, Ner AS DOUBLE, Far AS DOUBLE, _ RetVal AS VOID CALLDLL #LBOGL, "GLMatMode", GL.MODELVIEW AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID CALLDLL #LBOGL, "GLClearBuffers", ClearBits AS ULONG, RetVal AS VOID
END FUNCTION
'--------------------------------------- '---------------------------------------
FUNCTION FN.RenderScene(GfxDc, Ubnd, BeginRotation)
GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
GL.QUADS = HEXDEC("&H0007")
'<======= LOCAL VARIABLES ==========> ClrIdx = 0 RetVal = 0
ColorBits = 0
Z = BeginRotation I = 0 P1 = 1 P2 = 0 Deg = 0 Rx = 15 '<--- changed from 1(one)
ColorBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR GL.ACCUM.BUFFER.BIT OR _ GL.STENCIL.BUFFER.BIT DO CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID
IF Z <> 0 THEN CALLDLL #LBOGL, "GL3fRotate", Deg AS DOUBLE, P2 AS DOUBLE, P1 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Rx AS DOUBLE, P1 AS DOUBLE, P2 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID END IF CALLDLL #LBOGL, "GLStart", GL.QUADS AS ULONG, RetVal AS VOID FOR I = 0 TO Ubnd ClrIdx = Quad(I, 3) - 1
IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Quad(I, 0), Quad(I, 1), Quad(I, 2)) NEXT I CALLDLL #LBOGL, "GLStop", RetVal AS VOID
CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID CALLDLL #LBOGL, "GLSwap", GfxDc AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLClearBuffers", ColorBits AS ULONG, RetVal AS VOID
Deg = Deg + 2 CALLDLL #KERN, "Sleep", 150 AS LONG, RetVal AS VOID SCAN
IF App.Done THEN EXIT DO
IF Deg > 452 THEN EXIT DO LOOP WHILE Z <> 0 END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.Bcolor(R, G, B)
RetVal = 0 CALLDLL #LBOGL, "GLubColor", R AS USHORT, G AS USHORT, B AS USHORT, RetVal AS VOID
END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.Vertexf(X, Y, Z)
RetVal = 0 CALLDLL #LBOGL, "GL3fVertex", X AS DOUBLE, Y AS DOUBLE, Z AS DOUBLE, _ RetVal AS VOID END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.QuadData() '######################################## ' Changed the quad data. Notice that the ' walls are connected to the back of the ' box via the depth (Z) parameter. '########################################
' X Y Z color index DATA 5, 2.5, 0, 1 DATA -5, 2.5, 0, 0 DATA -5, -2.5, 0, 0 DATA 5, -2.5, 0, 3
DATA 5, 2.5, 0, 2 DATA -5, 2.5, 0, 0 DATA -5, 2.5, 5, 0 DATA 5, 2.5, 5, 3
DATA 5, -2.5, 0, 2 DATA -5, -2.5, 0, 0 DATA -5, -2.5, 5, 0 DATA 5, -2.5, 5, 1
DATA -5, -2.5, 0, 4 DATA -5, 2.5, 0, 3 DATA -5, 2.5, 5, 0 DATA -5, -2.5, 5, 0
DATA 5, 2.5, 0, 5 DATA 5, 2.5, 5, 0 DATA 5, -2.5, 5, 0 DATA 5, -2.5, 0, 1
'<======= LOCAL VARIABLES =========> I = 0 J = 0
Ubnd = 0 Varb = 0
Ubnd = 19 REDIM Quad(Ubnd, 3) '<--- 12 ROWS, 4 COLUMNS
FOR I = 0 TO Ubnd FOR J = O TO 3 READ Varb Quad(I, J) = Varb NEXT J NEXT I
FN.QuadData = Ubnd END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.ColorData() '######################################## ' Colors used to fill the shapes '########################################
' red green blue DATA 255, 255, 0 DATA 0, 255, 0 DATA 0, 255, 255 DATA 255, 0, 255 DATA 255, 128, 96
'<========== LOCAL VARIABLES ========> I = 0 J = 0 Ubnd = 0 Varb = 0
Ubnd = 4 REDIM Kolr(Ubnd, 2) '<--- 3 rows, 3 columns
FOR I = 0 TO Ubnd FOR J = 0 TO 2 READ Varb Kolr(I, J)= Varb NEXT J NEXT I
FN.ColorData = Ubnd END FUNCTION
'------------------------------------ '------------------------------------
FUNCTION FN.ClientSize(WinHndl, BYREF Xw, BYREF Yh)
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
RetVal = 0 CALLDLL #USER, "GetClientRect", WinHndl AS ULONG, tRect AS STRUCT, RetVal AS LONG
Xw = tRect.X1.struct Yh = tRect.Y1.struct
FN.GetClient = RetVal END FUNCTION
'--------------------------- '---------------------------
FUNCTION FN.ScreenCenter(BYREF Cx, BYREF Cy)
Cx = INT(DisplayWidth * 0.5) Cy = INT(DisplayHeight * 0.5)
FN.ScreenCenter = Cx * Cy END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.SetWinPos(PosX, PosY)
UpperLeftX = PosX UpperLeftY = PosY
FN.SetWinPos = PosX * PosY END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.SetWinSize(Szx, Szy)
WindowWidth = Szx WindowHeight = Szy
FN.SetWinSize = Szx * Szy END FUNCTION
'--------------------------- '--------------------------- '
|
|
|
OPENGL?
Jun 11, 2023 13:16:48 GMT -5
Post by Walt Decker on Jun 11, 2023 13:16:48 GMT -5
Translation (moving) and scaling:
' NOMAINWIN '############################################# ' For this demo some extensive changes are made ' in function FN.RenderScene(). '#############################################
DIM Quad(-1, -1) DIM Kolr(-1, -1)
GLOBAL Wrc, _ Wdc
GLOBAL Qubnd GLOBAL App.Done
OPEN "User32.DLL" FOR DLL AS #USER OPEN "Kernel32.DLL" FOR DLL AS #KERN OPEN "LBOGL 0" FOR DLL AS #LBOGL
WinHndl = 0 GfxHndl = 0 RetVal = 0 GfxDc = 0 GfxRc = 0
Qubnd = 0 Cubnd = 0
Xw = 0 Yh = 0
[BEGIN] Qubnd = FN.QuadData() Cubnd = FN.ColorData() WinHndl = FN.CreateWindow("QUADS 1", Xw, Yh, GfxHndl) GfxRc = FN.GetPixelFormat(GfxHndl, GfxDc) Wrc = GfxRc Wdc = GfxDc
RetVal = FN.DefineOglWindow(0, 0, Xw, Yh) RetVal = FN.RenderScene(GfxDc, Qubnd, 0) WAIT
'------------------------------- '-------------------------------
SUB CLOSE.ORTHO WinHndl$
WinRc = Wrc App.Done = 1
CALLDLL #LBOGL, "GLMakeCurrent", 0 AS ULONG, 0 AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLDeleteContext", WinRc AS ULONG, RetVal AS VOID
CLOSE #LBOGL CLOSE #USER CLOSE #KERN CLOSE #WinHndl$
END SUB
'------------------------------------ '------------------------------------
SUB ROTATE MsHndl$, Mx, My
RetVal = 0 Ubnd = Qubnd GfxDc = Wdc
RetVal = FN.RenderScene(GfxDc, Ubnd, 1) END SUB
'------------------------------------ '------------------------------------
FUNCTION FN.GetPixelFormat(WinHndl, BYREF Dc) '##################################################### ' The following commented out struct is the actual structure ' windows expects when requesting a rendering context for ' OPENGL.DLL. The structure used by LBOGL 0.DLL is a small ' part of this structure with a couple of features added. '#####################################################
'TYPEDEF STRUCT PIXELFORMATDESCRIPTOR ' nSize AS WORD <--- size of struct ' nVersion AS WORD <--- version, set to 1 ' dwFlags AS DWORD <--- constants describing ' what the format shoul look like ' iPixelType AS BYTE <--- RGBA pixels. Each pixel has ' four components: red, green, blue, and alpha ' cColorBits AS BYTE Specifies the number of color bitplanes in ' each color buffer. For RGBA pixel types, it ' is the size of the color buffer excluding the ' alpha bitplanes. For color index pixels, it ' is the size of the color index buffer. Values ' of 8, 16, 24, 32 are acceptable. ' cRedBits AS BYTE ' cRedShift AS BYTE ' cGreenBits AS BYTE ' cGreenShift AS BYTE ' cBlueBits AS BYTE ' cBlueShift AS BYTE ' cAlphaBits AS BYTE ' cAlphaShift AS BYTE ' cAccumBits AS BYTE ' cAccumRedBits AS BYTE ' cAccumGreenBits AS BYTE ' cAccumBlueBits AS BYTE ' cAccumAlphaBits AS BYTE ' cDepthBits AS BYTE ' cStencilBits AS BYTE ' cAuxBuffers AS BYTE ' iLayerType AS BYTE ' bReserved AS BYTE ' dwLayerMask AS DWORD <--- Specifies the type of layer. The ' current version supports only the main ' plane (there is no support for overlay or ' underlay planes) ' dwVisibleMask AS DWORD ' dwDamageMask AS DWORD
PFD.DOUBLEBUFFER = HEXDEC("&H00000001") PFD.STEREO = HEXDEC("&H00000002") PFD.DRAW.TO.WINDOW = HEXDEC("&H00000004") PFD.DRAW.TO.BITMAP = HEXDEC("&H00000008") PFD.SUPPORT.GDI = HEXDEC("&H00000010") PFD.SUPPORT.OPENGL = HEXDEC("&H00000020")
PFD.TYPE.RGBA = 0 PFD.MAIN.PLANE = 0
STRUCT tOgl, _ WinHndl AS ULONG, _ '<--- INPUT; handle of target window WinDc AS ULONG, _ '<--- RETURN; device context used for drawing WinRc AS ULONG, _ '<--- RETURN; rendering context for OPENGL. dwFlags AS ULONG, _ '<--- symbolic names(tags) iPixelType AS USHORT, _ '<--- type of pixel format cColorBits AS USHORT, _ '<--- # of bits required to display colors; _ 'accepted values: 8, 16, 24, 32 cDepthBits AS USHORT, _ '<--- # of bits for color depth calculations; _ 'accepted values: 8, 16, 24, 32 dwLayerMask AS ULONG '<--- which plain to draw on; one valid value: 'PFD.MAIN.PLANE
Dc = 0 WinRc = 0
tOgl.WinHndl.struct = WinHndl tOgl.dwFlags.struct = PFD.DRAW.TO.WINDOW OR PFD.SUPPORT.OPENGL OR PFD.DOUBLEBUFFER tOgl.dwLayerMask.struct = PFD.MAIN.PLANE tOgl.iPixelType.struct = PFD.TYPE.RGBA tOgl.cColorBits.struct = 32 tOgl.cDepthBits.struct = 32
CALLDLL #LBOGL, "FN_GLContext", tOgl AS STRUCT, RetVal AS LONG Dc = tOgl.WinDc.struct WinRc = tOgl.WinRc.struct
FN.GetPixelFormat = WinRc END FUNCTION
'----------------------------- '-----------------------------
FUNCTION FN.CreateWindow(Title$, BYREF Xwide, BYREF Yhigh, BYREF CtlHndl)
WS.BORDER = HEXDEC("&H00800000")
WinHndl = 0
Xwide = 300 Yhigh = 310
RetVal = 0
Ux = 0 Uy = 0 Cx = 0 Cy = 0
STYLEBITS #ORTHO.GFX, 0, WS.BORDER, 0, 0 GRAPHICBOX #ORTHO.GFX, 0, 0, 290, 270
RetVal = FN.ScreenCenter(Cx, Cy) Ux = INT(Cx - Xwide / 2) Uy = INT(Cy - Yhigh / 2) RetVal = FN.SetWinPos(Ux, Uy) RetVal = FN.SetWinSize(Xwide, Yhigh)
OPEN Title$ FOR WINDOW AS #ORTHO
WinHndl = HWND(#ORTHO) RetVal = FN.ClientSize(WinHndl, Xwide, Yhigh)
#ORTHO.GFX, "LOCATE 0 0 ";Xwide; " "; Yhigh #ORTHO, "REFRESH" #ORTHO, "TRAPCLOSE CLOSE.ORTHO" #ORTHO.GFX, "when leftButtonDown ROTATE" CtlHndl = HWND(#ORTHO.GFX) FN.CreateWindow = WinHndl END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.DefineOglWindow(Xleft, Ytop, Wide, High)
GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
GL.MODELVIEW = HEXDEC("&H1700") GL.PROJECTION = HEXDEC("&H1701")
GL.FRONT = HEXDEC("&H0404") GL.BACK = HEXDEC("&H0405") GL.FRONT.AND.BACK = HEXDEC("&H0408")
GL.POINT = HEXDEC("&H1B00") GL.LINE = HEXDEC("&H1B01") GL.FILL = HEXDEC("&H1B02")
GL.FLAT = HEXDEC("&H1D00") GL.SMOOTH = HEXDEC("&H1D01") GL.DEPTH.TEST = HEXDEC("&H0B71")
R = 0.75 G = 0.5 B = 0.0
ClearBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR GL.ACCUM.BUFFER.BIT OR _ GL.STENCIL.BUFFER.BIT
CALLDLL #LBOGL, "GLBkgColor", R AS DOUBLE, G AS DOUBLE, _ B AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GLEnableFunc", GL.DEPTH.TEST AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLShade", GL.FLAT AS ULONG, RetVal AS VOID
CALLDLL #LBOGL, "GLPolyMode", GL.FRONT.AND.BACK AS ULONG, GL.FILL AS ULONG, _ RetVal AS VOID CALLDLL #LBOGL, "GLView", Xleft AS LONG, Ytop AS LONG, Wide AS LONG, _ High AS LONG, RetVal AS VOID CALLDLL #LBOGL, "GLMatMode", GL.PROJECTION AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID Lft = VAL(USING("###.####", -15.0)) Rgt = VAL(USING("###.####", 15.0)) Btm = VAL(USING("###.####", -15.0)) Top = VAL(USING("###.####", 15.0)) Ner = VAL(USING("###.####", -20.0)) Far = VAL(USING("###.####", 20.0)) CALLDLL #LBOGL, "OrthoGL", Lft AS DOUBLE, Rgt AS DOUBLE, Btm AS DOUBLE, _ Top AS DOUBLE, Ner AS DOUBLE, Far AS DOUBLE, _ RetVal AS VOID CALLDLL #LBOGL, "GLMatMode", GL.MODELVIEW AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID CALLDLL #LBOGL, "GLClearBuffers", ClearBits AS ULONG, RetVal AS VOID
END FUNCTION
'--------------------------------------- '---------------------------------------
FUNCTION FN.RenderScene(GfxDc, Ubnd, BeginRotation)
GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
GL.QUADS = HEXDEC("&H0007")
'<======= LOCAL VARIABLES ==========> ClrIdx = 0 RetVal = 0
ColorBits = 0
Z = BeginRotation I = 0 P1 = 1 P2 = 0 Deg = 0 Rx = 80 '<--- rotation around horizontal (X) axis
'################################################## ' SCALING FACTORS ' If scaling is performed each parameter of GL3fScale() ' must have a value not equalt to zero. If any value is ' zero that element of the object will be zero and the ' object may not be rendered. '##################################################
Szx = 1.5 '<--- scaling factors Szy = 1.5 Szz = 1
'################################################## ' TRANSLATION (MOVE) FACTORS ' There are three parameters for moving an object: ' X moves along the horizontal (X) axis ' Y moves along the verticaly (Y) axis ' Z moves into or outof the screen. If perspective ' is enabled moving along the Z axis essentially ' enlarges or diminishes the object. '################################################## Trnx = 6 Trny = 0
ColorBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR GL.ACCUM.BUFFER.BIT OR _ GL.STENCIL.BUFFER.BIT DO CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID
IF Z <> 0 THEN CALLDLL #LBOGL, "GLMoveObj", Trnx AS DOUBLE, Trny AS DOUBLE, _ Trny AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fScale", Szx AS DOUBLE, Szy AS DOUBLE, _ Szz AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Deg AS DOUBLE, P2 AS DOUBLE, P1 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Rx AS DOUBLE, P1 AS DOUBLE, P2 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID END IF
'################################################## ' We want scaling and moving for the middle quad only. ' This is the middle quad although it is rendered first ' so it has its own begging and ending. '################################################## CALLDLL #LBOGL, "GLStart", GL.QUADS AS ULONG, RetVal AS VOID FOR I = 0 TO 3 ClrIdx = Quad(I, 3) - 1
IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Quad(I, 0), Quad(I, 1), Quad(I, 2)) NEXT I CALLDLL #LBOGL, "GLStop", RetVal AS VOID
'################################################## ' At this point the matrix for the middle quad is ' saved (GLPushMat()). To produce a smooth rotation ' an identity matrix (GLLoadIdent()) is acquired. If ' we do not use an identity matrix the middle quad ' will jump around the screen. '################################################## IF Z <> 0 THEN CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Deg AS DOUBLE, P2 AS DOUBLE, P1 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Rx AS DOUBLE, P1 AS DOUBLE, P2 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID END IF
CALLDLL #LBOGL, "GLStart", GL.QUADS AS ULONG, RetVal AS VOID FOR I = 4 TO Ubnd ClrIdx = Quad(I, 3) - 1
IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Quad(I, 0), Quad(I, 1), Quad(I, 2)) NEXT I CALLDLL #LBOGL, "GLStop", RetVal AS VOID
'<=========== here we retrieve all matricies we saved ==============> IF Z <> 0 THEN CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID END IF
CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID CALLDLL #LBOGL, "GLSwap", GfxDc AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLClearBuffers", ColorBits AS ULONG, RetVal AS VOID
Deg = Deg + 2 CALLDLL #KERN, "Sleep", 100 AS LONG, RetVal AS VOID SCAN
IF App.Done THEN EXIT DO
IF Deg > 452 THEN EXIT DO LOOP WHILE Z <> 0 END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.Bcolor(R, G, B)
RetVal = 0 CALLDLL #LBOGL, "GLubColor", R AS USHORT, G AS USHORT, B AS USHORT, RetVal AS VOID
END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.Vertexf(X, Y, Z)
RetVal = 0 CALLDLL #LBOGL, "GL3fVertex", X AS DOUBLE, Y AS DOUBLE, Z AS DOUBLE, _ RetVal AS VOID END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.QuadData() '######################################## ' Data for 3 rectangular plains. Notice that the ' X, Y coordinates are arranged in counter-clockwise ' direction. This is to conform to the opengl default ' rendering protocol, which is counter-clockwise. ' ' Also notice that the every point has the same Z value. ' This defines a plain that has the same orientation when ' rotated around the X-axis(horizontal) axis. '########################################
' X Y Z color index DATA 5, 2.5, 0, 1 DATA -5, 2.5, 0, 0 DATA -5, -2.5, 0, 0 DATA 5, -2.5, 0, 0
DATA 5, 2.5, 5, 2 DATA -5, 2.5, 5, 0 DATA -5, -2.5, 5, 0 DATA 5, -2.5, 5, 0
DATA 5, 2.5, -5, 3 DATA -5, 2.5, -5, 0 DATA -5, -2.5, -5, 0 DATA 5, -2.5, -5, 0
'<======= LOCAL VARIABLES =========> I = 0 J = 0
Ubnd = 0 Varb = 0
Ubnd = 11 REDIM Quad(11, 3) '<--- 12 ROWS, 4 COLUMNS
FOR I = 0 TO Ubnd FOR J = O TO 3 READ Varb Quad(I, J) = Varb NEXT J NEXT I
FN.QuadData = Ubnd END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.ColorData() '######################################## ' Colors used to fill the shapes '########################################
' red green blue DATA 255, 255, 0 '<--- yellow DATA 0, 255, 0 '<--- green DATA 0, 255, 255 '<--- cyan
'<========== LOCAL VARIABLES ========> I = 0 J = 0 Ubnd = 0 Varb = 0
Ubnd = 2 REDIM Kolr(Ubnd, 2) '<--- 3 rows, 3 columns
FOR I = 0 TO Ubnd FOR J = 0 TO 2 READ Varb Kolr(I, J)= Varb NEXT J NEXT I
FN.ColorData = Ubnd END FUNCTION
'------------------------------------ '------------------------------------
FUNCTION FN.ClientSize(WinHndl, BYREF Xw, BYREF Yh)
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
RetVal = 0 CALLDLL #USER, "GetClientRect", WinHndl AS ULONG, tRect AS STRUCT, RetVal AS LONG
Xw = tRect.X1.struct Yh = tRect.Y1.struct
FN.GetClient = RetVal END FUNCTION
'--------------------------- '---------------------------
FUNCTION FN.ScreenCenter(BYREF Cx, BYREF Cy)
Cx = INT(DisplayWidth * 0.5) Cy = INT(DisplayHeight * 0.5)
FN.ScreenCenter = Cx * Cy END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.SetWinPos(PosX, PosY)
UpperLeftX = PosX UpperLeftY = PosY
FN.SetWinPos = PosX * PosY END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.SetWinSize(Szx, Szy)
WindowWidth = Szx WindowHeight = Szy
FN.SetWinSize = Szx * Szy END FUNCTION
'--------------------------- '--------------------------- '
I would like to see something from some of you who are interested.
|
|
david
New Member
Posts: 6
|
Post by david on Jun 12, 2023 4:39:01 GMT -5
There was a board member on the old forum, Chung, he did a lot of good stuff with opengl. He has a blog, all in French and not updated now but his programs are there and he includes his source code. All way above my limitations but may be of use to some who are looking at dabbling with openGL and shows what can be achieved by someone with knowledge, unfortunately that is not me. chung.unblog.fr/
|
|
|
Post by Walt Decker on Jun 12, 2023 17:41:24 GMT -5
Blending and transparency is an interesting tool. One can define a window in a building and see either what is inside or outside depending on the view.
The attached zip contains source code for blending/transparency and an updated LBOGL 0.dll
' NOMAINWIN '############################################# ' For this demo I have introduced some new ' OPENGL functions and a new rendering function ' to illustrate blending/transparency. ' See function FN.RenderBlend(). ' ' Click on one of the radio buttons to see the ' effect. ' ' You might want to play with GLShade() in ' FN.DefineOglWindow(). Also, try adding colors ' to FN.ColorData() and add indicies to the points ' in FN.TriangleData(). '#############################################
DIM Trng(-1, -1) DIM Kolr(-1, -1)
GLOBAL Wrc, _ Wdc
GLOBAL Tubnd
OPEN "User32.DLL" FOR DLL AS #USER OPEN "Kernel32.DLL" FOR DLL AS #KERN OPEN "LBOGL 0" FOR DLL AS #LBOGL
WinHndl = 0 GfxHndl = 0 RetVal = 0 GfxDc = 0 GfxRc = 0
Tubnd = 0 Cubnd = 0
Xw = 0 Yh = 0
[BEGIN] Tubnd = FN.TriangleData() Cubnd = FN.ColorData()
WinHndl = FN.CreateWindow("BLEND/TRANSPARENT", Xw, Yh, GfxHndl)
GfxRc = FN.GetPixelFormat(GfxHndl, GfxDc) Wrc = GfxRc Wdc = GfxDc
RetVal = FN.DefineOglWindow(0, 0, Xw, Yh) RetVal = FN.RenderBlend(GfxDc, Tubnd, 0) RetVal = FN.Objects(WinHndl)
WAIT
'------------------------------- '-------------------------------
SUB CLOSE.ORTHO WinHndl$
WinRc = Wrc App.Done = 1
CALLDLL #LBOGL, "GLMakeCurrent", 0 AS ULONG, 0 AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLDeleteContext", WinRc AS ULONG, RetVal AS VOID
CLOSE #LBOGL CLOSE #USER CLOSE #KERN CLOSE #CLR CLOSE #WinHndl$
END SUB
'------------------------------------ '------------------------------------
SUB CLR.RDO RdoHndl$
RetVal = 0 Ubnd = Tubnd
Dc = Wdc
IsSet$ = ""
#RdoHndl$, "VALUE? IsSet$" IF IsSet$ = "set" THEN SELECT CASE RdoHndl$ CASE "#CLR.RDOFR" RetVal = FN.RenderBlend(Dc, Ubnd, 1)
CASE "#CLR.RDOBK" RetVal = FN.RenderBlend(Dc, Ubnd, 2)
CASE "#CLR.RDOBO" RetVal = FN.RenderBlend(Dc, Ubnd, 3) END SELECT END IF
END SUB
'------------------------------------ '------------------------------------
SUB QUIT.BUTTON BtnHndl$
CALL CLOSE.ORTHO "#ORTHO" END SUB
'------------------------------------ '------------------------------------
FUNCTION FN.GetPixelFormat(WinHndl, BYREF Dc) '##################################################### ' The following commented out struct is the actual structure ' windows expects when requesting a rendering context for ' OPENGL.DLL. The structure used by LBOGL 0.DLL is a small ' part of this structure with a couple of features added. '#####################################################
'TYPEDEF STRUCT PIXELFORMATDESCRIPTOR ' nSize AS WORD <--- size of struct ' nVersion AS WORD <--- version, set to 1 ' dwFlags AS DWORD <--- constants describing ' what the format shoul look like ' iPixelType AS BYTE <--- RGBA pixels. Each pixel has ' four components: red, green, blue, and alpha ' cColorBits AS BYTE Specifies the number of color bitplanes in ' each color buffer. For RGBA pixel types, it ' is the size of the color buffer excluding the ' alpha bitplanes. For color index pixels, it ' is the size of the color index buffer. Values ' of 8, 16, 24, 32 are acceptable. ' cRedBits AS BYTE ' cRedShift AS BYTE ' cGreenBits AS BYTE ' cGreenShift AS BYTE ' cBlueBits AS BYTE ' cBlueShift AS BYTE ' cAlphaBits AS BYTE ' cAlphaShift AS BYTE ' cAccumBits AS BYTE ' cAccumRedBits AS BYTE ' cAccumGreenBits AS BYTE ' cAccumBlueBits AS BYTE ' cAccumAlphaBits AS BYTE ' cDepthBits AS BYTE ' cStencilBits AS BYTE ' cAuxBuffers AS BYTE ' iLayerType AS BYTE ' bReserved AS BYTE ' dwLayerMask AS DWORD <--- Specifies the type of layer. The ' current version supports only the main ' plane (there is no support for overlay or ' underlay planes) ' dwVisibleMask AS DWORD ' dwDamageMask AS DWORD
PFD.DOUBLEBUFFER = HEXDEC("&H00000001") PFD.STEREO = HEXDEC("&H00000002") PFD.DRAW.TO.WINDOW = HEXDEC("&H00000004") PFD.DRAW.TO.BITMAP = HEXDEC("&H00000008") PFD.SUPPORT.GDI = HEXDEC("&H00000010") PFD.SUPPORT.OPENGL = HEXDEC("&H00000020")
PFD.TYPE.RGBA = 0 PFD.MAIN.PLANE = 0
STRUCT tOgl, _ WinHndl AS ULONG, _ '<--- INPUT; handle of target window WinDc AS ULONG, _ '<--- RETURN; device context used for drawing WinRc AS ULONG, _ '<--- RETURN; rendering context for OPENGL. dwFlags AS ULONG, _ '<--- symbolic names(tags) iPixelType AS USHORT, _ '<--- type of pixel format cColorBits AS USHORT, _ '<--- # of bits required to display colors; _ 'accepted values: 8, 16, 24, 32 cDepthBits AS USHORT, _ '<--- # of bits for color depth calculations; _ 'accepted values: 8, 16, 24, 32 dwLayerMask AS ULONG '<--- which plain to draw on; one valid value: 'PFD.MAIN.PLANE
Dc = 0 WinRc = 0
tOgl.WinHndl.struct = WinHndl tOgl.dwFlags.struct = PFD.DRAW.TO.WINDOW OR PFD.SUPPORT.OPENGL OR PFD.DOUBLEBUFFER tOgl.dwLayerMask.struct = PFD.MAIN.PLANE tOgl.iPixelType.struct = PFD.TYPE.RGBA tOgl.cColorBits.struct = 32 tOgl.cDepthBits.struct = 32
CALLDLL #LBOGL, "FN_GLContext", tOgl AS STRUCT, RetVal AS LONG Dc = tOgl.WinDc.struct WinRc = tOgl.WinRc.struct
FN.GetPixelFormat = WinRc END FUNCTION
'----------------------------- '-----------------------------
FUNCTION FN.CreateWindow(Title$, BYREF Xwide, BYREF Yhigh, BYREF CtlHndl)
WS.BORDER = HEXDEC("&H00800000")
WinHndl = 0
Xwide = 300 Yhigh = 310
RetVal = 0
Ux = 0 Uy = 0 Cx = 0 Cy = 0
STYLEBITS #ORTHO.GFX, 0, WS.BORDER, 0, 0 GRAPHICBOX #ORTHO.GFX, 0, 0, 290, 270
RetVal = FN.ScreenCenter(Cx, Cy) Ux = INT(Cx - Xwide / 2) Uy = INT(Cy - Yhigh / 2) RetVal = FN.SetWinPos(Ux, Uy) RetVal = FN.SetWinSize(Xwide, Yhigh)
OPEN Title$ FOR WINDOW AS #ORTHO
WinHndl = HWND(#ORTHO) RetVal = FN.ClientSize(WinHndl, Xwide, Yhigh)
#ORTHO.GFX, "LOCATE 0 0 ";Xwide; " "; Yhigh #ORTHO, "REFRESH" #ORTHO, "TRAPCLOSE CLOSE.ORTHO" '#ORTHO.GFX, "when leftButtonDown ROTATE" CtlHndl = HWND(#ORTHO.GFX) FN.CreateWindow = WinHndl END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.Objects(WinHndl)
WS.SYSMENU = HEXDEC("&H00080000") WS.EX.TOPMOST = HEXDEC("&H00000008") DS.ABSALIGN = 01
BS.PUSHLIKE = HEXDEC("&H00001000")
RetVal = 0
Ux = 0 Uy = 0 Wide = 107 High = 135
RetVal = FN.GetWinRect(WinHndl, Ux, Uy, 0, 0) Ux = Ux - Wide
RetVal = FN.SetWinPos(Ux, Uy) RetVal = FN.SetWinSize(Wide, High)
STYLEBITS #CLR.RDOFR, BS.PUSHLIKE, 0, 0, 0 STYLEBITS #CLR.RDOBK, BS.PUSHLIKE, 0, 0, 0 STYLEBITS #CLR.RDOBO, BS.PUSHLIKE, 0, 0, 0
RADIOBUTTON #CLR.RDOFR, "FRNT TRIANGLE", CLR.RDO, CLR.RDO, 5, 5, 90, 20 RADIOBUTTON #CLR.RDOBK, "BACK TRIANGLE", CLR.RDO, CLR.RDO, 5, 30, 90, 20 RADIOBUTTON #CLR.RDOBO, "BOTH", CLR.RDO, CLR.RDO, 5, 55, 90, 20
BUTTON #CLR.BTNOK, "QUIT", QUIT.BUTTON, UL, 30, 80, 40, 20
STYLEBITS #CLR, DS.ABSALIGN, WS.SYSMENU, WS.EX.TOPMOST, 0 OPEN "OBJECTS" FOR DIALOG AS #CLR
END FUNCTION '-------------------------- '--------------------------
FUNCTION FN.DefineOglWindow(Xleft, Ytop, Wide, High)
GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
GL.MODELVIEW = HEXDEC("&H1700") GL.PROJECTION = HEXDEC("&H1701")
GL.FRONT = HEXDEC("&H0404") GL.BACK = HEXDEC("&H0405") GL.FRONT.AND.BACK = HEXDEC("&H0408")
GL.POINT = HEXDEC("&H1B00") GL.LINE = HEXDEC("&H1B01") GL.FILL = HEXDEC("&H1B02")
GL.FLAT = HEXDEC("&H1D00") GL.SMOOTH = HEXDEC("&H1D01") GL.DEPTH.TEST = HEXDEC("&H0B71")
R = 0.75 G = 0.5 B = 0.5
ClearBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR GL.ACCUM.BUFFER.BIT OR _ GL.STENCIL.BUFFER.BIT
CALLDLL #LBOGL, "GLBkgColor", R AS DOUBLE, G AS DOUBLE, _ B AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GLEnableFunc", GL.DEPTH.TEST AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLShade", GL.FLAT AS ULONG, RetVal AS VOID
CALLDLL #LBOGL, "GLPolyMode", GL.FRONT.AND.BACK AS ULONG, GL.FILL AS ULONG, _ RetVal AS VOID CALLDLL #LBOGL, "GLView", Xleft AS LONG, Ytop AS LONG, Wide AS LONG, _ High AS LONG, RetVal AS VOID CALLDLL #LBOGL, "GLMatMode", GL.PROJECTION AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID Lft = VAL(USING("###.####", -15.0)) Rgt = VAL(USING("###.####", 15.0)) Btm = VAL(USING("###.####", -15.0)) Top = VAL(USING("###.####", 15.0)) Ner = VAL(USING("###.####", -20.0)) Far = VAL(USING("###.####", 20.0)) CALLDLL #LBOGL, "OrthoGL", Lft AS DOUBLE, Rgt AS DOUBLE, Btm AS DOUBLE, _ Top AS DOUBLE, Ner AS DOUBLE, Far AS DOUBLE, _ RetVal AS VOID CALLDLL #LBOGL, "GLMatMode", GL.MODELVIEW AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID CALLDLL #LBOGL, "GLClearBuffers", ClearBits AS ULONG, RetVal AS VOID
END FUNCTION
'--------------------------------------- '---------------------------------------
FUNCTION FN.RenderBlend(GfxDc, Ubnd, BeginBlend) '####################################################### ' This function blends colors and creates transparency. ' Function "GLFuncBlend"(P1, P2) defines the blending/ ' transparency function. There are 17 parameter names, ' 9 for P1, and 8 for P2. Some of them work with windows, ' some do not. ' ' Once the blend function is defined, blending is ' implimented by using "GLEnableFunc"(GL.BLEND). ' ' Because the color data is in byte format, function ' FN.BcolorAlpha(R, G, B, A) is used to define the red, ' green, blue, and alpha colors. The alpha color is ' expressed as a real(decimal) number in the range zero ' to one where zero is complete transparency and one is ' complete opacity. Thus, when FN.BcolorAlpha() is called ' it it might look something like this: ' ' RetVal = FN.BcolorAlpha(255, 126, 64, 0.25) ' ' RetVal will contain the byte alpha color. '#######################################################
'<======= OPENGL EQUATES ==========> GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
GL.LINES = HEXDEC("&H0001") GL.QUADS = HEXDEC("&H0007") GL.TRIANGLES = HEXDEC("&H0004")
GL.SRC.ALPHA = HEXDEC("&H0302") GL.ONE.MINUS.SRC.ALPHA = HEXDEC("&H0303") GL.BLEND = HEXDEC("&H0BE2")
'<======= LOCAL VARIABLES ==========> ClrIdx = 0 RetVal = 0
ColorBits = 0
Z = BeginBlend I = 0
Trnx = 0 Trny = 0
ColorBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR GL.ACCUM.BUFFER.BIT OR _ GL.STENCIL.BUFFER.BIT
CALLDLL #LBOGL, "GLFuncBlend", GL.SRC.ALPHA AS ULONG, _ GL.ONE.MINUS.SRC.ALPHA AS ULONG, RetVal AS VOID
IF (Z = 2) OR (Z = 3) THEN CALLDLL #LBOGL, "GLEnableFunc", GL.BLEND AS ULONG, RetVal AS VOID END IF
CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID
'###################################################### ' This is the back triangle; Z is less than zero. ' It blends with the background rather than showing ' transparency. '######################################################
CALLDLL #LBOGL, "GLStart", GL.TRIANGLES AS ULONG, RetVal AS VOID
FOR I = 0 TO 2 ClrIdx = Trng(I, 3) - 1 IF ClrIdx > -1 THEN '<======== play with the decimal alpha color ==========> RetVal = FN.BcolorAlpha(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2), .25) END IF
RetVal = FN.Vertexf(Trng(I, 0), Trng(I, 1), Trng(I, 2)) NEXT I CALLDLL #LBOGL, "GLStop", RetVal AS VOID
IF Z = 2 THEN CALLDLL #LBOGL, "GLDisableFunc", GL.BLEND AS ULONG, RetVal AS VOID END IF
IF Z = 1 THEN CALLDLL #LBOGL, "GLEnableFunc", GL.BLEND AS ULONG, RetVal AS VOID END IF
'###################################################### ' This is the front triangle; Z is greater than the ' back triangle. ' It blends with and is transparent over the back triangle and ' background. '######################################################
CALLDLL #LBOGL, "GLStart", GL.TRIANGLES AS ULONG, RetVal AS VOID FOR I = 3 TO Ubnd ClrIdx = Trng(I, 3) - 1 IF ClrIdx > -1 THEN RetVal = FN.BcolorAlpha(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2), .50) END IF
RetVal = FN.Vertexf(Trng(I, 0), Trng(I, 1), Trng(I, 2)) NEXT I CALLDLL #LBOGL, "GLStop", RetVal AS VOID
CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID CALLDLL #LBOGL, "GLSwap", GfxDc AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLClearBuffers", ColorBits AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLDisableFunc", GL.BLEND AS ULONG, RetVal AS VOID
END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.Bcolor(R, G, B)
RetVal = 0 CALLDLL #LBOGL, "GLubColor", R AS USHORT, G AS USHORT, B AS USHORT, RetVal AS VOID
END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.BcolorAlpha(R, G, B, Alpha)
RetVal = 0
IF Alpha < 0 THEN Alpha = 0 IF Alpha > 1 THEN Alpha = 1
Alpha = INT(255 * Alpha) CALLDLL #LBOGL, "GL4ubColor", R AS USHORT, G AS USHORT, B AS USHORT, _ Alpha AS USHORT, RetVal AS VOID FN.BcolorAlpha = Alpha END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.Vertexf(X, Y, Z)
RetVal = 0 CALLDLL #LBOGL, "GL3fVertex", X AS DOUBLE, Y AS DOUBLE, Z AS DOUBLE, _ RetVal AS VOID END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.TriangleData() '######################################## '########################################
' X Y Z color index DATA -03, 3, -2, 1 DATA -07, -3, -2, 0 DATA 02, -3, -2, 0
DATA 00, 2, 2, 3 DATA -03, -4, 2, 0 DATA 03, -4, 2, 0
'<======= LOCAL VARIABLES =========> I = 0 J = 0
Ubnd = 0 Varb = 0
Ubnd = 5 REDIM Trng(Ubnd, 3) '<--- 12 ROWS, 4 COLUMNS
FOR I = 0 TO Ubnd FOR J = O TO 3 READ Varb Trng(I, J) = Varb NEXT J NEXT I
FN.TriangleData = Ubnd END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.ColorData() '######################################## ' Colors used to fill the shapes '########################################
' red green blue DATA 255, 255, 0 '<--- yellow DATA 0, 255, 0 '<--- green DATA 0, 255, 255 '<--- cyan
'<========== LOCAL VARIABLES ========> I = 0 J = 0 Ubnd = 0 Varb = 0
Ubnd = 2 REDIM Kolr(Ubnd, 2) '<--- 3 rows, 3 columns
FOR I = 0 TO Ubnd FOR J = 0 TO 2 READ Varb Kolr(I, J)= Varb NEXT J NEXT I
FN.ColorData = Ubnd END FUNCTION
'------------------------------------ '------------------------------------
FUNCTION FN.ClientSize(WinHndl, BYREF Xw, BYREF Yh)
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
RetVal = 0 CALLDLL #USER, "GetClientRect", WinHndl AS ULONG, tRect AS STRUCT, RetVal AS LONG
Xw = tRect.X1.struct Yh = tRect.Y1.struct
FN.GetClient = RetVal END FUNCTION
'--------------------------- '---------------------------
FUNCTION FN.GetWinRect(WinHndl, BYREF Ux, BYREF Uy, BYREF Bx, BYREF By)
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
RetVal = 0 CALLDLL #USER, "GetWindowRect", WinHndl AS ULONG, tRect AS STRUCT, RetVal AS LONG
Ux = tRect.X.struct Uy = tRect.Y.struct Bx = tRect.X1.struct By = tRect.Y1.struct
FN.GetWinRect = RetVal END FUNCTION
'--------------------------- '---------------------------
FUNCTION FN.ScreenCenter(BYREF Cx, BYREF Cy)
Cx = INT(DisplayWidth * 0.5) Cy = INT(DisplayHeight * 0.5)
FN.ScreenCenter = Cx * Cy END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.SetWinPos(PosX, PosY)
UpperLeftX = PosX UpperLeftY = PosY
FN.SetWinPos = PosX * PosY END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.SetWinSize(Szx, Szy)
WindowWidth = Szx WindowHeight = Szy
FN.SetWinSize = Szx * Szy END FUNCTION
'--------------------------- '--------------------------- '
BLEND.ZIP (9.21 KB)
|
|
|
OPENGL?
Jun 13, 2023 17:09:33 GMT -5
Post by Walt Decker on Jun 13, 2023 17:09:33 GMT -5
MULTIPLE VIEW PORTS
I am amazed that, since I am using a graphic control, i. e. GRAPHIC BOX, no one has asked if it is possible to capture the image or make it stick if the window is minimized or obscured by another window. ' '############################################### ' LSN5_VIEWPORTS.BAS ' This introduces multiple viewports. ' See function FN.MultipleViewPorts() ' ' Function FN.RenderScene() is not used in this ' demo. '###############################################
NOMAINWIN
DIM Quad(-1, -1) DIM Trng(-1, -1) DIM Poly(-1, -1) DIM Lins(-1, -1) DIM Kolr(-1, -1)
GLOBAL Wrc, _ Wdc
GLOBAL Qubnd, _ Tubnd, _ Pubnd, _ Lubnd
GLOBAL App.Done
OPEN "User32.DLL" FOR DLL AS #USER OPEN "Kernel32.DLL" FOR DLL AS #KERN OPEN "LBOGL 0" FOR DLL AS #LBOGL
WinHndl = 0 GfxHndl = 0 RetVal = 0 GfxDc = 0 GfxRc = 0
Qubnd = 0 Cubnd = 0
Xw = 0 Yh = 0
[BEGIN] Qubnd = FN.QuadData() Tubnd = FN.TriangleData() Pubnd = FN.PolygonData() Lubnd = FN.LineData()
Cubnd = FN.ColorData() WinHndl = FN.CreateWindow("VIEWPORTS 1", Xw, Yh, GfxHndl) GfxRc = FN.GetPixelFormat(GfxHndl, GfxDc) Wrc = GfxRc Wdc = GfxDc
RetVal = FN.DefineOglWindow(0, 0, Xw, Yh) 'RetVal = FN.RenderScene(GfxDc, Qubnd, 0) RetVal = FN.MultipleViewports(GfxDc, WinHndl) WAIT
'------------------------------- '-------------------------------
SUB CLOSE.ORTHO WinHndl$
WinRc = Wrc App.Done = 1
CALLDLL #LBOGL, "GLMakeCurrent", 0 AS ULONG, 0 AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLDeleteContext", WinRc AS ULONG, RetVal AS VOID
CLOSE #LBOGL CLOSE #USER CLOSE #KERN CLOSE #WinHndl$
END SUB
'------------------------------------ '------------------------------------
SUB EXIT.VIEW MsHndl$, Mx, My
RetVal = 0 App.Done = 1
CALL CLOSE.ORTHO "#ORTHO" END SUB
'------------------------------------ '------------------------------------
FUNCTION FN.GetPixelFormat(WinHndl, BYREF Dc) '##################################################### ' The following commented out struct is the actual structure ' windows expects when requesting a rendering context for ' OPENGL.DLL. The structure used by LBOGL 0.DLL is a small ' part of this structure with a couple of features added. '#####################################################
'TYPEDEF STRUCT PIXELFORMATDESCRIPTOR ' nSize AS WORD <--- size of struct ' nVersion AS WORD <--- version, set to 1 ' dwFlags AS DWORD <--- constants describing ' what the format shoul look like ' iPixelType AS BYTE <--- RGBA pixels. Each pixel has ' four components: red, green, blue, and alpha ' cColorBits AS BYTE Specifies the number of color bitplanes in ' each color buffer. For RGBA pixel types, it ' is the size of the color buffer excluding the ' alpha bitplanes. For color index pixels, it ' is the size of the color index buffer. Values ' of 8, 16, 24, 32 are acceptable. ' cRedBits AS BYTE ' cRedShift AS BYTE ' cGreenBits AS BYTE ' cGreenShift AS BYTE ' cBlueBits AS BYTE ' cBlueShift AS BYTE ' cAlphaBits AS BYTE ' cAlphaShift AS BYTE ' cAccumBits AS BYTE ' cAccumRedBits AS BYTE ' cAccumGreenBits AS BYTE ' cAccumBlueBits AS BYTE ' cAccumAlphaBits AS BYTE ' cDepthBits AS BYTE ' cStencilBits AS BYTE ' cAuxBuffers AS BYTE ' iLayerType AS BYTE ' bReserved AS BYTE ' dwLayerMask AS DWORD <--- Specifies the type of layer. The ' current version supports only the main ' plane (there is no support for overlay or ' underlay planes) ' dwVisibleMask AS DWORD ' dwDamageMask AS DWORD
PFD.DOUBLEBUFFER = HEXDEC("&H00000001") PFD.STEREO = HEXDEC("&H00000002") PFD.DRAW.TO.WINDOW = HEXDEC("&H00000004") PFD.DRAW.TO.BITMAP = HEXDEC("&H00000008") PFD.SUPPORT.GDI = HEXDEC("&H00000010") PFD.SUPPORT.OPENGL = HEXDEC("&H00000020")
PFD.TYPE.RGBA = 0 PFD.MAIN.PLANE = 0
STRUCT tOgl, _ WinHndl AS ULONG, _ '<--- INPUT; handle of target window WinDc AS ULONG, _ '<--- RETURN; device context used for drawing WinRc AS ULONG, _ '<--- RETURN; rendering context for OPENGL. dwFlags AS ULONG, _ '<--- symbolic names(tags) iPixelType AS USHORT, _ '<--- type of pixel format cColorBits AS USHORT, _ '<--- # of bits required to display colors; _ 'accepted values: 8, 16, 24, 32 cDepthBits AS USHORT, _ '<--- # of bits for color depth calculations; _ 'accepted values: 8, 16, 24, 32 dwLayerMask AS ULONG '<--- which plain to draw on; one valid value: 'PFD.MAIN.PLANE
Dc = 0 WinRc = 0
tOgl.WinHndl.struct = WinHndl tOgl.dwFlags.struct = PFD.DRAW.TO.WINDOW OR PFD.SUPPORT.OPENGL OR PFD.DOUBLEBUFFER tOgl.dwLayerMask.struct = PFD.MAIN.PLANE tOgl.iPixelType.struct = PFD.TYPE.RGBA tOgl.cColorBits.struct = 32 tOgl.cDepthBits.struct = 32
CALLDLL #LBOGL, "FN_GLContext", tOgl AS STRUCT, RetVal AS LONG Dc = tOgl.WinDc.struct WinRc = tOgl.WinRc.struct
FN.GetPixelFormat = WinRc END FUNCTION
'----------------------------- '-----------------------------
FUNCTION FN.CreateWindow(Title$, BYREF Xwide, BYREF Yhigh, BYREF CtlHndl)
WS.BORDER = HEXDEC("&H00800000")
WinHndl = 0
Xwide = 300 Yhigh = 310
RetVal = 0
Ux = 0 Uy = 0 Cx = 0 Cy = 0
STYLEBITS #ORTHO.GFX, 0, WS.BORDER, 0, 0 GRAPHICBOX #ORTHO.GFX, 0, 0, 290, 270
RetVal = FN.ScreenCenter(Cx, Cy) Ux = INT(Cx - Xwide / 2) Uy = INT(Cy - Yhigh / 2) RetVal = FN.SetWinPos(Ux, Uy) RetVal = FN.SetWinSize(Xwide, Yhigh)
OPEN Title$ FOR WINDOW AS #ORTHO
WinHndl = HWND(#ORTHO) RetVal = FN.ClientSize(WinHndl, Xwide, Yhigh)
#ORTHO.GFX, "LOCATE 0 0 ";Xwide; " "; Yhigh #ORTHO, "REFRESH" #ORTHO, "TRAPCLOSE CLOSE.ORTHO" #ORTHO.GFX, "when leftButtonDown EXIT.VIEW" CtlHndl = HWND(#ORTHO.GFX) FN.CreateWindow = WinHndl END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.DefineOglWindow(Xleft, Ytop, Wide, High)
GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
GL.MODELVIEW = HEXDEC("&H1700") GL.PROJECTION = HEXDEC("&H1701")
GL.FRONT = HEXDEC("&H0404") GL.BACK = HEXDEC("&H0405") GL.FRONT.AND.BACK = HEXDEC("&H0408")
GL.POINT = HEXDEC("&H1B00") GL.LINE = HEXDEC("&H1B01") GL.FILL = HEXDEC("&H1B02")
GL.FLAT = HEXDEC("&H1D00") GL.SMOOTH = HEXDEC("&H1D01") GL.DEPTH.TEST = HEXDEC("&H0B71")
RetVal = 0 R = 0.0 G = 0.75 B = 0.0
ClearBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR GL.ACCUM.BUFFER.BIT OR _ GL.STENCIL.BUFFER.BIT
CALLDLL #LBOGL, "GLBkgColor", R AS DOUBLE, G AS DOUBLE, _ B AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GLEnableFunc", GL.DEPTH.TEST AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLShade", GL.SMOOTH AS ULONG, RetVal AS VOID TRACE 2 CALLDLL #LBOGL, "GLPolyMode", GL.FRONT.AND.BACK AS ULONG, GL.FILL AS ULONG, _ RetVal AS VOID 'CALLDLL #LBOGL, "GLView", Xleft AS LONG, Ytop AS LONG, Wide AS LONG, _ ' High AS LONG, RetVal AS VOID RetVal = FN.GlViewPort(Xleft, Ytop, Wide, High)
CALLDLL #LBOGL, "GLMatMode", GL.PROJECTION AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID Lft = VAL(USING("###.####", -15.0)) Rgt = VAL(USING("###.####", 15.0)) Btm = VAL(USING("###.####", -15.0)) Top = VAL(USING("###.####", 15.0)) Ner = VAL(USING("###.####", -20.0)) Far = VAL(USING("###.####", 20.0)) CALLDLL #LBOGL, "OrthoGL", Lft AS DOUBLE, Rgt AS DOUBLE, Btm AS DOUBLE, _ Top AS DOUBLE, Ner AS DOUBLE, Far AS DOUBLE, _ RetVal AS VOID CALLDLL #LBOGL, "GLMatMode", GL.MODELVIEW AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID CALLDLL #LBOGL, "GLClearBuffers", ClearBits AS ULONG, RetVal AS VOID
END FUNCTION
'--------------------------------------- '--------------------------------------- FUNCTION FN.GlViewPort(Ux, Uy, Xw, Yh)
CALLDLL #LBOGL, "GLView", Ux AS LONG, Uy AS LONG, Xw AS LONG, _ Yh AS LONG, RetVal AS VOID
FN.GlViewPort = Xw * Yh END FUNCTION
'--------------------------------------- '---------------------------------------
FUNCTION FN.RenderScene(GfxDc, Ubnd, BeginRotation)
'<=========== BACKGROUND COLOR =============> GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
'<=========== OBJECT PRIMATIVES =============> GL.QUADS = HEXDEC("&H0007") GL.POINTS = HEXDEC("&H0000") GL.LINES = HEXDEC("&H0001") GL.TRIANGLES = HEXDEC("&H0004") GL.POLYGON = HEXDEC("&H0009")
'<======= LOCAL VARIABLES ==========> ClrIdx = 0 RetVal = 0
ColorBits = 0
Z = BeginRotation I = 0 P1 = 1 P2 = 0 Deg = 0 Rx = 80 '<--- rotation around horizontal (X) axis
Szx = 1.5 '<--- scaling factors Szy = 1.5 Szz = 1
Trnx = 6 Trny = 0
ColorBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR GL.ACCUM.BUFFER.BIT OR _ GL.STENCIL.BUFFER.BIT DO CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID
IF Z <> 0 THEN CALLDLL #LBOGL, "GLMoveObj", Trnx AS DOUBLE, Trny AS DOUBLE, _ Trny AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fScale", Szx AS DOUBLE, Szy AS DOUBLE, _ Szz AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Deg AS DOUBLE, P2 AS DOUBLE, P1 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Rx AS DOUBLE, P1 AS DOUBLE, P2 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID END IF
CALLDLL #LBOGL, "GLStart", GL.QUADS AS ULONG, RetVal AS VOID FOR I = 0 TO 3 ClrIdx = Quad(I, 3) - 1
IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Quad(I, 0), Quad(I, 1), Quad(I, 2)) NEXT I CALLDLL #LBOGL, "GLStop", RetVal AS VOID
IF Z <> 0 THEN CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID CALLDLL #LBOGL, "GLLoadIdent", RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Deg AS DOUBLE, P2 AS DOUBLE, P1 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", Rx AS DOUBLE, P1 AS DOUBLE, P2 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID END IF
CALLDLL #LBOGL, "GLStart", GL.QUADS AS ULONG, RetVal AS VOID FOR I = 4 TO Ubnd ClrIdx = Quad(I, 3) - 1 IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Quad(I, 0), Quad(I, 1), Quad(I, 2)) NEXT I CALLDLL #LBOGL, "GLStop", RetVal AS VOID
'<=========== here we retrieve all matricies we saved ==============> IF Z <> 0 THEN CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID END IF
CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID CALLDLL #LBOGL, "GLSwap", GfxDc AS ULONG, RetVal AS VOID CALLDLL #LBOGL, "GLClearBuffers", ColorBits AS ULONG, RetVal AS VOID
Deg = Deg + 2 CALLDLL #KERN, "Sleep", 100 AS LONG, RetVal AS VOID SCAN
IF App.Done THEN EXIT DO
IF Deg > 452 THEN EXIT DO LOOP WHILE Z <> 0 END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.MultipleViewports(GfxDc, WinHndl) '################################################### ' Multiple view ports can come in handy, and they are ' fairly easy to implement. You just define the position ' on the drawing surface, save the modelview matrix, do ' whatever, get the original matrix, and move to the next ' viewport. ' ' In this demo the entire graphic control is first viewport is ' defined as the drawing surface and then it is divide up into ' three different viewports. '###################################################
'<=========== BACKGROUND COLOR =============> GL.DEPTH.BUFFER.BIT = HEXDEC("&H00000100") GL.COLOR.BUFFER.BIT = HEXDEC("&H00004000") GL.ACCUM.BUFFER.BIT = HEXDEC("&H00000200") GL.STENCIL.BUFFER.BIT = HEXDEC("&H00000400")
'<=========== OBJECT PRIMATIVES =============> GL.QUADS = HEXDEC("&H0007") GL.POINTS = HEXDEC("&H0000") GL.LINES = HEXDEC("&H0001") GL.TRIANGLES = HEXDEC("&H0004") GL.POLYGON = HEXDEC("&H0009")
ColorBits = GL.DEPTH.BUFFER.BIT OR GL.COLOR.BUFFER.BIT OR _ GL.ACCUM.BUFFER.BIT OR GL.STENCIL.BUFFER.BIT
RetVal = 0 ClrIdx = 0
V1.Angle = 0.0 V2.Angle = 0.0 V3.Angle = 0.0
Ux = 0 Uy = 0 Bx = 0 By = 0 Xw = 0 Yh = 0 P1 = 1 P2 = 0
RetVal = FN.ClientSize(WinHndl, Bx, By)
DO '################################################### ' This is the first viewport. You may wonder why ' "GLView"() is called directly rather than using ' function FN.GlViewPort(). The reason is there ' appears to be a glitch in LB. The first pass ' through FN.GlViewPort() the parser recognizes ' "GLView"() as a valid function. With subsequent ' passes through it does not recognize it as a ' valid function. Consequently, this is a work-around. '###################################################
Ux = 0 Uy = INT(By / 2) Xw = INT(Bx / 2) Yh = INT(By / 2) CALLDLL #LBOGL, "GLView", Ux AS LONG, Uy AS LONG, Xw AS LONG, Yh AS LONG, _ RetVal AS VOID '<--- define the viewport
' RetVal = FN.GlViewPort(Ux, Uy, INT(Bx / 2), INT(By / 2))
CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID '<--- save modelview matrix CALLDLL #LBOGL, "GL3fRotate", V1.Angle AS DOUBLE, P1 AS DOUBLE, P2 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID
CALLDLL #LBOGL, "GLStart", GL.TRIANGLES AS ULONG, RetVal AS VOID '<--- do stuff FOR I = 0 TO Tubnd ClrIdx = Trng(I, 3) - 1
IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Trng(I, 0), Trng(I, 1), Trng(I, 2)) NEXT I
CALLDLL #LBOGL, "GLStop", RetVal AS VOID CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID '<--- get clean modelview matrix
'<========= define next viewport and repeate above =============> Ux = INT(Bx / 2) Uy = INT(By / 2) Xw = INT(Bx / 2) Yh = INT(By / 2) CALLDLL #LBOGL, "GLView", Ux AS LONG, Uy AS LONG, Xw AS LONG, Yh AS LONG, _ RetVal AS VOID ' RetVal = FN.GlViewPort(Ux, Uy, Bx / 2, By / 2)
CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", V2.Angle AS DOUBLE, P2 AS DOUBLE, P1 AS DOUBLE, _ P2 AS DOUBLE, RetVal AS VOID
CALLDLL #LBOGL, "GLStart", GL.QUADS AS ULONG, RetVal AS VOID FOR I = 0 TO Qubnd ClrIdx = Quad(I, 3) - 1
IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Quad(I, 0), Quad(I, 1), Quad(I, 2)) NEXT I
CALLDLL #LBOGL, "GLStop", RetVal AS VOID CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID
Ux = 0 Uy = 0 Xw = Bx Yh = INT(By / 2) CALLDLL #LBOGL, "GLView", Ux AS LONG, Uy AS LONG, Xw AS LONG, Yh AS LONG, _ RetVal AS VOID ' RetVal = FN.GlViewPort(0, 0, Bx, By / 2) CALLDLL #LBOGL, "GLPushMat", RetVal AS VOID CALLDLL #LBOGL, "GL3fRotate", V3.Angle AS DOUBLE, P2 AS DOUBLE, P2 AS DOUBLE, _ P1 AS DOUBLE, RetVal AS VOID
CALLDLL #LBOGL, "GLStart", GL.POLYGON AS ULONG, RetVal AS VOID FOR I = 0 TO Pubnd ClrIdx = Poly(I, 3) - 1
IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Poly(I, 0), Poly(I, 1), Poly(I, 2)) NEXT I
CALLDLL #LBOGL, "GLStop", RetVal AS VOID CALLDLL #LBOGL, "GLPopMat", RetVal AS VOID
Ux = 0 Uy = 0 CALLDLL #LBOGL, "GLView", Ux AS LONG, Uy AS LONG, Bx AS LONG, By AS LONG, _ RetVal AS VOID ' RetVal = FN.GlViewPort(0, 0, Bx, By) 'full screen CALLDLL #LBOGL, "GLStart", GL.LINES AS ULONG, RetVal AS VOID FOR I = 0 TO Lubnd ClrIdx = Lins(I, 3) - 1
IF ClrIdx > -1 THEN RetVal = FN.Bcolor(Kolr(ClrIdx, 0), Kolr(ClrIdx, 1), Kolr(ClrIdx, 2)) END IF
RetVal = FN.Vertexf(Lins(I, 0), Lins(I, 1), Lins(I, 2)) NEXT I
CALLDLL #LBOGL, "GLStop", RetVal AS VOID
CALLDLL #LBOGL, "GLSwap", GfxDc AS ULONG, RetVal AS VOID 'Show the picture CALLDLL #LBOGL, "GLClearBuffers", ColorBits AS ULONG, RetVal AS VOID
V1.Angle = V1.Angle + 0.3 V2.Angle = V2.Angle - 0.3 V3.Angle = V3.Angle + 0.35
IF V3.Angle > 1450.0 THEN EXIT DO
CALLDLL #KERN, "Sleep", 10 AS LONG, ReVal AS VOID SCAN LOOP WHILE App.Done = 0
END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.Bcolor(R, G, B)
RetVal = 0 CALLDLL #LBOGL, "GLubColor", R AS USHORT, G AS USHORT, B AS USHORT, RetVal AS VOID
END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.BcolorAlpha(R, G, B, Alpha)
RetVal = 0
IF Alpha < 0 THEN Alpha = 0 IF Alpha > 1 THEN Alpha = 1
Alpha = INT(255 * Alpha) CALLDLL #LBOGL, "GL4ubColor", R AS USHORT, G AS USHORT, B AS USHORT, _ Alpha AS USHORT, RetVal AS VOID FN.BcolorAlpha = Alpha END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.Vertexf(X, Y, Z)
RetVal = 0 CALLDLL #LBOGL, "GL3fVertex", X AS DOUBLE, Y AS DOUBLE, Z AS DOUBLE, _ RetVal AS VOID END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.QuadData()
' X Y Z color index DATA -5, 5, 0, 5 DATA 5, 5, 0, 0 DATA 5, -5, 0, 1 DATA -5, -5, 0, 0
'<======= LOCAL VARIABLES =========> I = 0 J = 0
Ubnd = 0 Varb = 0
Ubnd = 3 REDIM Quad(Ubnd, 3)
FOR I = 0 TO Ubnd FOR J = O TO 3 READ Varb Quad(I, J) = Varb NEXT J NEXT I
FN.QuadData = Ubnd END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.TriangleData()
' X Y Z color index DATA 0, 5, 0, 1 DATA 5, 0, 0, 3 DATA -5, 0, 0, 4
I = 0 J = 0
Varb = 0 Ubnd = 2 REDIM Trng(Ubnd, 3)
FOR I = 0 TO Ubnd FOR J = 0 TO 3 READ Varb Trng(I, J) = Varb NEXT J NEXT I
FN.TriangleData = Ubnd END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.LineData()
' X Y Z COLOR INDEX DATA 0, 10, 0, 5 DATA 0, 0, 0, 0 DATA -10, 0, 0, 0 DATA 10, 0, 0, 0
Varb = 0 Ubnd = 3
I = 0 J = 0
DIM Lins(Ubnd, 3)
FOR I = 0 TO Ubnd FOR J = 0 TO 3 READ Varb Lins(I, J) = Varb NEXT J NEXT I
FN.LineData = Ubnd END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.PolygonData()
DegStep = 0
Radius = 5 Rad = 4 * ATN(1) / 180
I = 0 J = -1 X = 0 Y = 0 Ubnd = 4
REDIM Poly(5, 3) DegStep = 360 / 5
X = Radius Y = Radius
FOR I = 0 TO 360 STEP DegStep J = J + 1 X = Radius * SIN(I * Rad) Y = 0 - Radius * COS(I * Rad) Poly(J, 0) = X Poly(J, 1) = Y Poly(J, 2) = -1 Poly(J, 3) = J + 1 NEXT I
FN.PolygonData = Ubnd END FUNCTION
'---------------------------------------------------------------- '----------------------------------------------------------------
FUNCTION FN.ColorData() '######################################## ' Colors used to fill the shapes '########################################
' red green blue DATA 255, 255, 0 '<--- yellow DATA 0, 255, 0 '<--- green DATA 0, 255, 255 '<--- cyan DATA 255, 255, 255 '<--- white DATA 255, 0, 255 '<--- magenta DATA 255, 0, 0 '<--- red
'<========== LOCAL VARIABLES ========> I = 0 J = 0 Ubnd = 0 Varb = 0
Ubnd = 5 REDIM Kolr(Ubnd, 2)
FOR I = 0 TO Ubnd FOR J = 0 TO 2 READ Varb Kolr(I, J)= Varb NEXT J NEXT I
FN.ColorData = Ubnd END FUNCTION
'------------------------------------ '------------------------------------
FUNCTION FN.ClientSize(WinHndl, BYREF Xw, BYREF Yh)
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
RetVal = 0 CALLDLL #USER, "GetClientRect", WinHndl AS ULONG, tRect AS STRUCT, RetVal AS LONG
Xw = tRect.X1.struct Yh = tRect.Y1.struct
FN.GetClient = RetVal END FUNCTION
'--------------------------- '---------------------------
FUNCTION FN.ScreenCenter(BYREF Cx, BYREF Cy)
Cx = INT(DisplayWidth * 0.5) Cy = INT(DisplayHeight * 0.5)
FN.ScreenCenter = Cx * Cy END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.SetWinPos(PosX, PosY)
UpperLeftX = PosX UpperLeftY = PosY
FN.SetWinPos = PosX * PosY END FUNCTION
'-------------------------- '--------------------------
FUNCTION FN.SetWinSize(Szx, Szy)
WindowWidth = Szx WindowHeight = Szy
FN.SetWinSize = Szx * Szy END FUNCTION
'--------------------------- '--------------------------- '
|
|
|
OPENGL?
Jun 28, 2023 14:15:19 GMT -5
Post by Walt Decker on Jun 28, 2023 14:15:19 GMT -5
Terrain generation. I was going to have this using the standard functions in "LBOGL 0.DLL" but LB is just not fast enough to generate and render a complex image therefore I am using the extended functions resident in the dll. LB is still generating a small portion of the terrain.
The function that the dll uses is an exact copy of the commented out FN.Contour() which I wrote some 40-odd years ago.
On my 15+ year-old computer it takes about 1/2 second to generate a 100 x 100 terrain and display it. Once the terrain is displayed, changes to the orientation and primitive type are almost instantaneous and is comparable to the OPENGL display list functions.
There appears to be little interest in this subject therefore, this is the last I will be doing until there are questions or posted code indicating some interest in the subject.
ZIP CONTENTS:
LBOGL 0.DLL
TERRAIN_EX._BAS <--- source code
TERRAIN.ZIP
|
|
|
OPENGL?
Jun 28, 2023 14:47:03 GMT -5
via mobile
Post by Rod on Jun 28, 2023 14:47:03 GMT -5
I think it was about four years after I posted my blitter code that I got a sensible question. Still waiting on seeing someone actually use the blitter. But, I did enjoy the learning experience.
To sell something you need to take folks by the hand and lead them step by step till the can walk. Dumping a massive .dll is likely to scare folks away.
I have said this before, you have forgotten how much skill you have achieved. Mere beginners cannot hope to follow without assistance.
|
|
|
OPENGL?
Jun 28, 2023 16:09:53 GMT -5
Post by Walt Decker on Jun 28, 2023 16:09:53 GMT -5
I have not forgotten, Rod. I have not used opengl for years and have forgotten more than I ever knew about it. Most of the code I have posted or included in zip files is translations from code I wrote years ago. I have to go to the ogl man pages to see what the functions are doing and why I used those particular functions in that order.
Up until the post concerning blending, everything is very basic. The dll is just basic, very few functions other than the extended functions for terrain rendering.
The thread is for giving assistance. I can learn right along with others. The problem is, I may not have much more time on this rock and I have not even made it to Mars. That is still on my bucket list.
|
|
|
OPENGL?
Jun 30, 2023 15:56:51 GMT -5
Post by tsh73 on Jun 30, 2023 15:56:51 GMT -5
Hello Walt It's not so long - month still did not passed - as I finally read that topic. (real life scared me off from even looking into this supposedly big thing) Downloaded all stuff linked (TERRAIN.ZIP and four programs inlined here - quad, move, transparency, viewports) Tried them. They does work for me (this is good, my setup is pretty weird). Tried to tinker with "quad" demo (rotating box) with some unstructured googling. (Even Wikipedia, because I had NO DAMNED IDEA about it, at all.) I think I could make some cubes out of it now But understanding what it does really wants some reading. Line in your post looks really promising, but all previous (before TERRAIN.ZIP) zip links seems to be non-functional? So I did not got dll function list as well. Could you repost them somewhere, or mail them to me (email is in the profile)? Also, could you recommend some Open GL tutorial? Because I've seen some very old ones ( 1999) - and very new ones ("forget all you read before and start new way up"). What open GL version would work with LB?
|
|
|
OPENGL?
Jun 30, 2023 16:16:53 GMT -5
Post by tsh73 on Jun 30, 2023 16:16:53 GMT -5
Rod,
I never looked that stuff before (or I do not remember) but text still on LBPE. But zip file from the first lesson "OpenGL in LB.zip" does not opens for me. It looks like it contains LB wrappers for OpenGL functions, used in this tutorial. May be you still have it?
|
|