Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Yohumbus

dynamic arrays to load in textures

This topic is 5749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I seem to be having a little problem getting some dynamic arrays to load into textures or to draw using glDrawPixels I am creating a 3 dimentional array and using new to allocate it as seen in my code (its a member function but just forget that for a moment)
  
void GLbmp::GenArray(){
    int Xtemp,Ytemp;
    
    try{
    mTex=new char**[mSizeX](NULL);
    
    try{
    for(Xtemp=0;Xtemp<mSizeX;++Xtemp){
        mTex[Xtemp]=new char*[mSizeY](NULL);
    }
    try{
    for(Xtemp=0;Xtemp<mSizeX;++Xtemp)
    for(Ytemp=0;Ytemp<mSizeY;++Ytemp){
        mTex[Xtemp][Ytemp]=new char[mBytes](128);
    }
    
    
    }catch(std::bad_alloc noneed){
        for(Xtemp=0;Xtemp<mSizeX;++Xtemp)
        for(Ytemp=0;Ytemp<mSizeY;++Ytemp){
            delete[] mTex[Xtemp][Ytemp];}
        throw;
    }
    }catch(std::bad_alloc noneed){
        for(Xtemp=0;Xtemp<mSizeX;++Xtemp){
            delete[] mTex[Xtemp];}
        throw;
    }
    }catch(std::bad_alloc noneed){
        delete[] mTex;
        throw std::runtime_error("didn''t have enough memory for a bitmap");
    }
}
  
now I made all the variables and member functions public temporarily so I can test it and I call GLbmp Me; Me.mSizeX=checkImageWidth; <-equals 64 Me.mSizeY=checkImageHeight; <-equals 64 Me.mBytes=3; Me.GenArray(); and in my message loop glRasterPos3f(0, 0,-3); glDrawPixels(checkImageWidth, checkImageHeight, GL_RGB, GL_UNSIGNED_BYTE, Me.mTex); among other things needed to render but when the drawing shows up it is gibberish as if it were referencing wrong memory. I have also tried excplicitly setting each char value in the array to 255 but nothing changed. anyway any help would be appreciated btw: anyone know what happened to the red book that was hosted in the opengl reference the html format is getting a broken link

Share this post


Link to post
Share on other sites
Advertisement
never mind it turns out that the arrays for opengl use a single continuous array. Anyway I was confused because the tutorials in the red book use static multi dimensional arrays but I guess they are optimized by the compiler so they dont need the overhead

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!