Howdy people, appols for posting this in 2 locations but no joy as yet and i wondered if it was in the right place, anyways…
OK, I am writting a “small” (getting bigger by the second tho ) app for me and a few freinds to be able to play chess via tcp/ip and as I am a glutten for punishment I decided to code it myself from scratch in a language I have never used before and with OpenGL to do the graphics with, Dumb huh ! Meh I like a challenge
OK here is my problem I will include the code at the bottom, but please be gentle with my pathetic coding skills as up until 2 days ago i did not even have a c++ compiler and OpenGL was somthing that half life had a mode for, now i am attempting to code in both so the code is sloppy and somwhat hard coded etc etc, I realise it makes it a pain to look through but is any expert does have the odd few mins to take a look at it and work out whats wrong I would be very greatfull.
Right onto the problem itself:
I have created a number of chess piece bmp files in photoshop with an alpha channel to mask the bits of the texture i do not want to be displayed, these bmp files are loaded in and mapped to gldisk’s just for what of somthing better to texture them to, the disks form the playing pieces what i wanted to happen is the alpha test to remove the unwanted texture from around saw a pawn or a king and just leave the texture almost like a sprite, but alas this is not happening.
What is happening is that the disk is still visiable no matter what set of blends or alpha tests i do i have tried just about every combination out there so i have ugly round disks with nice textures on them sitting on top of a chess board and (pulling my hair out) i want the part of the disk that is not textures and alpha mapped to go away to actualy go away
OK here is a link to a screen shot of the problem I have deliberatly coloured the bishops in red so you can see the problem the bishop is currently the only peice to have an alpha channel in the BMP the rest i will do once i get this one working
http://img457.imageshack.us/my.php?image=chess7ou.jpg
[img]http://img457.imageshack.us/img457/9093/chess7ou.jpg[/img]
The blue square is just the cursor for piece movment
and here is the ugly code DONT LAUGH !!!
void __fastcall TFormMain::DrawPiece(int Piece,float x,float y, float Depth, float Rotation)
{
glPushMatrix();
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glColor4f(0, 0, 0,0.1);
//glEnable (GL_BLEND);
//glBlendFunc (GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc (GL_SRC_COLOR, GL_DST_COLOR);
//glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER, 0.2);
glEnable(GL_TEXTURE_2D);
glAlphaFunc(GL_GREATER, 0.5);
glEnable(GL_ALPHA_TEST);
//glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
//glBlendFunc(GL_ONE, GL_ONE);
//glEnable(GL_POLYGON_OFFSET);
glPolygonOffset(0.0, -3);
//gluDisk(WhiteBishopMap, 0, 7, 15, 1);
switch (Piece)
{
case 1 : glBindTexture(GL_TEXTURE_2D, WhiteRookTexture);break;
case 2 : glBindTexture(GL_TEXTURE_2D, WhiteKnightTexture);break;
case 3 : glBindTexture(GL_TEXTURE_2D, WhiteBishopTexture);break;
case 4 : glBindTexture(GL_TEXTURE_2D, WhiteQueenTexture);break;
case 5 : glBindTexture(GL_TEXTURE_2D, WhiteKingTexture);break;
case 11 : glBindTexture(GL_TEXTURE_2D, WhitePawnTexture);break;
case 12 : glBindTexture(GL_TEXTURE_2D, WhitePawnTexture);break; // en passant pawn
case 31 : glBindTexture(GL_TEXTURE_2D, BlackRookTexture);break;
case 32 : glBindTexture(GL_TEXTURE_2D, BlackKnightTexture);break;
case 33 : glBindTexture(GL_TEXTURE_2D, BlackBishopTexture);break;
case 34 : glBindTexture(GL_TEXTURE_2D, BlackQueenTexture);break;
case 35 : glBindTexture(GL_TEXTURE_2D, BlackKingTexture);break;
case 21 : glBindTexture(GL_TEXTURE_2D, BlackPawnTexture);break;
case 22 : glBindTexture(GL_TEXTURE_2D, BlackPawnTexture);break; // en passant pawn
case 100 : glBindTexture(GL_TEXTURE_2D, BoardLightTexture);break;
case 101 : glBindTexture(GL_TEXTURE_2D, BoardDarkTexture);break;
case 102 : glBindTexture(GL_TEXTURE_2D, BoardGreenTexture);break;
case 103 : glBindTexture(GL_TEXTURE_2D, BoardBlueTexture);break;
case 104 : glBindTexture(GL_TEXTURE_2D, BoardRedTexture);break;
}
//glEnable(GL_BLEND);
//glBlendFunc (GL_ONE, GL_ONE);
//glDisable(GL_DEPTH_TEST);
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER, 0.5);
//glPushMatrix();
//glDisable(GL_CULL_FACE);
//glColor4f(1, 1, 1,0.51);
//glDisable(GL_DEPTH_TEST);
glTranslatef(y, x, Depth);
glRotatef(Rotation, 0.0, 0.0, 1.0);
glCallList(startoflist+Piece);
//glEnable(GL_CULL_FACE);
//glEnable (GL_BLEND);
//glBlendFunc (GL_ONE, GL_ONE);
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_RGBA);
glPopMatrix();
}
WhiteKnightMap = gluNewQuadric();
gluQuadricTexture(WhiteKnightMap, GL_TRUE);
gluQuadricDrawStyle(WhiteKnightMap, GLU_FILL);
gluQuadricNormals(WhiteKnightMap, GL_LINEAR);
glNewList(startoflist +2, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(WhiteKnightMap, 0, PieceSize, 15, 1);
glEndList();
filePtr = fopen("WhiteBishop copy.bmp","rb");
fread(buff, 10,1,filePtr);
fread(buff, 4,1, filePtr);
offset = buff[0];
fread(buff, offset-11,1, filePtr);
fread(picbuff,(128*128*4),1,filePtr);
fclose(filePtr);
f =0;
for (int x=0; x<128; x++)
{
for (int y=0; y<128; y++)
{
a = picbuff[f+1];
b = picbuff[f+2];
c = picbuff[f+3];
d = picbuff[f+0];
pixel = (a)+(b*256)+(c*65536);
bits[x][127-y][2] = a;
bits[x][127-y][1] = b;
bits[x][127-y][0] = c;
bits[x][127-y][3] = 255-d;
f = f + 4;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &WhiteBishopTexture);
glBindTexture(GL_TEXTURE_2D, WhiteBishopTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
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, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);