PDA

View Full Version : Few functions types



Petr Schreiber
27-11-2005, 15:32
Hi,

The DECLARE statement is definitely impressive, but
it could be nice if functions like this could be declared:



DECLARE SUB glVertex3f LIB "opengl32.dll" ALIAS "glVertex3f" (BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL z AS SINGLE)

( 3 single parameters )



DECLARE SUB glColor4f LIB "opengl32.dll" ALIAS "glColor4f" (BYVAL red AS SINGLE, BYVAL green AS SINGLE, BYVAL blue AS SINGLE, BYVAL alpha AS SINGLE)

(4 single parameters)



DECLARE FUNCTION mciSendString LIB "WINMM.DLL" ALIAS "mciSendStringA" (lpstrCommand AS ASCIIZ, lpstrReturnString AS ASCIIZ, BYVAL uReturnLength AS DWORD, BYVAL hwndCallback AS DWORD) AS LONG

( ASCIIZ/STRING and numeric parameters )

Thanks,
Psch

ErosOlmi
27-11-2005, 21:45
Psch,

can you please give me an example script (no more than 5 lines if possible) I can use to see if declare is working? In this way I can make some tests.

Regarding ASCIIZ passed as reference, it is like passing a DWORD. For example you can declare mciSendString in this way:

DECLARE FUNCTION mciSendString LIB "WINMM.DLL" ALIAS "mciSendStringA" (lpstrCommand AS dword, lpstrReturnString AS dword, BYVAL uReturnLength AS DWORD, BYVAL hwndCallback AS DWORD) AS LONG
and passing parameters like: STRPTR(AnyNullTerminatedString)

DIM SendStr AS STRING = "Play ALIAS WhatEvere wait"
SendStr += chr$(0)
mciSendString(strptr(SendStr), %NULL, %NULL, %NULL)
or something like:

SendStr = "set cdaudio door open" + chr$(0)
mciSendString(strptr(SendStr), %NULL, %NULL, %NULL)
Let me know.
Eros

Petr Schreiber
27-11-2005, 21:58
Hi Eros,

that MCI trick works perfectly !

Here is code ( I'm sorry, it's more than 5 lines :( )



Uses "TBGL"


DIM i AS LONG

DECLARE function glVertex3f LIB "opengl32.dll" ALIAS "glVertex3f" (BYVAL x AS single, BYVAL y AS single, BYVAL z AS single) as long
DECLARE FUNCTION glColor4f LIB "opengl32.dll" ALIAS "glColor4f" (BYVAL red AS SINGLE, BYVAL green AS SINGLE, BYVAL blue AS SINGLE, BYVAL alpha AS SINGLE) AS LONG

TBGL_CreateWindow ' Creates OpenGL window, it returns handle
TBGL_ShowWindow ' Shows the window

FOR i = 1 TO 360 ' 360 iterations = 360 frames
TBGL_ClearFrame ' Prepares clear frame
TBGL_Camera 0,0,5,0,0,0 ' Setups camera to look from 0,0,5 to 0,0,0

TBGL_BeginPoly %GL_TRIANGLES ' Starts polygon definition based on triangles
glColor4f (1,0,0,1) ' Sets RGBA color
glVertex3f (-1,-1,0) ' Adds vertex
glColor4f (0,1,0,1)
glVertex3f (1,-1,0)
glColor4f (0,0,1,1)
glVertex3f (0, 1,0)
TBGL_EndPoly ' Ends polygon definition

TBGL_DrawFrame ' Swaps the buffers - displays rendered image
NEXT
TBGL_DestroyWindow ' Closes OpenGL window


Hope it's representative example


Thanks,
Psch

ErosOlmi
27-11-2005, 22:07
OK, thanks. I will have a look and see what I can do.

Regarding ASCIIZ parameters, remember you can get back values also preparing enough space in the returing ASCIIZ. For example:

DECLARE FUNCTION GetShortPathName LIB "KERNEL32.DLL" ALIAS "GetShortPathNameA" (lpszLongPath AS dword, lpszShortPath AS dword, BYVAL cchBuffer AS LONG) AS LONG

DIM szIn AS STRING = "C:\Program Files\Adobe\Acrobat 5.0\Resource\ENUtxt.pdf" & CHR$(0)
DIM szOut AS STRING = STRING$(%MAX_PATH + 1, CHR$(0))
GetShortPathName(STRPTR(szIn), STRPTR(szOut), %MAX_PATH + 1)
MSGBOX 0, szOut


%MAX_PATH will be defined in next version :)

