Results 1 to 3 of 3

Thread: Loading texture using SDL

  1. #1
    Newbie Newbie
    Join Date
    Oct 2012

    Loading texture using SDL


    I'm coding an application with openGL using SDL on Linux. I followed the Nehe tutorial and arrived in the texture section. Here, he uses this :

    Code :
     if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
          glGenTextures(1, &texture[0]);
          glBindTexture(GL_TEXTURE_2D, texture[0]);
          glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, 
                         TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

    where TextureImage is AUX_RGBImageRec *TextureImage[1];

    But I can't use GLaux and I don't want to. I've tried to use an SDL_surface instead of AUX_RGBImageRec and use TextureImage->pixels instead of TextureImage[0]->data but it didn't work (I've got a blue square and not a texture).

    Can someone explain to me how I can load a texture using SDL ?

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2013
    if u are following Nehe's tutorial then this code for SDL should work

    Code :
    int LoadGLTextures( )
        /* Status indicator */
        int Status = FALSE;
        /* Create storage space for the texture */
        SDL_Surface *TextureImage[1]; 
        /* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
        if ( ( TextureImage[0] = SDL_LoadBMP( "nehe.bmp" ) ) )
    	    /* Set the status to true */
    	    Status = TRUE;
    		OutputDebugStringW(L"My output string.");
    	    /* Create The Texture */
    	    glGenTextures( 1, &texture[0] );
    	    /* Typical Texture Generation Using Data From The Bitmap */
    	    glBindTexture( GL_TEXTURE_2D, texture[0] );
    	    /* Generate The Texture */
    	    glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->w,
    			  TextureImage[0]->h, 0, GL_RGB,
    			  GL_UNSIGNED_BYTE, TextureImage[0]->pixels );
    	    /* Linear Filtering */
    	    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    	    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
        /* Free up any memory we may have used */
        if ( TextureImage[0] )
    	    SDL_FreeSurface( TextureImage[0] );
        return Status;

    i tried this in Fedora,OpenSUSE,ubuntu,and linux Mint everything worked fine.though im facing trouble with windows :P

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Karachi, Pakistan
    Probably the third parameter to glTexImage2D should be the internal format which in this case should be GL_RGB.

Similar Threads

  1. Texture loading and PBO
    By prunkdump in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-14-2012, 06:24 AM
  2. Loading a texture
    By Daniel Harrison in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-06-2011, 12:00 PM
  3. texture loading
    By JanHH in forum OpenGL: Windows
    Replies: 2
    Last Post: 08-02-2007, 09:16 AM
  4. texture loading
    By nergal in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-20-2002, 09:27 AM
  5. Loading up a texture
    By Cyclon in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-30-2002, 04:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean