need help with glInterleavedArrays

BlitzMax Forums/BlitzMax OpenGL Programming/need help with glInterleavedArrays

I am trying to figure out how to use glInterLeaveArrays with out any luck. I am using it to draw a texture box. some how it is not working correctly. I can do it fine with independent GL_QUADS for each side but I can't get it to work with glInterleaveArrays. this is the code so far:

Strict
Type Vertex
    Field tu#, tv#;
    Field x#, y#, z#;
End Type

Global ScreenWidth:Int=800
Global ScreenHeight:Int=600
Global Checkimage:Byte[256,256,4]
Global Texname:Int
Global g_fDistance# = -4.5;
Global g_cubeVertices:vertex[24]
Global light_position#[] = [1.0, 1.0, 0.0, 0.0] 

RestoreData verts
For Local i% = 0 To 23
	g_cubeVertices[i] = New Vertex
	ReadData g_cubeVertices[i].tu 
	ReadData g_cubevertices[i].tv
	ReadData g_cubevertices[i].x
	ReadData g_cubevertices[i].y
	ReadData g_cubevertices[i].z
Next  

#verts
		' Front Face
DefData 0.0, 0.0, -1.0, -1.0, 1.0       ' Bottom Left Of The Texture And Quad
DefData 1.0, 0.0,  1.0, -1.0, 1.0       ' Bottom Right Of The Texture And Quad
DefData 1.0, 1.0,  1.0,  1.0, 1.0       ' Top Right Of The Texture And Quad
DefData 0.0, 1.0, -1.0,  1.0, 1.0       ' Top Left Of The Texture And Quad
		' Back Face
DefData 1.0, 0.0, -1.0, -1.0, -1.0      ' Bottom Right Of The Texture And Quad
DefData 1.0, 1.0, -1.0,  1.0, -1.0      ' Top Right Of The Texture And Quad
DefData 0.0, 1.0,  1.0,  1.0, -1.0      ' Top Left Of The Texture And Quad
DefData 0.0, 0.0,  1.0, -1.0, -1.0      ' Bottom Left Of The Texture And Quad
		' Top Face
DefData 0.0, 1.0, -1.0,  1.0, -1.0      ' Top Left Of The Texture And Quad
DefData 0.0, 0.0, -1.0,  1.0,  1.0      ' Bottom Left Of The Texture And Quad
DefData 1.0, 0.0,  1.0,  1.0,  1.0      ' Bottom Right Of The Texture And Quad
DefData 1.0, 1.0,  1.0,  1.0, -1.0      ' Top Right Of The Texture And Quad
		' Bottom Face
DefData 1.0, 1.0, -1.0, -1.0, -1.0      ' Top Right Of The Texture And Quad
DefData 0.0, 1.0,  1.0, -1.0, -1.0      ' Top Left Of The Texture And Quad
DefData 0.0, 0.0,  1.0, -1.0,  1.0      ' Bottom Left Of The Texture And Quad
DefData 1.0, 0.0, -1.0, -1.0,  1.0      ' Bottom Right Of The Texture And Quad
		' Right face
DefData 1.0, 0.0,  1.0, -1.0, -1.0      ' Bottom Right Of The Texture And Quad
DefData 1.0, 1.0,  1.0,  1.0, -1.0      ' Top Right Of The Texture And Quad
DefData 0.0, 1.0,  1.0,  1.0,  1.0      ' Top Left Of The Texture And Quad
DefData 0.0, 0.0,  1.0, -1.0,  1.0      ' Bottom Left Of The Texture And Quad
		' Left Face
DefData 0.0, 0.0, -1.0, -1.0, -1.0      ' Bottom Left Of The Texture And Quad
DefData 1.0, 0.0, -1.0, -1.0,  1.0      ' Bottom Right Of The Texture And Quad
DefData 1.0, 1.0, -1.0,  1.0,  1.0      ' Top Right Of The Texture And Quad
DefData 0.0, 1.0, -1.0,  1.0, -1.0      ' Top Left Of The Texture And Quad

GLGraphics ScreenWidth,ScreenHeight
LoadGlTextures()
glClearColor( 0.0, 0.0, 0.0, 1.0 )

glEnable( GL_TEXTURE_2D );
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0,Float(ScreenWidth)/Float(ScreenHeight),0.1,100.0)
glMatrixMode(GL_MODELVIEW)
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_TEXTURE_2D)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
glBindTexture(GL_TEXTURE_2D,Texname)
glLoadIdentity()
glTranslatef (0.0,0.0,-8.0)
glBindTexture( GL_TEXTURE_2D, Texname );
glInterleavedArrays( GL_T2F_V3F, 0, g_cubeVertices );
glDrawArrays( GL_QUADS, 0,24 );
glDisable(GL_TEXTURE_2D)
Flip()
WaitKey()