ErosOlmi
27-11-2005, 22:50
I think to have fixed SINGLE numeric type.
Please download again thinBasic 1.0.7.1 from:
http://www.thinbasic.com/public/products/thinBasic/Temp/thinBasic_1.0.7.1.zip

Let me know.
Ciao
Eros


PS: you forgot TBGL_Rotate i,1,1,1 in your example loop ;)

Petr Schreiber
28-11-2005, 10:43
Hi Eros,

The glVertex3f and glColor4f seems to work as it should - that'ts really great.
Many OpenGL statements are using similar syntax so I can access them directly now :eusaclap: :



Uses "TBGL"


DIM i AS LONG

%GL_COLOR_BUFFER_BIT = &H00004000
%GL_DEPTH_BUFFER_BIT = &H00000100
DECLARE function glVertex3f LIB "opengl32.dll" ALIAS "glVertex3f" ( x AS single, y AS single, z AS single) as long
DECLARE FUNCTION glColor4f LIB "opengl32.dll" ALIAS "glColor4f" ( red AS SINGLE, green AS SINGLE, blue AS SINGLE, alpha AS SINGLE) AS LONG
DECLARE FUNCTION glBegin LIB "opengl32.dll" ALIAS "glBegin" (BYVAL mode AS DWORD) As Long
DECLARE FUNCTION glEnd LIB "opengl32.dll" ALIAS "glEnd" () AS LONG
DECLARE FUNCTION glRotatef LIB "opengl32.dll" ALIAS "glRotatef" (BYVAL angle AS SINGLE, BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL z AS SINGLE) AS LONG
DECLARE FUNCTION glClear LIB "opengl32.dll" ALIAS "glClear" (BYVAL mask AS DWORD) AS long
DeCLARE FUNCTION glLoadIdentity LIB "opengl32.dll" ALIAS "glLoadIdentity" () AS LONG

DECLARE FUNCTION gluLookAt LIB "glu32.dll" ALIAS "gluLookAt" (BYVAL eyex AS DOUBLE, BYVAL eyey AS DOUBLE, BYVAL eyez AS DOUBLE, BYVAL centerx AS DOUBLE, BYVAL centery AS DOUBLE, BYVAL centerz AS DOUBLE, BYVAL upx AS DOUBLE,BYVAL _
upy AS DOUBLE, BYVAL upz AS DOUBLE) AS LONG


TBGL_CreateWindow ' Creates OpenGL window, it returns handle
TBGL_ShowWindow ' Shows the window

For i = 1 to 360

glClear (%GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT)
glLoadIdentity

gluLookAt (0,0,5,0,0,0,0,1,0) ' Setups camera to look from 0,0,5 to 0,0,0

glRotatef (i,1,1,1)

glBegin %GL_TRIANGLES ' Starts polygon definition based on triangles
glColor4f (1,0,0,1) ' Sets RGBA color
glVertex3f (-1,-1,0) ' Adds vertex
glColor4f (0,1,0,1)
glVertex3f (1,-1,0)
glColor4f (0,0,1,1)
glVertex3f (0, 1,0)
glEnd ' Ends polygon definition

TBGL_DrawFrame ' Swaps the buffers - displays rendered image
next
TBGL_DestroyWindow ' Closes OpenGL window


Thanks a lot,
Psch

P.S. No I didn't forgot :), I just eliminated unnecessary code ( well I could delete even the main loop and add sleep before tbgl_DeleteWindow :))

Petr Schreiber
28-11-2005, 14:06
I forgot one thing :),

here are converted headers for OpenGL 1.1, TBGL module is needed only to create, display,kill window and to swap the buffers.

I haven't tested all the functions, but at least the majority should work.

Enjoy,
Psch

ErosOlmi
28-11-2005, 14:30
Wow, that's cool.

Please remember API interface is quite unstable and I will need to change it in some part. For numeric parameters there should not be big problems but for ASCIIZ and in general string buffers I will need to change and double check again all. BYVAL and BYREF are not 100% managed. In any case the whole proces seems working, just few refine are missing.

Also we are trying to manage ASCIIZ type natively as thinBasic native data type. If we will be able to implement this, also API interface will be more easy and VARPTR or STRPTR will not be needed anymore.

Ciao
Eros