PDA

View Full Version : tbgl help



kryton9
07-12-2006, 10:10
Petr, I can't figure out what I am doing wrong with this code.

I want to see if I can alpha the text output to the screen. I can't even get the text to show up, hence the commented lines.
Thanks for any insights, I am sure I am missing something simple somewhere.

'
' TBGL Script Skeleton
'
Uses "TBGL"
Uses "UI"

Dim hWnd As Dword
DIM hFont AS DWORD = Font_Create("Courier New", 14)
TBGL_BuildFont hFont

hWnd = TBGL_CreateWindow("My Demo - press ESC to quit")
TBGL_ShowWindow

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

While IsWindow(hWnd)
tbgl_ClearFrame
'tbgl_Camera 0,0,5,0,0,0
tbgl_Camera 0,0,-5,0,0,0
'TBGL_UseBlend 1
'TBGL_ColorALPHA 255, 175, 0, 200
TBGL_Color 255, 175, 0
TBGL_PrintFont "This is a test to see if this works", 0, 0, 0
tbgl_DrawFrame
If GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_KillFont
TBGL_DestroyWindow

Petr Schreiber
07-12-2006, 14:49
Hi kryton9,

I'm very happy you explore TBGL :)

Your code is right, but it has just one basic problem - you should create the TBGL font after creating the TBGL window ! Before this, there is no OpenGL context created, and so it produces nothing. I will add it to the help file !

Both variants are acceptable:


hWnd = TBGL_CreateWindow("My Demo - press ESC to quit")
TBGL_ShowWindow

DIM hFont AS DWORD = Font_Create("Courier New", 14)
TBGL_BuildFont hFont


or



DIM hFont AS DWORD = Font_Create("Courier New", 14)

hWnd = TBGL_CreateWindow("My Demo - press ESC to quit")
TBGL_ShowWindow

TBGL_BuildFont hFont


... this will solve problem with text display.
Then you will see the alpha blending ( if you enable it and use alpha color ) "doesn't work".
This is because TBGL_BlendFunc is set to default %GL_ONE, %GL_ONE mode, which deals only with color.
To correct this, just call:


tbgl_BlendFunc %GL_src_ALPHA, %GL_dst_ALPHA

... this will set blending mode to deal with alpha channel.

Hope I expresed me clearly, if not, ask again please :)


Bye,
Petr

kryton9
07-12-2006, 21:10
Thanks, I had to take resetmatrix out, when I did that it started working too, this is after I made the changes you recommended.
Thanks, for the help!!

Petr Schreiber
07-12-2006, 22:44
Hi,

good to hear it, or else I could get nervous and later mad :)

About TBGL_ResetMatrix...
In your example it would mean reseting all previous transformations - that means even TBGL_Camera.
Then viewer position would be reseted to 0,0,0, looking to -Z,


TBGL_PrintFont "This is a test to see if this works", 0, 0, 0

would place it "in your eye" ( hurts, huh :D ).
I use some clipping optimization in TBGL, which allows rendering of objects from 0.1 meters to specified draw distance ( default is 150 ), so the text is not visible for this reason.

In case of BMP defined font I use specific coordinate system. In this case you must call TBGL_ResetMatrix once before ploting the text. I could make each TBGL_PrintBMP to reset matrix automatically, but believe me, few texts ploted this way could hurt performance. I'm trying to keep OpenGL calls at lowest possible level, it has ( should ) possitive impact on speed.


Thanks,
Petr

kryton9
07-12-2006, 23:44
Petr, is there a blur and size and rotate commands for text.

For example if I wanted some text on the center of the screen, increase in size as it spins and then it blurs the previous text?

Petr Schreiber
08-12-2006, 02:10
Hi,

