glBegin questions

BlitzMax Forums/BlitzMax OpenGL Programming/glBegin questions

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Use glClientActiveTexture to set the active (client) texture unit and then set the pointer for that unit.

As for interleaved arrays, that's really just a waste of time. Just use the appropriate gl*Pointer functions. At least that way you decide how to structure your data instead of following the specific formats glInterleavedArrays provides.

E.g.
Local tc:Byte Ptr ' the data -- in the case of a vbo, this would remain Null
' for the sake of example, the data is arranged as such: uv0, uv1, uv0, uv1
' where uv are the respective components and the number is the channel
' you'll probably want to organize your data so that it's all lumped together contiguously
' which would basically look like u0v0, u0v0, u0v0, u0v0, u1v1, u1v1, u1v1, u1v1 where each channel has
' a stride of 0 (is tightly packed) and it is only necessary to point to the appropriate offset into the data

glClientActiveTexture( GL_TEXTURE0 ) ' set the unit
glEnableClientState( GL_TEXTURE_COORD_ARRAY ) ' enable the texcoord pointer for this unit
glTexCoordPointer( 2, GL_FLOAT, 8, tc ) ' set the pointer
' stride is set to 8 so it skips over channel 1 and uses only channel 0

' repeat for the next unit
glClientActiveTexture( GL_TEXTURE1 )
glEnableClientState( GL_TEXTURE_COORD_ARRAY )
glTexCoordPointer( 2, GL_FLOAT, 8, tc+8 ) ' set it to use the second set of texture coordinates


This is a snippet from my engine's material code, basically shows how I handle the data.

If _maps.Count( ) = 0 And _class <> TEX_TARGET Then
    Return 0
EndIf
' set unit
ActiveTexture( unit )
ClientActiveTexture( unit )

' attempt to get a texture
Local tex:ITexture
Try
    tex = ITexture(_maps.ValueAtIndex( Floor((time * animspeed) Mod _maps.Count( )) ))
Catch o:Object
    tex = Null
End Try
 
' offset into the data that the texture coordinates start at
Local off%=0
' you know, this would be a lot easier if i had a ternary operator
Select textype
    Case GL_FLOAT, GL_INT
        off = texoff+(4*texSize)*_tcSet
    Case GL_DOUBLE
        off = texoff+(8*texSize)*_tcSet
    Case GL_SHORT
        off = texoff+(2*texSize)*_tcSet
    Default
        If Not (_class&9) Then
            Return 0
        EndIf
End Select

Select _class
    Case TEX_NORMAL
        If Not tex Then Return 0
        tex.Bind( unit ) ' set unit & bind texture
        
        ' disable coordinate generation
        glDisable( GL_TEXTURE_GEN_S )
        glDisable( GL_TEXTURE_GEN_T )
        
        EnableClientTextureArray( unit )
        glTexCoordPointer( texsize, textype, stride, texp+off )
        
        MatrixMode( GL_TEXTURE )
        glLoadIdentity( )
        For Local i:Int = 0 To _tcmods.Length-1
            If _tcmods[i] Then _tcmods[i].Do( time, tex.ow, tex.oh )
        Next