PDA

View Full Version : Help with ALPHA_TEST



Foxabilo
10-25-2005, 05:43 PM
Howdy people,

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

http://img457.imageshack.us/img457/9093/chess7ou.jpg

The blue square is just the cursor for piece movment

and here is the ugly code DONT LAUGH !!! ;)



//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "GlSkel.h"
#include "math.h"
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "stdio.h"
#include "iostream.h"
#include "fstream.h"
//#include "SysUtils.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"


TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
: TForm(Owner)
{
Application->OnIdle = IdleLoop;
size = 50.0f;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::IdleLoop(TObject*, bool&amp; done)
{
done = false;
RenderGLScene();
SwapBuffers(hdc);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormCreate(TObject *Sender)
{
hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
if(hrc == NULL)
ShowMessage(":-)~ hrc == NULL");
if(wglMakeCurrent(hdc, hrc) == false)
ShowMessage("Could not MakeCurrent");
w = ClientWidth;
h = ClientHeight;
Memo1->Lines->Add("OpenGL Window made current OK");

glEnable(GL_DEPTH_TEST);
Memo1->Lines->Add("OpenGL Enable to GL_DEPTH_TEST");
glEnable(GL_CULL_FACE);
Memo1->Lines->Add("OpenGL Enable to Gl_CULL_FACE");

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Memo1->Lines->Add("OpenGL Clear Colour OK");
SetupLighting();
Memo1->Lines->Add("Lighting Setup OK");
SetupTextures();
Memo1->Lines->Add("Texture Setup OK");
CreateInpriseCorporateLogo();
Memo1->Lines->Add("Main Board Render OK");

int DefaultBoardArray[8][8]= { { 1 ,2 ,3 ,4 ,5 ,3 ,2 ,1 },
{ 11,11,11,11,11,11,11,11},
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 21,21,21,21,21,21,21,21},
{ 31,32,33,34,35,33,32,31}
};

for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
BoardArray[x][y] = DefaultBoardArray[x][y];
}
}

xof = 9;
yof = 9;
xdiv = 44.875;
ydiv = 44.875;
Cursor = 103;
Black = false;

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0,0,0,0,0,0,
32,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};
PixelFormat = ChoosePixelFormat(hdc, &amp;pfd);
SetPixelFormat(hdc, PixelFormat, &amp;pfd);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormResize(TObject *Sender)
{

GLfloat nRange = 50.0;

w = ClientWidth;
h = ClientHeight;//450

if(h == 0)
h = 1;

glViewport(00, 00, w, h);


glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if (w <= h)
glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
else
glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);

//For perspective correction
//GLfloat aspect = (GLfloat)w/(GLfloat)h;
//gluPerspective(30.0f, aspect, 1.0, 2.0);


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::RenderGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
DrawBoard();

glFlush();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::DrawBoard()
{


float yos = BoardSpacing;
float yop = -30;
float xos = BoardSpacing;
float xop = -43;

float xro,yro;
int rot = 0;
if (Black)
{
rot = -180;
xro = 16;
yro = -10;
}
else
{
rot = 0;
xro = 0;
yro = 0;
}

//White Squares
glBindTexture(GL_TEXTURE_2D, BoardLightTexture);

for (int xt = 0; xt < 4; xt++)
{
for (int yt = 0; yt < 8; yt++)
{
glPushMatrix();
//glDisable(GL_CULL_FACE);
glColor3f(0.8f, 0.8f, 0.8f);
if ( fmod(yt, 2) == 0.0 )
{
glTranslatef(xt * xos*2 +xop+xro, yt * yos +yop+yro, 20);
}
else
{
glTranslatef((xt * xos*2) +xop + xos+xro, yt * yos +yop+yro, 20.0);
}
glRotatef(45, 0.0, 0.0, 1.0);
glCallList(startoflist);
glEnable(GL_CULL_FACE);
glPopMatrix();
}
}

glBindTexture(GL_TEXTURE_2D, BoardDarkTexture);

for (int x = 0; x < 4; x++)
{
for (int y = 0; y < 8; y++)
{
glPushMatrix();
//glDisable(GL_CULL_FACE);
//glColor3f(0.1f, 0.1f, 0.1f);
if ( fmod(y, 2) != 0.0 )
{
glTranslatef(x * xos*2 +xop+xro, y * yos +yop+yro, 20);
}
else
{
glTranslatef((x * xos*2) +xop+xro + xos, y * yos +yop+yro, 20.0);
}
glRotatef(45, 0.0, 0.0, 1.0);
glCallList(startoflist );
glEnable(GL_CULL_FACE);
glPopMatrix();
}
}





for (int xx = 0; xx < 8; xx++)

{
for (int yy = 0; yy < 8; yy++)
{
int papa = BoardArray[xx][yy];

if (papa != 0) DrawPiece(papa,xx*yos+yop+yro,yy*xos+xop+xro,20.2, rot);
}
}

//DrawPiece(1,-OffsetY,OffsetX,22);

int X = OffsetX;
int Y = OffsetY;

//if (X >-1 &amp;&amp; X < 8 &amp;&amp; Y >-1 &amp;&amp; Y < 8)
{
if (PiecePicked == false)
{
DrawPiece(Cursor,((7-Y)*yos+yop+yro),X*xos+xop+xro,20.1,45);
}
else
{
if (!Black)
DrawPiece(Cursor,((7-Y)*yos+yop+yro),X*xos+xop+xro,20.3,30);
else
DrawPiece(Cursor,((7-Y)*yos+yop+yro),X*xos+xop+xro,20.3,210);
}
}
}