uh, text handling has not very advanced support in TBGL :-[
But if you want to create some "trailer" or "titles" effect, you can type lines of text in texture and then blur it.

Please see attached script

Bye,
Petr

kryton9
08-12-2006, 05:58
Petr, I never expected to get an answer tonight my time, as I thought it was late your time when I posted. Thanks for the reply and sample. Don't say it is a fake blur as it is a blur, all of it is an effect if you think about it, this shows how to do it, thanks. Gives me something to study really hard this weekend.

I came on the forums to post another link, I am sorry, just so much news and stuff to think about. I am sure you will find this fascinating.
http://rd.bcentral.com/?ID=4736098&s=135900407 About 65 MB's and in mp4 format, my quicktime player did play it. I selected view to fit screen and the quality is nice and high so you can really see what is going on.

You might want to read this article before downloading the movie, this way you can decide if you want to eat up your bandwidth or not.
http://www.thegamecreators.com/data/newsletter/newsletter_issue_47.html

The video is in the section titled:
The Game Creators into 2007

Right below that is an interesting look into google's free sketch-up and converter and what can be done.

Thanks for the cool example, really a nice effect, you really know this stuff, I just wasted tonight trying every combo I could think of with all the blend functions with the text. I am excited to play with this a little tonight after I get some work done and more this weekend!!

kryton9
08-12-2006, 08:26
Your blur program is fun to play with. Here is slight change for slightly different effect, lots of fun Petr, thanks!!!

' Basic bluring effect

Uses "TBGL"
Uses "UI"

Dim hWnd As Dword

hWnd = TBGL_CreateWindow("Poor mans motion blur - press ESC to quit")
TBGL_ShowWindow

TBGL_LOADTEXTURE "Textures\tdbf.bmp", 1, %TBGL_TEX_MIPMAP

tbgl_UseTexture 1 ' We will turn texturing on
tbgl_bindTexture 1 ' We will use texture 0

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

tbgl_UseDepthMask 0
tbgl_Useblend 1

dim FrameRate as single
dim i as long
dim BlurFactor as long = 128

dim R, G, B as long

dim actualImage as long = 1
dim actualImageAngle as single = 0
dim oldImageAngle(BlurFactor) as single = 0

R = rnd(0,255)
G = rnd(0,255)
B = rnd(0,255)



While IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate

tbgl_ClearFrame
tbgl_Camera 0,0,5,0,0,0
actualImageAngle += 96 / FrameRate
ActualizeBlur(actualImageAngle)

if actualImageAngle > 180 then
ResetBlur
actualImage += 1
actualImageAngle = 0
R = rnd(0,255)
G = rnd(0,255)
B = rnd(0,255)
end if
IF actualImageAngle <45 THEN tbgl_Scale 5, 5, 5
for i = 1 to BlurFactor
tbgl_PushMatrix

tbgl_Rotate 180+oldImageAngle(i),0,0,1
tbgl_Scale -1+oldImageAngle(i)/45, -1+oldImageAngle(i)/45, -1
tbgl_Color R/i, G/i, B/i

DrawTextLineFromBMP(actualImage, 4)

tbgl_PopMatrix
next


tbgl_DrawFrame

If GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While

Wend

TBGL_DestroyWindow

sub DrawTextLineFromBMP( nLine as long, numLines as long ) ' which line of how many
local oneLineSize as single = 1 / numLines

tbgl_BeginPoly %GL_QUADS
tbgl_TexCoord2d 0, 1 -(oneLineSize*(nLine-1))
tbgl_vertex -1, oneLineSize, 0

tbgl_TexCoord2d 1, 1-(oneLineSize*(nLine-1))
tbgl_vertex 1, oneLineSize, 0

tbgl_TexCoord2d 1, 1-(oneLineSize*nLine)
tbgl_vertex 1, -oneLineSize, 0

tbgl_TexCoord2d 0, 1-(oneLineSize*nLine)
tbgl_vertex -1, -oneLineSize, 0


tbgl_EndPoly
end sub

sub ActualizeBlur( bValue as single )

local j as long

for j = BlurFactor-1 to 1 step -1
oldImageAngle(j+1) = oldImageAngle(j)
next

oldImageAngle(1) = bValue

end sub

sub ResetBlur()
local j as long

for j = 1 to BlurFactor
oldImageAngle(j) = 0
next

end sub

Petr Schreiber
08-12-2006, 14:52
Hi kryton9,

nice mod ! Your version is better effect as you don't see text upside down :)

I'm just accumulating images with different intensity, I think creators of "Project Offset" engine do it in much more photo real way. This is why my way I call it fake, they use some more advanced stuff I think.

Please see their engine overview here (http://projectoffset.com/game.html)
You MUST :) see videos from here too (http://projectoffset.com/downloads.html)

Today, when Vista hardware is getting ready it might not be as shocking as when I saw it for the first time almost 2 years ago, but still amazing.

Thanks for the link to video I will download it not later than in 3 days!

Bye,
Petr

kryton9
08-12-2006, 21:43
Petr, breath taking videos, wow. Thanks never heard of this game or seen anything like it. Definitly on my purchase list when it comes out.

Now to save up for the newest nvidia card to enjoy all of these neat games coming out soon!!

kryton9
09-12-2006, 10:42
Petr, surprise... I need help :)

I wanted to see if I can get like a slider control on a gl screen, so as a first step I drew 2 bmp's the bar and marker(indicator)
The idea is the marker will sit on top of the bar. I tried to load them in and then I was going to see if I can get the right size
and overlapped correctly. And then I was going to work on the mouse being over and moving the marker to change a value.

Here is the code:

'
' TBGL 0.1.6 Demoscript : Textured square
'
' Petr Schreiber 2006
'

Uses "TBGL"
USES "UI"


DIM hWnd AS Dword

'MSGBOX 0, "Welcome to the TBGL module demonstration"+$LF+$LF+"It displays colorful textured rotating square", %MB_ICONINFORMATION, "TBGL demo"

hWnd = TBGL_CreateWindow("Textured square - press ESC to quit") ' Creates OpenGL window, it returns handle
TBGL_ShowWindow ' Shows the window

TBGL_LoadTexture App_SourcePath+"k9GreenSliderBar.bmp",1, %TBGL_TEX_MIPMAP ' Loads texture as #1, with best quality
TBGL_LoadTexture App_SourcePath+"k9SliderMarker.bmp",2, %TBGL_TEX_MIPMAP ' Loads texture as #1, with best quality


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

while isWindow(hWnd)

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_Useblend 1
'TBGL_Rotate GetTickCount/10,1,1,1 ' Rotates around all axis ( 1 enables axis, 0 disables )
TBGL_UseTexture 1 ' I want to use textures
TBGL_BindTexture 1 ' I want to use texture #1
TBGL_BeginPoly %GL_QUADS ' Starts polygon definition based on 4 vertexes
'TBGL_Color 255,0,0 ' Sets RGB color
TBGL_TexCoord2d 0,0 ' Sets texture coordinate
TBGL_Vertex -1,-1,0 ' Adds vertex

'TBGL_Color 0,255,0
TBGL_TexCoord2d 1,0
TBGL_Vertex 1,-1,0

'TBGL_Color 0,0,255
TBGL_TexCoord2d 1,1
TBGL_Vertex 1, 1,0

'TBGL_Color 255,255,255
TBGL_TexCoord2d 0,1
TBGL_Vertex -1, 1,0

TBGL_EndPoly ' Ends polygon definition

TBGL_UseTexture 2 ' I want to use textures
TBGL_BindTexture 2 ' I want to use texture #1
TBGL_BeginPoly %GL_QUADS ' Starts polygon definition based on 4 vertexes
'TBGL_Color 255,0,0 ' Sets RGB color
TBGL_TexCoord2d 0,0 ' Sets texture coordinate
TBGL_Vertex -1,-1,0 ' Adds vertex

'TBGL_Color 0,255,0
TBGL_TexCoord2d 1,0
TBGL_Vertex 1,-1,0

'TBGL_Color 0,0,255
TBGL_TexCoord2d 1,1
TBGL_Vertex 1, 1,0

'TBGL_Color 255,255,255
TBGL_TexCoord2d 0,1
TBGL_Vertex -1, 1,0

TBGL_EndPoly ' Ends polygon definition
TBGL_DrawFrame ' Swaps the buffers - displays rendered image

if GetAsyncKeyState(%VK_ESCAPE) THEN exit while

wend

TBGL_DestroyWindow ' Closes OpenGL window

I will attach the bmps zipped. The file named k9SliderBarGoal.bmp is what am trying to get it to look like on the screen, but using the other 2 bmp files so they will be separate and easy to move.
Hope this makes sense.

The problem is it crashes. I would like to treat them as sprites almost and have the alpha blending properties and being able to fade it so the user can see the stuff behind. Maybe it can't be done this way and needs to be a model, let me know if I am wrong in what I am attempting to do. Thanks.

Found a video yesterday where the interface is like I would dream ours to be. I couldn't believe this when I saw it. This is what I always imagined in my mind. Really powerful stuff they are doing, hopefully ours will be as cool.
http://video.google.com/videoplay?docid=-636999085452619198&q=genesis&hl=en

Petr Schreiber
09-12-2006, 14:16
Hi kryton9,

always happy to answer :)

The reason of GPF is the one I have already mentioned in another thread.
If you watch the help topic for TBGL_LoadTexture, you will see your textures have "wrong dimensions".

You are using 200x48 size, which is not power-of-two based.
I would recommned something like resizing to 256x64, as you will not loose any image information, it will just get stretched, which is thing you can always solve using proper texture mapping.

So this was the main mistake causing application fall.

Few more thoughts:

You use


TBGL_UseTexture 1
TBGL_BindTexture 1


and then


TBGL_UseTexture 2
TBGL_BindTexture 2


