problem with TexCoor/VertexArray/MultiTex

Vector3 pVert[] = {0.0f, 200.0f, 0.1f, 200.0f, 200.0f, 0.1f, 200.0f, 0.0f, 0.1f, 0.0f, 0.0f, 0.1f};
// ---------------------- ---------------------- ---------------------- ----------------------
Vector pTexCoor1[] = {0.0f, 0.0f, 1.0f, 0.1f, 0.1f, 0.0f, 1.0f, 0.1f, 0.1f, 0.1f, 1.0f, 0.1f, 0.0f, 0.1f, 1.0f, 0.1f};
Vector pTexCoor2[] = {0.0f, 0.0f, 1.0f, 0.1f, 0.1f, 0.0f, 1.0f, 0.1f, 0.1f, 0.1f, 1.0f, 0.1f, 0.0f, 0.1f, 1.0f, 0.1f};
u_long pColor[] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};

glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, pColor);

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(4, GL_FLOAT, 0, pTexCoor1);

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(4, GL_FLOAT, 0, pTexCoor2);

glVertexPointer(3, GL_FLOAT, 0, pVert);
glEnableClientState(GL_VERTEX_ARRAY);

//now if I diplay a GL_QUADS, I see a perfect //Quad with multitexturing.
glDrawArrays (GL_QUADS, 0, 4);

//but the problem is when I want to display //GL_TRIANGLES… the texture is strched to //the last vertex.
glDrawArrays (GL_TRIANGLES, 0, 3);

note: if I disable the multitex is mapped correctly.

Triangles and Quads are different…

Use Triangle strips, and/or Triangle fans, 3D cards are optimized for strips and fans…

That’s pretty neat that you can texture map a Quad with vertex arrays…

Now then make a cube and texture map that…

Here’s a start on one that i have been doing… it draws a cube, but two surfaces, there texture Coords are weird…

Im using my OpenGL windows toolkit, which should be online in a few days… Heres the full source code…

#pragma hdrstop
#include <GL/GLWin.h>
#ifdef BORLANDC
#include <condefs.h>
#endif /* End BROLANDC */
#include

//---------------------------------------------------------------------------
USERC(“resource.rc”);
//---------------------------------------------------------------------------
#define WinMain /* C++Builder */
//---------------------------------------------------------------------------
#define xyz 30.0
#define uv 1.0
#define u0 0.0
//---------------------------------------------------------------------------
static LPCTSTR AppName = “Hello World!”;

static GLfloat Cube = {
-xyz, xyz, -xyz,
xyz, xyz, -xyz,
xyz, -xyz, -xyz,
-xyz, -xyz, -xyz,
-xyz, xyz, xyz,
xyz, xyz, xyz,
xyz, -xyz, xyz,
-xyz, -xyz, xyz
};
//---------------------------------------------------------------------------
static GLfloat texCoords = {
uv, uv, u0, uv, u0, u0, uv, u0,
uv, u0, u0, u0, u0, uv, uv, uv,
u0, uv, uv, uv, uv, u0, u0, u0,
uv, u0, u0, u0, u0, uv, uv, uv,
uv, uv, u0, u0, u0, uv, uv, u0,
u0, uv, uv, uv, uv, u0, u0, u0
};
//---------------------------------------------------------------------------
static GLuint DrawCube = {
4, 5, 6, 7,
1, 2, 6, 5,
0, 1, 5, 4,
1, 0, 3, 2,
0, 4, 7, 3,
7, 6, 2, 3
};
//---------------------------------------------------------------------------
enum Coord{ X, Y, Z, W };
static GLfloat Rot = { 0.0, 0.0, 0.0 };
static float animspeed = 20;

GLuint Textures[ 6 ];

