Jump to content
  • Advertisement

Archived

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

insomniac2846

OpenGL Taking Images from DevIL and using as OpenGL Textures

This topic is 5261 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

Okay, Im new to DevIL and after goin through the hell of getting it to work with DevC++, Im still getting problems. I think it has to do with the way I pass the texture I make in my LoadBMPfile to my draw_bitmap file. Here just look for yourselves:
void bmp_picture::LoadBMPFile(char* filename){   
    //this is so I can use the image as an OpenGL texture

    //this is initialization stuff

    ILuint temp;
    ilGenImages(1,&temp);
    ilBindImage(temp);
    ilLoadImage(filename);                  //loads image from file

    imageWidth=ilGetInteger(IL_IMAGE_WIDTH);//gets its width

    imageHeight=ilGetInteger(IL_IMAGE_HEIGHT);//gets its height

    //now I should be able to make it into a texture

    GLuint temp_gl;
    glGenTextures(1,&temp_gl);
    glBindTexture(GL_TEXTURE_2D, temp_gl);    
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    int BytePerPixel = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL) ;			
    GLenum format = (BytePerPixel == 4)?GL_RGBA:GL_RGB ;\
    temp_gl=ilutGLBindTexImage();    			
    //ilutGLTexImage();

    //now cleanup the mess

    ilDeleteImages(1,&temp);
    //now work!!

    ID=temp_gl;
    cout<<temp_gl<<"   "<<ID<<endl;
    cout<<"Loaded the bmp"<<endl;    
}

void bmp_picture::draw_bitmap(){    
   glPushMatrix();   
        glBindTexture(GL_TEXTURE_2D, this->ID);
        glBegin(GL_QUADS);
                glTexCoord2f(0.0,0.0); 
                glVertex2f(-this->imageWidth/2.0,-this->imageHeight/2.0);
                glTexCoord2f(1.0,0.0);
                glVertex2f(this->imageWidth/2.0,-this->imageHeight/2.0);
                glTexCoord2f(1.0,1.0);
                glVertex2f(this->imageWidth/2.0,this->imageHeight/2.0);
                glTexCoord2f(0.0,1.0);
                glVertex2f(-this->imageWidth/2.0,this->imageHeight/2.0);
        glEnd();
    glPopMatrix();
}
all I get is a white block, the same size as the image I try to load. Any and all help will be appresciated. Btw, If anyone knows any place that actually has a step by step tutorial (not the page on imagelib.org) or the source code for a simple project that uses DevIL that would be helpful. Any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Try saving the file back to your HD if you understand how (I''m not going into that, the tuts on devil websites are well done). If you have 1x1 blank square it''s devil way of telling you something went wrong during the file load. Usualy, it''s because it can''t find the file.

Beside that, I can''t help much as I''m getting the pixel data pointer from devil and load it myself after some pre processing steps.

Share this post


Link to post
Share on other sites
Ah i c that you have got it working on devc++. Could you please tell me what you did? Or could you just put up the compiled libraries, i dont really want to compile the sources for which i will need to download all the 92837492376429374 libraries which devil uses and realise that they are all .lib for msvc and i will have to compile those as well.

Anyway, as for your topic, i don''t see anything wrong. I believe there is a ilut function which directly loads and uploads an image to the videocard and returns the OpenGL id. If you need more control, here is my code:



glGenTextures(1,&tID);
glBindTexture(GL_TEXTURE_2D,tID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);



ILuint ILid;
char name[50];

strcpy(name,filename.c_str());
ilGenImages(1, &ILid);
ilBindImage(ILid);
ilLoadImage(name); // Loads into the current bound image


ILuint Width, Height, RequestFormat;
GLint Format, InternalFormat;
Width = ilGetInteger(IL_IMAGE_WIDTH);
Height = ilGetInteger(IL_IMAGE_HEIGHT);
Format = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
unsigned char* data = NULL;
data = new unsigned char[Width * Height * Format];

if(ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL) == 3)
{//No Alpha

Format = GL_RGB;
InternalFormat = GL_RGB8;
RequestFormat = IL_RGB;
}
else if(ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL) == 4)
{//Has Alpha

Format = GL_RGBA;
InternalFormat = GL_RGBA;
RequestFormat = IL_RGBA;
}
ilCopyPixels(0,0,0,Width,Height,1,RequestFormat,IL_UNSIGNED_BYTE, data);


if( buildMipMaps )
{
//build mipmaps

gluBuild2DMipmaps(GL_TEXTURE_2D, InternalFormat, Width,Height, Format, GL_UNSIGNED_BYTE, data);
}
else
{ //no mipmaps

glTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, Width, Height, 0, Format, GL_UNSIGNED_BYTE, data);

}

delete []data;
ilDeleteImages(1,&ILid);

Share this post


Link to post
Share on other sites
Yeah, Thanx for the responses. About the one step load of the tesxture. I was thinking of using it but I need to know the objects width and height to draw it so I cant use it. Thanx for any help

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!