glBegin questions

BlitzMax Forums/BlitzMax OpenGL Programming/glBegin questions

So i'm writing my mesh system and some of the file formats keep track of rather a face is just a triangle or quad. Understanding that even the GL_Quad uses triangles in the background. I'm thinking that you will only have 4 vertex calls compared to 6 for the same effect. Though it could be faster, but i hear glBegin is costly. SO i'm thinking 2 phrase, GL_Triangle and a GL_Quad with only 2 begins per mesh might be worth the extra work?

Or you could just use vertex and index arrays/buffer objects and make zero calls to glBegin/glEnd. So no, none of it is worth the extra work since vertex and index arrays/buffer objects are easy to use and faster. Use VBOs for large amounts of data that matter if you were going to send it to the GPU from software, otherwise use vertex arrays as the time required is negligable.

i'm looking at glInterleavedArrays and glTextureCoordPointer. How do you get mutliply UVs to work in these systems? glMultiTexCoord2fARB needs to be called doesn't it?

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


Sweet, i have another one though. Is there a texture matrix per texture slot?

Thanks for your help :)

Yes.