Function LoadGlTextures()
	Local PointeurImg:Byte Ptr
	Local TexWidth
	Local TexHeight
	Local tex01:TPixmap=LoadPixmap("data\radiation_box.png")
	TexWidth=tex01.Width
	TexHeight=tex01.Height
	PointeurImg=PixmapPixelPtr(tex01,0,0)
	Local pp%=0
	For Local y%=TexHeight-1 To 0 Step -1
		For Local x%=0 To TexWidth-1
			If x> 31 And x< (TexWidth-31) And y > 31 And y<(TexHeight-31)
			
				Checkimage[y,x,0]=PointeurImg[pp]
				Checkimage[y,x,1]=PointeurImg[pp+1]
				Checkimage[y,x,2]=PointeurImg[pp+2]
				Checkimage[y,x,3]=100 ' alpha
			Else
				Checkimage[y,x,0]=PointeurImg[pp]
				Checkimage[y,x,1]=PointeurImg[pp+1]
				Checkimage[y,x,2]=PointeurImg[pp+2]
				Checkimage[y,x,3]=255 ' alpha
			EndIf	
			pp=pp+3
		Next
	Next
	tex01=Null
	glPixelStorei(GL_UNPACK_ALIGNMENT,1)
	glGenTextures(1, Varptr Texname)
	glBindTexture(GL_TEXTURE_2D, Texname)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, Checkimage)
End Function



well, I finally figure it out. I guess the way types in Blitzmax does not work the same way as in c and must be saved in a straight single dimension array of type floats.
the above sample is a stripped down sample of what i was trying to figure out. I was trying to convert a c tutoral file from c to basic. i finally sort of did it except for the text part which I am still trying to figure out. here is what I got so far it uses alpha channel to see into the cube but not through. Use your own 255x255 png texture.
'//-----------------------------------------------------------------------------
'//           Name: ogl_alpha_blending_texture.cpp
'//         Author: Kevin Harris
'//  Last Modified: 03/25/05
'//    Description: This sample demonstrates how To perform alpha blending using
'//                 the alpha channel of a standard .tga texture. For proper
'//                 alpha blending, the sample uses a cull-mode sorting trick
'//                 To ensure the sides of the textured cube get rendered in
'//                 back-To-front order.
'//
'//   Control Keys: b - Toggle blending
'//                 s - Toggle usage of cull-mode sorting trick
'//                 Up Arrow - Move the test cube closer
'//                 Down Arrow - Move the test cube away
'//-----------------------------------------------------------------------------
SuperStrict
Const stric% = 1
Const WIN32_LEAN_AND_MEAN% = 1

Type Vertex
    Field tu#, tv#;
    Field x#, y#, z#;
End Type
Type point
	Field x%,y%
End Type

Global g_bBlending% = True;
Global g_bSortUsingCullModeTrick% = True;
Global ptLastMousePosit:point = New point
Global ptCurrentMousePosit:point = New point
Global bMousing%;
Global oldx%,oldy%
Global g_fDistance# = -4.5;
Global g_fSpinX#    = 0.0;
Global g_fSpinY#    = 0.0;
Global Checkimage:Byte[256,256,4]
Global Texname:Int
Global g_textureID% = -1
Global g_cubeVertices:Float[] = [..
..		' Front Face
 0.0, 0.0, -1.0, -1.0, 1.0,..       ' Bottom Left Of The Texture And Quad
 1.0, 0.0,  1.0, -1.0, 1.0,..       ' Bottom Right Of The Texture And Quad
 1.0, 1.0,  1.0,  1.0, 1.0,..       ' Top Right Of The Texture And Quad
 0.0, 1.0, -1.0,  1.0, 1.0,..       ' Top Left Of The Texture And Quad
..		' Back Face
 1.0, 0.0, -1.0, -1.0, -1.0,..      ' Bottom Right Of The Texture And Quad
 1.0, 1.0, -1.0,  1.0, -1.0,..      ' Top Right Of The Texture And Quad
 0.0, 1.0,  1.0,  1.0, -1.0,..      ' Top Left Of The Texture And Quad
 0.0, 0.0,  1.0, -1.0, -1.0,..      ' Bottom Left Of The Texture And Quad
..		' Top Face
 0.0, 1.0, -1.0,  1.0, -1.0,..      ' Top Left Of The Texture And Quad
 0.0, 0.0, -1.0,  1.0,  1.0,..      ' Bottom Left Of The Texture And Quad
 1.0, 0.0,  1.0,  1.0,  1.0,..      ' Bottom Right Of The Texture And Quad
 1.0, 1.0,  1.0,  1.0, -1.0,..      ' Top Right Of The Texture And Quad
..		' Bottom Face
 1.0, 1.0, -1.0, -1.0, -1.0,..      ' Top Right Of The Texture And Quad
 0.0, 1.0,  1.0, -1.0, -1.0,..      ' Top Left Of The Texture And Quad
 0.0, 0.0,  1.0, -1.0,  1.0,..      ' Bottom Left Of The Texture And Quad
 1.0, 0.0, -1.0, -1.0,  1.0,..      ' Bottom Right Of The Texture And Quad
..		' Right face
 1.0, 0.0,  1.0, -1.0, -1.0,..      ' Bottom Right Of The Texture And Quad
 1.0, 1.0,  1.0,  1.0, -1.0,..      ' Top Right Of The Texture And Quad
 0.0, 1.0,  1.0,  1.0,  1.0,..      ' Top Left Of The Texture And Quad
 0.0, 0.0,  1.0, -1.0,  1.0,..      ' Bottom Left Of The Texture And Quad
..		' Left Face
 0.0, 0.0, -1.0, -1.0, -1.0,..      ' Bottom Left Of The Texture And Quad
 1.0, 0.0, -1.0, -1.0,  1.0,..      ' Bottom Right Of The Texture And Quad
 1.0, 1.0, -1.0,  1.0,  1.0,..      ' Top Right Of The Texture And Quad
 0.0, 1.0, -1.0,  1.0, -1.0]      ' Top Left Of The Texture And Quad

