Sign in to follow this  

OpenGL texture with FreeImage

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

Hi fellows I encounter some issues in the loading of texture here is the code I wrote You have to assume that the Load3Dmesh() and Draw3Dmesh() work perfectly When I lunch the program I have a untextured plane which not should be the case
int main(int argc, char *argv[])
{

    int l = 0;
    SDL_Init(SDL_INIT_VIDEO);
    if ( SDL_WasInit(SDL_INIT_VIDEO) == -1)
    {
        exit(1);
    }
    SDL_Surface *ecran = NULL;
    SDL_WM_SetCaption("Render", NULL);
    ecran = SDL_SetVideoMode(400,400,32,SDL_OPENGL);
    if ( ecran == NULL)
    {
        exit(1);
    }
    MeshData plane;
    plane.filename = "Plane.txt";
    plane.texfilename = "Uvtest.png";
    FreeImage_Initialise(TRUE);
    glMatrixMode(GL_PROJECTION);
	FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(plane.texfilename, 0);
	FIBITMAP *dib = FreeImage_Load(fifmt, plane.texfilename,0);
    dib = FreeImage_ConvertTo32Bits(dib);
    glGenTextures( 1, &g_textureID );
	glBindTexture( GL_TEXTURE_2D, g_textureID );
	glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    BYTE *bits = malloc( FreeImage_GetWidth(dib) * FreeImage_GetHeight(dib) * 3 );
    BYTE *pixels = (BYTE*)FreeImage_GetBits(dib);
    //FreeImage store file in BGR format so we swap the bits to have a RGB format 
    int pix;
    		for(pix=0; pix<FreeImage_GetWidth(dib) * FreeImage_GetHeight(dib); pix++)
		{
			bits[pix*3+2]=pixels[pix*3+0];
			bits[pix*3+1]=pixels[pix*3+1];
			bits[pix*3+0]=pixels[pix*3+2];

		}
    glTexImage2D( GL_TEXTURE_2D, 0, 3, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0,GL_RGB, GL_UNSIGNED_BYTE,  bits);
    glBindTexture( GL_TEXTURE_2D, g_textureID );
    glLoadIdentity();
    glPushMatrix();
    gluPerspective(70, (float)400/400, 1, 1000);
    int count = 1;
    Load3Dmesh(&plane);
    SDL_Event event;
    while(count)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
            {
                case SDL_QUIT : count = 0;break;
                case SDL_KEYDOWN :
                    switch(event.key.keysym.sym)
                    {
                        case SDLK_ESCAPE : count = 0;break;
                    };break;
            }

    DrawInit();
    glScaled(2,2,2);
    Draw3Dmesh(plane);
    SDL_GL_SwapBuffers();
    }
    SDL_Quit();
    FreeImage_DeInitialise();
    getchar();
    return 1;
}

What's wrong ? I thank people you will help me

Share this post


Link to post
Share on other sites
Quote:
You have to assume that the Load3Dmesh() and Draw3Dmesh() work perfectly


Are you sure? Do you enable texturing? Do you supply texture coordinates with glTexCoord*() or some other method? Have you compared your code with a working texturing sample (you can some here) and looked for differences?

Share this post


Link to post
Share on other sites

This topic is 3589 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.

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

Sign in to follow this