Click to See Complete Forum and Search --> : Alpha blending? masking wrong...


Hiyo
March 27th, 2005, 01:45 PM
Hi,

I created a chess board use texture mapping to load bmp, but when i to put the piece on the board, if won't appear properly(just a square come out), and even affect whole board's color, what's wrong with it?the masking part coding shows below:

..........
void build_piece(void)
{
piece = glGenLists(1);
glBindTexture(GL_TEXTURE_2D, textures[9]);
glNewList(piece, GL_COMPILE);
glBegin(GL_QUADS);
/* Bottom Left Of The Texture and Quad */
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, 0.0f, 1.0f);
/* Bottom Right Of The Texture and Quad */
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.0f, 0.0f, 1.0f);
/* Top Right Of The Texture and Quad */
glVertex3f( 1.0f, 0.0f,-1.0f);
/* Top Left Of The Texture and Quad */
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 0.0f, -1.0f);
glEnd();
glEndList();
printf("piece = %d\n", piece);
}
.........
void draw_pieces(void)
{
GLfloat white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat black[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
GLfloat *color;
int x,z;

//glPushAttrib(GL_LIGHTING | GL_TEXTURE_BIT);
//glPushAttrib(GL_TEXTURE_BIT);
glEnable(GL_TEXTURE_2D);

for (x = 0; x < 11; x++)
for (z = 0; z < 11; z++) {
if (board[x][z] != -1) {
color = board[x][z] == 0 ? white : black;

glColor4fv(color);

glPushMatrix();
glTranslatef(z * 2.0 - 10, 0.0, 10 - x * 2.0);
glCallList(piece);
glPopMatrix();
}
}
//glPopAttrib();
}
.............
void display(void)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
translate_view();
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glCallList(board_list);
//glEnable(GL_BLEND);
//glDisable(GL_DEPTH_TEST);
draw_pieces();
glPopMatrix();
glutSwapBuffers();
}
.......