PDA

View Full Version : TBGL_LoadTexture and loading



Michael Clease
01-06-2007, 21:23
Can TBGL_LoadTexture only be called after my TBGL_CreateWindowEx.

If i put it before create window I dont get any textures.

kryton9
01-06-2007, 23:48
Abraxas, glad you are tinkering with tbgl too. I don't know if you checked out the example files in the samples directory.

C:\thinBasic\SampleScripts\TbGl

Also in the tbgl help, there is a nice tbgl skeleton file to use that you can flesh out.


'
' TBGL Script Skeleton
'
Uses "TBGL"

Dim hWnd As Dword

hWnd = TBGL_CreateWindowEx("My Demo - press ESC to quit", 640, 480, 32, 0)
TBGL_ShowWindow

TBGL_GetAsyncKeyState(-1) ' Resets status of all keys

While TBGL_IsWindow(hWnd)

tbgl_ClearFrame

tbgl_DrawFrame

If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While

Wend

TBGL_DestroyWindow


Here is an example with textures from the sample files:

'
' TBGL 0.1.6 Demoscript : Textured and blended 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, with some advanced blending", %MB_ICONINFORMATION, "TBGL demo"

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

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

TBGL_UseTexture 1 ' I want to use textures
TBGL_BindTexture 1 ' I want to use texture #1

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_Rotate GetTickCount/10,1,1,1 ' Rotates around all axis ( 1 enables axis, 0 disables )

TBGL_BeginPoly %GL_QUADS ' Starts polygon definition based on 4 vertexes
TBGL_TexCoord2d 0,0 ' Sets texture coordinate for this vertex
TBGL_Vertex -1,-1,0 ' Adds vertex

TBGL_TexCoord2d 1,0
TBGL_Vertex 1,-1,0

TBGL_TexCoord2d 1,1
TBGL_Vertex 1, 1,0

TBGL_TexCoord2d 0,1
TBGL_Vertex -1, 1,0

TBGL_EndPoly ' Ends polygon definition

TBGL_UseBlend 1 ' Use blending

TBGL_Translate 0,0,1 ' This polygon will be moved by 1 in Z axis

TBGL_BeginPoly %GL_QUADS ' Starts polygon definition based on 4polys
TBGL_Color 255,0,0 ' Sets RGB color
TBGL_TexCoord2d 0,0
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_UseBlend 0 ' Don't use blending

TBGL_DrawFrame ' Swaps the buffers - displays rendered image

if GetAsyncKeyState(%VK_ESCAPE) THEN exit while

wend

TBGL_DestroyWindow ' Closes OpenGL window

MSGBOX 0, "Show is over", %MB_ICONINFORMATION or %MB_TOPMOST, "TBGL demo"

You can only at the moment use bmp and tga files and they need to be in the power of 2's: 32,64,128,256,512,1024 etc.

Michael Clease
02-06-2007, 00:03
Thanks for the info. but can it only be called after creating the window because it makes my program pause while it loads 10 textures.

kryton9
02-06-2007, 08:08
I am not sure on the order, Petr I am sure will have the answer for you when he logs on.

Michael Hartlef
02-06-2007, 09:55
Thanks for the info. but can it only be called after creating the window because it makes my program pause while it loads 10 textures.


You gave the answer youself, as it doesn't work if you try to load textures before you create the window.
How about a little loading text on the screen while you load the textures. You could even animate this (change of color, or use graphics) between each texture you load, so the user doesn't look at a blank screen and think that your game might have crashed.

Michael

Michael Clease
02-06-2007, 10:16
I dont see why you would need the handle for an gl window to load a file, decode the BMP structure and assign it to a texture but I must be missing something.

ErosOlmi
02-06-2007, 10:24
Abraxas,

it should be by design, I mean Petr should have decided to do that way.
I'm with you on this but you have to wait Petr to reply. I'm pretty sure he will have a solution or a reason why.

Eros

Michael Clease
02-06-2007, 10:45
Its not a problem i just thought i was doing something wrong.

ErosOlmi
02-06-2007, 10:52
I have a Petr example loading textures and showing their names on screen just not letting user think something is going wrong with a black screen.
As Mike suggested, some info on screen can even be nice to see.

Maybe you already have this example. If yes, sorry.

Ciao
Eros

Petr Schreiber
02-06-2007, 19:55
Hi Abraxas,



Can TBGL_LoadTexture only be called after my TBGL_CreateWindowEx.

If i put it before create window I dont get any textures.

This is documented behaviour in help file - window creation must go first.

I am sorry you find this uncomfortable, but it was designed this way.

To be able to load texture, OpenGL window must be created already.
To create rendering context I need to know handle of display device, which can't be obtained for no window. Then setup pixelformat and pass device context to OpenGL driver.

Theoretically it would be possible to load raw data and as soon as window exists bind it to GL, but this seems quite weird to me. But I am weird too :D, if it would be better for you I could write something like tbgl_CreateTexture, which would have as a parameter not file name, but already preprocessed RGBA buffer?

In case loading of textures before window creation would be possible, what would user see ? Hourglass cursor maybe ? And I can't guarantee passing data to GL is instant too, some time can take creating of mipmaps and so on.
It is easier to render any loading screen ( progressbar and/or game hints ) while loading program resources, this way user/player can see what happens.

I will try to optimize texture loading procedures to take less time :-[, what size did you used ?


Thanks,
Petr

P.S. I'm sorry to reply so late, but I was out of house all the day

Michael Clease
02-06-2007, 23:54
thanks for the reply but i have rewritten some code to give it a load screen.

the filesizes were quite small but there were 10+ of them.

thank you for your help.

kryton9
03-06-2007, 06:05
Theoretically it would be possible to load raw data and as soon as window exists bind it to GL, but this seems quite weird to me. But I am weird too :D, if it would be better for you I could write something like tbgl_CreateTexture, which would have as a parameter not file name, but already preprocessed RGBA buffer?

Petr from my studies in c++ and looking into procedural and dynamic textures, this is the key to have that sort of command.

Here is an awesome c++ code I found that works wonderfully. http://www.sorgonet.com/linux/noise_textures/
As you can see no textures, the perlin noise is created dynamically. I also found another great animated texture dynamically, but the guy used a graphic file that was a cgi format. When I removed that small file, it would not render and say a file is missing, but when I put it in, it would work. What is funny is I don't see anywhere in the code where he loads that cgi file?
http://www.delphi3d.net/download/rendertex.zip
Still this is really cool. You can change the texture resolution from all the way down to 1x1 to, well at 1024x1024 my notebook with ati card started to not draw fast enough.

Ken Perlin, I guess the guy who discovered Perlin Noise routine, has a neat site with lots of cool stuff in Java he has written. Very inspirational.
http://mrl.nyu.edu/~perlin/

Petr Schreiber
03-06-2007, 12:05
Hi abraxas,

is that for your platform game ?

kryton, thanks for the links, I will go through them this evening!


Thanks,
Petr

Michael Clease
03-06-2007, 12:29
yes, while i am writing it i will stick to seperate textures.

In time i will use a single texture and use texcoord to slice it up.