//---------------------------------------------------------------------------
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);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//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();




}

//---------------------------------------------------------------------------
void __fastcall TFormMain::FormPaint(TObject *Sender)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
DrawBoard();

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormDestroy(TObject *Sender)
{

gluDeleteQuadric(BoardMap);

delete bitmap;
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hrc);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::CreateInpriseCorporateLogo()
{
startoflist = glGenLists(200);
Board();


}
//---------------------------------------------------------------------------
void __fastcall TFormMain::Board()
{
BoardSpacing = 10;

float PieceSize = BoardSpacing /2.222 ;
float BoardSize = BoardSpacing /1.405;


BoardMap = gluNewQuadric();


gluQuadricTexture(BoardMap, GL_TRUE);
gluQuadricDrawStyle(BoardMap, GLU_FILL);
gluQuadricNormals(BoardMap, GL_LINEAR);

glNewList(startoflist , GL_COMPILE);
gluDisk(BoardMap, 0, BoardSize, 4, 1);
glEndList();

WhiteKingMap = gluNewQuadric();


gluQuadricTexture(WhiteKingMap, GL_TRUE);
gluQuadricDrawStyle(WhiteKingMap, GLU_FILL);
gluQuadricNormals(WhiteKingMap, GL_LINEAR);

glNewList(startoflist +5, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(WhiteKingMap, 0, PieceSize, 15, 1);
glEndList();

WhiteQueenMap = gluNewQuadric();

gluQuadricTexture(WhiteQueenMap, GL_TRUE);
gluQuadricDrawStyle(WhiteQueenMap, GLU_FILL);
gluQuadricNormals(WhiteQueenMap, GL_LINEAR);

glNewList(startoflist +4, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(WhiteQueenMap, 0, PieceSize, 15, 1);
glEndList();

WhiteRookMap = gluNewQuadric();

gluQuadricTexture(WhiteRookMap, GL_TRUE);
gluQuadricDrawStyle(WhiteRookMap, GLU_FILL);
gluQuadricNormals(WhiteRookMap, GL_LINEAR);

glNewList(startoflist +1, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(WhiteRookMap, 0, PieceSize, 15, 1);
glEndList();

WhiteBishopMap = gluNewQuadric();

gluQuadricTexture(WhiteBishopMap, GL_TRUE);
gluQuadricDrawStyle(WhiteBishopMap, GLU_FILL);
gluQuadricNormals(WhiteBishopMap, GL_LINEAR);

glNewList(startoflist +3, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
//glBegin( GL_QUADS );
// glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Facing Forward
// glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
// glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
// glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
// glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
//glEnd();

gluDisk(WhiteBishopMap, 0, PieceSize, 15, 1);
glEndList();

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();

WhitePawnMap = gluNewQuadric();

gluQuadricTexture(WhitePawnMap, GL_TRUE);
gluQuadricDrawStyle(WhitePawnMap, GLU_FILL);
gluQuadricNormals(WhitePawnMap, GL_LINEAR);

glNewList(startoflist +11, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(WhitePawnMap, 0, PieceSize, 15, 1);
glEndList();

BlackKingMap = gluNewQuadric();


gluQuadricTexture(BlackKingMap, GL_TRUE);
gluQuadricDrawStyle(BlackKingMap, GLU_FILL);
gluQuadricNormals(BlackKingMap, GL_LINEAR);

glNewList(startoflist +35, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(BlackKingMap, 0, PieceSize, 15, 1);
glEndList();

BlackQueenMap = gluNewQuadric();

gluQuadricTexture(BlackQueenMap, GL_TRUE);
gluQuadricDrawStyle(BlackQueenMap, GLU_FILL);
gluQuadricNormals(BlackQueenMap, GL_LINEAR);

glNewList(startoflist +34, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(BlackQueenMap, 0, PieceSize, 15, 1);
glEndList();

BlackRookMap = gluNewQuadric();

gluQuadricTexture(BlackRookMap, GL_TRUE);
gluQuadricDrawStyle(BlackRookMap, GLU_FILL);
gluQuadricNormals(BlackRookMap, GL_LINEAR);

glNewList(startoflist +31, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(BlackRookMap, 0, PieceSize, 15, 1);
glEndList();

BlackBishopMap = gluNewQuadric();

gluQuadricTexture(BlackBishopMap, GL_TRUE);
gluQuadricDrawStyle(BlackBishopMap, GLU_FILL);
gluQuadricNormals(BlackBishopMap, GL_LINEAR);

glNewList(startoflist +33, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(BlackBishopMap, 0, PieceSize, 15, 1);
glEndList();

BlackKnightMap = gluNewQuadric();

gluQuadricTexture(BlackKnightMap, GL_TRUE);
gluQuadricDrawStyle(BlackKnightMap, GLU_FILL);
gluQuadricNormals(BlackKnightMap, GL_LINEAR);

glNewList(startoflist +32, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(BlackKnightMap, 0, PieceSize, 15, 1);
glEndList();

BlackPawnMap = gluNewQuadric();

gluQuadricTexture(BlackPawnMap, GL_TRUE);
gluQuadricDrawStyle(BlackPawnMap, GLU_FILL);
gluQuadricNormals(BlackPawnMap, GL_LINEAR);

glNewList(startoflist +21, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(BlackPawnMap, 0, PieceSize, 15, 1);
glEndList();

GreenBoardMap = gluNewQuadric();

gluQuadricTexture(GreenBoardMap, GL_TRUE);
gluQuadricDrawStyle(GreenBoardMap, GLU_FILL);
gluQuadricNormals(GreenBoardMap, GL_LINEAR);

glNewList(startoflist +102, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(GreenBoardMap, 0, BoardSize, 4, 1);
glEndList();

RedBoardMap = gluNewQuadric();

gluQuadricTexture(RedBoardMap, GL_TRUE);
gluQuadricDrawStyle(RedBoardMap, GLU_FILL);
gluQuadricNormals(RedBoardMap, GL_LINEAR);

glNewList(startoflist +104, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(RedBoardMap, 0, BoardSize, 4, 1);
glEndList();

BlueBoardMap = gluNewQuadric();

gluQuadricTexture(BlueBoardMap, GL_TRUE);
gluQuadricDrawStyle(BlueBoardMap, GLU_FILL);
gluQuadricNormals(BlueBoardMap, GL_LINEAR);

glNewList(startoflist +103, GL_COMPILE); //King is plus 1 in GL element List , Board is 0
gluDisk(BlueBoardMap, 0, BoardSize, 4, 1);
glEndList();

}

//---------------------------------------------------------------------------
void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &amp;Key,
TShiftState Shift)
{
if(Key == VK_UP)
glRotatef(-1, 1.0, 0.0, 0.0);
if(Key == VK_DOWN)
glRotatef(1, 1.0, 0.0, 0.0);
if(Key == VK_LEFT)
glRotatef(-1, 0.0, 1.0, 0.0);
if(Key == VK_RIGHT)
glRotatef(1, 0.0, 1.0, 0.0);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetupLighting()
{
GLfloat MaterialAmbient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat MaterialDiffuse[] = {0.5, 0.5, 0.5, 0.5};
GLfloat MaterialSpecular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat MaterialShininess[] = {50.0};
GLfloat AmbientLightPosition[] = {0.5, 2.0, 1.0, 0.0};
GLfloat LightAmbient[] = {0.5, 0.5, 0.5, 1.0};

glMaterialfv(GL_FRONT, GL_AMBIENT, MaterialAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, MaterialDiffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, MaterialSpecular);
glMaterialfv(GL_FRONT, GL_SHININESS, MaterialShininess);
glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightAmbient);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glShadeModel(GL_SMOOTH);
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetupTextures()
{

FILE *filePtr;
unsigned char a,b,c,d;
int offset;
unsigned long pixel;
unsigned long f;
unsigned char picbuff[65536];
char buff[255];

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BoardDark.bmp");
GLubyte bits[128][128][4];
for(int i = 0; i < 128; i++)
{
for(int j = 0; j < 128; j++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BoardLightTexture);
glBindTexture(GL_TEXTURE_2D, BoardLightTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BoardLight.bmp");
//GLubyte bits[128][128][4];
for(int i = 0; i < 128; i++)
{
for(int j = 0; j < 128; j++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BoardDarkTexture);
glBindTexture(GL_TEXTURE_2D, BoardDarkTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("WhiteKing.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;WhiteKingTexture);
glBindTexture(GL_TEXTURE_2D, WhiteKingTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("WhiteQueen.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;WhiteQueenTexture);
glBindTexture(GL_TEXTURE_2D, WhiteQueenTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BlackKing.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BlackKingTexture);
glBindTexture(GL_TEXTURE_2D, BlackKingTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BlackQueen.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BlackQueenTexture);
glBindTexture(GL_TEXTURE_2D, BlackQueenTexture);
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);


//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BlackRook.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BlackRookTexture);
glBindTexture(GL_TEXTURE_2D, BlackRookTexture);
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);


//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BlackBishop.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BlackBishopTexture);
glBindTexture(GL_TEXTURE_2D, BlackBishopTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BlackKnight.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BlackKnightTexture);
glBindTexture(GL_TEXTURE_2D, BlackKnightTexture);
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);


//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BlackPawn.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BlackPawnTexture);
glBindTexture(GL_TEXTURE_2D, BlackPawnTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("WhiteRook.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;WhiteRookTexture);
glBindTexture(GL_TEXTURE_2D, WhiteRookTexture);
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);


//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


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, &amp;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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("WhiteKnight.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)128;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;WhiteKnightTexture);
glBindTexture(GL_TEXTURE_2D, WhiteKnightTexture);
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);


//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("WhitePawn.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;WhitePawnTexture);
glBindTexture(GL_TEXTURE_2D, WhitePawnTexture);
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);


//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("GreenMove.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BoardGreenTexture);
glBindTexture(GL_TEXTURE_2D, BoardGreenTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("BlueMove.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BoardBlueTexture);
glBindTexture(GL_TEXTURE_2D, BoardBlueTexture);
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);

//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("RedMove.bmp");
//GLubyte bits[128][128][4];
for(int j = 0; j < 128; j++)
{
for(int i = 0; i < 128; i++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j][127-i]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &amp;BoardRedTexture);
glBindTexture(GL_TEXTURE_2D, BoardRedTexture);
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);


glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
void __fastcall TFormMain::Timer1Timer(TObject *Sender)
{
glRotatef(-1, 0, 0, 1);


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

void __fastcall TFormMain::Connect1Click(TObject *Sender)
{
Form1->Visible = true;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Exit1Click(TObject *Sender)
{
FormMain->Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::HostGame1Click(TObject *Sender)
{
Form2->Visible = true;
}
//---------------------------------------------------------------------------



void __fastcall TFormMain::Chat1Click(TObject *Sender)
{
Form3->Visible = true;
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------



void __fastcall TFormMain::ServerSocket1Accept(TObject *Sender,
TCustomWinSocket *Socket)
{
ClientSocket1->Address = Socket->RemoteAddress;
ClientSocket1->Active = true;
Memo1->Lines->Add("Client from "+Socket->RemoteAddress);
}
//---------------------------------------------------------------------------


void __fastcall TFormMain::Button1Click(TObject *Sender)
{
BoardArray[1][1] = 0;
BoardArray[3][1] = 11;
DrawPiece(102,0,0,22,0);
//Memo1->Lines->Add("blah");
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
Memo1->Lines->Add("Client Connecting...");
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::ClientSocket1Error(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &amp;ErrorCode)
{
Memo1->Lines->Add("Error: "+ ErrorCode );
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::Timer2Timer(TObject *Sender)
{
BoardArray[random(8)][random(8)] = random(37)+1;
BoardArray[random(8)][random(8)] = 0;
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::FormMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{

X = (X - xof) / xdiv;
Y = (Y - yof) / ydiv;
if (Black) {X = 7-X; Y = 7-Y;}
if (X >-1 &amp;&amp; X < 8 &amp;&amp; Y >-1 &amp;&amp; Y < 8)
{
if (PiecePicked == false)
{
PiecePicked = true;


Cursor = BoardArray [7-Y][X];
OY=Y;
OX=X;
OP=BoardArray [7-Y][X];
BoardArray[7-Y][X] = 0;


}
else
{


BoardArray [7-Y][X]= Cursor;
Cursor = 103;

PiecePicked = false;

AnsiString Got =" ";
Got[1] = X+1;
Got[2] = Y+1;
Got[3] = BoardArray[7-Y][X]+64;
Got[4] = OX+1;
Got[5] = OY+1;
if (ClientSocket1->Active == true)
{
ClientSocket1->Socket->SendText(Got);
}

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

void __fastcall TFormMain::FormMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if (!Black)
{
OffsetX = (X - xof)/xdiv;
OffsetY = (Y - yof)/ydiv;
}
else
{
OffsetX = 8-((X - xof)/xdiv);
OffsetY = 8-((Y - yof)/ydiv);
}

// Memo1->Lines->Add(IntToStr(X)+","+IntToStr(Y));

//DrawPiece(104,X/7.5-40,Y/7.5-20,22.0);

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

void __fastcall TFormMain::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
AnsiString Got = Socket->ReceiveText();
int X= Got[1]-1;
int Y= Got[2]-1;
int Piece = Got[3]-64;


BoardArray[7-Y][X] = Piece;
X= Got[4]-1;
Y= Got[5]-1;
BoardArray[7-Y][X] = 0;

if (PlaySounds1->Checked )
{
MediaPlayer1->FileName = "YourMove.wav";
MediaPlayer1->Open();
MediaPlayer1->Play();
}

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

void __fastcall TFormMain::ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
AnsiString Got = Socket->ReceiveText();
int X= StrToInt(Got[1]);
int Y= StrToInt(Got[2]);
int Piece = Got[3];

BoardArray[X][Y] = Piece;


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

void __fastcall TFormMain::Button2Click(TObject *Sender)
{
if (Black)
{
glRotatef(180, 0, 0, 1);
Black = false;
Button2->Caption = "Play as Black";
}
else
{
glRotatef(-180, 0, 0, 1);
Black = true;
Button2->Caption = "Play as White";
}
}
//---------------------------------------------------------------------------


void __fastcall TFormMain::PlaySounds1Click(TObject *Sender)
{
PlaySounds1->Checked = !PlaySounds1->Checked;
}
//---------------------------------------------------------------------------

memfr0b
10-28-2005, 08:11 AM
Both the alpha test and blend values SRC_ALPHA/ONE_MINUS_SRC_ALPHA use the fragment's alpha value after texturing. You're using the texture environment mode GL_DECAL with GL_RGBA textures, which retains the original fragment's alpha value and blends the fragment's color with the texture color, using the texture's alpha value.

In short, the fragment's alpha value is not being taken from the texture, but from the initial color/material value.

The texture environment mode GL_REPLACE might be more suitable. See the glTexEnv manual page (http://pyopengl.sourceforge.net/documentation/manual/glTexEnv.3G.html) for a list of environment modes, and how they work.

Foxabilo
10-28-2005, 09:01 AM
Wow thanks !!

Perfect :DDDDDD thankyou Soooooo much