'//-----------------------------------------------------------------------------
'// PROTOTYPES
'//-----------------------------------------------------------------------------
'Int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, 
'				   LPSTR lpCmdLine, Int nCmdShow);
'LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
'void loadTexture(void);
'void init(void);
'void render(void);
'void shutDown(void);

'//-----------------------------------------------------------------------------
'// Name: WinMain()
'// Desc: The application's entry point
'//-----------------------------------------------------------------------------

	GLGraphics 800,600
	oldx = MouseX()
	oldy = MouseY()
	
	init();
	
	Repeat
		
		'GLDrawText("B - blending ",1,1)
		'GLDrawText("s - cull sorting",10,30)
		callback();
		render();
		Flip()
	Forever 'Until KeyDown(KEY_ESCAPE)

	End

'//-----------------------------------------------------------------------------
'// Name: WindowProc()
'// Desc: The window's message handler
'//-----------------------------------------------------------------------------
Function CALLBACK%()
		
    Select True
		Case KeyDown(KEY_B) 
            g_bBlending = Not g_bBlending;
        Case KeyDown(KEY_S)
            g_bSortUsingCullModeTrick = Not g_bSortUsingCullModeTrick;
        Case KeyDown(KEY_ESCAPE)
			 End
        Case KeyDown(KEY_UP) '// Up Arrow Key
             g_fDistance :- 0.1;
        Case KeyDown(KEY_DOWN)' // Down Arrow Key
            g_fDistance :+ 0.1;
	End Select
	Select PollEvent()
		
        Case EVENT_MOUSEDOWN 
			ptLastMousePosit.x = ptCurrentMousePosit.x = MouseX()
            ptLastMousePosit.y = ptCurrentMousePosit.y = MouseY()
			bMousing = True;
		Case EVENT_MOUSEMOVE
			
			ptCurrentMousePosit.x = MouseX()
			ptCurrentMousePosit.y = MouseY()

			If( bMousing )
			
				g_fSpinX :- (ptCurrentMousePosit.x - ptLastMousePosit.x);
				g_fSpinY :- (ptCurrentMousePosit.y - ptLastMousePosit.y);
			EndIf
			
			ptLastMousePosit.x = ptCurrentMousePosit.x;
            ptLastMousePosit.y = ptCurrentMousePosit.y;
	End Select
	If Not MouseDown(1) bMousing = False;

End Function 

'//-----------------------------------------------------------------------------
'// Name: loadTexture()
'// Desc: 
'//-----------------------------------------------------------------------------
Function loadTexture( )	
	Local PointeurImg:Byte Ptr
	Local TexWidth%
	Local TexHeight%
	Local tex01:TPixmap=LoadPixmap("data\radiation_box.png")
	TexWidth=tex01.Width
	TexHeight=tex01.Height
	PointeurImg=PixmapPixelPtr(tex01,0,0)
	Local pp%=0
	For Local y%=TexHeight-1 To 0 Step -1
		For Local x%=0 To TexWidth-1
			If x> 28 And x< (TexWidth-29) And y > 28 And y<(TexHeight-29)
				Checkimage[y,x,0]=PointeurImg[pp]
				Checkimage[y,x,1]=PointeurImg[pp+1]
				Checkimage[y,x,2]=PointeurImg[pp+2]
				Checkimage[y,x,3]=100
			Else
				Checkimage[y,x,0]=PointeurImg[pp]
				Checkimage[y,x,1]=PointeurImg[pp+1]
				Checkimage[y,x,2]=PointeurImg[pp+2]
				Checkimage[y,x,3]=200
			EndIf	
			pp=pp+3
		Next
	Next
	tex01=Null
	glPixelStorei(GL_UNPACK_ALIGNMENT,1)
	glGenTextures(1, Varptr Texname)
	glBindTexture(GL_TEXTURE_2D, Texname)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, Checkimage)
