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 1 of 1

Thread: Unhandless access violation with glTexImage2D

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Aug 2013
    Posts
    32

    Unhandless access violation with glTexImage2D

    edit: I got this working with the code below... although I'd still really like to know why the other doesn't work...
    Code :
    unsigned int loadTexture(const char* name)
    {
    	SDL_Surface* img = IMG_Load(name);
    	SDL_PixelFormat form={NULL,32,4,0,0,0,0,8,8,8,8,0xff000000,0x00ff0000,0x0000ff00,0x000000ff,0,255};
    	SDL_Surface* img2 = SDL_ConvertSurface(img,&form,SDL_SWSURFACE);
    	unsigned int texture;
     
    	glGenTextures(1,&texture);
    	glBindTexture(GL_TEXTURE_2D,texture);
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img2->w, img2->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img2->pixels);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    	glBindTexture(GL_TEXTURE_2D, 0);
    	SDL_FreeSurface(img);
    	SDL_FreeSurface(img2);
    	return texture;
    }

    I'm a bit lost as to how this is failing to load a 32bit RGBA .bmp image into a texture. I'm getting a unhandled access violation so I assume it's going out of bounds but I'm not sure why it would be.

    Code :
    unsigned int loadTexture(const char* filename)
    {
    	SDL_Surface* img = IMG_Load(filename);
    	unsigned int id;
     
    	glGenTextures(1, &id);
    	glBindTexture(GL_TEXTURE_2D, id);
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->w, img->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img->pixels);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
    	glBindBuffer(GL_TEXTURE_2D, 0);
     
    	SDL_FreeSurface(img);
    	return id;
    }
    Last edited by Exempt; 08-18-2013 at 01:32 PM.

Posting Permissions

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