include "ogl.inc"
window 640,480,1
Enable GL_POINT_SMOOTH
Enable GL_LINE_SMOOTH
fontload(1,"glfonts/font15.bmp")
while key(27)=0
cls 100, 100, 100
color 255,255,0,255
line 0,100,639,100,6
color 255,255,0,200
line 0,106,639,106,6
color 255,255,0,128
line 0,112,639,112,6
color 255,200,200,255
box 50, 20,60,60,1
fillbox 110,20,60,60
circle 210,50,40,1
fillcircle 290,50,40
ellipse 370,50,40,20,1
fillellipse 430,50,20,40
color 0,255,255,255
for x=0 to 9
SetPoint(150+rand(1,19),150+rand(1,19),8)
next
GetPixel(110,112)
text(1,0, 0,"RED " + str(RED) ,16,16)
text(1,0,12,"GREEN " + str(GREEN),16,16)
text(1,0,24,"BLUE " + str(BLUE) ,16,16)
redraw
wait 10
wend
winExit
include "ogl.inc"
window 800,700,1
fontload 1,"glfonts/font01.bmp"
Enable GL_POINT_SMOOTH
float x,y,n
string s="LORENZ LANDSCAPE"
Color 255,255,255,255
while key(27)=0
cls 0,0,0
for t=0 to 100000
x=Sin(t*0.99)-0.7*cos(t*3.01)
y=Cos(t*1.01)+0.1*sin(t*15.03)
x=x*200+350
y=y*200+360
setpixel y,x
next
for i=1 to Len(s)
text 1,700,32+i*16,Mid(s,i,1),16,16
next
swap
wait 10
wend
winExit
Can any of your libraries or Win API + O2 code draw a similar picture?Of course not!
Dim %NZ[511, 511], !WB[1024, 384 To 768], !WX[1023, 384 To 767], !WY[1023, 384 To 767]
Dim %Col[1023, 767], %CC[128, 8]
NZ[(x + d) BAnd 511, y] = (NZ[x, y] + NZ[(x + d2) BAnd 511, y]) * 0.5 + d * (Rnd() - 0.5)
I did translate Mike's code to PB, however i must have done several errors in the translation, because what i get is rather far from the posted screen shot.How does it look?
and i would rather use a memory DIB bitmap to setup the pixels using direct addressing (pointer), then BitBlting everything in WM_PAINT in a blink eye.yes we like to know that ...if is not a problem.... ;)
FUNCTION zCreateDIBSection(BYVAL hDC AS LONG, BYVAL nWidth AS LONG, BYVAL nHeight AS LONG, BYVAL BitCount AS LONG) AS LONG
LOCAL bi AS BITMAPINFO
bi.bmiHeader.biSize = SIZEOF(bi.bmiHeader)
bi.bmiHeader.biWidth = nWidth
bi.bmiHeader.biHeight = nHeight
bi.bmiHeader.biPlanes = 1
bi.bmiHeader.biBitCount = BitCount
bi.bmiHeader.biCompression = %BI_RGB
FUNCTION = CreateDIBSection(hDC, bi, %DIB_RGB_COLORS, 0, 0, 0)
END FUNCTION
#COMPILE EXE "ML.exe"
#INCLUDE "MiniPB.inc" '// Flat API declaration
'MACRO Pi = 3.141592653589793##
'MACRO HalfPI = 1.5707963267948965##
'MACRO PiDiv4 = 0.785398163397448##
MACRO M_TWOPI = 6.28318530718##
'SetWindowLong(ME, GWL_STYLE, &H6000000)
%ClientW = 1024
%ClientH = 768
TYPE PROP
hMain as dword
MinTrackSizeW as long
MinTrackSizeH as long
col(1023, 767) as long
CC(128, 8) as long
NZ(511, 511) as long
WB(1024, 384 to 768) as single
WX(1023, 384 to 767) as single
WY(1023, 384 to 767) as single
FC as single
SX as single
SY as single
END TYPE
GLOBAL gP as PROP ''// Global class properties
function Lerp(byval c1 as single, byval c2 as single, byval k as single) as dword
function = ((c1 and &HFF) * k + (c2 and &HFF) * (1 - k)) or (((c1 and &HFF00) * k + (c2 and &HFF00) * (1 - k)) and &HFF00) or (((c1 and &HFF0000) * k + (c2 and &HFF0000) * (1 - k)) and &HFF0000)
end function
function BC(byval x as single, byval y as single) as single
local ix, iy as long
ix = round(x, 0): iy = round(y, 0)
gP.SX = x - ix: gP.SY = y - iy
local c0, c1, c2, c3 as long
local ixy, isyx, isxy, xy as single
ixy = (1 - gP.SX) * (1 - gP.SY)
isxy = gP.SX * (1 - gP.SY)
isyx = gP.SY * (1 - gP.SX)
xy = gP.SX * gP.SY
c0 = gP.CC(ix and 127, iy mod 9)
c1 = gP.CC((ix + 1) and 127, iy mod 9)
c2 = gP.CC(ix and 127, (iy + 1) mod 9)
c3 = gP.CC((ix + 1) and 127, (iy + 1) mod 9)
function = (c0 and &HFF) * ixy + (c1 and &HFF) * isxy + (c2 and &HFF) * isyx + (c3 and &HFF) * xy + _
((c0 and &HFF00) * ixy + (c1 and &HFF00) * isxy + (c2 and &HFF00) * isyx + (c3 and &HFF00) * xy and &HFF00) + _
((c0 and &HFF0000) * ixy + (c1 and &HFF0000) * isxy + (c2 and &HFF0000) * isyx + (c3 and &HFF0000) * xy and &HFF0000)
end function
function BN(byval x as single, byval y as single) as long
local ix, iy, idx, idy as long
ix = round(x, 0): iy = round(y, 0)
local ssx, ssy as single
gP.SX = x - ix: gP.SY = y - iy
ssx = 1 - gP.SX: ssy = 1 - gP.SY
idx = (ix + 1) and 511: idy = (iy + 1) and 511
ix = ix and 511: iy = iy and 511
function = gP.NZ(ix, iy) * ssx * ssy + gP.NZ(idx, iy) * gP.SX * ssy + gP.NZ(ix, idy) * ssx * gP.SY + gP.NZ(idx, idy) * gP.SX * gP.SY
end function
Sub Air(byval hDC as dword)
local x, y as long, c as dword, k1, k2, s as single
'local gtc as dword: gtc = GetTickCount()
'print "Running Air() ";
for y = 0 to 767
k1 = (1 - abs(383.5 - y) / 384) ^ 5
for x = 0 to 1023
if (y = gP.SY) then
k2 = 0.25
else
k2 = atn((x - gP.SX) / (y - gP.SY)) / M_TWOPI + 0.25
end if
if (y - gP.SY < 0) then k2 = k2 + 0.5
k2 = BN(k2 * 512, 0) * 0.03
k2 = 0.2 - k2 ^ 2: if k2 < 0 then k2 = 0
s = 30 / sqr((x - gP.SX) ^ 2 + (y - gP.SY) ^ 2)
if (s > 1) then s = 1
c = Lerp(&HFFFFFF, gP.FC, k2 * (1 - s))
SetPixelV(hDC, x, y, Lerp(c, gP.col(x, y), k1))
next
next
'Print GetTickCount() - gtc, " msec"
end sub
sub Water()
local sx1, sy1, sx2, sy2 as single
local x, y, x1, y1, k, kx as long
'local gtc as dword: gtc = GetTickCount()
'Print "Running Water() "
for y = 767 to 384 step -1
k = (y - 383) * 0.5: kx = (900 - y) / 580
for x = 1023 to 0 step -1
sy1 = 64000 / (y - 380)
sx1 = (x - 511.5) * sy1 * 0.002
sy2 = sy1 * 0.34 - sx1 * 0.71
sx2 = sx1 * 0.34 + sy1 * 0.71
sy1 = sy2 * 0.34 - sx2 * 0.21
sx1 = sx2 * 0.34 + sy2 * 0.21
gP.WB(x, y) = BN(sx1, sy1) - BN(sx2, sy2)
gP.WX(x, y) = (gP.WB(x + 1, y) - gP.WB(x, y)) * k * kx
gP.WY(x, y) = (gP.WB(x, y + 1) - gP.WB(x, y)) * k
x1 = abs(x + gP.WX(x, y))
y1 = 768 - y + gP.WY(x, y)
if (y1 < 0) then
y1 = 0
elseif (y1 > 383) then
y1 = 383
end if
gP.col(x, y) = Lerp(BC(x1 / 8 / 2, y1 / 48 / 2), &H251510, kx) ' water tint
next
next
'Print GetTickCount() - gtc, " msec"
end sub
sub Sky()
local x, y, k as long
local c1, c2 as dword
local s, sx1, sy1, dy as single
'local gtc as dword: gtc = GetTickCount()
'Print "Running Sky() ";
gP.SX = 100 + rnd() * 824: gP.SY = 192 + rnd() * 157
for y = 0 to 383
sy1 = 100000 / (390 - y)
for x = 0 to 1023
sx1 = (x - 511.5) * sy1 * 0.0005
k = BN(sx1, sy1) - BN(sx1 * 0.14 + sy1 * 0.21, sy1 * 0.14 - sx1 * 0.21)
if (k < -8) then
k = 0
else
k = (k + 8) * 0.02 ' cloud density
end if
if (k > 1) then k = 1
dy = y / 384
gP.FC = &H908000 + (gP.SY + 500) * 0.2 ' haze tint
c1 = Lerp(gP.FC + 25, &H906050, dy)
c2 = Lerp(&H807080, &HD0D0D0, dy)
s = 30 / sqr((x - gP.SX) ^ 2 + (y - gP.SY) ^ 2) ' sun size
if (s > 1) then s = 1
c1 = Lerp(&HFFFFFF, c1, s)
gP.col(x, y) = Lerp(c2, c1, k)
next
next
'Print GetTickCount() - gtc, " msec"
end sub
sub Colorize()
local x, y, xx, yy, c, r, g, b, nc as long
'local gtc as dword: gtc = GetTickCount()
'Print "Running Colorize() ";
for x = 0 to 127
for y = 0 to 7
r = g = b = 0
for yy = 0 to 47
for xx = 0 to 7
c = gP.col(xx + x * 8, yy + y * 48)
r = r + (c and &HFF)
g = g + (c and &HFF00)
nc = c and &HFF0000: shift right nc, 8
b = b + nc
next
next
nc = (b \ 384) and &HFF00: shift left nc, 8
gP.CC(x, y) = r \ 384 + ((g \ 384) and &HFF00) + nc
next
gP.CC(x, 8) = gP.CC(x, 7)
next
'Print GetTickCount() - gtc, " msec"
end sub
sub Initialize()
local x, y, d, d2 as long
d = 64: d2 = 128
'local gtc as dword: gtc = GetTickCount()
'Print "Running Initialize() ";
randomize
do
for y = 0 to 511 step d2
for x = 0 to 511 step d2
gP.NZ((x + d) and 511, y) = (gP.NZ(x, y) + gP.NZ((x + d2) and 511, y)) * 0.5 + d * (rnd() - 0.5)
gP.NZ(x, (y + d) and 511) = (gP.NZ(x, y) + gP.NZ(x, (y + d2) and 511)) * 0.5 + d * (rnd() - 0.5)
gP.NZ((x + d) and 511, (y + d) and 511) = (gP.NZ(x, y) + gP.NZ((x + d2) and 511, (y + d2) and 511) + gP.NZ(x, (y + d2) and 511) + gP.NZ((x + d2) and 511, y)) * 0.25 + d * (rnd() - 0.5)
next
next
if d = 1 then exit do
d = d \ 2: d2 = d + d
loop
'Print GetTickCount() - gtc, " msec"
end sub
sub RenderScene(byval hDC as dword)
Initialize()
Sky()
Colorize()
Water()
Air(hDC)
end sub
function WndProc(byval hWnd as dword, byval Msg as dword, byval wParam as dword, byval lParam as dword) as long
LOCAL ps as PAINTSTRUCT
LOCAL rc as RECT
SELECT CASE long Msg
CASE %WM_GETMINMAXINFO
LOCAL pMM as MINMAXINFO PTR
pMM = lParam
@pMM.ptMinTrackSize.x = gP.MinTrackSizeW
@pMM.ptMinTrackSize.y = gP.MinTrackSizeH
'case %WM_NCHITTEST
' function = 2 ' %HTCAPTION
' exit function
CASE %WM_SIZE
InvalidateRect(hWnd, byval(%NULL), %TRUE)
CASE %WM_COMMAND
LOCAL wmId, wmEvent as long
wmID = LOINT(wParam)
wmEvent = HIINT(wParam)
'//SELECT CASE long LOWRD(wParam)
'//
'//END SELECT
CASE %WM_PAINT
LOCAL hDC as dword
'InvalidateRect(hWnd, %NULL, %FALSE)
hDC = BeginPaint(hWnd, ps)
'// Paint the window content here
RenderScene(hDC)
EndPaint(hWnd, ps)
function = 0: EXIT function
CASE %WM_DESTROY
PostQuitMessage(0)
function = 0: EXIT function
END SELECT
function = DefWindowProc(hWnd, Msg, wParam, lParam)
end function
function WinMain (byval hInstance as long, _
byval hPrevInstance as long, _
byval lpCmdLine as ASCIIZ PTR, _
byval iCmdShow as long) as long
LOCAL nRet as dword
LOCAL wcx as WNDCLASSEXA
LOCAL szClass as ASCIIZ * 16
szClass = "FLAT_API_POPUP" '// The class name of our popup window.
wcx.cbSize = SIZEOF(wcx)
LOCAL IsInitialized as long
IsInitialized = GetClassInfoEx(hInstance, szClass, wcx)
if IsInitialized& = 0 then
wcx.style = %CS_HREDRAW OR %CS_VREDRAW
wcx.lpfnWndProc = CODEPTR(WndProc)
wcx.cbClsExtra = 0
wcx.cbWndExtra = 0 '// %EXTEND_EXTRA * 4
wcx.hInstance = hInstance
wcx.hIcon = %NULL
wcx.hCursor = LoadCursor(%NULL, byval %IDC_ARROW)
wcx.hbrBackground = GetStockObject(%WHITE_BRUSH)
wcx.lpszMenuName = %NULL
wcx.lpszClassName = VARPTR(szClass)
wcx.hIconSm = wcx.hIcon
if RegisterClassEx(wcx) then IsInitialized = %TRUE
end if
if (IsInitialized) then
LOCAL r as RECT
LOCAL uMsg as TagMSG
LOCAL dwExStyle, dwStyle, hMain as dword
LOCAL x, y as long
dwExStyle = %WS_EX_APPWINDOW OR %WS_EX_WINDOWEDGE
dwStyle = %WS_POPUP OR %WS_CAPTION OR %WS_SYSMENU OR %WS_THICKFRAME OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN
SetRect(r, 0, 0, %ClientW, %ClientH)
AdjustWindowRectEx(r, dwStyle, %FALSE, dwExStyle)
gP.MinTrackSizeW = r.nRight - r.nLeft
gP.MinTrackSizeH = r.nBottom - r.nTop
x = MAX&((GetSystemMetrics(%SM_CXSCREEN) - gP.MinTrackSizeW) \ 2, 0)
y = MAX&((GetSystemMetrics(%SM_CYSCREEN) - gP.MinTrackSizeH) \ 2, 0)
gP.hMain = CreateWindowEx(dwExStyle, szClass, "Popup window 32-bit", dwStyle, _
x, y, gP.MinTrackSizeW, gP.MinTrackSizeH, 0, 0, hInstance, byval %NULL)
if (gP.hMain) then
ShowWindow(gP.hMain, iCmdShow)
SetForegroundWindow(gP.hMain) '// Slightly Higher Priority
WHILE GetMessage(uMsg, %NULL, 0, 0)
TranslateMessage(uMsg)
DispatchMessage(uMsg)
WEND
nRet = uMsg.wParam
end if
end if
function = nRet
end function
'// Flat API declaration
%CS_VREDRAW = &H0001
%CS_HREDRAW = &H0002
%SM_CXSCREEN = 0
%SM_CYSCREEN = 1
%IDC_ARROW = 32512
%WS_BORDER = 8388608
%WS_POPUP = -2147483648
%WS_CHILD = 1073741824
%WS_VISIBLE = 268435456
%WS_CLIPSIBLINGS = 67108864
%WS_CLIPCHILDREN = 33554432
%WS_CAPTION = 12582912
%WS_SYSMENU = 524288
%WS_THICKFRAME = 262144
%WS_MINIMIZEBOX = 131072
%WS_MAXIMIZEBOX = 65536
%WS_TABSTOP = %WS_MAXIMIZEBOX
%WS_VSCROLL = 2097152
%WS_EX_APPWINDOW = 262144
%WS_EX_WINDOWEDGE = 256
%WM_CREATE = &H1
%WM_DESTROY = &H2
%WM_PAINT = &HF
%WM_CLOSE = &H10
%WM_COMMAND = &H111
%WM_GETMINMAXINFO = &H24
%TRUE = 1
%FALSE = 0
%NULL = 0
%SW_HIDE = 0
%SW_SHOW = 5
%WHITE_BRUSH = 0
TYPE POINT
x AS LONG '// long x
y AS LONG '// long y
END TYPE
TYPE TagMSG
hWnd AS DWORD '// HWND hwnd
nMessage AS DWORD '// UINT Message
wParam AS DWORD '// WPARAM wParam
lParam AS DWORD '// LPARAM lParam
nTime AS DWORD '// DWORD time
pt AS POINT '// POINT pt
END TYPE
TYPE RECT
nLeft AS LONG '// long Left
nTop AS LONG '// long top
nRight AS LONG '// long Right
nBottom AS LONG '// long bottom
END TYPE
TYPE WNDCLASSEXA
cbSize AS DWORD '//Type C : UINT
style AS DWORD '//Type C : UINT
lpfnWndProc AS DWORD '//Type C : WNDPROC
cbClsExtra AS LONG '//Type C : int
cbWndExtra AS LONG '//Type C : int
hInstance AS DWORD '//Type C : HINSTANCE
hIcon AS DWORD '//Type C : HICON
hCursor AS DWORD '//Type C : HCURSOR
hbrBackground AS DWORD '//Type C : HBRUSH
lpszMenuName AS DWORD '//Type C : LPCSTR
lpszClassName AS DWORD '//Type C : LPCSTR
hIconSm AS DWORD '//Type C : HICON
END TYPE
TYPE PAINTSTRUCT
hdc AS DWORD '//Type C : HDC
fErase AS LONG '//Type C : BOOL
rcPaint AS RECT '//RECT est une autre structure
fRestore AS LONG '//Type C : BOOL
fIncUpdate AS LONG '//Type C : BOOL
rgbReserved AS ASCIIZ * 32 '//Type C : BYTE
END TYPE
TYPE MINMAXINFO
ptReserved AS POINT
ptMaxSize AS POINT
ptMaxPosition AS POINT
ptMinTrackSize AS POINT
ptMaxTrackSize AS POINT
END TYPE
DECLARE FUNCTION AdjustWindowRectEx LIB "USER32.DLL" ALIAS "AdjustWindowRectEx" (lpRect AS RECT, BYVAL dsStyle AS LONG, BYVAL bMenu AS LONG, BYVAL dwEsStyle AS DWORD) AS LONG
DECLARE FUNCTION BeginPaint LIB "USER32.DLL" ALIAS "BeginPaint" (BYVAL hWnd AS DWORD, lpPaint AS PAINTSTRUCT) AS LONG
DECLARE FUNCTION CreateWindowEx LIB "USER32.DLL" ALIAS "CreateWindowExA" (BYVAL dwExStyle AS DWORD, lpClassName AS ASCIIZ, lpWindowName AS ASCIIZ, BYVAL dwStyle AS DWORD, BYVAL x AS LONG, BYVAL y AS LONG, _
BYVAL nWidth AS LONG, BYVAL nHeight AS LONG, BYVAL hWndParent AS DWORD, BYVAL hMenu AS DWORD, BYVAL hInstance AS DWORD, lpParam AS ANY) AS DWORD
DECLARE FUNCTION DefWindowProc LIB "USER32.DLL" ALIAS "DefWindowProcA" (BYVAL hWnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
DECLARE FUNCTION DispatchMessage LIB "USER32.DLL" ALIAS "DispatchMessageA" (lpMsg AS tagMSG) AS LONG
DECLARE FUNCTION EndPaint LIB "USER32.DLL" ALIAS "EndPaint" (BYVAL hWnd AS DWORD, lpPaint AS PAINTSTRUCT) AS LONG
DECLARE FUNCTION GetClassInfoEx LIB "USER32.DLL" ALIAS "GetClassInfoExA" (BYVAL hInst AS DWORD, lpszClass AS ASCIIZ, lpWndClass AS WNDCLASSEXA) AS LONG
DECLARE FUNCTION GetMessage LIB "USER32.DLL" ALIAS "GetMessageA" (lpMsg AS tagMSG, BYVAL hWnd AS DWORD, BYVAL uMsgFilterMin AS DWORD, BYVAL uMsgFilterMax AS DWORD) AS LONG
DECLARE FUNCTION GetStockObject LIB "GDI32.DLL" ALIAS "GetStockObject" (BYVAL nIndex AS LONG) AS DWORD
DECLARE FUNCTION GetSystemMetrics LIB "USER32.DLL" ALIAS "GetSystemMetrics" (BYVAL nIndex AS LONG) AS LONG
DECLARE FUNCTION InvalidateRect LIB "USER32.DLL" ALIAS "InvalidateRect" (BYVAL hWnd AS DWORD, lpRect AS RECT, BYVAL bErase AS LONG) AS LONG
DECLARE SUB PostQuitMessage LIB "USER32.DLL" ALIAS "PostQuitMessage" (BYVAL nExitCode AS LONG)
DECLARE FUNCTION RegisterClassEx LIB "USER32.DLL" ALIAS "RegisterClassExA" (pcWndClassEx AS WNDCLASSEXA) AS WORD
DECLARE FUNCTION SetForegroundWindow LIB "USER32.DLL" ALIAS "SetForegroundWindow" (BYVAL hWnd AS DWORD) AS LONG
DECLARE FUNCTION SetRect LIB "USER32.DLL" ALIAS "SetRect" (lpRect AS RECT, BYVAL X1 AS LONG, BYVAL Y1 AS LONG, BYVAL X2 AS LONG, BYVAL Y2 AS LONG) AS LONG
DECLARE FUNCTION ShowWindow LIB "USER32.DLL" ALIAS "ShowWindow" (BYVAL hWnd AS DWORD, BYVAL nCmdShow AS LONG) AS LONG
DECLARE FUNCTION TranslateMessage LIB "USER32.DLL" ALIAS "TranslateMessage" (lpMsg AS tagMSG) AS LONG
DECLARE FUNCTION LoadCursor LIB "USER32.DLL" ALIAS "LoadCursorA" (BYVAL hInstance AS DWORD, lpCursorName AS ASCIIZ) AS DWORD
declare function SetPixelV lib "GDI32.DLL" alias "SetPixelV" (byval hDC as dword, byval x as long, byval y as long, byval crColor as dword) as long
John's servers weren't accessible from this country for quite some time,
Why didn't you e-mail me with the issue on your end?