End Function


'//-----------------------------------------------------------------------------
'// Name: init()
'// Desc: 
'//-----------------------------------------------------------------------------
Function init()
	loadTexture();
	glClearColor( 0.35, 0.53, 0.7, 1.0 );
	glEnable( GL_TEXTURE_2D );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 45.0, 640.0 / 480.0, 0.1, 100.0);
End Function


'//-----------------------------------------------------------------------------
'// Name: render()
'// Desc: 
'//-----------------------------------------------------------------------------
Function render( )

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    glTranslatef( 0.0, 0.0, g_fDistance );
    glRotatef( -g_fSpinY, 1.0, 0.0, 0.0 );
    glRotatef( -g_fSpinX, 0.0, 1.0, 0.0 );
	
Rem
    //
    // Transparency sorting For our cube...
    //
    // If you have a single transparent Object, Or multiple transparent objects 
    // which do Not overlap in screen space (i.e., each screen pixel is touched 
    // by at most one of the transparent objects), there's a sorting short-cut 
    // which can be used under certain conditions.
    //
    // If your transparent objects are closed, convex, And viewed from the 
    // outside, culling may be used To draw the back-facing polygons prior To 
    // the front-facing polygons. This will accomplish the same thing
    // as sorting your objects Or polygons into back-To-front order.
    // Fortunately For us, our cube is a perfect candidate For this sorting 
    // trick.
    // 
    // On the other hand, If we can't use the cull-mode sorting trick, we would 
    // need To sort our objects manually, which would require us To transform 
    // the geometry into eye-space so we could compare their Final position 
    // along the z axis. Only Then, could we could render them in the proper 
    // back-To-front order For alpha blending.
    //
    // Also, If transparent objects intersect in any way, the individual 
    // triangles of the objects touching will have To be sorted And drawn 
    // individually from back-To-front. And is some rare cases, triangles that 
    // intersect each other may have To be broken into smaller triangles so they
    // no longer intersect Or blending artifacts will persist regardless of our
    // sorting efforts.
    //
    // It’s plain To see, transparency sorting can become a big, hairy mess real quick.
    //
    // <a href="http://www.opengl.org/resources/tutorials/sig99/advanced99/notes/node204.html" target="_blank">http://www.opengl.org/resources/tutorials/sig99/advanced99/notes/node204.html</a>
    //
EndRem
	If( g_bBlending = True )
	
'        //
'        // Use the texture's alpha channel to blend it with whatever’s already 
'        // in the frame-buffer.
'        //

		glDisable( GL_DEPTH_TEST );

        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

        glBindTexture( GL_TEXTURE_2D, texname);

       If( g_bSortUsingCullModeTrick = True )
				    
'            //
'            // Use the cull-mode sorting trick For convex non-overlapping 
'            // geometry.
'            //

            glEnable( GL_CULL_FACE );

'            //
'            // Render the cube but only render the back-facing polygons.
'            //

            glCullFace( GL_FRONT );
			
            glInterleavedArrays( GL_T2F_V3F, 0, g_cubeVertices );
			glDrawArrays( GL_QUADS, 0, 24 );

'            //
'            // Render the cube again, but this time we only render the 
'            // front-facing polygons.
'            //

            glCullFace( GL_BACK );

           glInterleavedArrays( GL_T2F_V3F, 0, g_cubeVertices );
           glDrawArrays( GL_QUADS, 0, 24 );

           glDisable( GL_CULL_FACE );
       
        Else
'        
'            //
'            // Do no sorting And hope For the best. From certain viewing 
'            // positions the cube's sides will appear sorted correctly, but this
'            // is typically rare And the cube will Not look Right most of the 
'            // time.
'            //

            glInterleavedArrays( GL_T2F_V3F, 0, g_cubeVertices );
            glDrawArrays( GL_QUADS, 0, 24 );
        EndIf'
'
	Else
'	
'        //
'        // Render the cube, but do no blending...
'        //

		glDisable( GL_BLEND );
		glEnable( GL_DEPTH_TEST );

        glBindTexture( GL_TEXTURE_2D, Texname);
        glInterleavedArrays( GL_T2F_V3F, 0, g_cubeVertices );
        glDrawArrays( GL_QUADS, 0, 24 );
	EndIf

End Function


thanks everybod for your help :).