PDA

View Full Version : Testing older code, TB throws up



Michael Hartlef
21-04-2016, 10:27
Hi Eros,

I am browsing through my huge library of TB code from back then and found that the parser doesn't like some things these days. Maybe TB has changed in the last 7 years, i don't know.

For an example, this function definition:


Function SDL_LoadWAV (ByRef szFile As Asciiz, ByVal spec As SDL_AudioSpec Ptr, ByRef audio_buf As DWord, ByRef audio_len As DWord) As DWord

FUNCTION = SDL_LoadWAV_RW(SDL_RWFromFile(szFile, "rb"), 1, spec, audio_buf, audio_len)
END FUNCTION

The parser complains about the PTR after SDL_AudioSpec. It expects a ). Is PTR not valid anymore?

ErosOlmi
21-04-2016, 13:00
Ciao Michael,

well, just a little some thousands of changes occurred in the last 7 years :)

I will check, it should allow to pass.
If you are in hurry just pass a LONG when you need to pass a pointer to something.

Eros

Michael Hartlef
21-04-2016, 15:49
No problem Eros, I am just going through some old code of mine and others I had collected over the years. And I am sure that thinBasic has envolved over such a long time. I am glad to see that you still keep your motivation high to support TB!!!!!

ErosOlmi
21-04-2016, 19:39
Michael,

I checked Core source code and I cannot find the possibility to declare function/sub parameters using PTR like: Byval <paramName> As <anytype> PTR
I also checked in old version code but nothing.
If you are sure it was thinBasic code, it is very strange: maybe some code ported from other Basic but never used?

Instead that syntax is supported in thinBasic only when using DECLARE Function/Sub .... to interface external functions from DLLs.

Ciao
Eros

Michael Hartlef
21-04-2016, 19:55
It is inside an SDL.inc file . MAybe it was a powerbasic file. The calling tbasic script was from Kent, but maybe it never worked. Sorry.

But could you look at the attached scripts if you have a chance? The parser always complains and I don't know why?

primo
22-04-2016, 08:33
Hi Michael
about the SDL there is an old posts here
http://www.thinbasic.com/community/showthread.php?9028-Are-UDT-pointers-in-function-headers-supported
haven't read it yet. hope it contains an answer.
but about the buggy scripts, i have corrected 3 and still trying the fourth.
Bezier-Try_Frankos_NURBS_2D.tbasic : thinbasic stopped at :
%GL_MAP1_VERTEX_3 = &H00D97
since it is loaded before, it is defined in thinbasic_gl.inc
so i have deleted it
HoverCraftAI_JasonMod_ works again if we corrected
Dim stime, etime, dtime, ifps, fps as single
seems was working before

Michael Hartlef
22-04-2016, 10:13
Thanks primo. I see that with the missing type declaration now (etime).
And thanks for the link too. Next time I will better search the forum first!

I wonder what the problem with the render text demo is.

Eros: Imho the parser should have complaint about the missing type of give it a standard type.
Same goes for a duplicatedefinition of identifieres.

primo
22-04-2016, 10:28
Hi Michael
regarding RenderedTextDemo02.tbasic
in line 31 glTexImage2D ( %GL_TEXTURE_2D.... texture) change texture to texture(1)
and change all the words size to sizo since size seems a keyword
the original thread is here
http://www.thinbasic.com/community/showthread.php?8160-Oh-wow-got-it-working-dynamic-textures
the Petr version in Page 2 gives more interesting graphics, just apply the same changes above
here is kryton9 program again (corrected to the current TB version)

' Demo 2 of Rendered Text by Kryton9
' based on the great base code from
' Demonstration of rendering to texture
' Copyright (C) 2005 Julien Guertault

Uses "TBGL"
uses "UI"
#INCLUDE "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#INCLUDE "%APP_INCLUDEPATH%\thinbasic_glu.inc"

%_sizo = 256

static texture(3 * %_sizo * %_sizo) as GLvoid
static texture_id as GLuint
static window_width as LONG = 500
static window_height as LONG = 500
dim speed as double = 75
dim sizze as double = 2
dim hWnd as dword

hWnd = TBGL_CreateWindowEX("Render to texture - press ESC to quit",window_width,window_height,32,0)
TBGL_ShowWindow

'/* OpenGL settings */
glEnable (%GL_DEPTH_TEST)

