Skip to main content
GameDev.net gamedev.net
🔒 Locked

Masking Problem

Started by hiyo Mar 26, 2005 at 11:51 AM 11 replies 2.6k views
Original Post
hiyo
hiyo
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, and even affect whole board's color, what's wrong with it?some part of code 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();
}
.......

is there anything wrong? my board is yellow color, and the piece is bulit in a black square,and a white color stone in the middle. Please Help! Thank you.
hiyo
hiyo
just saw the topic 'Alpha blending properly' i m thinking i maight have the same problem, i can't mix the color with the board...is that so?pls help...
hiyo
hiyo
is this problem really no hopes to solve?y seems nobody would like to help me....
ff8
ff8
post some shots
hiyo
hiyo
how to post screenshot here, i can't see the way in Forum FAQ
ff8
ff8
just put the pictures in free server like 8m.com then use img tag like
[img src="picture_link"]
replace [] with <>
aKeye
aKeye
You wanner blend your piece with your board, right?
I'd like to give you two suggestions:
Fisrt one, use GL_BLEND. I suggest you use a texture image with alpha channel info. A TGA format image supports alpha channel, while ms BMP not! A typical TGA image pixel should have 0 alpha value if it will be transparent!
you can eidt your texture image in Photoshop by setting alpha value, and export the image as a 32bit TGA format(24bit for rgb, 8bit for alpha).
You should load TGA file then. Read TGA specifications here: http://www.wotsit.org/
and many TGA loaders can be found on internet!
and then, call OpenGL blend function:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
and glEnable(GL_BLEND);
Second one, use alpha test. As your piece image is of black background, you can just use BMP format by setting alpha value for each pixel when you load it(dont use auxDIBImageLoad, read file by yourself). I mean you can set alpha value to 0 for the pixels with black color while to 1 for white color pixels.
and then use alpha test to toss 0 alpha! like this:
glAlphaFunc (GL_NOTEQUAL, 0);
glEnable (GL_ALPHA_TEST);
hiyo
hiyo
ChessBoard



After click, the stone should be black and white,n sometimes the whole board even effected,turns to green color, what's wrong with my masking?(pls refer to my code and give a help thanks)



Stone

hiyo
hiyo
Quote:
Original post by aKeye
Second one, use alpha test. As your piece image is of black background, you can just use BMP format by setting alpha value for each pixel when you load it(dont use auxDIBImageLoad, read file by yourself). I mean you can set alpha value to 0 for the pixels with black color while to 1 for white color pixels.
and then use alpha test to toss 0 alpha! like this:
glAlphaFunc (GL_NOTEQUAL, 0);
glEnable (GL_ALPHA_TEST);


hey, i think this is what i want, i m using bmp file, but maybe my alpha setting got problem, would u like to view my code which i post there? I try your way see how...

thank you!
hiyo
hiyo
huh~~a problem urgent but still not solve yet. Anyone pls~~~~
hiyo
hiyo
thank you Anonymous Poster, but i still can't see it works, if i changed x glTexCoord call and 4x glVertex, the piece totally wont' appear on the board. I try to post the full source code let you see, whould u pls tell me where should i modify.

http://hiyo.4t.com/Board.rar
ff8
ff8
your linke is broken just send the files that content the problem and i'll try to fix it
ff8_flash4pro@hotmail.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.