   glpng transparency
  i am not sure if it was the spritesheet image's fault but after attempting and failing at creating an alpha channel mask (also wondering how to properly use the PNG_ALPHA i decided to use the default background and use PNG_STENCIL. however, it still wouldn't create the transparency. i remembered it said 0-255 for the colours so i also attempted 255-## for the stencil input. i also tried setting te stencil both before as well as after (haven't tried both at the same time yet) and it still wouldn't work. for the alpha value, i read http://www.gamedev.net/community/forums/topic.asp?topic_id=448373 that 8 should be the proper value for alpha channel transparency but my image was still fully solid. (the solid fill background was still in the image)==========================================================ImgLoader//#ifdef IMGLOADER_H//#define IMGLOADER#include "imgLoader.h"#include <iostream>using namespace std;//GLuint _imgParam::id;//unsigned int _imgParam::imgID;imgLoader::imgLoader(){}imgLoader::imgLoader(const char *filename){}int imgLoader::retH(){if(retIsAnimated())return imgParam.animParam.height;elsereturn imgParam.height;}int imgLoader::retW(){if(retIsAnimated())return imgParam.animParam.width;elsereturn imgParam.width;}bool imgLoader::retIsAnimated(){return imgParam.isAnimated;}void imgLoader::load(const char *filename){cout<<"pre load"<<endl;//pngInfo *_info;//_info = new pngInfo;//GLuint id;imgParam.id = pngBind(filename, PNG_NOMIPMAP, PNG_ALPHA, &imgParam.infoDump, GL_CLAMP, GL_NEAREST, GL_NEAREST);//imgParam.infoDump=*_info;imgParam.height = imgParam.infoDump.Height;imgParam.width = imgParam.infoDump.Width;imgParam._filename = filename;cout<<"post load"<<endl;//show_pngInfo_dump();//imgParam.width = imgParam.infoDump.Width;//imgParam.height = imgParam.infoDump.Height;imgParam.imgID = imgParam.id;//id;////cout<<"current item has the following id: "<<getImgID()<<endl;//default to still imagecout<<"isAnimated currently is: "<<retIsAnimated()<<endl;imgParam.isAnimated=false;cout<<"isAnimated currently is: "<<retIsAnimated()<<endl;showAllInfo();}/*unsigned char *imgLoader::alphaCallback(unsigned char r, unsigned char g, unsigned char b){unsigned char *a;*a = (unsigned char)8;return a;}*/void imgLoader::load(const char *filename, int r, int g, int b){cout<<"pre load"<<endl;//pngInfo *_info;//_info = new pngInfo;//GLuint id;//pngSetAlphaCallback(alphaCallback(r, g, b));pngSetStencil(static_cast<unsigned char>(r), static_cast<unsigned char>(g), static_cast<unsigned char>(b));imgParam.id = pngBind(filename, PNG_NOMIPMAP, PNG_STENCIL, &imgParam.infoDump, GL_CLAMP, GL_NEAREST, GL_NEAREST);//imgParam.infoDump=*_info;imgParam.height = imgParam.infoDump.Height;imgParam.width = imgParam.infoDump.Width;imgParam._filename = filename;cout<<"post load"<<endl;//show_pngInfo_dump();//imgParam.width = imgParam.infoDump.Width;//imgParam.height = imgParam.infoDump.Height;imgParam.imgID = imgParam.id;//id;////cout<<"current item has the following id: "<<getImgID()<<endl;//default to still imagecout<<"isAnimated currently is: "<<retIsAnimated()<<endl;imgParam.isAnimated=false;cout<<"isAnimated currently is: "<<retIsAnimated()<<endl;showAllInfo();}void imgLoader::show_pngInfo_dump(){printf("Size=%i,%i Depth=%i Alpha=%i\n", imgParam.infoDump.Width, imgParam.infoDump.Height, imgParam.infoDump.Depth, imgParam.infoDump.Alpha);}void imgLoader::showFilename(){cout<<imgParam._filename<<endl;}void imgLoader::flipVisiblity(){imgParam.isVisible = !imgParam.isVisible;}GLuint imgLoader::getImgID(){return imgParam.id;}void imgLoader::setToAnimate(){imgParam.isAnimated = true;}void imgLoader::setupAnimation(int num_states, int *frameArray, int h, int w){cout<<"isAnimated currently is: "<<retIsAnimated()<<endl;setToAnimate();//isAnimated = true;cout<<"isAnimated currently is: "<<retIsAnimated()<<endl;imgParam.animParam.numStates=num_states;//int temp[num_states];imgParam.animParam.numFrames = frameArray;//new int[num_states];//temp;//imgParam.animParam.height=h;imgParam.animParam.width=w;setupFrames();imgParam.animParam.currentState=0;imgParam.animParam.animate_status=true;showAllInfo();}void imgLoader::setupAnimation(int num_states, int *frameArray, int num_frames_in_longest_state){imgParam.isAnimated = true;imgParam.animParam.numStates=num_states;//int temp[num_states];imgParam.animParam.numFrames = new int[num_states];//temp;//imgParam.animParam.height=imgParam.height/num_states;imgParam.animParam.width=imgParam.width/num_frames_in_longest_state;setupFrames();imgParam.animParam.currentState=0;imgParam.animParam.animate_status=true;showAllInfo();}void imgLoader::setInvisible(){imgParam.isVisible=false;}void imgLoader::setVisible(){imgParam.isVisible=true;}void imgLoader::playAnim(){imgParam.animParam.animate_status=true;}void imgLoader::pauseAnim(){imgParam.animParam.animate_status=false;}void imgLoader::advFrame(){if(imgParam.animParam.animate_status=true)imgParam.animParam.animate[imgParam.animParam.currentState].current=imgParam.animParam.animate[imgParam.animParam.currentState].current->next;/*animParam.imgCorners[0];animParam.imgCorners[1];animParam.imgCorners[2];animParam.imgCorners[3];*/}bool imgLoader::getVisibility(){return imgParam.isVisible;}string imgLoader::getFilename(){return imgParam._filename;}void imgLoader::setupFrames(){const int x1 = 0; const int y1 = 1; const int x2 = 2; const int y2 = 3;imgParam.animParam.animate = new frameSet[imgParam.animParam.numStates];frame *_temp;// = new frame;for(int i=0; i< imgParam.animParam.numStates;i++){for(int j=0; j< imgParam.animParam.numFrames; j++){frame temp;//float temp[4];temp.frameCorners[x1] = ((float)j+(float)j*(float)imgParam.animParam.width)/(float)imgParam.width;temp.frameCorners[y1] = ((float)i+(float)i*(float)imgParam.animParam.height)/(float)imgParam.height;temp.frameCorners[x2] = (((float)j+1)*(float)imgParam.animParam.width)/(float)imgParam.width;temp.frameCorners[y2] = (((float)i+1)*(float)imgParam.animParam.height)/(float)imgParam.height;temp.frame_num=j+1;//float **_temp;//*_temp = new float[4];_temp = &temp;imgParam.animParam.animate.insNext(_temp);if(imgParam.animParam.animate.current->next != 0)imgParam.animParam.animate.moveFwd();}imgParam.animParam.animate.tieLoop();imgParam.animParam.animate.current=imgParam.animParam.animate.head;}}void imgLoader::showFrameNum()//etFrameNum(){cout<<imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frame_num;}GLuint imgLoader::retID(){return imgParam.imgID;}void imgLoader::changeState(int state){//updatesimgParam.animParam.currentState=state;//resets to initial frameimgParam.animParam.animate[state].current=imgParam.animParam.animate[state].head;}void imgLoader::showAllInfo(){cout<<"============================================================================="<<endl;cout<<"Show All Info"<<endl;cout<<"_filename : "<<imgParam._filename<<"  |  filename : <POINTER>"<<"  |  isVisible : "<<imgParam.isVisible<<endl;cout<<"isAnimated  :  "<<imgParam.isAnimated<<"  |  id : "<<imgParam.id<<"  |  imgID : "<<imgParam.imgID<<endl;cout<<"width : "<<imgParam.width<<"  |  height : "<<imgParam.height<<endl;show_pngInfo_dump();if(retIsAnimated()){cout<<"currentState : "<<imgParam.animParam.currentState<<"  |  numStates : "<<imgParam.animParam.numStates<<"  |  animate_status : "<<imgParam.animParam.animate_status<<endl;cout<<"width : "<<imgParam.animParam.width<<"  |  height : "<<imgParam.animParam.height<<endl;}cout<<"============================================================================="<<endl;cout<<"";}frame *imgLoader::_sendToRender(){frame *j;if(retIsAnimated()){j = new frame;j->frameCorners[0] = imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners[0];j->frameCorners[1] = imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners[1];j->frameCorners[2] = imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners[2];j->frameCorners[3] = imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners[3];}else{j = new frame;j->frameCorners[0] = 0.0;j->frameCorners[1] = 1.0;j->frameCorners[2] = 0.0;j->frameCorners[3] = 1.0;}return j;}float *imgLoader::sendToRender(){float *j;j = new float[4];j[0]=0.0;j[1] = 1.0;j[2] = 0.0;j[3] = 1.0;if(!retIsAnimated())//imgParam.isAnimated)return j;elsereturn imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners;//getCurrentData();//current->data;//animParam.imgCorners;}void imgLoader::sendToRender(float *a, float *b, float *c, float *d){if(imgParam.isAnimated==false){*a = (float)0.0;*b = (float)1.0;*c = (float)0.0;*d = (float)1.0;}else{*a = imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners[0];*b = imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners[1];*c = imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners[2];*d = imgParam.animParam.animate[imgParam.animParam.currentState].current->data.frameCorners[3];}}//#endif-------------------------------------------------------Rendering/*This File Renders the Images based on information passed by AreaGraphics*/#ifndef RENDER#define RENDER#include "Rendering.h"#include <iostream>using namespace std;//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;int mainWindow;#define defWidth 640#define defHeight 480int wid = defWidth;int hei = defHeight;//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;//need search function to send appropriate nodes to draw functionvoid cycleNode(){//cout<<"running cycleNode()"<<endl;if(render_root.currentEmpty())//.current->data)return;int j=0;cout<<"render_root is not empty"<<endl;cout<<"render_root has "<<render_root.totalItems()<<" items linked."<<endl;cout<<"================================================================="<<endl;render_root.current=render_root.head;//retFirst();do{render_root.current->data.show_pngInfo_dump();cout<<endl;cout<<"rendering item: "<<render_root.current->data.getFilename()<<endl;// number: "<<++j<<endl;cout<<render_root.current->data.getFilename()<<"'s animation status is: "<<render_root.current->data.retIsAnimated()<<endl;cout<<"current item has id: "<<render_root.current->data.getImgID();if(render_root.current->data.retIsAnimated())drawAnim(&render_root.current->data);elsedrawStill(&render_root.current->data);cout<<"==========================================================="<<endl;if(!render_root.retNext())break;elserender_root.moveFwd();}while(true);//draw(render_root.current->data);}void drawStill(visualNode *a){cout<<"running drawStill()"<<endl;glPushMatrix();{glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);glBindTexture(GL_TEXTURE_2D, a->getImgID());//retID());a->showFilename();//glTranslated((double)a.xpos, (double)a.ypos,0);glBegin(GL_QUADS);{//float *temp = a.sendToRender();glTexCoord2f(0, 0); glVertex2f(0, 0);glTexCoord2f(0, 1); glVertex2f(0, a->retH());glTexCoord2f(1, 1); glVertex2f(a->retW(), a->retH());glTexCoord2f(1, 0); glVertex2f(a->retW(), 0);}glEnd();}glPopMatrix();}void drawAnim(visualNode *a){cout<<"running drawAnim() at frame#: ";a->showFrameNum();cout<<endl;glPushMatrix();{glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);glBindTexture(GL_TEXTURE_2D, a->getImgID());//retID());//glTranslated((double)a.xpos, (double)a.ypos,0);glBegin(GL_QUADS);{float temp[4];// a->sendToRender(&temp[0], &temp[1], &temp[2], &temp[3]);for(int j = 0; j<4; j++)temp[j] = a->_sendToRender()->frameCorners[j];glTexCoord2f(temp[0], temp[1]); glVertex2f(0, 0);glTexCoord2f(temp[0], temp[3]); glVertex2f(0, a->retH());glTexCoord2f(temp[2], temp[3]); glVertex2f(a->retW(), a->retH());glTexCoord2f(temp[2], temp[1]); glVertex2f(a->retW(), 0);}glEnd();}glPopMatrix();}void drawScene(){startCam();glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);adjustPixels();glPushMatrix();{cycleNode();}glPopMatrix();glutSwapBuffers();endCam();}//========================================================================================//========================================================================================void startCam(){if (hei==0)hei=1;float aspRatio = 1.0*wid/hei;glMatrixMode(GL_PROJECTION);glLoadIdentity();glViewport(0,0,wid,hei);gluOrtho2D(0,wid,hei,0);//gluPerspective(fovy,aspRatio,anear,afar);}void adjustPixels(){glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.375,0.375,0);}void endCam(){glMatrixMode(GL_MODELVIEW);glLoadIdentity();//gluLookAt(camX,camY,camZ,targetX,targetY,targetZ,0.0f,1.0f,0.0f);}//=====================================================================//=====================================================================void resizeFunc(int w, int h){if (h==0)h=1;float aspRatio = 1.0*w/h;glMatrixMode(GL_PROJECTION);glLoadIdentity();glViewport(0,0,w,h);gluOrtho2D(0,w,h,0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();//gluLookAt(camX,camY,camZ,targetX,targetY,targetZ,0.0f,1.0f,0.0f);}//====================================================================void mainInit(int c, char **v){glutInit(&c,v);glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);glutInitWindowSize(defWidth,defHeight);glutInitWindowPosition(100,150);mainWindow = glutCreateWindow("Game Engine");glClearColor (0.0, 0.0, 0.0, 0.0);glEnable(GL_TEXTURE_2D);glEnable(GL_ALPHA_TEST);    //glShadeModel(GL_FLAT);    glDisable(GL_DEPTH_TEST);//readyBricks();//readyCheckerboard();}#endif