...in main loop code

TBGL_UseTexture can take only values 0/1 for disabling/enabling texture mapping generally, and you should call it like this in your script:


TBGL_UseTexture 1


... before main loop.
TBGL works like state-automat. Texturing will remain enabled until you disable it!
The same would work for blending.

TBGL_BindTexture is used correctly.

:D now I must go for a lunch and then I will continue :D

Few minutes later...

Your are drawing two objects at same position, this can lead to different results depending on OpenGL implementation. As this is "2D" stuff, please, again before main loop, disable depth masking using:


tbgl_UseDepthMask 0


You can find my version of solution, including arranged textures in attached file.
As you can see, I get smaller texture source finally, as I use stretching of resources from one image.
Also, it is wise to use blending only when needed - it is per-pixel operation, usually main bottleneck ( well, not for your PC :) ).
So I decided to map polygons without blending.


Bye,
Petr

P.S. I'v viewed the videos. The "editor" is really nice, only similar thing thinEdge has it's the terramorph tool working best on highly tesselated meshes. The other video was also nice, but I think their engine doesn't take advantage of all DX10 stuff. But I like the instancing, seems quite fast method :) The depth-of-field can be done even using OpenGL 1.1-1.2 with accumulation buffer with similar quality output. I like the one from Crysis engine, heave you seen thier videos ?

kryton9
09-12-2006, 22:45
Thanks Petr, for the explanation and example. I forgot to mention I did make the first texture 256 x256 when I got the error the first time, and it still gave the error, so I figured the power of 2 maybe didn't matter now, as before if you remember it worked not being power of 2 either, I remember you mentioned to be compliant it should be power of 2. Anyways, will stick to power of 2 as I know it should be that from now on.

I am confused on one point. You combined the bmps into one bmp, is this how I need to do all my stuff? I can't make them separate bmps and load them up separatly? I wasn't sure, but it sounds like openGl is for 3d and not 2d, hence no sprite like systems?

Thanks I will play with the great example and try every idea I have with it. Thanks for this great start.

Petr Schreiber
09-12-2006, 23:24
Hi,

with 256x256 it should work, I made some tests and... it worked :) Weird thing...

Regarding combining all BMPs in one texture - sure you don't have to !
It is just matter of your personal ... whatever :D ... and you occupy only 1 texture slot ( of 256, ahem )

Sure your tbgl_bindTexture 1 and 2 would did the trick. In this case, I just wanted to show you another way, not the only correct one ( as there is nothing such as ). Also less texture bind swapping means % of performance for you. This is why it is better to have one texture for character models ( for example ).

To make things easier, I will try to add TGA textures setup in next TBGL. It is similar to BMP, it can be loaded perfectly fast and it has one huge advantage over BMPs - it can hold alpha channel !

So you will be able to have both "image" data and "mask" for sprite in one.

Thanks for your ideas/suggestions/tips kryton,
I wan't more and more ;D

Petr

kryton9
10-12-2006, 09:34
Petr, somehow I missed your response and when I came to post my next ask for help, saw your response, thanks. Have you ever written stuff for png format. It also supports alpha and is smaller file size.

I tried to put in code to read the mouse from one of Eros's examples. I commented out the crash causing lines to find what could be doing it. I think it is the handling msg from a tbgl window. Anyways here is the code. I put ************************** where the error first started when uncommented. That line let's me believe that handling msg's from tbgl are not like other windows msgs maybe?


'
' kryton9ish slider :)
'
' kryton9 & Petr Schreiber 2006
'code for mouse from Eros from the form_move example


Uses "TBGL"
USES "UI"

uses "console"

TYPE POINTAPI
x AS LONG
y AS LONG
END TYPE

DECLARE FUNCTION GetCursorPos LIB "USER32.DLL" ALIAS "GetCursorPos" (lpPoint AS POINTAPI) AS LONG
DECLARE FUNCTION ScreenToClient LIB "USER32.DLL" ALIAS "ScreenToClient" (BYVAL hWnd AS DWORD, lpPoint AS POINTAPI) AS LONG

DIM hWnd AS Dword
dim gpt as POINTAPI
GLOBAL msg, wParam,lParam as long

hWnd = TBGL_CreateWindow("Slider demo - press ESC to quit") ' Creates OpenGL window, it returns handle
TBGL_ShowWindow ' Shows the window

TBGL_LoadTexture App_SourcePath+"Textures\slider_texture.bmp",1, %TBGL_TEX_NEAREST ' Loads texture as #1, with best quality




TBGL_BindTexture 1 ' Texture #1 will be used in whle program

tbgl_UseLighting 1 ' Lighting used
tbgl_UseLightsource %GL_LIGHT0, 1 ' Source 0

dim SliderPos as single

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

while isWindow(hWnd)

TBGL_ClearFrame ' Prepares clear frame
TBGL_Camera 0,5,5,0,0,0 ' Setups camera to look from 0,0,5 to 0,0,0
tbgl_Rotate GetTickCount/100,0,1,0

TBGL_UseTexture 0 ' Texturing not for cube
tbgl_UseLighting 1 ' Light yes
tbgl_Color 128+SliderPos*127,0,0
tbgl_box 1,1,1

TBGL_UseTexture 1 ' Texturing yes for "GUI"

tbgl_ResetMatrix
tbgl_Color 255,255,255' Default
tbgl_UseDepthMask 0 ' No depth, we don't need it as it will be 2D art ( order of operations depends )
tbgl_UseLighting 0 ' No light for GUI please
TBGL_Camera 0,0,5,0,0,0 ' Setups camera to look from 0,0,5 to 0,0,0
' Base body for our slider
' It's texture is situated in upper left corner of texture
' TBGL tex mapping starts with 0,0 as left-down, 1,1 as right-up for not repeated texture
TBGL_BeginPoly %GL_QUADS ' Starts polygon definition based on 4 vertexes

TBGL_TexCoord2d 0,0
TBGL_Vertex -1,-0.24,0

TBGL_TexCoord2d 0.5,0
TBGL_Vertex 1,-0.24,0

TBGL_TexCoord2d 0.5,1
TBGL_Vertex 1, 0,0

TBGL_TexCoord2d 0,1
TBGL_Vertex -1, 0,0

TBGL_EndPoly ' Ends polygon definition

SliderPos = sin(GetTickCount/1000)

tbgl_Translate SliderPos,0,0
TBGL_BeginPoly %GL_QUADS
' Slider pointer texture
TBGL_TexCoord2d 0.55,0.33
TBGL_Vertex -0.1,-0.2,0

TBGL_TexCoord2d 1,0
TBGL_Vertex -0.01,-0.32,0

TBGL_TexCoord2d 1,1
TBGL_Vertex -0.01, 0,0