char* bitmaps[ 6 ] = {
“xray.bmp”,
“lightning.bmp”,
“fall.bmp”,
“coins.bmp”,
“sand.bmp”,
“eye.bmp”
};
//---------------------------------------------------------------------------
void Init( void )
{
for( int t = 0; t < 6; t++ )
Textures[ t ] = glWin_LoadBMPTexture( bitmaps[ t ] );

glEnable( GL_TEXTURE_2D );
glEnable( GL_DEPTH_TEST );
glEnable( GL_CULL_FACE );
glFrontFace( GL_CW );
glClearColor( 0.2f, 0.2f, 0.7f, 0.0f );
glInterleavedArrays( GL_V3F, 0, Cube );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, texCoords );

}
//---------------------------------------------------------------------------
#pragma argsused /* Stop the x and y not used warnings */
void Keydown( UINT key, int x, int y )
{
switch( key )
{
case VK_ESCAPE:
glWin_Close();
break;
}
}
//---------------------------------------------------------------------------
void Resize( GLsizei w, GLsizei h )
{
GLfloat aspect;

if( h == 0 ) h = 1;

aspect  = ( GLfloat )w / ( GLfloat )h;
glViewport( 0, 0, w, h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0f, aspect, 60, 300 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0f, 20.0f, -200.0f );

}
//---------------------------------------------------------------------------
void Draw( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glRotatef( Rot[ X ], 1.0f, 0.0f, 0.0f );
glRotatef( Rot[ Y ], 0.0f, 1.0f, 0.0f );
glRotatef( Rot[ Z ], 0.0f, 0.0f, 1.0f );

    for( int t = 0, offset = 0; t < 6; t++, offset += 4 )
    {
        glBindTexture( GL_TEXTURE_2D, Textures[ t ] );
        glDrawElements( GL_QUADS, 4, GL_UNSIGNED_INT, &DrawCube[ offset ] );
    }

glPopMatrix();
glFlush();

}
//---------------------------------------------------------------------------
#define CLAMP_TO( x, y ) if( x > y ){ x -= y; }
void Animate( float milliseconds, BOOL& reset )
{
if( milliseconds > animspeed )
{
Rot[ X ] += 2.0f;
Rot[ Y ] += 8.0f;
Rot[ Z ] += 1.0f;

    CLAMP_TO( Rot[ X ], 360.0f );
    CLAMP_TO( Rot[ Y ], 360.0f );
    CLAMP_TO( Rot[ Z ], 360.0f );

    reset   = TRUE; 
}

}
//---------------------------------------------------------------------------
void Destroy( void )
{
glDeleteTextures( 6, Textures );
}
//---------------------------------------------------------------------------
GLWINENTRY GLWINDCLASS RegisterGLWindowClass( LPSTR params )
{
string commands = string( params );
GLWIN_MODE mode = GLWIN_WINDOW;

if( commands.find( "-fullscreen", 0 ) != string::npos )
    mode = GLWIN_FULLSCREEN;

if( commands.find( "-fast", 0 ) != string::npos )
    animspeed = 1.0;

GLWINDCLASS glwc    = { AppName,
                        mode,
                        640, 480,
                        0, 0,
                        Init,
                        Keydown,
                        NULL,
                        NULL,
                        NULL,
                        Resize,
                        Draw,
                        Animate,
                        Destroy };

return glwc;

}
//---------------------------------------------------------------------------

I am bamboozled with the Vertex Array texture coords… No matter what i do, they still look weird…

Maybe it’s because your texture coordinates are not ordered correctly. Look at this re-replacement of your uv and u0 defines:
(BTW, the chosen names and small caps are anything but readable. You would have found the error yourself without them.)

static GLfloat texCoords[] =
{
1, 1, 0, 1, 0, 0, 1, 0,
1, 0, 0, 0, 0, 1, 1, 1,
0, 1, 1, 1, 1, 0, 0, 0,
1, 0, 0, 0, 0, 1, 1, 1,
1, 1, 0, 0, 0, 1, 1, 0, // 1,1 to 0,0 goes diagonally through the quad!!
0, 1, 1, 1, 1, 0, 0, 0
};

I wouldn’t recommend glInterleavedArrays if you have no interleaved data. Use glVertexPointer for your case.
And even if the data is interleaved, the stride in all pointers can be used to represent that with the standard vertex array functions.

Hope that helps.

My data was originally interleaved…

Here’s what that looked like…

#define xyz 30.0
#define uv 1.0
#define u0 0.0

static GLfloat Cube[] = {
uv, uv, -xyz, xyz, -xyz,
u0, uv, xyz, xyz, -xyz,
u0, u0, xyz, -xyz, -xyz,
uv, u0, -xyz, -xyz, -xyz,
u0, uv, -xyz, xyz, xyz,
uv, uv, xyz, xyz, xyz,
uv, u0, xyz, -xyz, xyz,
u0, u0, -xyz, -xyz, xyz
};

Everything looked fine but the top, and bottom texture was screwed up… I think Interleaving with texture mapping kinda sucks… Becuase every one is having trouble with it…

[This message has been edited by warlordQ (edited 07-27-2000).]

Ah, so you were reusing the texture coordinates and had to care for the proper assignments for each face.
With each vertex sharing three faces it’s not possible to avoid the diagonal crossover of the texture coordinates.
You have to generate 6*4 vertices to assign the texture coordinates in proper and simple order in an interleaved array.

So is it working now?

[This message has been edited by Relic (edited 07-27-2000).]

For my problem, I did somes tests. It’s working if I put only 2 component for texcoor on the texture unit 1 and 4 on the unit 0. But not working if I put 4 component on each unit. It’s so weird… does the 2 texture unit can make perspective correct?