[Gambas-user] gb3: gb.opengl - dynamically dimensioning a public 2D array of texture IDs

Kevin Fishburne kevinfishburne at ...1887...
Thu Aug 4 04:14:33 CEST 2011


Previously I needed to create a 2D array of texture IDs. I couldn't get 
it to work worth a damn, so what I did instead was to create a texture 
Structure, then create an array of those structures. It works extremely 
well and allows me to store more information about each texture:

' Texture definition structure.
Public Struct Texture
   Loaded As Boolean
   FileName As String
   ID As Integer[]
   SubID As Short
   Width As Short
   Height As Short
   LastUsed As Single
End Struct

' Texture indices.
Public tiObject[32768] As Struct Texture

' Assign some texture IDs.
tiObject[1000].ID = Gl.GenTextures(16)

I'm now trying to do the same thing but to create the array of 
structures dynamically in a procedure rather than at the beginning of a 
module. Doing this for a normal array works fine (thank you Benoît), but 
when I use the same syntax with a Structure it fails with various errors:

Public tTileGrid[] As Struct Texture  ' = fail.
Public tTileGrid As Struct Texture[]  ' = fail.

If creating an array of structures that can be dimensioned in a later 
procedure is impossible, that is fine, but I'd like to know if there's a 
way to create a 2D array of OpenGL texture indices. Both methods would 
be terribly useful, actually. An OpenGL texture index is an array of 
Integers of undefined dimensions and is assigned values of 1...x when 
you call the Gl.GenTextures(x) function. For example, if I do this:

Public TextureIDs[] As Integer
TextureIDs = Gl.GenTextures(4)

TextureIDs[0 - 3] will be 1, 2, 3 and 4. I tried assigning these numbers 
manually, but Gl.GenTextures() does something hidden (probably creates 
an internal index to accept the textures into VRAM) so it is a required 
call to be able to load the textures.

I'm guessing I need a 2D array of 1D Integer arrays, so the 1D array 
will accept the results of Gl.GenTextures() and the 2D array will 
reference their "coordinates" in the array. If that is so, then what 
would the initial public declaration and subsequent procedural 
dimensioning look like? I think I have some kind of mild mental problem, 
as these things really make my head spin.

FYI I'm doing a near total rewrite of the rendering pipeline in my game 
in order for it to use OpenGL as much as possible. Everything's been 
converted successfully except for landscape rendering, which is the most 
complex part. I expect my game to be broken for the next several days 
while I sort everything out. :/

-- 
Kevin Fishburne
Eight Virtues
www:http://sales.eightvirtues.com
e-mail:sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list