TBGL_TexCoord2d 0.55,1
TBGL_Vertex -0.1, 0,0

'
TBGL_TexCoord2d 0.55,0.33
TBGL_Vertex 0.1,-0.2,0

TBGL_TexCoord2d 1,0
TBGL_Vertex 0.01,-0.32,0

TBGL_TexCoord2d 1,1
TBGL_Vertex 0.01, 0,0

TBGL_TexCoord2d 0.55,1
TBGL_Vertex 0.1, 0,0


TBGL_EndPoly ' Ends polygon definition
tbgl_UseDepthMask 1 ' return back to norma;

TBGL_DrawFrame ' Swaps the buffers - displays rendered image

if GetWindowKeyState(hWnd, %VK_ESCAPE) THEN exit while
'Code to handle mouse events
' msg = GetMessage(hwnd, wParam, lParam) '****************************************************** this line is causing an error?
' select case msg
' case %WM_MOUSEMOVE
' console_writeline(MsgFormat("User MouseMove", Msg, wParam, lParam))
' if lowrd(wParam) = 1 then
' '---Get the screen coordinates of the cursor
' GetCursorPos gpt
' '---Transform to local coordinates
' ScreenToClient hwnd, gpt
' end if
' case %WM_LBUTTONDOWN
' console_writeline(MsgFormat("User LeftMouseDown", Msg, wParam, lParam))
' case %WM_LBUTTONup
' console_writeline(MsgFormat("User LeftMouseUp", Msg, wParam, lParam))
' case %WM_RBUTTONUP
' console_writeline(MsgFormat("User RightMouseUP", Msg, wParam, lParam))

' case %WM_SIZE
' console_writeline(MsgFormat("User Size", Msg, wParam, lParam))
' case %WM_SIZING
' console_writeline(MsgFormat("User Sizing", Msg, wParam, lParam))
'
' case <> 0
' console_writeline(MsgFormat("User", Msg, wParam, lParam))
' end select

wend

TBGL_DestroyWindow


function MsgFormat(byval sText as string, byval Msg as long, byval wParam as long, byval lParam as long) as string
function = sText & ": msg[" & Msg & "] wPar[" & wParam & "][" & hiwrd(wParam) & "-" & lowrd(wParam) & "] lPar[" & lParam & "][" & hiwrd(lParam) & "-" & lowrd(lParam) & "]"
end function

Anyways, even once we read the mouse locations how do we know when the user clicks on our control? Is it just looking up positions and comparing against where we know them to be?

Since I am stuck, I am going to read about opengl from the official site to see if I can understand what all can be done with it.
Then off to sleep. Hope you can figure out what is wrong, but I figure this way you are writing the program and I am learning :) So thanks!!

Petr Schreiber
10-12-2006, 11:54
Hi kryton9,

I will check out PNG, thanks!

Regarding crash ... do you have the latest thinBASIC 1.2.0.0 preview ? I can run the sample with problematic lines uncomented, and all is OK. Even the Lesson6_TBGL_LightWithMouse.tbasic, if you remember, now works. Eros solved the problem.

How to detect a click ... it can be done the hard way using positions retrieved from %WM_LBUTTONDOWN compared to proportional positions.
Second, more ellegant way can be done directly from OpenGL, please see this NeHe tutorial (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=32). TBGL does not include this commands, you will need to include the "thinbasic_gl.inc" and "thinbasic_glu.inc" to do this stuff.

On other side - if you consider using this for thinFX, I recommend to keep rendering by OpenGL and controls using classic thinBASIC dialog way. It must not cover the image and it is easier to handle, no hard checking if control was used.

Waiting for your questions :),
Petr

kryton9
10-12-2006, 21:28
Petr, hmmmm... I do have that version of thinBasic. So something else must be goofy on my system. I will try it on my other computer later and see how it runs on there.

One thing really interesting. So you are saying I have access to all of openGL with thinBasic by using those include files? That will be awesome. Thanks Petr, will try that out now.

Yes, I think using regular form for user input will be much easier, besides we can make the form translucent to users desires. So they can still see behind if they want. I really like that. I want to make sure we have total control of users mouse use as that is a big part of gaming and doing things in a game of course with the keyboard.

When I hit another wall or need help will be back. till then thanks!!

Petr Schreiber
10-12-2006, 21:45
Hi kryton9,

I will check the problem again :-[

Regarding thinBASIC OpenGL headers - yes, they provide even things TBGL has not in feature list.
But be warned, they are designed for oldies OpenGL 1.2 ! Please be patient with waiting to more recent version, but it is lot of thing to understand to make "translation" correct.
but if zou take it from bright side, all programs done using this headers + TBGL will run even on "ancient" cards.

Transparent XP window is good stuff, I almost forgot about it :)

Thanks,
Petr

kryton9
11-12-2006, 06:41
Thanks Petr, I looked through that tutorial, the delphi version didn't run, but I realize how much work all of this stuff is. I also see how much simpler you made the commands for us in the TBGL compared to just openGL code, thanks. Very neat how you made things so much easier. Thanks for your work and help!!
Here is info on png files.

Can you tell me how you go about writing an imported for a file format. If you find the right info on this site, tell me what I should look at and maybe we can work on it together. I would love to learn how to do stuff like this.

http://www.libpng.org/pub/png/

Petr Schreiber
11-12-2006, 12:24
Hi kryton9,

I'm happy you like TBGL :)
It has many functions that are +/- just wrappers, but all tbgl_m15*, window handling and texture loading is new.

I'm now checking the TBGL help file to provide better information.
Just found I forgot to mention that glViewport and TBGL_Viewport work different, in TBGL I think better :)

While glViewport works with current resolution values and goes from lower-left corner to upper-right,
TBGL_Viewport works with relative proportions which need no programmer care about current resolution, starting from upper-left to lower-right.

Also there is something like display list and texture "garbage collection" taking care of all stuff behind the scenes.

I will look for the link you provided, thanks a lot. Sadly in next 2 days I have some critical stuff to do, but after this I will dive into and report you about the image importing stuff.

Thanks a lot !,
Petr

kryton9
11-12-2006, 21:04
Good luck on your stuff for the next 2 days. No rush, I am reading a lot and trying to graps what is out there. You can tell by the game engines, toolkits and other third party libraries, that there is a void out there in terms of making life easier when it comes to this stuff.

I watched 2 interesting lecture videos last night, one by one of the small talk guys. Although it was about smalltalk, it was more about the benefits of oop languages and why you should go all objects and not halfway to get the full benefits of oop. He answered looking passed the speed differences as over time he said that would be irrelevant because of hardware. Also and this I don't understand, he points out how the OS could really benefit from this approach, but yet they never go on to develop an OS on the hardware, but sitting on top of the existing OS.

