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?
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
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
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.