View Full Version : sending a required byref parameter error
I am getting an error for a gl command that requires a parameter passed byref. I read the topic where there was a similar problem and Petr seemed to correct stuff in the gl headers to fix it.
I am running into the same problem I think and need help. I think I got the code converted pretty much, but I do get the message about expecting a byref parameter.
Also in this example there are many instances of typecasting. I just took them out thinking that thinBasic makes the conversions for us automatically, but I am not sure about this.
The original c code is at the end of the script in its entirety. The top part is my conversion. It takes a while to process the original 524x524 texture, so i cut it down to 32x32 while developing and am trying to overcome all the errors. I am stuck at this point with this byref problem.
Thanks for any help!!
OK, I got passed the error. I changed the type of the variable to match what is in the include definitions and it stopped giving the error.
Next, the program would run and nothing would appear. But I kept tinkering and finally got 32x32 garbage to appear, but it is not the noise pattern-- as when I run the c version, it looks like a cloud noise filter in paint programs.
Perhaps someone can figure out what is wrong. Sorry for all the comments and experiments in the code. It is by trial and error I got this far. This gives no errors, but is reading from either the wrong area in memory or is not writing correctly to it as it should. Hope someone can figure out where it goofs. The original c code is still in the first post's attachment, just my part of the code is changed as shown here. The attachment has the original error script as it is the closest to the original conversion of the c source.
Thanks for any help.
Uses "TBGL"
Uses "UI"
#INCLUDE "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#INCLUDE "%APP_INCLUDEPATH%\thinbasic_glu.inc"
%ImageWidth = 32 '--- cut it down to 32 as it took too long with 524
%ImageHeight = 32 '--- cut it down to 32 as it took too long with 524
global MatrixImage(%ImageHeight,%ImageWidth,3) as GLvoid
global perlinRGB(3) as single
global height as GLint
Dim hDlg As Dword
hDlg = TBGL_CreateWindow("Procedural Texture")
TBGL_ShowWindow
init()
WHILE IsWindow(hDlg)
TBGL_ClearFrame
'tbgl_UseDepthMask 0
'tbgl_RenderMatrix2D
'glLoadIdentity
'gluLookAt (0,0,5,0,0,0,0,0,0) ' Setups camera to look from 0,0,5 to 0,0,0
'display()
'glRasterPos2i(0, 0)
'glDrawPixels(%ImageWidth, %ImageHeight, %GL_RGB,%GL_UNSIGNED_BYTE, MatrixImage)
reshape(%ImageWidth,%ImageHeight)
display()
TBGL_DrawFrame
'reshape(32,32)
'display()
if GetAsyncKeyState(%VK_ESCAPE) then
EXIT WHILE
end if
WEND
TBGL_DestroyWindow
function InterPolation(a as single, b as single, c as single) as single
function = a+(b-a)*c*c*(3-2*c)
end function
function InterLinear(a as single, b as single, c as single) as single
function = a*(1-c)+b*c
end function
function Noise( x as integer) as single
x = (shift left x,13)^x
function = (((x * (x * x * 15731 + 789221) + 1376312589) and &H7fffffff) / 2147483648.0)
end function
function PerlinNoise(x as single,y as single,width as integer,octaves as integer,seed as integer,periode as double) as single
local a,b,valuee,freq,tam_pas,zone_x,zone_y as double
local s,box,num,step_x,step_y as integer
local amplitude as integer =120
local noisedata as integer
freq = 1/(periode)
s=0
do while s<octaves
num =(width*freq)
step_x=(x*freq)
step_y=(y*freq)
zone_x=x*freq-step_x
zone_y=y*freq-step_y
box=step_x+step_y*num
noisedata=(box+seed)
a=InterPolation(Noise(noisedata),Noise(noisedata+1),zone_x)
b=InterPolation(Noise(noisedata+num),Noise(noisedata+1+num),zone_x)
valuee=InterPolation(a,b,zone_y)*amplitude
incr s
loop
function = valuee
end function
sub colour (valor as single)
local r as integer = InterLinear(valor,0,0 )
local g as integer = InterLinear(0,0,valor)
local b as integer = InterLinear(0,0,valor)
perlinRGB(1)=r
perlinRGB(2)=g
perlinRGB(3)=b
end sub
'
sub makeImage()
local x,y as integer
local colorr as single
local seed as integer
local width as integer
local disp1,disp2,disp3,disp4,disp5,disp6,scale as single
y = 1
do while y < %ImageWidth
x = 1
do while x < %ImageHeight
scale=1
width=12413
seed=63
disp1= PerlinNoise(x*scale,y*scale,width,1,seed,100)
disp2= PerlinNoise(x*scale,y*scale,width,1,seed,25)
disp3= PerlinNoise(x*scale,y*scale,width,1,seed,12.5)
disp4= PerlinNoise(x*scale,y*scale,width,1,seed,6.25)
disp5= PerlinNoise(x*scale,y*scale,width,1,seed,3.125)
disp6= PerlinNoise(x*scale,y*scale,width,1,seed,1.56)
colour(disp1+(disp2*0.25)+(disp3*0.125)+(disp4*0.0625)+(disp5*0.03125)+(disp6*0.0156))
MatrixImage(x,y,1) = perlinRGB(1)
MatrixImage(x,y,2) = perlinRGB(2)
MatrixImage(x,y,3) = perlinRGB(3)
TBGL_SetWindowTitle( hDlg, "Procedural Texture y = "+y +" of 32 x = "+x + " of 32 ESC to Exit")
incr x
loop
incr y
loop
end sub
sub init()
glClearColor (0.0, 0.0, 0.0, 0.0)
glShadeModel(%GL_FLAT)
makeImage()
glPixelStorei(%GL_UNPACK_ALIGNMENT, 1)
end sub
sub display()
glClear(%GL_COLOR_BUFFER_BIT)
glRasterPos2i(0, 0)
glDrawPixels(%ImageWidth, %ImageHeight, %GL_RGB,%GL_UNSIGNED_BYTE, MatrixImage)
' glDrawPixels(%ImageWidth, %ImageHeight, %GL_RGB,%GL_UNSIGNED_BYTE, MatrixImage())
' glDrawPixels(%ImageWidth, %ImageHeight, %GL_RGB,%GL_UNSIGNED_BYTE, MatrixImage(%ImageHeight,%ImageWidth,3))
glFlush()
end sub
sub reshape(w as integer,h as integer)
glViewport(0, 0, w, h)
height = h
glMatrixMode(%GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0.0, w, 0.0, h)
glMatrixMode(%GL_MODELVIEW)
glLoadIdentity()
end sub
Attached is the executeable c version so you can see what it outputs when working correctly.
Petr Schreiber
07-06-2007, 09:59
Hi kryton,
this looks as very interesting project!
The problem is quite tricky one, I am looking into it. Problem could be in declaration of glDrawPixels.
Instead of glDrawPixels I used good old tbgl_BeginPoly:
sub display()
local x,y as long
glClear(%GL_COLOR_BUFFER_BIT)
glRasterPos2i(0, 0)
tbgl_BeginPoly %GL_POINTS
for x = 1 to %ImageWidth
for y = 1 to %ImageHeight
tbgl_color MatrixImage(x,y,1), MatrixImage(x,y,2), MatrixImage(x,y,3)
tbgl_Vertex x,y
next
next
tbgl_EndPoly
' glDrawPixels(%ImageWidth, %ImageHeight, %GL_RGB,%GL_UNSIGNED_BYTE, MatrixImage())
' glDrawPixels(%ImageWidth, %ImageHeight, %GL_RGB,%GL_UNSIGNED_BYTE, MatrixImage(%ImageHeight,%ImageWidth,3))
glFlush()
end sub
So I did check on data your algo produces and realized, it probably doesn't work as expected - always RGB 114,0,0!
So my tip for reason of problem is in noise function, which now does not produce anything noisy.
One of the tricks could be in fact in C/C++ "^" does not mean power of something but XOR, but I do not remember it very well :-[. So to get closer:
function Noise( x as integer) as single
local xx as integer = x
shift left x,13
x = x xor xx
function = (((x * (x * x * 15731 + 789221) + 1376312589) and &H7fffffff) / 2147483648.0)
end function
This way it looks almost like it should for 64x64, but it is fragmented to squares somehow.
There are lot of places in code which would need explanation, for example what is width in makeImage...
But Roberto or Eros will probably know better, me and C... :)
Bye,
Petr
Petr, you are good. I figured out the shift left and ANDing the hex, but thought that was a power operator and it never occurred to me it was XOR. At least you got it to this point. There is lots of typecasting going on in the c source too, so that could messing it up too.
If you look at that site, I also posted about it the other day, he shows how each display is a different resolution of noise, then it is all mixed into one. So one of them looks like the pixelated version, so maybe we are getting info for that display?
Petr Schreiber
07-06-2007, 11:53
Hi kryton,
I am not sure, but I think current code does not prouce results for any phase perfectly, there are still some troubles.
Also I am not sure if integer in C means always 16bit integer. I will have a look at the evening as I have to go somewhere during afternoon and tommorow I am leaving for 3 days :-\.
Here is some code just for fun using very primitive technique:
'
' TBGL Poor Mans Noise
'
Uses "TBGL"
Dim hWnd As Dword
dim xSize, ySize as long
xSize = 640
ySize = 480
Global CursorX, CursorY as long
Global RGBArray(xSize, ySize) as byte
hWnd = TBGL_CreateWindowEx("Generating noise...", 640, 480, 32, 0)
TBGL_ShowWindow
gGenerateNoise(20000, 20)
tbgl_setWindowTitle ( hwnd, "Caching...")
tbgl_NewList 1
gRenderNoise
tbgl_EndList
tbgl_setWindowTitle ( hwnd, "Done, press ESC to quit")
TBGL_GetAsyncKeyState(-1) ' Resets status of all keys
While TBGL_IsWindow(hWnd)
tbgl_ClearFrame
tbgl_renderMatrix2d
tbgl_callList 1
tbgl_DrawFrame
If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
sub gGenerateNoise( nCycles as long, NumCursors as long )
local c as long
local CurID as long
local CursorX(NumCursors) as long
local CursorY(NumCursors) as long
for CurID = 1 to NumCursors
CursorX(CurID) = rnd(0, xSize)
CursorY(CurID) = rnd(0, ySize)
next
for c = 1 to nCycles
if (c mod 1000) = 0 then
tbgl_setWindowTitle ( hwnd, "Pass "+FORMAT$(c)+" /"+STR$(nCycles)+" ...")
' tbgl_ClearFrame
' tbgl_renderMatrix2d
'
' gRenderNoise
' tbgl_DrawFrame
end if
for CurID = 1 to NumCursors
CursorX(CurID) += rnd(-1,1)
CursorY(CurID) += rnd(-1,1)
if CursorX(CurID) < 1 then
CursorX(CurID) = 1
elseif CursorX(CurID) > xSize then
CursorX(CurID) = xSize
end if
if CursorY(CurID) < 1 then
CursorY(CurID) = 1
elseif CursorY(CurID) > ySize then
CursorY(CurID) = ySize
end if
RGBArray(CursorX(CurID), CursorY(CurID)) += 10
if RGBArray(CursorX(CurID), CursorY(CurID)) >= 255 then RGBArray(CursorX(CurID), CursorY(CurID)) = 245
next
next
end sub
sub gRenderNoise()
local x,y as long
tbgl_beginPoly %GL_POINTS
for x = 1 to xSize
for y = 1 to ySize
tbgl_Color RGBArray(x,y), RGBArray(x,y), RGBArray(x,y)
tbgl_Vertex x,y
next
next
tbgl_EndPoly
end sub
... but it is not Perlin noise :(
Bye,
Petr
Thanks Petr, have a nice trip, see you when you get back.
Oops. forgot to mention about the poor man's noise, it is a lot faster than the routine I am using that is for sure and looks better than what I am getting. As always you have secrets and files for everything... glad I brought it up and we see this very interesting code.
Again have a nice weekend and trip!
ErosOlmi
07-06-2007, 12:57
I imagine that situations like this one, where many many thousands loops are needed, are not the best field for thinBasic.
So something like realtime image manipulation or generation is not doable using 100% interpreted code but must be supported by a compiled dedicated module.
In any case it is interesting for us to look at code like that in order to use for our internal performance tests.
Ciao
Eros
Petr Schreiber
07-06-2007, 12:58
Thanks Kent :),
I remembered that I have book on graphics at home which might contain some info on Perlin noise, I will take it with me and hopefully I will find something explaining current troubles with producing it.
My script is just little bit improved thing from DOS times, I called it "caterpillar", don't know why :)
Bye,
Petr
It is an interesting program. I am trying to get it so we can see it while it is drawing the image instead of waiting for it to finish. But using saved textures is the way to go I can see.
Petr Schreiber
07-06-2007, 17:41
Hi kryton,
I am not sure it is good idea, per pixel drawing is damned slow,
if you uncomment few lines in my sample in gGenerateNoise sub, you can watch it.
Bye,
Petr
If you're interested in Perlin Noise you should check out this (http://student.kuleuven.be/~m0216922/CG/randomnoise.html#Smooth_Noise_) Site if you haven't already.
Davy on the Basic4GL Forum wrote a simple Perlin Noise Generator, you can get the Source-Code here (http://basic4gl.proboards20.com/index.cgi?action=display&board=demo&thread=1164085256&page=1).
After the Programme has been running for a few Seconds you'll get an Image like the One pictured.
matthew thanks for the links, unfamiliar with both, so really liked them. Your attachment didn't come through, so I couldn't see the output of the basic4gl. Have you converted any of those over to thinBasic? I would be interested for sure. Thanks for the links again, gives me something to read while I pull my hair out trying to figure this stuff out :)
Lol, earlier Today I tried converting the Basic4GL Perlin Noise Generator to thinBASIC but I couldn't get anything to appear on the Screen. :P
I've uploaded the Picture again which shows the Output of the Basic4GL Programme.
That is strange, the attachment is appearing now in both messages. Glad I saw the output as that does look like the noise pattern that Petr made in his poor man's noise post. So you can look at that code to figure out how Petr got it to work. That is a very nice site. I went through and looked at all the articles, he sure made it simpler to do things than I have seen in other c programs.
Petr Schreiber
08-06-2007, 07:51
Last post before departure :D,
Matthew, it seems I used basically the same technique as your Basic4GL friend :)
And I was so proud when I "invented it" few years ago ::)
Article is interesting, I will print it out!
Bye guys!,
Petr
Petr Schreiber
10-06-2007, 19:02
Hi guys,
now I can see the Perlin noise principles clearly, it is so elegant !
Here are 2 implementations, neither is good, but I will work on it :)
Variant one: Fast but unsmoothed
'
' TBGL Perlin noise without smoothing
' Petr Schreiber 2007
'
Uses "TBGL"
Dim hWnd As Dword
dim xSize as long = 512
dim ySize as long = xSize
dim NoiseArray(xSize, ySize) as long
dim NoiseArray16(xSize, ySize) as long
dim NoiseArray8(xSize, ySize) as long
dim NoiseArray4(xSize, ySize) as long
dim NoiseArray2(xSize, ySize) as long
hWnd = TBGL_CreateWindowEx("Generating perlin noise...", xSize, ySize, 32, 0)
TBGL_ShowWindow
FillArrayWithNoise( NoiseArray, xSize, ySize )
tbgl_setWindowTitle(hWnd, "Generating perlin noise: Base noise...")
CopyZoomedArray( NoiseArray, NoiseArray16, xSize, ySize, 16 )
tbgl_setWindowTitle(hWnd, "Generating perlin noise: Base noise / 16...")
CopyZoomedArray( NoiseArray, NoiseArray8, xSize, ySize, 8 )
tbgl_setWindowTitle(hWnd, "Generating perlin noise: Base noise / 8...")
CopyZoomedArray( NoiseArray, NoiseArray4, xSize, ySize, 4 )
tbgl_setWindowTitle(hWnd, "Generating perlin noise: Base noise / 4...")
CopyZoomedArray( NoiseArray, NoiseArray2, xSize, ySize, 2 )
tbgl_setWindowTitle(hWnd, "Generating perlin noise: Values precalculated... Now caching...")
TBGL_GetAsyncKeyState(-1) ' Resets status of all keys
tbgl_NewList 1
tbgl_UseBlend 1
tbgl_Usedepthmask 0
DrawArray( NoiseArray16, xSize, ySize )
DrawArray( NoiseArray8, xSize, ySize )
DrawArray( NoiseArray4, xSize, ySize )
DrawArray( NoiseArray2, xSize, ySize )
DrawArray( NoiseArray, xSize, ySize )
tbgl_Usedepthmask 1
tbgl_UseBlend 0
tbgl_EndList
tbgl_setWindowTitle(hWnd, "Perlin noise ready, press ESC to quit")
While TBGL_IsWindow(hWnd)
tbgl_ClearFrame
tbgl_renderMatrix2d
tbgl_CallList 1
tbgl_DrawFrame
If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE ) Then Exit While
Wend
TBGL_DestroyWindow
sub FillArrayWithNoise( byref someArray() as long, sizeX as long, sizeY as long )
local x,y as long
for x = 1 to sizeX
for y = 1 to sizeY
someArray(x,y) = rnd(0,51)
next
next
end sub
sub CopyZoomedArray( byref srcArray() as long, byref dstArray() as long, sizeX as long, sizeY as long, zoom as long )
local x,y as long
for x = 1 to sizeX
for y = 1 to sizeY
dstArray(x,y) = srcArray(x/zoom+1,y/zoom+1)
next
next
end sub
sub DrawArray( byref someArray() as long, sizeX as long, sizeY as long )
local x,y as long
tbgl_BeginPoly %GL_POINTS
for x = 1 to sizeX
for y = 1 to sizeY
tbgl_color someArray(x,y),0,0
tbgl_vertex x,y
next
next
tbgl_endPoly
end sub
Variant two: This one is smoothed ( via texture filter, so nicer ) but deadly slow for bigger textures:
Uses "TBGL"
uses "FILE"
Dim hWnd As Dword
doevents on
dim xSize as long = 128
dim ySize as long = xSize
dim NoiseArray(xSize* ySize) as string * 4
dim nPass as long = 5
dim i as long
dim stringie as string
hWnd = TBGL_CreateWindowEx("Generating perlin noise...", xSize, ySize, 32, 0)
TBGL_ShowWindow
FillArrayWithNoise( NoiseArray, xSize, ySize )
tbgl_setWindowTitle(hWnd, "Noise generated...")
stringie = join$(NoiseArray(), "") ' .. a bit slow for many elements
tbgl_setWindowTitle(hWnd, "String joined...")
for i = 1 to nPass
tbgl_setWindowTitle(hWnd, "/"+PARSE$("16,8,4,2,1", ",", i)+" saved...")
SaveDataAsTGA(stringie, xSize, ySize, val(PARSE$("16,8,4,2,1", ",", i)), i)
tbgl_LoadTexture "Perlin"+FORMAT$(i)+".tga", i, %TBGL_TEX_LINEAR
next
tbgl_NewList 1
tbgl_UseBlend 1
tbgl_Usedepthmask 0
tbgl_useTexture 1
for i = 1 to nPass
tbgl_BindTexture i
tbgl_beginPoly %GL_QUADS
tbgl_TexCoord2d 0,0
tbgl_vertex 0,0
tbgl_TexCoord2d 1,0
tbgl_vertex xSize,0
tbgl_TexCoord2d 1,1
tbgl_vertex xSize,ySize
tbgl_TexCoord2d 0,1
tbgl_vertex 0,ySize
tbgl_EndPoly
next
tbgl_Usedepthmask 1
tbgl_UseBlend 0
tbgl_EndList
tbgl_setWindowTitle(hWnd, "Perlin noise ready, press ESC to quit")
TBGL_GetAsyncKeyState(-1) ' Resets status of all keys
While TBGL_IsWindow(hWnd)
tbgl_ClearFrame
tbgl_renderMatrix2d
tbgl_CallList 1
tbgl_DrawFrame
If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE ) Then Exit While
Wend
TBGL_DestroyWindow
sub FillArrayWithNoise( byref someArray() as long, sizeX as long, sizeY as long )
local x,y, index as long
for x = 1 to sizeX
for y = 1 to sizeY
incr index
someArray(index) = REPEAT$( 3, chr$(rnd(0,51)))+CHR$(0)
next
next
end sub
sub SaveDataAsTGA( byref stringie as string, sizeX as long, sizeY as long, zoom as long, nTh as long )
local fBuffer as string
local MaxPixel as long = sizeX / zoom
' Header
fBuffer = CHR$( 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
' Info about xSize, ySize and bit depth
fBuffer += CHR$(MaxPixel mod 256)+CHR$(MaxPixel\256)+CHR$(MaxPixel mod 256)+CHR$(MaxPixel\256)+CHR$(32)+CHR$(0)
fBuffer += left$(stringie, MaxPixel*MaxPixel*4)
file_Save( APP_SOURCEPATH+"Perlin"+FORMAT$(nTh)+".tga", fBuffer)
end sub
sub DrawArray( byref someArray() as long, sizeX as long, sizeY as long )
local x,y as long
tbgl_BeginPoly %GL_POINTS
for x = 1 to sizeX
for y = 1 to sizeY
tbgl_color someArray(x,y),0,0
tbgl_vertex x,y
next
next
tbgl_endPoly
end sub
Hope you will like it, meanwhile I will think how to boost it.
Bye,
Petr
Petr Schreiber
10-06-2007, 19:28
I think I got it :),
here is both visually acceptable and quite fast version, all this in stylish 128 lines of code ;)
Bottleneck in previous version was join$, so I made it two-pass, finally joining bigger chunks.
'===============================================================================
'= TBGL Perlin noise =
'= =
'= - quite fast version =
'= =
'= Petr Schreiber, 2007 =
'===============================================================================
Uses "TBGL"
uses "FILE"
Dim hWnd As Dword
dim xSize as long = 512 ' -- Just powers of two !
dim ySize as long = xSize
' No need for 2 dimensions, this way it will work too :)
dim NoiseArray(xSize*ySize) as string * 4
' Different passes, different detail; 5 is ideal
dim nPass as long = 5
dim i as long
' Array to hold parts of noise, joining will be faster
dim Lines(ySize) as string
' String to hold whole RGBA chunk
dim stringie as string
hWnd = TBGL_CreateWindowEx("Generating perlin noise...", xSize, ySize, 32, 0)
TBGL_ShowWindow
' This creates just random pixels
FillArrayWithNoise( NoiseArray, xSize, ySize )
' Lets join it to smaller chunks
tbgl_setWindowTitle(hWnd, "Noise generated...")
for i = 1 to ySize
tbgl_setWindowTitle(hWnd, "Processing line"+STR$(i)+" ...")
Lines(i) = join$(NoiseArray(), "", "", (i-1)*xSize+1, i*xSize)
next
' Joining to final string, doing it with fewer small chunks is faster than with million little ones
tbgl_setWindowTitle(hWnd, "Joining lines...")
stringie = join$( Lines(), "")
tbgl_setWindowTitle(hWnd, "String joined...")
' Save & Load
for i = 1 to nPass
tbgl_setWindowTitle(hWnd, "Processing Perlin"+FORMAT$(i)+".tga ...")
SaveDataAsTGA(stringie, xSize, ySize, 2^(i-1), i)
tbgl_LoadTexture "Perlin"+FORMAT$(i)+".tga", i, %TBGL_TEX_LINEAR
next
%LIST_PERLINNOISE = 1
tbgl_NewList %LIST_PERLINNOISE
tbgl_UseBlend 1
tbgl_Usedepthmask 0
tbgl_useTexture 1
for i = 1 to nPass
tbgl_BindTexture i
tbgl_beginPoly %GL_QUADS
tbgl_TexCoord2d 0,0
tbgl_vertex 0,0
tbgl_TexCoord2d 1,0
tbgl_vertex xSize,0
tbgl_TexCoord2d 1,1
tbgl_vertex xSize,ySize
tbgl_TexCoord2d 0,1
tbgl_vertex 0,ySize
tbgl_EndPoly
next
tbgl_Usedepthmask 1
tbgl_UseBlend 0
tbgl_EndList
tbgl_setWindowTitle(hWnd, "Perlin noise ready, press ESC to quit")
TBGL_GetAsyncKeyState(-1) ' Resets status of all keys
local xRes, yRes as long
While TBGL_IsWindow(hWnd)
tbgl_getWindowClient hwnd, xres, yres
tbgl_ClearFrame
tbgl_renderMatrix2d
tbgl_scale xRes/xSize, yRes/ySize, 1
tbgl_CallList %LIST_PERLINNOISE
tbgl_DrawFrame
If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE ) Then Exit While
Wend
TBGL_DestroyWindow
sub FillArrayWithNoise( byref someArray() as long, sizeX as long, sizeY as long )
local x,y, index as long
for x = 1 to sizeX
for y = 1 to sizeY
incr index
someArray(index) = REPEAT$( 3, chr$(rnd(0,255\nPass)))+CHR$(0) ' RGBA byte data
next
next
end sub
sub SaveDataAsTGA( byref stringie as string, sizeX as long, sizeY as long, zoom as long, nTh as long )
local fBuffer as string
local MaxPixel as long = sizeX / zoom
' Header
fBuffer = CHR$( 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
' Info about xSize, ySize and bit depth
fBuffer += CHR$(MaxPixel mod 256)+CHR$(MaxPixel\256)+CHR$(MaxPixel mod 256)+CHR$(MaxPixel\256)+CHR$(32)+CHR$(0)
fBuffer += left$(stringie, MaxPixel*MaxPixel*4)
file_Save( APP_SOURCEPATH+"Perlin"+FORMAT$(nTh)+".tga", fBuffer)
end sub
Hope you like it,
Petr
I went through each one in sequence to see the progression. The increase in quality and speed is incredible Petr.
I did example 2 at 512x512 and then to see the third version, you really see the speed difference!!
Welcome back and thanks for these great examples. Perlin Noise is nice!!