How to fix: Black shimmering sprites (opengl + sdl)

-1

I have a couple of sprites to load which may result in an error:

Exception thrown at 0x7AF40CFE (nvoglv32.dll) in some.exe: 0xC0000005: Access violation reading location 0x0BA80000.

Sometimes for some reason they are loaded, but are displayed as such:


All these sprites open well in other applications, so I don't think the problem is that they are broken.

Here is my image loading code:

SDL_Surface* image = IMG_Load(fileName);

if (image == nullptr)
{
    return false;
}

_width = static_cast<float>(image->w);
_height = static_cast<float>(image->h);

int mode = GL_RGB;

if (image->format->BytesPerPixel == 4)
{
    mode = GL_RGBA;
}

glGenTextures(1, &_sprite_ID);
glBindTexture(GL_TEXTURE_2D, _sprite_ID);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexImage2D( // ERROR HERE
   GL_TEXTURE_2D,
   0,
   mode,
   static_cast<GLsizei>(_width),
   static_cast<GLsizei>(_height),
   0,
   mode,
   GL_UNSIGNED_BYTE,
   image->pixels);

SDL_FreeSurface(image);

return true;

Rendering:

UseShader();
glBindVertexArray(_VAO);
glBindTexture(GL_TEXTURE_2D, _sprite_ID);
glDrawArrays(GL_TRIANGLES, 0, 6);
glUseProgram(0);

File Format: PNG

and

Im set 32 bytes per pixel:

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
c++
opengl
sdl-2
asked on Stack Overflow Oct 31, 2019 by Dee • edited Oct 31, 2019 by Dee

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0