'/* Texture setting */
glEnable (%GL_TEXTURE_2D)
glGenTextures (1, texture_id)
glBindTexture (%GL_TEXTURE_2D, texture_id)
glTexImage2D ( %GL_TEXTURE_2D, 0, %GL_RGB, %_sizo, %_sizo, 0, %GL_RGB, %GL_UNSIGNED_BYTE, texture(1))
glTexParameteri (%GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR)
glTexParameteri (%GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR)
glTexParameteri (%GL_TEXTURE_2D, %GL_TEXTURE_WRAP_S, %GL_CLAMP)
glTexParameteri (%GL_TEXTURE_2D, %GL_TEXTURE_WRAP_T, %GL_CLAMP)

GetAsyncKeyState(%VK_ESCAPE) ' Resets ESC key status before checking

while IsWindow(hWnd)

glClear (%GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT)
glLoadIdentity
glTranslatef (0, 0, -10)
glRotatef (30, 1, 0, 0)
glRotatef (GetTickCount/speed, 0, 1, 0)

'/* Define a view-port adapted to the texture */
glMatrixMode(%GL_PROJECTION)
glLoadIdentity ()
gluPerspective (20, 1, 5, 15)
glViewport(0, 0, %_sizo, %_sizo)
glMatrixMode(%GL_MODELVIEW)

'/* Render to buffer */
glClearColor (255, 175, 1, 0)
glClear (%GL_COLOR_BUFFER_BIT or %GL_DEPTH_BUFFER_BIT)
plane()
'Cube ()
glFlush ()

'/* Copy buffer to texture */
glCopyTexSubImage2D(%GL_TEXTURE_2D, 0, 5, 5, 0, 0, %_sizo - 10, %_sizo - 10)

'/* Render to screen */
glMatrixMode(%GL_PROJECTION)
glLoadIdentity ()
gluPerspective (20, window_width / window_height, 5, 15)
glViewport(0, 0, window_width, window_height)
glMatrixMode(%GL_MODELVIEW)
glClearColor (0, 0, 0, 0)
glClear (%GL_COLOR_BUFFER_BIT or %GL_DEPTH_BUFFER_BIT)
'plane()
Cube ()

TBGL_DrawFrame

if GetAsyncKeyState(%VK_ESCAPE) THEN exit while
if GetAsyncKeyState(%VK_UP) THEN speed += 1 : if speed <= 0 then speed = 1 endif
if GetAsyncKeyState(%VK_DOWN) THEN speed -= 1
if GetAsyncKeyState(%VK_RIGHT) THEN sizze += 0.1 :sleep 100
if GetAsyncKeyState(%VK_LEFT) THEN sizze -= 0.1 :sleep 100
if GetAsyncKeyState(%VK_SPACE) THEN
sizze = 2
speed = 75
end if

TBGL_SetWindowTitle (hwnd,"ESC to quit speed = "+Format$(speed,"0.00")+" sizo = "+Format$(sizze,"0.00"))

wend

TBGL_DestroyWindow ' Closes TBGL window


sub Cube()

glBegin %GL_QUADS

glTexCoord2i (0, 0) : glVertex3f (-1, -1, -1)
glTexCoord2i (0, 1) : glVertex3f (-1, -1, 1)
glTexCoord2i (1, 1) : glVertex3f (-1, 1, 1)
glTexCoord2i (1, 0) : glVertex3f (-1, 1, -1)

glTexCoord2i (0, 0) : glVertex3f ( 1, -1, -1)
glTexCoord2i (0, 1) : glVertex3f ( 1, -1, 1)
glTexCoord2i (1, 1) : glVertex3f ( 1, 1, 1)
glTexCoord2i (1, 0) : glVertex3f ( 1, 1, -1)

glTexCoord2i (0, 0) : glVertex3f (-1, -1, -1)
glTexCoord2i (0, 1) : glVertex3f (-1, -1, 1)
glTexCoord2i (1, 1) : glVertex3f ( 1, -1, 1)
glTexCoord2i (1, 0) : glVertex3f ( 1, -1, -1)

glTexCoord2i (0, 0) : glVertex3f (-1, 1, -1)
glTexCoord2i (0, 1) : glVertex3f (-1, 1, 1)
glTexCoord2i (1, 1) : glVertex3f ( 1, 1, 1)
glTexCoord2i (1, 0) : glVertex3f ( 1, 1, -1)

glTexCoord2i (0, 0) : glVertex3f (-1, -1, -1)
glTexCoord2i (0, 1) : glVertex3f (-1, 1, -1)
glTexCoord2i (1, 1) : glVertex3f ( 1, 1, -1)
glTexCoord2i (1, 0) : glVertex3f ( 1, -1, -1)

