I tried to use the following code to bind my SDL_Texture in opengl:
if (SDL_GL_BindTexture(myTexture, NULL, NULL))
throw SDL_GetError();
glUniform1i(glGetUniformLocation(programID, "texture1"), 0);
However, SDL_GL_BindTexture always returns -1, and the SDL error is “Operation not supported”.
I can’t use SDL_LockTexture to create a texture using raw pixel data with glTexImage2D, and then bind this new texture, because my SDL_Texture is created with the SDL_TEXTUREACCESS_TARGET flag, and thus I can’t set the SDL_TEXTUREACCESS_STREAMING flag (else SDL_SetRenderTarget complains that the texture hasn’t been initialized as a target).
I tried several hacks to retrieve the GLuint of the SDL_Texture, however it appears to be always 0.
Thus, how could I bind my SDL_Texture to send it to my fragment shader?
Can you show the code you use to create the renderer and the texture? SDL_GL_BindTexture works for me (returns zero) for the current render target, tested in Windows/OpenGL:
myTexture = SDL_GetRenderTarget(renderer);
if (SDL_GL_BindTexture(myTexture, NULL, NULL))
throw SDL_GetError();
The only significant difference from my code is that I include SDL_RENDERER_PRESENTVSYNC in the renderer flags, but it seems unlikely that it is the cause of the different behavior. You didn’t list the code which creates your target texture; I wonder if the issue might be the texture pixel format, I use SDL_PIXELFORMAT_ARGB8888 for OpenGL.