I don't know why they don't make a smalltalk based OS that boots like linux can from CD's or install into a separate partition. The other one was about Perl, not much code examples but a good overview of the language. I won't put the links as I know you are busy, but they are both of google tech talk videos, so easy to find if you do a search, tech talk perl for eample.

Yes what you did with tbgl is really nice. I am looing through the opengl manuals, and from looking at the manual and seeing what can be created is 2 different things.

Petr Schreiber
11-12-2006, 21:20
Hi kryton9,

just quick reply.

Please post the links ! I will visit them when I'll have time !
Perl is language which my friend loves. But he also practices dark magic like haskell :D

It is true hardware will "erase" the speed problems, but there will be always users with slow machines

Please check out OpenGL Red Book (http://fly.cc.fer.hr/~unreal/theredbook/) ( also here in PDF (http://www.opengl.org/documentation/red_book/) ). Basic but important stuff here.


Thanks,
Petr

kryton9
11-12-2006, 21:34
Thanks for the link Petr.

Here are the ones about programming.
Dan Ingalls OOP
http://video.google.com/videoplay?docid=-2058469682761344178&q=programming&hl=en

Perl
http://video.google.com/videoplay?docid=-876009974056913377&q=programming&hl=en

Not much code but more overviews in both of these. The OOP one is interesting in that you
can see the potential more than in any other OOP presentation I have seen. In other OOP
they never mention messaging and to me that is what makes OOP so great when used like this.
A totally event driven system. If we could mimic that in our stuff, it would be awesome.

Petr Schreiber
11-12-2006, 22:48
Thanks kryton9,

it sounds exciting!
I will watch it ASAP.

Bye,
Petr

kryton9
12-12-2006, 01:18
Petr these videos there is no rush to watch for you. The oop is the one you might find interesting more and useful in thinking of developing our systems, I usually watch these videos when I am eating my dinner or something.

The perl one is interesting in giving you an overview of Perl. I never used it and am not sure if I will, but at least I know a little about it now. Not much coding wise, but of its strengths and weaknesses.

I forgot to write how funny and correct you were with Haskell being Dark Magic. After I read article by My Epic, Sweeney and the next language he mentioned Haskell a lot in there and so I took a look at it and saw what truly was dark magic and rubbed my eyes and came back to the good side :)

Petr Schreiber
13-12-2006, 19:33
Hi kryton,

I'm again approaching my download limit. This means I am enjoying last days ( hours ) on fast speed.
Once I drop over the edge again :) I will visit the links and download it. It is terrific it can be downloaded as AVI from video.google.com. Then I can watch it without stress and take all information needed from it.


Petr

P.S. Good you are back on good side :D

kryton9
13-12-2006, 21:52
Petr, please save your bandwidth for sharing your wonderful code, ideas and posts for the forums, the videos can wait!!

kryton9
21-01-2007, 08:59
Hi Petr, hope studies are going well for you. I decided to do some programming before i forget things and I already forgot basic things like how to declare a variable in thinbasic, can you believe how bad my memory is :) I just laugh.

Anyways, I decided to go through your tbgl lessons again. This time to really experiment with each one so i can understand more.

So this is lesson 1, with making points out of 3 vertices.

Anyways, I read where you can't change the pointsize in between begin poly and end poly and that is why my code is not working, but I was trying to figure out how to get around that, what happens is I wanted to make certain vertices based on a mod value for example to make a vertex 2 points instead?

Maybe there is an easy solution and because I didn't program for over a week, my mind is not working, but am stuck. Hope it is an easy thing and you can laugh at how stupid I can be at times :)


'
' Lesson #1 from thinBASIC TBGL tutorials
' "Initializing TBGL window, displaying triangle"
'
' by Petr Schreiber
'
' Downloaded from http://psch.thinbasic.com/
'


Uses "TBGL"
Uses "UI"

DIM hWnd as dword
dim cx as integer
dim cy as integer
'MsgBox (0, "You should see black screen with white triangle soon"+$LF+$LF+"Press ESCAPE to quit window", %MB_ICONINFORMATION, "Lesson 1")

' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindow "Lesson 1 - press ESC to quit"


tbgl_ShowWindow ' This will display the window on the screen

GetAsyncKeyState %VK_ESCAPE ' Reset status of the ESCAPE to prevent immediate quit

while IsWindow hWnd ' While window exists, we will draw and check for ESCAPE

tbgl_ClearFrame ' This clears the frame and prepares it for drawing

tbgl_Camera 50,50,100,50,50,0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )

tbgl_PointSize 1
tbgl_LineWidth 1
tbgl_BeginPoly %GL_POINTS

' Here begins definition of traditional triangle polygon
for cy = 1 to 100
for cx = 1 to 100
if cx = 50 then
tbgl_PointSize 2
else
tbgl_PointSize 1
end if
tbgl_Vertex cx,cy,0
next
next
tbgl_EndPoly ' We must end the definition

tbgl_DrawFrame ' This will display the scene

' When ESCAPE is pressed, we will leave the main loop
IF GetAsyncKeyState %VK_ESCAPE THEN EXIT while
Wend

tbgl_DestroyWindow ' This will destroy the window

Petr Schreiber
21-01-2007, 12:05
Hi kryton9,

studies go ok, now learnig for another exam :)
But in the pause between learning and learning ... time for thinBASIC relaxing :)

Regarding your sample - you almost made it !

To render what you want, you would need to change the rendering proces just like this:


for cy = 1 to 100
for cx = 1 to 100

if cx = 50 then
tbgl_PointSize 2
else
tbgl_PointSize 1
end if

tbgl_BeginPoly %GL_POINTS
tbgl_Vertex cx,cy,0
tbgl_EndPoly

next
next


This is easy. But this way, you will set point size before each point draw, not speaking of multiple calls to tbgl_BeginPoly / tbgl_EndPoly. This is very performance expensive.

If you want to get triple (!) framerate, try this:


'
' "Point size change"
'
' by Petr Schreiber
'


Uses "TBGL"
Uses "UI"

DIM hWnd as dword
dim cx as integer
dim cy as integer

' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindow( "Lots of dots - press ESC to quit")

tbgl_ShowWindow ' This will display the window on the screen

GetAsyncKeyState (%VK_ESCAPE) ' Reset status of the ESCAPE to prevent immediate quit

tbgl_PointSize 1
dim LastPointSize as long = 1

while IsWindow (hWnd) ' While window exists, we will draw and check for ESCAPE
win_SetTitle( hWnd, TBGL_GetFramerate)
tbgl_ClearFrame ' This clears the frame and prepares it for drawing

tbgl_Camera 50,50,100,50,50,0 ' We will look from point 50,50,100 to 50,50,0

' Here begins the points rendering stuff
tbgl_BeginPoly %GL_POINTS

for cy = 1 to 100
for cx = 1 to 100

if cx = 50 and LastPointSize <> 2 then

tbgl_EndPoly ' This ends drawing of 1 pixeled points

tbgl_PointSize 2
LastPointSize = 2

tbgl_BeginPoly %GL_POINTS

elseif LastPointSize <> 1 then

tbgl_EndPoly ' This ends drawing of 2 pixeled points

tbgl_PointSize 1
LastPointSize = 1

tbgl_BeginPoly %GL_POINTS

end if

tbgl_Vertex cx,cy,0

next
next

tbgl_EndPoly

tbgl_DrawFrame ' This will display the scene

' When ESCAPE is pressed, we will leave the main loop
IF GetwindowKeyState( hWnd, %VK_ESCAPE) THEN EXIT while
Wend

tbgl_DestroyWindow


This way we change pointsize only when necessary ( less calls to driver ), it means we can bundle more vertices in one tbgl_BeginPoly / tbgl_EndPoly too.

Nice thing in this sample is, that you can see more complex code is not a problem for thinBASIC, and if we tweak the code for GPU, we get it a lot faster !

Of course, precaching whole this into display list would add even more raw speed.
Please next questions :)


Bye,
Petr

kryton9
21-01-2007, 13:16
Thanks Petr, I stayed up both last night and tonight till a little after 6am tonight and till 7am yesterday. Feeling really sleepy, but happy you had time to respond. I will have some code to study when I get up, so can sleep well. Thanks for both examples!!

I will keep testing out things and seeing what happens and will I am sure ask again with something new soon.

How are your thoughts on mouse handling going? I think it is such an important interface tool for games and anything graphical.

Also have you thought about gamepads and joysticks at all? Maybe there is a library out there for such inputs we could access. I have spent some time looking but besides SDL have not really found anything. I am sure since opengl is widely supported there must be a good library for handling input. I am surprised my searches have not turned up that killer library yet with all input routines.

Anyways, off to sleep, hope what I wrote made some sense as tired typing. Thanks again for your wonderful reply and wake up code for me to look at when I get up. More Petr Tutorial drills for me tomorrow!!

Petr Schreiber
21-01-2007, 17:41
Hi kryton,

the mouse stuff is one of the high priority improvements to TBGL.
As I am still in exam time, I have very little time to fully concentrate on this :(
But I am gathering all possible inormation from the web and various samples to make it quick, when I'll have time.

Regarding joysticks - one of my games I made looong time ago in PowerBASIC used basic joystick handling ( buttons + axis stuff ). It is pretty easy to do using pure Win32API, so I think no extra library will be needed.
Using this way, it is very simple to get info from various devices, including gamepads and "wheels" for race sims.
They all behave on the same principle. So it should not be problem too.


Bye,
Petr

kryton9
22-01-2007, 00:38
Great new Petr about the input then!! It does make it fun to use the correct device for the type of game. After intense Blender efforts last week and being very pleased with the speed performance tests with thinBasic, TBGL I am very excited by the possibilities that will come!!

I did intense game playing this weekend. I cleared out about 40 gigs of space on my hard drive and installed most of my games.
In terms of sucking you into a story line, being almost like an interactive movie, Halo is still incredible. I never finished it before, so hopefully will get through it this time.

have some fun talking about games:

Games I am playing or playing again:
Serious Sam 2 is absolutely a blast to play. My friends and I go through the whole game in a day or 2 in coop play it is so much fun.

IL-2 Forgotten Battles is just the most incredible coop flight combat game. The terrains are huge, based on real maps and incredibly rich. I don't know how it is done. At times when flying you swear you are in a real plane the views are so spectacular. The game play is awesome as well as the controls and action.

Warcraft III, always played multiplayer and never went through single player, so hopefully will do that. It still looks great.

Black and White looked so dated, I remember it as wowing me with graphics a few years ago, but now looks old. So does Need for Speed 3. It used to looks so good, but with Need For Speed Most Wanted the graphics are just so good and the game play so intense.

I bought microsoft flight simulator X, so far very disappointed. I get terrible performance and the graphics and scenery are not that good. I think this could be because of the terrorist attacks that they ruined the reality of this game.

I still love Starcraft Broodwars.

Commanche 4 is an awesome Helicopter Sim, it still looks good and is fun to play.

Freespace 2 is lots of fun. On both Commanche 4 and Freespace 2 I love going through the training modes. I used to enjoy doing the same on Mechwarrior 3, but it no longer runs.

Of course Unreal Tournament 2004 is still a favorite to play. I love onlslaught games as well as vehicle capture the flag games.

I installed Half-Life 2 and Counterstrike Source, but I got an error saying my cd key is a duplicate, I emailed Steam and hopefully hear back with what the problem is.

Games I am looking forward to playing:
Command and Conquer 2007
Unreal 2007
Lord of the Rings MiddleEarth (it has been out, but I have yet to see the movies so have been waiting to watch the trilogy then get into the game)
World of Warcraft ( I have a free 2 month offer waiting to try, but am afraid I will get addicted and not do anything else :) My friend who likes games but is not obsessive about them says that World of Warcraft is addicting and you want to spend all your time on it, so I know it must be very addicting for him to say that!!)
Spore (again looks addicting, but wow)
Project Offset, looks incredible, I think this is one you introduced to me!!

When you take a break tell me your gaming thoughts!!

Well off to study you code from yesterday, thanks again and I am sure before I got to bed I will have something else to ask about, really enjoying these, so glad you made them. I went through them before just doing them, but now will try to really understand more about what is going on and why.

kryton9
22-01-2007, 05:06
Guys, can you try copying and pasting Petr's code in reply #28 on this thread. When I copy and paste the code I get a lot garbage mixed in with the code. I think it has to do with that color syntaxing.

Let me know if this happens to you too or just a new problem on my end. Thanks.

kryton9
22-01-2007, 06:18
Here from that nice lesson one of Petr's comes a matrix screen sort of, like the one in the movie not an opengl matrix :)


'
' Lesson #1 from thinBASIC TBGL tutorials
' "Initializing TBGL window, displaying triangle"
'
' by Petr Schreiber
'
' Downloaded from http://psch.thinbasic.com/
'


Uses "TBGL"
Uses "UI"

DIM hWnd as dword
dim cx as integer
dim cy as integer
'MsgBox (0, "You should see black screen with white triangle soon"+$LF+$LF+"Press ESCAPE to quit window", %MB_ICONINFORMATION, "Lesson 1")

' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindow ("Lesson 1 - press ESC to quit",1024,768,32)


tbgl_ShowWindow ' This will display the window on the screen
tbgl_Camera 50,50,200,50,50,0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )
tbgl_SetDrawDistance 50000

GetAsyncKeyState %VK_ESCAPE ' Reset status of the ESCAPE to prevent immediate quit

while IsWindow hWnd ' While window exists, we will draw and check for ESCAPE

tbgl_ClearFrame ' This clears the frame and prepares it for drawing

tbgl_Camera 67,50,125,68,51,0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )
tbgl_PointSize 1
tbgl_LineWidth 1
'tbgl_color 0,255,0
tbgl_BeginPoly %GL_POINTS

for cy = 1 to 100
for cx = 1 to 136
if mod(cx,7) and mod(cy,rnd(100)) then
tbgl_color 0,125+rnd(1,130),0
tbgl_PointSize 5
else
tbgl_color 0,75+rnd(1,130),0
tbgl_PointSize 2
end if
tbgl_BeginPoly %GL_POINTS
tbgl_Vertex cx,cy,0
tbgl_EndPoly
next
next

tbgl_DrawFrame ' This will display the scene

' When ESCAPE is pressed, we will leave the main loop
IF GetAsyncKeyState %VK_ESCAPE THEN EXIT while
Wend

tbgl_DestroyWindow ' This will destroy the window

Tonight's question about tbgl:

In many games you have the option of changing the screen resolution while in the game. Usually on the fly from an options menu while the game is still running. Can we do the same sort of thing in tbgl?

Petr Schreiber
22-01-2007, 18:46
Hi kryton9,

very nice Matrix effect, Neo would like it ;)
I just came to check it here and so many interesting posts to reply :)

I must go out now, but I will try to respond all your questions during this ( UTC+1 ;D ) night, or in worst case tommorow.

Thanks a lot kryton,
now I must dive into Matrix again 8)

Petr

P.S. I can see the source copy problem too, try to paste it first to Notepad and than to thinAir

Petr Schreiber
22-01-2007, 20:29
Hi,

TBGL currently can switch resolution just by killing old window and creating new, this is not very versatile.
Eros had requests for switching windowed/fullscreen window too.

I need to solve it soon, as I find it very important too. I already made some preparation steps in current TBGL, like moving internal initialization from tbgl_createWindow to module specific "hidden" function. I still need to solve few issues, but it should be possible.
I think - fullscreen 640x480 to fullscreen 1280x1024 - no problem. Just doing some stuff and resizing the window, but windowed -> fullscreen is much trickier. Problem is to make loaded textures survive the window recreation :(.



Great new Petr about the input then!! It does make it fun to use the correct device for the type of game. After intense Blender efforts last week and being very pleased with the speed performance tests with thinBasic, TBGL I am very excited by the possibilities that will come!!


Yes, I liked the Blender challenge a lot too!
Even the images from the little demo made my friends surprised, so thanks again for the models, good to have skilled modeler in arsenal ;)



I did intense game playing this weekend. I cleared out about 40 gigs of space on my hard drive and installed most of my games.

I envy you :D

Regarding Halo, following Eros recomendation I downloaded a demo and liked it very much. I also noticed although models are sometimes relatively low poly ( please no crucifiction for this ;) ), there is very high effort to use specular and bump maps. I realized it when switched to higher resolution. The feeling when driving the buggy, shooting with guns to colorful enemies ... really fun !

I have at home only Serious Sam 1, it was very cheap and with OpenGL mode :) so I spent some time with it. But as there is nothing like story, I will hardly return to it.

IL-2 Sturmovik is BEST! Incredible detail, incredible sound, incredible physics model of plane, wiiide landscape... best simulator ever :) Forgotten Battles seem to push the limits even more, at least from what I have read. I like the "experimental" planes like russian BI-1 ( metal tube flying 3 mintes using jet engine :D )

Regarding Warcraft III, I had the "luck" to play localised version with czech dubbing which is so bad it was super :)

I am very sad you find B&W look dated, this game makes me almost cry :-[.
I especially love the creature handling and its learning. There is so much little details in the game - if you touch water where fish are behind, they quickly go away. People is doing various tasks. Day cycle... Generally games from Peter Molyneux head are my favourite. I also like a lot the original Dungeon Keeper. It is RTS, where you can also switch to some unit and play it as FPS. Old game, but incredible atmosphere it has. And very low HW requirements.

I am very curious about MSFS X. My friend has an older version, and I like most its pluginability ( of the game, not friend ;D ). So I could fly with plane over my city. The graphic detail was generally very low, comparing to Sturmovik.
I thought MSFS X was DX10 game? The anti-terrorist stuff is present in all versions I had chance to play. Although I am not terrorist :) I miss the oportunity to collide with objects ( buildings ). Without that, you just have to keep you higher than terrain and no other problems to solve :( When you are in air, airplane needs so much care as screensaver then :(

I have never played Commanche, I just remeber I used screens in magazine to explain multitexturing long time ago to my friend :).

It seems I am generation back again, because I haven't played Freespace 2 but just FS 1 :D. I liked it a lot - it was first 3D accelerated title I played ! Mechwarrior does not run on XP ? It is Microsoft game ???



I installed Half-Life 2 and Counterstrike Source, but I got an error saying my cd key is a duplicate, I emailed Steam and hopefully hear back with what the problem is.

:( And I want to buy it soon, hope no such a problems, grrr

Your "looking forward" list is interesting, I would add Alan Wake, although I know I won't be able to play it :) Gears of War look profi too.

Too bad not so much new adventure games announced :(

To clear my mind, I played in last week each day for 30 minutes one old game I discovered as bundle to one gaming magazine - Giants: Citizen Kabuto.

It is again combination of shooter and bit of RTS, but with lots of really funny videos, I had to really laugh. Very compatible sense of humour :). It is not serious game, and it has still very moody graphic and perfect cartoon character animations. What I didn't like was almost no optimization of game engine, so I was jumping from 60 to 4 FPS in worst cases. Also second half of game seems to be done in time pressure ( no more animtations, except the end ). But it has many, many unforgetable moments.

I am also adventure games addict, so I can recommend - Syberia 1&2, Post Mortem, Still Life, Gabriel Knight series, Broken Sword 1&2, Fahrenheit... I think this kind of games is the hardest to create - story must be perfect, as it is main base of the game. Catventure has my huge respect for his "Piggery Jokery" TAB game.

I hope we will be able to produce some worth to remember game, if we put brains on it :)


Bye,
Petr

kryton9
22-01-2007, 21:11
Thanks for the reply Petr and I know how busy you must be with all your studies, so thanks for the reply!!

I am glad you have played IL-2, any idea how they pull off those massive real terrains and action all over the map? It just amazed me.
You will have to join my friend and I in a game one night when school is out for a long break!!

Citizen Kabuto is hilarous, I played it quite a lot when it first came out as I did with Black and White. Both games were jaw dropping to me at the time and stayed that way in my memory, so when I reinstalled Black and White, I was really sad that what looked so great now looked average at best, but of course the game idea is still amazing.

I loved throwing the boulders and once in a while a villager out to the water. The pet idea was amazing, as was the whole game!!

Serious Sam 1 had that awesome ending round, and then serious sam second encounter had that great battle at the end, if you ever watched Buffy the Vampire slayer tv series and Angel tv series, that last battle outside the cathederal reminded me of those kind of epic battles as the last seasons of those shows had. The music was incredible too.

Serious Sam 2 is incredible too, vast worlds, many races, cool enemies and one of the longest funniest endings to a game I have seen.
It is really fun playing with friends in coop mode it just adds to the game. It is really cheap compared to most games too. If you ever get it you will need to play with my friend and I as we go through the whole game. Lots of fun!!

I haven't tried any of those adventure games in your list, I had heard of Gabriel Knight but none of the others that I remember. So many games and not enough time. It will take me awhile to go through the ones I listed to make room for the new ones coming out this year.

In regards to doing dll's and me going with powerbasic, I think I will leave tbgl creation to you and just give you ideas, I realize you are light years ahead of me in understanding all of it. I am lucky to just follow along and use your efforts work in tbgl. I will give you lots of feedback and likes and dislikes in developing it so you can make it as great as it can be.

I keep going to the red book in opengl, read other sites and come back to tbgl to see if I understand more, each time I do this cycle I understand more and more.

I am confused how you will handle the inputs, is all of that in windows in win32 api? I know in directx they have their own input routines, I was wondering why they would do that if they have them in win32? I don't know openGL games put input handling, sound and physics together, I know it is with libraries, but which ones, who knows. It gets very confusing trying to use any of them. I am really impressed you can sort through them. I do like looking for new things though.

I am sure you read about the new game engine for opengl at release 1 on the opengl site. Irrlich looks interesting too, so if you ever need ideas you might want to look at them too.

I have to go out today and won't have time to do anything today or tonight. But starting tomorrow afternoon, I am going to put a good effort to give us something to look at and to experiment.

ErosOlmi
22-01-2007, 23:25
Kryton9,

a little variation of your nice code example. I like it.

Thanks
Eros


'
' Lesson #1 from thinBASIC TBGL tutorials
' "Initializing TBGL window, displaying triangle"
'
' by Petr Schreiber
'
' Downloaded from http://psch.thinbasic.com/
'


Uses "TBGL"
Uses "UI"

DIM hWnd as dword
dim cx as integer
dim cy as integer
'MsgBox (0, "You should see black screen with white triangle soon"+$LF+$LF+"Press ESCAPE to quit window", %MB_ICONINFORMATION, "Lesson 1")

' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindow ("Lesson 1 - press ESC to quit")', 1024, 768, 32)