glTexCoord2i (0, 0) : glVertex3f (-1, -1, 1)
glTexCoord2i (0, 1) : glVertex3f (-1, 1, 1)
glTexCoord2i (1, 1) : glVertex3f ( 1, 1, 1)
glTexCoord2i (1, 0) : glVertex3f ( 1, -1, 1)

glEnd
end sub

sub plane()
glBegin %GL_QUADS
glColor3ub 255, 0, 0 : glTexCoord2i 0,0 : glVertex3f -sizze , -sizze, 0
glColor3ub 0 , 255, 0 : glTexCoord2i 0,1 : glVertex3f sizze , -sizze, 0
glColor3ub 0 , 0, 255 : glTexCoord2i 1,1 : glVertex3f sizze , sizze, 0
glColor3ub 255, 200, 0 : glTexCoord2i 1,0 : glVertex3f -sizze , sizze, 0
glEnd
glColor3ub 255, 175, 0
end sub

ErosOlmi
22-04-2016, 10:58
It is inside an SDL.inc file . MAybe it was a powerbasic file. The calling tbasic script was from Kent, but maybe it never worked. Sorry.

But could you look at the attached scripts if you have a chance? The parser always complains and I don't know why?

In script scrollingtext_2.tbasic variable defined twice

FUNCTION ScrollText() STATIC MoveLeft as boolean = %true
STATIC cx,cy, xpos as long
static Characterwidth as long = 12 ' change this value if you choose another font. Always use a fixed font, otherwise it won't work.
Static maxpos As Long = (Len($ScrollText)*Characterwidth)-cx
Static MoveLeft As Boolean = %TRUE '<<<-----------Defined twice


In script RenderedTextDemo02.tbasic a pointer to the first element of the array is needed, 9th parameter is declared as GLpointer (alias of DWord) while texture is declared as GLVoid alias of ANY.
So pass somthing like VarPtr(texture(1))


glTexImage2D ( %GL_TEXTURE_2D, 0, %GL_RGB, %_SIZE, %_SIZE, 0, %GL_RGB, %GL_UNSIGNED_BYTE, VarPtr(texture(1)))


In script HoverCraftAI_JasonMod_.tbasic some variables are declared as VARIANT because they have no type declared.
In older versions of thinBasic variables declared without type were considered DOUBLE but when I introduced VARIANT this changed.
Change line 8 from


Dim stime, etime, dtime, ifps, fps As Quad

to


Dim stime, etime, dtime, ifps, fps As Quad as Quad '---or whatever type



In script Bezier-Try_Frankos_NURBS_2D.tbasic an hexadecimal number is not valid. It must have an even number of digits after &H.
Change line 9 from


%GL_MAP1_VERTEX_3 = &H00D97

to something like


%GL_MAP1_VERTEX_3 = &H000D97





I will see if I can better intercepts those kind of errors and give better error messages.

Ciao
Eros

Michael Hartlef
22-04-2016, 11:29
Thank you both!!!

primo
22-04-2016, 13:50
just want to refer that there is another great example using glTexImage2D, it is here http://www.thinbasic.com/community/showthread.php?8181-Sine-Wave-Dynamic-Texture-Fonty-thingy&p=60836&viewfull=1#post60836
look example Abraxas_SineWave.tbasic . it runs now if we change texture to varptr(texture(1))

Michael Clease
10-05-2016, 17:41
just want to refer that there is another great example using glTexImage2D, it is here http://www.thinbasic.com/community/showthread.php?8181-Sine-Wave-Dynamic-Texture-Fonty-thingy&p=60836&viewfull=1#post60836
look example Abraxas_SineWave.tbasic . it runs now if we change texture to varptr(texture(1))

if you use the version at the first post it works! (without modifying)

http://www.thinbasic.com/community/showthread.php?8181-Sine-Wave-Dynamic-Texture-Fonty-thingy&p=60794&viewfull=1#post60794

primo
13-05-2016, 11:03
Thanks Michael for the note.
regarding the function glTexImage2D which producing errors in Abraxas_SineWave.tbasic if its parameter is texture instead of varptr(texture(1)) i have downloaded from archive.org thinbasic 1.8, 1.7, 1.6 and it seems they all refuse to consider texture as a pointer, they needs varptr(texture(1)). seems only tb v1.4 (from year 2007) which allow that.