Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    177
  • comments
    531
  • views
    164185

Fun!

Sign in to follow this  
Scet

189 views

Part of the reason I switched to D3D years back was because of D3DX. In OpenGL things like texture loading and fonts where always a pain in the ass since I had to make my own functions for them. This restricted me to just Targas and Bitmaps. Now however wxWidgets is taking care of all that bull:

edit: It would appear that the forum software raped my nice tabbed code [sad]

class wxTexture : public wxImage{
private:
GLuint Texture;
unsigned char *Data,*DataPntr;
unsigned char Colour[3];
unsigned int Counter;
bool *Alpha,*AlphaPntr;
public:
wxTexture();
wxTexture(const wxString &File,const wxColour &Key=wxColour(0,0,0),long Type=wxBITMAP_TYPE_ANY,int Index=-1);
bool Load(const wxString &File,const wxColour &Key=wxColour(0,0,0),long Type=wxBITMAP_TYPE_ANY,int Index=-1);
bool Generate(const wxColour &Key=wxColour(0,0,0));
void Bind();
};

wxTexture::wxTexture():wxImage(){return;}

wxTexture::wxTexture(const wxString &File,const wxColour &Key,long Type,int Index):
wxImage(File,Type,Index){
Generate(Key);
return;}

bool wxTexture::Load(const wxString &File,const wxColour &Key,long Type,int Index){
LoadFile(File,Type,Index);
return Generate(Key);}

bool wxTexture::Generate(const wxColour &Key){
if(Ok()){
Counter=0;
if(Alpha!=NULL){delete[] Alpha;}
if(Data!=NULL){delete[] Data;}
AlphaPntr=Alpha=new bool[GetWidth()*GetHeight()];
DataPntr=Data=new unsigned char[GetWidth()*GetHeight()*4];
for(unsigned int y=0;y for(unsigned int x=0;x for(int i=0;i<3;i++){
Colour=*DataPntr=*(GetData()+Counter);
++DataPntr;
++Counter;}
if(Colour[0]==Key.Red() && Colour[1]==Key.Green() && Colour[2]==Key.Blue()){
*AlphaPntr=*DataPntr=0;
}else{
*AlphaPntr=*DataPntr=255;}
++DataPntr;
++AlphaPntr;}}
glGenTextures(1,&Texture);
glBindTexture(GL_TEXTURE_2D,Texture);
glTexImage2D(GL_TEXTURE_2D,0,4,GetWidth(),GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,Data);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
return 1;}
return 0;}

void wxTexture::Bind(){
glBindTexture(GL_TEXTURE_2D,Texture);
return;}




I want to add a few more functions of course, but it works. Now I can load the following formats:

BMP
PNG
JPEG
GIF (loading only, due to legal issues)
PCX
TIFF

Unfortunately wxWidget's alpha/masking support is completely retarded. An alpha channel(of 0) does not get set to (0,0,0), but rather whatever wxWidgets feels like, hence why I had to add my own colour keying. Lame.

Continuing with all things retarded, wxTimer. It's awful, I swear the thing must use clock(). Give it an interval time under 100ms and it falls apart, completely random timing. *sigh*
Sign in to follow this  


3 Comments


Recommended Comments

I have some image loading gear for OpenGL that uses SDL_image.

It supports pretty much any image format under the sun, and is endian independent. Lemme know if you want to use it; you only need to use SDL for the image loader and then you can just use OpenGL like normal from then on.

Share this comment


Link to comment
The big problem with OpenGL and wxWindows is that ATI drivers leak memory every time you call wglMakeCurrent.

Unfortunately the OpenGL widget calls this every draw. That means leaking every 60th of a second or more for a game or emulator.

When I checked, it was leaking about a megabyte a minute, which is obviously pretty bad.

Share this comment


Link to comment
ravuya - No, I don't want to use SDL. I believe wxWidgets is endian independent and it supports enough formats for me.

siaspete - Wow, that blows. I'll have to check that out.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!