tbgl_ShowWindow ' This will display the window on the screen
tbgl_Camera 50,50,200,50,50,0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )
tbgl_SetDrawDistance 50000

GetAsyncKeyState %VK_ESCAPE ' Reset status of the ESCAPE to prevent immediate quit

'---This is necessary when using RND functions. It seeds random number generator
randomize

while IsWindow hWnd ' While window exists, we will draw and check for ESCAPE

win_settitle(hWnd, TBGL_GetFramerate & " FPS")

tbgl_ClearFrame ' This clears the frame and prepares it for drawing

tbgl_Camera 50, 90, 40, 38, 51, 0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )
TBGL_Rotate GetTickCount/80, 1, 1, 0

'tbgl_color 0,255,0
tbgl_PointSize 1
tbgl_LineWidth 1
tbgl_BeginPoly %GL_POINTS

for cy = 1 to 100
for cx = 1 to 136
if mod(cx, 7) and mod(cy, rnd(100)) then
tbgl_color 255, 100 + rnd(1, 10), 0
tbgl_PointSize rnd(1, 3)
else
tbgl_color 0, 75 + rnd(1, 130), 0
tbgl_PointSize 1
end if

tbgl_BeginPoly %GL_POINTS
tbgl_Vertex cx, cy, 0
tbgl_EndPoly
next
next

tbgl_DrawFrame ' This will display the scene

' When ESCAPE is pressed, we will leave the main loop
IF GetAsyncKeyState %VK_ESCAPE THEN EXIT while

Wend

tbgl_DestroyWindow ' This will destroy the window

kryton9
23-01-2007, 05:25
Eros, first that is really cool. It gave me an idea to use your technique for an effect to simulate flying over a city at night, that is the first thought that came to my mind when I saw your cool program!!

I will study to see what all you did and learn a lot I am sure, thansk!!

I had to use Petr's trick to copy and paste into notepad first, then copy and paste into thinAir.
Using the syntax highlighting of the code on the forum is inserting strange characters when
copy and pasted into thinAir directly.

Thanks again for your code, going to look more in depth at it now!

ErosOlmi
23-01-2007, 12:29
Well, I just added a RANDOMIZE, a WIN_SETTITLE, a TBGL_ROTATE and a red color :)

Problem here is the number of loops it perform: 100 * 136 = 13600 FOR/NEXT iterations every time.
On my box this script run at 11/13 FPF so it means it computes about 1.5 million loop per seconds and for an interpreter (reading source code again and again) is too much.

For testing, it is fine. I will also use this script for my speed tests in future.
But for real life applications, some kind of pre-caching using TBGL lists or other technique should be considered (for example storing the base dot green grid in a list and change only red dots in the loop).

Ciao and thanks for the idea
Eros

Petr Schreiber
23-01-2007, 14:29
Hi Eros,

cool sample !
It reminds me of some retro scifi :)

Problem in speed is generally in fact points are one of the slowest primitives in OpenGL ( surprise ! :o )
I will try to create some optimized variation ( as you suggested using scripts ) of your and kryton script.

Very nice,
Petr

kryton9
23-01-2007, 18:40
Eros, I was getting to 9 to 12 frames per second on my computer.

Petr provided an example which is supposed to be 3 times faster but because of the syntax color in the forum code, it was messing up, but he mentioned that if you paste it into notepad first and then into thinAir it works fine. So I will try to do yours and my program with that method tonight when I get back home.

That is amazing that it is that many instructions per second, love to see info like that!!

Petr, it cracks me up how you know so many ways to optimize, you are one smart kid and I love reading your enthusiastic responses and effective results in very short time, thanks!!

ErosOlmi
23-01-2007, 18:59
kryton9,

we already discovered copy/paste colored problem but we solved it under IE. Every browser adopt different techniques to made the job. IE uses RTF format in some cases and HTML in other. So not easy to solve.

Can you confirm you are using a browser different from IE?

Thanks
Eros

ErosOlmi
24-01-2007, 13:09
Post plitted.
Script from Kryton9 and Petr merit a dedicated post.

Continue here (http://community.thinbasic.com/index.php?topic=499.0)