Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Loading texture using SDL

  1. #1
    Newbie Newbie
    Join Date
    Oct 2012
    Posts
    1

    Loading texture using SDL

    Hello.

    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"))
       {
           Status=TRUE;
          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);
         etc.
      }

    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
    Posts
    18
    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 );
    		glGetError();
     
    	    /* 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
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    812
    Probably the third parameter to glTexImage2D should be the internal format which in this case should be GL_RGB.
    http://www.opengl.org/discussion_boa...59#post1249559
    Regards,
    Mobeen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •